factor: EBNF: -> : word ( string -- obj ) EBNF{{ }} ; for now.

locals-and-roots
Doug Coleman 2016-06-06 18:06:54 -07:00
parent 9d4b5e73ba
commit 06335ae6e7
32 changed files with 123 additions and 137 deletions

View File

@ -34,7 +34,7 @@ TUPLE: sub < operator ; C: <sub> sub ;
TUPLE: mul < operator ; C: <mul> mul ;
TUPLE: div < operator ; C: <div> div ;
EBNF: expr-ast
: expr-ast ( string -- obj ) EBNF{{
spaces = [\n\t ]*
digit = [0-9]
number = (digit)+ => [[ string>number ]]
@ -51,7 +51,7 @@ exp = exp:a spaces "+" fac:b => [[ a b <add> ]]
| fac
main = exp:e spaces !(.) => [[ e ]]
EBNF;
}} ;
GENERIC: eval-ast ( ast -- result ) ;

View File

@ -3,15 +3,17 @@ USING: smalltalk.parser smalltalk.ast
peg.ebnf tools.test accessors
io.files io.encodings.ascii kernel ;
EBNF: test-Character
test = <foreign parse-smalltalk Character>
EBNF;
: test-Character ( string -- obj )
EBNF{{
test = <foreign parse-smalltalk Character>
}} ;
{ char: a } [ "a" test-Character ] unit-test
EBNF: test-Comment
test = <foreign parse-smalltalk Comment>
EBNF;
: test-Comment ( string -- obj )
EBNF{{
test = <foreign parse-smalltalk Comment>
}} ;
{ T{ ast-comment f "Hello, this is a comment." } }
[ "\"Hello, this is a comment.\"" test-Comment ]
@ -21,15 +23,15 @@ unit-test
[ "\"Hello, \"\"this\"\" is a comment.\"" test-Comment ]
unit-test
EBNF: test-Identifier
: test-Identifier ( string -- obj ) EBNF{{
test = <foreign parse-smalltalk Identifier>
EBNF;
}} ;
{ "OrderedCollection" } [ "OrderedCollection" test-Identifier ] unit-test
EBNF: test-Literal
: test-Literal ( string -- obj ) EBNF{{
test = <foreign parse-smalltalk Literal>
EBNF;
}} ;
{ nil } [ "nil" test-Literal ] unit-test
{ 123 } [ "123" test-Literal ] unit-test
@ -76,22 +78,22 @@ EBNF;
}
[ "[5. self]" test-Literal ] unit-test
EBNF: test-FormalBlockArgumentDeclarationList
: test-FormalBlockArgumentDeclarationList ( string -- obj ) EBNF{{
test = <foreign parse-smalltalk FormalBlockArgumentDeclarationList>
EBNF;
}} ;
{ V{ "x" "y" "elt" } } [ ":x :y :elt" test-FormalBlockArgumentDeclarationList ] unit-test
EBNF: test-Operand
: test-Operand ( string -- obj ) EBNF{{
test = <foreign parse-smalltalk Operand>
EBNF;
}} ;
{ { 123 15.6 { t f } } } [ "#(123 15.6 (true false))" test-Operand ] unit-test
{ T{ ast-name f "x" } } [ "x" test-Operand ] unit-test
EBNF: test-Expression
: test-Expression ( string -- obj ) EBNF{{
test = <foreign parse-smalltalk Expression>
EBNF;
}} ;
{ self } [ "self" test-Expression ] unit-test
{ { 123 15.6 { t f } } } [ "#(123 15.6 (true false))" test-Expression ] unit-test
@ -227,17 +229,17 @@ EBNF;
}
[ "(#(['a']) at: 0) value" test-Expression ] unit-test
EBNF: test-FinalStatement
: test-FinalStatement ( string -- obj ) EBNF{{
test = <foreign parse-smalltalk FinalStatement>
EBNF;
}} ;
{ T{ ast-name f "value" } } [ "value" test-FinalStatement ] unit-test
{ T{ ast-return f T{ ast-name f "value" } } } [ "^value" test-FinalStatement ] unit-test
{ T{ ast-assignment f T{ ast-name f "value" } 5 } } [ "value:=5" test-FinalStatement ] unit-test
EBNF: test-LocalVariableDeclarationList
: test-LocalVariableDeclarationList ( string -- obj ) EBNF{{
test = <foreign parse-smalltalk LocalVariableDeclarationList>
EBNF;
}} ;
{ T{ ast-local-variables f { "i" "j" } } } [ " | i j |" test-LocalVariableDeclarationList ] unit-test

View File

@ -13,7 +13,7 @@ ERROR: bad-number str ;
: check-number ( str -- n )
>string dup string>number [ ] [ bad-number ] ?if ;
EBNF: parse-smalltalk
: parse-smalltalk ( string -- obj ) EBNF{{
Character = .
WhitespaceCharacter = [ \t\n\r]
@ -225,4 +225,4 @@ End = !(.)
Program = TopLevelForm End
EBNF;
}} ;

View File

@ -169,7 +169,7 @@ CONSTANT: galois-slides
"Some parsing words are more complicated"
}
{ $slide "Example: printf"
{ { $link postpone\ EBNF: } ": a complex parsing word" }
{ { $link \ EBNF{{ } ": a complex parsing word" }
"Implements a custom syntax for expressing parsers: like OMeta!"
{ "Example: " { $vocab-link "printf-example" } }
{ $code "\"vegan\" \"cheese\" \"%s is not %s\\n\" printf" }

View File

@ -332,7 +332,7 @@ CONSTANT: google-slides
"Some parsing words are more complicated"
}
{ $slide "Parser expression grammars"
{ { $link postpone\ EBNF: } ": a complex parsing word" }
{ { $link postpone\ EBNF{{ } ": a complex parsing word" }
"Implements a custom syntax for expressing parsers"
{ "Example: " { $vocab-link "printf-example" } }
{ $code "\"vegan\" \"cheese\" \"%s is not %s\\n\" printf" }

View File

@ -189,7 +189,7 @@ CONSTANT: vpri-slides
"Some parsing words are more complicated"
}
{ $slide "Example: printf"
{ { $link postpone\ EBNF: } ": a complex parsing word" }
{ { $link postpone\ EBNF{{ } ": a complex parsing word" }
"Implements a custom syntax for expressing parsers: like OMeta!"
{ "Example: " { $vocab-link "printf-example" } }
{ $code "\"vegan\" \"cheese\" \"%s is not %s\\n\" printf" }

View File

@ -5,7 +5,7 @@ combinators.short-circuit accessors math.parser quoting
locals ;
in: db.postgresql.errors
EBNF: parse-postgresql-sql-error
: parse-postgresql-sql-error ( string -- obj ) EBNF{{
Error = "ERROR:" [ ]+
@ -35,18 +35,18 @@ UnknownError = .* => [[ >string <sql-unknown-error> ]]
PostgresqlSqlError = (TableError | DatabaseError | FunctionError | SyntaxError | UnknownError)
EBNF;
}} ;
TUPLE: parse-postgresql-location column line text ;
C: <parse-postgresql-location> parse-postgresql-location ;
EBNF: parse-postgresql-line-error
: parse-postgresql-line-error ( string -- obj ) EBNF{{
Line = "LINE " [0-9]+:line ": " .+:sql
=> [[ f line >string string>number sql >string <parse-postgresql-location> ]]
EBNF;
}} ;
:: set-caret-position ( error caret-line -- error )
caret-line length

View File

@ -14,7 +14,7 @@ SINGLETONS: table-exists table-missing ;
{ table-exists [ <sql-table-exists> ] }
} case ;
EBNF: parse-sqlite-sql-error
: parse-sqlite-sql-error ( string -- obj ) EBNF{{
TableMessage = " already exists" => [[ table-exists ]]
@ -25,4 +25,4 @@ SqliteError =
=> [[ table >string <sql-table-missing> ]]
| .*:error
=> [[ error >string <unparsed-sqlite-error> ]]
EBNF;
}} ;

View File

@ -4,12 +4,12 @@ in: compiler.tests.peg-regression-2
GENERIC: <times> ( times -- term' ) ;
M: string <times> ;
EBNF: parse-regexp
: parse-regexp ( string -- obj ) EBNF{{
Times = .* => [[ "foo" ]]
Regexp = Times:t => [[ t <times> ]]
EBNF;
}} ;
[ "foo" ] [ "a" parse-regexp ] unit-test

View File

@ -16,9 +16,9 @@ M: pipeline-expr blah ;
: ast>pipeline-expr ( -- obj )
pipeline-expr new blah ;
EBNF: expr
: expr ( string -- obj ) EBNF{{
pipeline = "hello" => [[ ast>pipeline-expr ]]
EBNF;
}} ;
use: tools.test

View File

@ -38,26 +38,6 @@ HELP: EBNF{{
}
} ;
HELP: EBNF:
{ $syntax "EBNF: word ...ebnf... EBNF;" }
{ $values { "word" word } { "...ebnf..." "EBNF DSL text" } }
{ $description
"Defines a word that when called will parse a string using the syntax "
"defined with the EBNF DSL. The word has stack effect "
{ $snippet "( string -- ast )" } " where 'string' is the text to be parsed "
"and 'ast' is the resulting abstract syntax tree. If the parsing fails the "
"word throws an exception."
}
{ $examples
{ $example
"USING: prettyprint peg.ebnf ;"
"in: scratchpad"
"EBNF: foo rule=\"a\" \"b\" EBNF;"
"\"ab\" foo ."
"V{ \"a\" \"b\" }"
}
} ;
ARTICLE: "peg.ebnf.strings" "EBNF Rule: Strings"
"A string in a rule will match that sequence of characters from the input string. "
"The string is delimited by matching single or double quotes. "
@ -338,22 +318,22 @@ ARTICLE: "peg.ebnf.foreign-rules" "EBNF Foreign Rules"
{ $examples
{ $code
"USING: prettyprint peg.ebnf ;"
"EBNF: parse-string"
": parse-string ( string -- obj ) EBNF{{"
"StringBody = (!('\"') .)*"
"String= '\"' StringBody:b '\"' => [[ b >string ]]"
"EBNF;"
"EBNF: parse-two-strings"
"}} ;"
": parse-two-strings ( string -- obj ) EBNF{{"
"TwoStrings = <foreign parse-string String> <foreign parse-string String>"
"EBNF;"
"EBNF: parse-two-strings"
"}} ;"
": parse-two-strings ( string -- obj ) EBNF{{"
"TwoString = <foreign parse-string> <foreign parse-string>"
"EBNF;"
"}} ;"
}
{ $code
": a-token ( -- parser ) \"a\" token ;"
"EBNF: parse-abc"
": parse-abc ( string -- obj ) EBNF{{"
"abc = <foreign a-token> 'b' 'c'"
"EBNF;"
"}} ;"
}
}
;
@ -364,9 +344,9 @@ ARTICLE: "peg.ebnf.tokenizers" "EBNF Tokenizers"
"Terminals in a rule match successive characters in the array or string. "
{ $examples
{ $code
"EBNF: foo"
": foo ( string -- obj ) EBNF{{"
"rule = \"++\" \"--\""
"EBNF;"
"}} ;"
}
}
"This parser when run with the string \"++--\" or the array "
@ -375,11 +355,11 @@ ARTICLE: "peg.ebnf.tokenizers" "EBNF Tokenizers"
"between the terminals:"
{ $examples
{ $code
"EBNF: foo"
": foo ( string -- obj ) EBNF{{"
"space = (\" \" | \"\\r\" | \"\\t\" | \"\\n\")"
"spaces = space* => [[ drop ignore ]]"
"rule = spaces \"++\" spaces \"--\" spaces"
"EBNF;"
"}} ;"
}
}
"In a large grammar this gets tedious and makes the grammar hard to read. "
@ -388,12 +368,12 @@ ARTICLE: "peg.ebnf.tokenizers" "EBNF Tokenizers"
"might look:"
{ $examples
{ $code
"EBNF: foo"
": foo ( string -- obj ) EBNF{{"
"space = (\" \" | \"\\r\" | \"\\t\" | \"\\n\")"
"spaces = space* => [[ drop ignore ]]"
"tokenizer = spaces ( \"++\" | \"--\" )"
"rule = \"++\" \"--\""
"EBNF;"
"}} ;"
}
}
"'tokenizer' is the name of a built in rule. Once defined it is called to "
@ -418,7 +398,7 @@ $nl
"TUPLE: ast-number value ;"
"TUPLE: ast-string value ;"
""
"EBNF: foo-tokenizer"
": foo-tokenizer ( string -- obj ) EBNF{{"
"space = (\" \" | \"\\r\" | \"\\t\" | \"\\n\")"
"spaces = space* => [[ drop ignore ]]"
""
@ -427,16 +407,16 @@ $nl
""
"token = spaces ( number | operator )"
"tokens = token*"
"EBNF;"
"}} ; @ebnf"
""
"EBNF: foo"
": foo ( string -- obj ) EBNF{{"
"tokenizer = <foreign foo-tokenizer token>"
""
"number = . ?[ ast-number? ]? => [[ value>> ]]"
"string = . ?[ ast-string? ]? => [[ value>> ]]"
""
"rule = string:a number:b \"+\" number:c => [[ a b c + 2array ]]"
"EBNF;"
"}} ;"
""
"\"123 456 +\" foo-tokenizer ."
"V{\n T{ ast-number { value 123 } }\n T{ ast-number { value 456 } }\n \"+\"\n}"
@ -453,7 +433,7 @@ $nl
"was defined lexically before the rule. This is useful in the JavaScript grammar:"
{ $examples
{ $code
"EBNF: javascript"
": javascript ( string -- obj ) EBNF{{"
"tokenizer = default"
"nl = \"\\r\" \"\\n\" | \"\\n\""
"tokenizer = <foreign tokenize-javascript Tok>"
@ -491,7 +471,6 @@ ARTICLE: "peg.ebnf" "EBNF"
{ $subsections
\ EBNF<
\ EBNF{{
\ EBNF:
}
"The EBNF syntax is composed of a series of rules of the form:"
{ $code

View File

@ -287,7 +287,7 @@ in: peg.ebnf.tests
"abcd='9' | ('8'):x => [[ x ]]" ebnf-parser (parse) remaining>> empty?
] unit-test
EBNF: primary
: primary ( string -- obj ) EBNF{{
Primary = PrimaryNoNewArray
PrimaryNoNewArray = ClassInstanceCreationExpression
| MethodInvocation
@ -310,7 +310,7 @@ MethodName = "m" | "n"
ExpressionName = Identifier
Expression = "i" | "j"
main = Primary
EBNF;
}} ;
{ "this" } [
"this" primary
@ -469,22 +469,22 @@ EBNF;
] unit-test
<<
EBNF: parser1
: parser1 ( string -- obj ) EBNF{{
foo='a'
EBNF;
}} ;
>>
EBNF: parser2
: parser2 ( string -- obj ) EBNF{{
foo=<foreign parser1 foo> 'b'
EBNF;
}} ;
EBNF: parser3
: parser3 ( string -- obj ) EBNF{{
foo=<foreign parser1> 'c'
EBNF;
}} ;
EBNF: parser4
: parser4 ( string -- obj ) EBNF{{
foo=<foreign any-char> 'd'
EBNF;
}} ;
{ "a" } [
"a" parser1
@ -523,7 +523,7 @@ EBNF;
TUPLE: ast-number value ;
EBNF: a-tokenizer
: a-tokenizer ( string -- obj ) EBNF{{
Letter = [a-zA-Z]
Digit = [0-9]
Digits = Digit+
@ -539,7 +539,7 @@ Special = "(" | ")" | "{" | "}" | "[" | "]" | "," | "
| "-" | "*=" | "*" | "/=" | "/" | "%=" | "%" | "&&="
| "&&" | "||=" | "||" | "." | "!"
Tok = Spaces (Number | Special )
EBNF;
}} ;
{ V{ char: 1 T{ ast-number f 23 } ";" char: x } } [
"123;x" EBNF{{ bar = .
@ -592,13 +592,17 @@ EBNF;
{
{ "a" "a" }
} [
EBNF: foo Bar = "a":a1 "a":a2 => [[ a1 a2 2array ]] EBNF;
: foo ( string -- obj ) EBNF{{
Bar = "a":a1 "a":a2 => [[ a1 a2 2array ]]
}} ;
"aa" foo
] unit-test
{
{ "a" "a" }
} [
EBNF: foo2 Bar = "a":a-1 "a":a-2 => [[ a-1 a-2 2array ]] EBNF;
: foo2 ( string -- obj ) EBNF{{
Bar = "a":a-1 "a":a-2 => [[ a-1 a-2 2array ]]
}} ;
"aa" foo2
] unit-test

View File

@ -552,3 +552,6 @@ SYNTAX: \ EBNF:
ebnf>quot swapd
( input -- ast ) define-declared "ebnf-parser" set-word-prop
reset-tokenizer ;
SYNTAX: @ebnf
words:last-word dup "ebnf-parser" set-word-prop ;

View File

@ -37,7 +37,7 @@ in: formatting
ERROR: unknown-printf-directive ;
EBNF: parse-printf
: parse-printf ( string -- obj ) EBNF{{
zero = "0" => [[ char: 0 ]]
char = "'" (.) => [[ second ]]
@ -90,7 +90,7 @@ plain-text = (!("%").)+ => [[ >string ]]
text = (formats|plain-text)* => [[ ]]
EBNF;
}} ;
: printf-quot ( format-string -- format-quot n )
parse-printf [ [ callable? ] count ] keep [
@ -155,7 +155,7 @@ MACRO: sprintf ( format-string -- quot )
: week-of-year-monday ( timestamp -- n ) 1 week-of-year ; inline
EBNF: parse-strftime
: parse-strftime ( string -- obj ) EBNF{{
fmt-% = "%" => [[ "%" ]]
fmt-a = "a" => [[ [ day-of-week day-abbreviation3 ] ]]
@ -191,7 +191,7 @@ plain-text = (!("%").)+ => [[ >string ]]
text = (formats|plain-text)* => [[ ]]
EBNF;
}} ;
PRIVATE>

View File

@ -12,7 +12,7 @@ in: globs
: wild-path-separator ( -- sep )
os windows? R/ [^\\/\\][\\/\\]|[^\\/\\]/ R/ [^\\/][\\/]|[^\\/]/ ? ; foldable
EBNF: <glob>
: <glob> ( string -- obj ) EBNF{{
Character = "\\" .:c => [[ c 1string <literal> ]]
| !(","|"}") . => [[ 1string <literal> ]]
@ -45,7 +45,7 @@ End = !(.)
Main = Concatenation End
EBNF;
}} ;
: glob-matches? ( input glob -- ? )
[ >case-fold ] bi@ <glob> matches? ;

View File

@ -52,7 +52,7 @@ ERROR: bad-vector-length seq n ;
[ bad-vector-length ]
} case ;
EBNF: parse-gml
: parse-gml ( string -- obj ) EBNF{{
Letter = [a-zA-Z]
Digit = [0-9]
@ -124,4 +124,4 @@ Tokens = Token* => [[ [ comment? ] reject ]]
Program = Tokens Spaces !(.) => [[ parse-proc ]]
EBNF;
}} ;

View File

@ -4,7 +4,7 @@ USING: infix.ast infix.tokenizer kernel math peg.ebnf sequences
strings vectors ;
in: infix.parser
EBNF: parse-infix
: parse-infix ( string -- obj ) EBNF{{
Number = . ?[ ast-number? ]?
Identifier = . ?[ string? ]?
Array = Identifier:i "[" Sum:s "]" => [[ i s ast-array boa ]]
@ -29,7 +29,7 @@ Sum = Sum:s ("+"|"-"):op Product:p => [[ s p op ast-op boa ]]
End = !(.)
Expression = Sum End
EBNF;
}} ;
: build-infix-ast ( string -- ast )
tokenize-infix parse-infix ;

View File

@ -4,7 +4,7 @@ USING: infix.ast kernel peg peg.ebnf math.parser sequences
strings ;
in: infix.tokenizer
EBNF: tokenize-infix
: tokenize-infix ( string -- obj ) EBNF{{
Letter = [a-zA-Z]
Digit = [0-9]
Digits = Digit+
@ -21,4 +21,4 @@ Special = [+*/%(),] | "-" => [[ char: - ]]
Tok = Spaces (Name | Number | Special )
End = !(.)
Toks = Tok* Spaces End
EBNF;
}} ;

View File

@ -4,7 +4,7 @@ USING: kernel arrays strings math.parser sequences
peg peg.ebnf peg.parsers memoize math accessors ;
in: peg.expr
EBNF: expr
: expr ( string -- obj ) EBNF{{
number = ([0-9])+ => [[ string>number ]]
value = number
| ("(" exp ")") => [[ second ]]
@ -16,4 +16,4 @@ fac = fac "*" value => [[ first3 nip * ]]
exp = exp "+" fac => [[ first3 nip + ]]
| exp "-" fac => [[ first3 nip - ]]
| fac
EBNF;
}} ;

View File

@ -18,7 +18,7 @@ in: peg.javascript.parser
! This operates a character at a time. Using this 'nl' in the parser
! allows us to detect newlines when we need to for the semicolon
! insertion rule, but ignore it in all other places.
EBNF: javascript
: javascript ( string -- obj ) EBNF{{
tokenizer = default
nl = "\r\n" | "\n"
@ -197,4 +197,4 @@ SrcElem = "function" Name:n FuncRest:f => [[ n f a
| Stmt
SrcElems = SrcElem* => [[ ast-begin boa ]]
TopLevel = SrcElems Spaces
EBNF;
}} ;

View File

@ -8,7 +8,7 @@ in: peg.javascript.tokenizer
use: prettyprint
EBNF: tokenize-javascript
: tokenize-javascript ( string -- obj ) EBNF{{
Letter = [a-zA-Z]
Digit = [0-9]
Digits = Digit+
@ -87,4 +87,4 @@ Special = "(" | ")" | "{" | "}" | "[" | "]" | "," |
| "^"
Tok = Spaces (Name | Keyword | Number | Str | RegExp | Special )
Toks = Tok* Spaces
EBNF;
}} ;

View File

@ -6,7 +6,7 @@ in: peg.pl0
! Grammar for PL/0 based on http://en.wikipedia.org/wiki/PL/0
EBNF: pl0
: pl0 ( string -- obj ) EBNF{{
block = { "CONST" ident "=" number { "," ident "=" number }* ";" }?
{ "VAR" ident { "," ident }* ";" }?
@ -24,4 +24,4 @@ factor = ident | number | "(" expression ")"
ident = (([a-zA-Z])+) => [[ >string ]]
number = ([0-9])+ => [[ string>number ]]
program = { block "." }
EBNF;
}} ;

View File

@ -126,7 +126,7 @@ ERROR: nonexistent-option name ;
! add greedy and nongreedy forms of matching
! (once it's all implemented)
EBNF: parse-regexp
: parse-regexp ( string -- obj ) EBNF{{
CharacterInBracket = !("}") Character
@ -217,4 +217,4 @@ Alternation = Concatenation:c ("|" Concatenation)*:a
End = !(.)
Main = Alternation End
EBNF;
}} ;

View File

@ -41,7 +41,7 @@ TUPLE: factor-expr expr ;
: ast>factor-expr ( ast -- obj )
second >string factor-expr boa ;
EBNF: expr
: expr ( string -- obj ) EBNF{{
space = " "
@ -89,4 +89,4 @@ pipeline = _ command _ (in-file)? _ "|" _ (command _ "|" _)* command _ (to-file
submission = (pipeline | basic)
EBNF;
}} ;

View File

@ -3,11 +3,11 @@
USING: peg.ebnf strings ;
in: simple-tokenizer
EBNF: tokenize
: tokenize ( string -- obj ) EBNF{{
space = [ \t\n\r]
escaped-char = "\\" .:ch => [[ ch ]]
quoted = '"' (escaped-char | [^"])*:a '"' => [[ a ]]
unquoted = (escaped-char | [^ \t\n\r"])+
argument = (quoted | unquoted) => [[ >string ]]
command = space* (argument:a space* => [[ a ]])+:c !(.) => [[ c ]]
EBNF;
}} ;

View File

@ -96,7 +96,7 @@ TUPLE: elliptical-arc radii x-axis-rotation large-arc? sweep? p relative? ;
: (set-relative) ( args rel -- args )
'[ [ _ >>relative? drop ] each ] keep ;
EBNF: svg-path>array
: svg-path>array ( string -- obj ) EBNF{{
moveto-drawto-command-groups =
moveto-drawto-command-group:first wsp* moveto-drawto-command-groups:rest
@ -219,7 +219,7 @@ wsp = [ \t\r\n]
svg-path = wsp* moveto-drawto-command-groups?:x wsp* => [[ x ]]
EBNF;
}} ;
: tag-d ( tag -- d )
"d" svg-name attr svg-path>array ;

View File

@ -17,12 +17,10 @@
[ dup <vocab-link> . flush vocab>literals ] map-zip
"resource:libs" vocabs-from
{ "brainfuck" "metar" "svg"
"gml.parser" "infix.tokenizer"
"math.blas.matrices" "math.blas.vectors"
{ "metar"
"math.blas.matrices" "math.blas.vectors"
"math.vectors.simd" "math.vectors.simd.cords"
"peg.pl0" "peg.javascript.parser" "peg.javascript.tokenizer"
"yaml.conversion"
"yaml.conversion"
} diff
[ dup <vocab-link> . flush vocab>literals ] map-zip

View File

@ -65,7 +65,7 @@ MEMO: resolved-primitives ( -- seq )
TUPLE: c++-type name params ptr ;
C: <c++-type> c++-type ;
EBNF: (parse-c++-type)
: (parse-c++-type) ( string -- obj ) EBNF{{
dig = [0-9]
alpha = [a-zA-Z]
alphanum = [1-9a-zA-Z]
@ -77,7 +77,7 @@ param = "," " "* type " "* => [[ third ]]
params = "<" " "* type " "* param* ">" => [[ [ 4 swap nth ] [ third ] bi prefix ]]
type = name " "* params? " "* ptr? => [[ { 0 2 4 } [ swap nth ] with map first3 <c++-type> ]]
EBNF;
}} ;
: parse-c++-type ( str -- c++-type )
factorize-type (parse-c++-type) ;

View File

@ -206,7 +206,7 @@ M: up-ref (>tref)
[ LLVMDumpModule ]
[ LLVMDisposeModule ] tri ;
EBNF: parse-type
: parse-type ( string -- obj ) EBNF{{
WhiteSpace = " "*
@ -241,6 +241,6 @@ Type = WhiteSpace T:t WhiteSpace => [[ t ]]
Program = Type
EBNF;
}} ;
SYNTAX: TYPE: ";" parse-multiline-string parse-type suffix! ;
SYNTAX: \ TYPE: ";" parse-multiline-string parse-type suffix! ;

View File

@ -4,13 +4,13 @@ USING: kernel modules.rpc peg peg-lexer peg.ebnf sequences
strings vocabs.parser ;
in: modules.using
EBNF: modulize
: modulize ( string -- obj ) EBNF{{
tokenpart = (!(':').)+ => [[ >string ]]
s = ':' => [[ drop ignore ]]
rpc = tokenpart s s tokenpart => [[ first2 remote-vocab ]]
remote = tokenpart s tokenpart => [[ first2 remote-load ]]
module = rpc | remote | tokenpart
EBNF;
}} ;
ON-BNF: USING*:
tokenizer = <foreign factor>
@ -25,4 +25,4 @@ long = "{" ( from | exclude | rename | qualified-with | qualified ) "}" => [[ dr
short = modspec => [[ use-vocab ignore ]]
wordSpec = long | short
using = wordSpec+ ";" => [[ drop ignore ]]
;ON-BNF
ON-BNF;

View File

@ -1,9 +1,9 @@
USING: peg.ebnf help.syntax help.markup strings ;
in: peg-lexer
HELP: ON-BNF:
{ $syntax "ON-BNF: word ... ;ON-BNF" }
{ $description "Creates a parsing word using a parser for lexer control, adding the resulting ast to the stack. Parser syntax is as in " { $link postpone\ EBNF: } } ;
HELP: \ ON-BNF:
{ $syntax "ON-BNF: word ... ON-BNF;" }
{ $description "Creates a parsing word using a parser for lexer control, adding the resulting ast to the stack. Parser syntax is as in " { $link postpone\ EBNF{{ } } ;
HELP: create-bnf
{ $values { "name" string } { "parser" parser } }

View File

@ -56,9 +56,9 @@ SYNTAX: ON-BNF:
main of create-bnf ;
! Tokenizer like standard factor lexer
EBNF: factor
: factor ( string -- obj ) EBNF{{
space = " " | "\n" | "\t"
spaces = space* => [[ drop ignore ]]
chunk = (!(space) .)+ => [[ >string ]]
expr = spaces chunk
EBNF;
}} ;