factor: fix EBNF: syntax.

locals-and-roots
Doug Coleman 2016-06-22 17:40:56 -07:00
parent c3c923749c
commit 542eecab1c
21 changed files with 44 additions and 45 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 ;
: expr-ast ( string -- obj ) EBNF{{
EBNF: expr-ast [=[
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 ]]
}} ;
]=] ;
GENERIC: eval-ast ( ast -- result ) ;

View File

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

View File

@ -5,7 +5,7 @@ combinators.short-circuit accessors math.parser quoting
locals ;
IN: db.postgresql.errors
: parse-postgresql-sql-error ( string -- obj ) EBNF{{
EBNF: parse-postgresql-sql-error [=[
Error = "ERROR:" [ ]+
@ -35,7 +35,7 @@ UnknownError = .* => [[ >string <sql-unknown-error> ]]
PostgresqlSqlError = (TableError | DatabaseError | FunctionError | SyntaxError | UnknownError)
}} ;
]=] ;
TUPLE: parse-postgresql-location column line text ;

View File

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

View File

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

View File

@ -4,7 +4,7 @@ USING: accessors assocs combinators combinators.short-circuit
effects kernel make math math.parser multiline namespaces parser
peg peg.parsers quotations sequences sequences.deep splitting
stack-checker strings strings.parser summary unicode
vocabs.parser words ;
vocabs.parser words lexer ;
FROM: vocabs.parser => search ;
FROM: peg.search => replace ;
IN: peg.ebnf
@ -558,7 +558,7 @@ SYNTAX: \ EBNF((
suffix! \ call suffix! reset-tokenizer ;
SYNTAX: \ EBNF:
reset-tokenizer scan-new-word dup "EBNF;" parse-multiline-string
reset-tokenizer scan-new-word dup scan-object ";" expect
ebnf>quot swapd
( input -- ast ) define-declared "ebnf-parser" set-word-prop
reset-tokenizer ;

View File

@ -49,7 +49,7 @@ TUPLE: brainfuck pointer memory ;
: compose-all ( seq -- quot )
[ ] [ compose ] reduce ;
: parse-brainfuck ( string -- obj ) EBNF{{
EBNF: parse-brainfuck [=[
inc-ptr = (">")+ => [[ length '[ _ (>) ] ]]
dec-ptr = ("<")+ => [[ length '[ _ (<) ] ]]
@ -66,7 +66,7 @@ loop = "[" {loop|ops}+ "]" => [[ second compose-all '[ [ (?) ] _ while ] ]]
code = (loop|ops|unknown)* => [[ compose-all ]]
}} ;
]=] ;
PRIVATE>

View File

@ -37,7 +37,7 @@ PRIVATE<
ERROR: unknown-printf-directive ;
: parse-printf ( string -- obj ) EBNF{{
EBNF: parse-printf [=[
zero = "0" => [[ char: 0 ]]
char = "'" (.) => [[ second ]]
@ -90,7 +90,7 @@ plain-text = (!("%").)+ => [[ >string ]]
text = (formats|plain-text)* => [[ ]]
}} ;
]=] ;
: printf-quot ( format-string -- format-quot n )
parse-printf [ [ callable? ] count ] keep [

View File

@ -12,7 +12,7 @@ IN: globs
: wild-path-separator ( -- sep )
os windows? R{{ [^\\/\\][\\/\\]|[^\\/\\]}} R{{ [^\\/][\\/]|[^\\/]}} ? ; foldable
: <glob> ( string -- obj ) EBNF{{
EBNF: <glob> [=[
Character = "\\" .:c => [[ c 1string <literal> ]]
| !(","|"}") . => [[ 1string <literal> ]]
@ -45,7 +45,7 @@ End = !(.)
Main = Concatenation End
}} ;
]=] ;
: 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 ;
: parse-gml ( string -- obj ) EBNF{{
EBNF: parse-gml [=[
Letter = [a-zA-Z]
Digit = [0-9]
@ -124,4 +124,4 @@ Tokens = Token* => [[ [ comment? ] reject ]]
Program = Tokens Spaces !(.) => [[ parse-proc ]]
}} ;
]=] ;

View File

@ -4,7 +4,7 @@ USING: infix.ast infix.tokenizer kernel math peg.ebnf sequences
strings vectors ;
IN: infix.parser
: parse-infix ( string -- obj ) EBNF{{
EBNF: parse-infix [=[
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
}} ;
]=] ;
: 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
: tokenize-infix ( string -- obj ) EBNF{{
EBNF: tokenize-infix [=[
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
}} ;
]=] ;

View File

@ -4,7 +4,7 @@ USING: kernel arrays strings math.parser sequences
peg peg.ebnf peg.parsers memoize math accessors ;
IN: peg.expr
: expr ( string -- obj ) EBNF{{
EBNF: expr [=[
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
}} ;
]=] ;

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.
: javascript ( string -- obj ) EBNF{{
EBNF: javascript [=[
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
}} ;
]=] ;

View File

@ -8,7 +8,7 @@ IN: peg.javascript.tokenizer
USE: prettyprint
: tokenize-javascript ( string -- obj ) EBNF{{
EBNF: tokenize-javascript [=[
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
}} ;
]=] ;

View File

@ -6,7 +6,7 @@ IN: peg.pl0
! Grammar for PL/0 based on http://en.wikipedia.org/wiki/PL/0
: pl0 ( string -- obj ) EBNF{{
EBNF: pl0 [=[
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 "." }
}} ;
]=] ;

View File

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

View File

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

View File

@ -3,11 +3,11 @@
USING: peg.ebnf strings ;
IN: simple-tokenizer
: tokenize ( string -- obj ) EBNF{{
EBNF: tokenize [=[
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 ]]
}} ;
]=] ;

View File

@ -16,8 +16,7 @@ XML-NS: inkscape-name http://www.inkscape.org/namespaces/inkscape ;
: degrees ( deg -- rad ) pi * 180.0 / ;
: svg-transform>affine-transform ( string -- obj )
EBNF{{
EBNF: svg-transform>affine-transform [=[
transforms =
transform:m comma-wsp+ transforms:n => [[ m n a. ]]
@ -77,7 +76,7 @@ wsp = [ \t\r\n]
transform-list = wsp* transforms?:t wsp*
=> [[ t [ identity-transform ] unless* ]]
}} ;
]=] ;
: tag-transform ( tag -- transform )
"transform" svg-name attr svg-transform>affine-transform ;
@ -96,7 +95,7 @@ TUPLE: elliptical-arc radii x-axis-rotation large-arc? sweep? p relative? ;
: (set-relative) ( args rel -- args )
'[ [ _ >>relative? drop ] each ] keep ;
: svg-path>array ( string -- obj ) EBNF{{
EBNF: svg-path>array [=[
moveto-drawto-command-groups =
moveto-drawto-command-group:first wsp* moveto-drawto-command-groups:rest
@ -219,7 +218,7 @@ wsp = [ \t\r\n]
svg-path = wsp* moveto-drawto-command-groups?:x wsp* => [[ x ]]
}} ;
]=] ;
: tag-d ( tag -- d )
"d" svg-name attr svg-path>array ;

View File

@ -35,7 +35,7 @@ M: url >url ;
PRIVATE<
: parse-url ( string -- obj ) EBNF{{
EBNF: parse-url [=[
protocol = [a-z+]+ => [[ url-decode ]]
username = [^/:@#?]+ => [[ url-decode ]]
@ -57,7 +57,7 @@ url = (((protocol "://") => [[ first ]] auth hostname)
("?" query => [[ second ]])?
("#" anchor => [[ second ]])?
}} ;
]=] ;
PRIVATE>