peg: use escaped character classes.
parent
04c5f5bfce
commit
cd6ccdadc3
|
@ -58,7 +58,7 @@ dec-mem = ("-")+ => [[ length '[ _ (-) ] ]]
|
||||||
output = "." => [[ [ (.) ] ]]
|
output = "." => [[ [ (.) ] ]]
|
||||||
input = "," => [[ [ (,) ] ]]
|
input = "," => [[ [ (,) ] ]]
|
||||||
debug = "#" => [[ [ (#) ] ]]
|
debug = "#" => [[ [ (#) ] ]]
|
||||||
space = (" "|"\t"|"\r\n"|"\n")+ => [[ [ ] ]]
|
space = [ \t\n\r]+ => [[ [ ] ]]
|
||||||
unknown = (.) => [[ "Invalid input" throw ]]
|
unknown = (.) => [[ "Invalid input" throw ]]
|
||||||
|
|
||||||
ops = inc-ptr|dec-ptr|inc-mem|dec-mem|output|input|debug|space
|
ops = inc-ptr|dec-ptr|inc-mem|dec-mem|output|input|debug|space
|
||||||
|
|
|
@ -62,11 +62,11 @@ Sign = ('+' => [[ first ]]|'-' => [[ first ]])?
|
||||||
|
|
||||||
StopChar = ('('|')'|'['|']'|'{'|'}'|'/'|'/'|';'|':'|'!'|'.')
|
StopChar = ('('|')'|'['|']'|'{'|'}'|'/'|'/'|';'|':'|'!'|'.')
|
||||||
|
|
||||||
Space = ' ' | '\t' | '\r' | '\n'
|
Space = [ \t\n\r]
|
||||||
|
|
||||||
Spaces = Space* => [[ ignore ]]
|
Spaces = Space* => [[ ignore ]]
|
||||||
|
|
||||||
Newline = ('\n' | '\r')
|
Newline = [\n\r]
|
||||||
|
|
||||||
Number = Sign Digit+ ('.' => [[ first ]] Digit+)? ('e' => [[ first ]] Sign Digit+)?
|
Number = Sign Digit+ ('.' => [[ first ]] Digit+)? ('e' => [[ first ]] Sign Digit+)?
|
||||||
=> [[ flatten sift >string string>number ]]
|
=> [[ flatten sift >string string>number ]]
|
||||||
|
|
|
@ -10,7 +10,7 @@ Digit = [0-9]
|
||||||
Digits = Digit+
|
Digits = Digit+
|
||||||
Number = Digits '.' Digits => [[ "" concat-as string>number ast-number boa ]]
|
Number = Digits '.' Digits => [[ "" concat-as string>number ast-number boa ]]
|
||||||
| Digits => [[ >string string>number ast-number boa ]]
|
| Digits => [[ >string string>number ast-number boa ]]
|
||||||
Space = " " | "\n" | "\r" | "\t"
|
Space = [ \t\n\r]
|
||||||
Spaces = Space* => [[ ignore ]]
|
Spaces = Space* => [[ ignore ]]
|
||||||
NameFirst = Letter | "_" => [[ CHAR: _ ]]
|
NameFirst = Letter | "_" => [[ CHAR: _ ]]
|
||||||
NameRest = NameFirst | Digit
|
NameRest = NameFirst | Digit
|
||||||
|
|
|
@ -19,17 +19,17 @@ IN: peg.javascript.parser
|
||||||
#! allows us to detect newlines when we need to for the semicolon
|
#! allows us to detect newlines when we need to for the semicolon
|
||||||
#! insertion rule, but ignore it in all other places.
|
#! insertion rule, but ignore it in all other places.
|
||||||
EBNF: javascript
|
EBNF: javascript
|
||||||
tokenizer = default
|
tokenizer = default
|
||||||
nl = "\r" "\n" | "\n"
|
nl = "\r\n" | "\n"
|
||||||
|
|
||||||
tokenizer = <foreign tokenize-javascript Tok>
|
tokenizer = <foreign tokenize-javascript Tok>
|
||||||
End = !(.)
|
End = !(.)
|
||||||
Space = " " | "\t" | "\n"
|
Space = [ \t\n]
|
||||||
Spaces = Space* => [[ ignore ]]
|
Spaces = Space* => [[ ignore ]]
|
||||||
Name = . ?[ ast-name? ]? => [[ value>> ]]
|
Name = . ?[ ast-name? ]? => [[ value>> ]]
|
||||||
Number = . ?[ ast-number? ]?
|
Number = . ?[ ast-number? ]?
|
||||||
String = . ?[ ast-string? ]?
|
String = . ?[ ast-string? ]?
|
||||||
RegExp = . ?[ ast-regexp? ]?
|
RegExp = . ?[ ast-regexp? ]?
|
||||||
SpacesNoNl = (!(nl) Space)* => [[ ignore ]]
|
SpacesNoNl = (!(nl) Space)* => [[ ignore ]]
|
||||||
|
|
||||||
Expr = OrExpr:e "?" Expr:t ":" Expr:f => [[ e t f ast-cond-expr boa ]]
|
Expr = OrExpr:e "?" Expr:t ":" Expr:f => [[ e t f ast-cond-expr boa ]]
|
||||||
|
@ -175,7 +175,7 @@ Switch1 = "case" Expr:c ":" SrcElems:cs => [[ c cs ast-case boa ]]
|
||||||
SwitchBody = Switch1*
|
SwitchBody = Switch1*
|
||||||
Finally = "finally" Block:b => [[ b ]]
|
Finally = "finally" Block:b => [[ b ]]
|
||||||
| Spaces => [[ "undefined" ast-get boa ]]
|
| Spaces => [[ "undefined" ast-get boa ]]
|
||||||
Stmt = Block
|
Stmt = Block
|
||||||
| "var" Bindings:bs Sc => [[ bs ast-begin boa ]]
|
| "var" Bindings:bs Sc => [[ bs ast-begin boa ]]
|
||||||
| "if" "(" Expr:c ")" Stmt:t "else" Stmt:f => [[ c t f ast-if boa ]]
|
| "if" "(" Expr:c ")" Stmt:t "else" Stmt:f => [[ c t f ast-if boa ]]
|
||||||
| "if" "(" Expr:c ")" Stmt:t => [[ c t "undefined" ast-get boa ast-if boa ]]
|
| "if" "(" Expr:c ")" Stmt:t => [[ c t "undefined" ast-get boa ast-if boa ]]
|
||||||
|
@ -196,5 +196,5 @@ Stmt = Block
|
||||||
SrcElem = "function" Name:n FuncRest:f => [[ n f ast-var boa ]]
|
SrcElem = "function" Name:n FuncRest:f => [[ n f ast-var boa ]]
|
||||||
| Stmt
|
| Stmt
|
||||||
SrcElems = SrcElem* => [[ ast-begin boa ]]
|
SrcElems = SrcElem* => [[ ast-begin boa ]]
|
||||||
TopLevel = SrcElems Spaces
|
TopLevel = SrcElems Spaces
|
||||||
;EBNF
|
;EBNF
|
||||||
|
|
|
@ -14,7 +14,7 @@ Digit = [0-9]
|
||||||
Digits = Digit+
|
Digits = Digit+
|
||||||
SingleLineComment = "//" (!("\n") .)* "\n" => [[ ignore ]]
|
SingleLineComment = "//" (!("\n") .)* "\n" => [[ ignore ]]
|
||||||
MultiLineComment = "/*" (!("*/") .)* "*/" => [[ ignore ]]
|
MultiLineComment = "/*" (!("*/") .)* "*/" => [[ ignore ]]
|
||||||
Space = " " | "\t" | "\r" | "\n" | SingleLineComment | MultiLineComment
|
Space = [ \t\r\n] | SingleLineComment | MultiLineComment
|
||||||
Spaces = Space* => [[ ignore ]]
|
Spaces = Space* => [[ ignore ]]
|
||||||
NameFirst = Letter | "$" => [[ CHAR: $ ]] | "_" => [[ CHAR: _ ]]
|
NameFirst = Letter | "$" => [[ CHAR: $ ]] | "_" => [[ CHAR: _ ]]
|
||||||
NameRest = NameFirst | Digit
|
NameRest = NameFirst | Digit
|
||||||
|
@ -48,7 +48,7 @@ Name = !(Keyword) iName => [[ ast-name boa ]]
|
||||||
Number = Digits:ws '.' Digits:fs => [[ ws "." fs 3array "" concat-as string>number ast-number boa ]]
|
Number = Digits:ws '.' Digits:fs => [[ ws "." fs 3array "" concat-as string>number ast-number boa ]]
|
||||||
| Digits => [[ >string string>number ast-number boa ]]
|
| Digits => [[ >string string>number ast-number boa ]]
|
||||||
|
|
||||||
EscapeChar = "\\n" => [[ 10 ]]
|
EscapeChar = "\\n" => [[ 10 ]]
|
||||||
| "\\r" => [[ 13 ]]
|
| "\\r" => [[ 13 ]]
|
||||||
| "\\t" => [[ 9 ]]
|
| "\\t" => [[ 9 ]]
|
||||||
StringChars1 = (EscapeChar | !('"""') .)* => [[ >string ]]
|
StringChars1 = (EscapeChar | !('"""') .)* => [[ >string ]]
|
||||||
|
@ -58,11 +58,11 @@ Str = '"""' StringChars1:cs '"""' => [[ cs ast-string boa ]]
|
||||||
| '"' StringChars2:cs '"' => [[ cs ast-string boa ]]
|
| '"' StringChars2:cs '"' => [[ cs ast-string boa ]]
|
||||||
| "'" StringChars3:cs "'" => [[ cs ast-string boa ]]
|
| "'" StringChars3:cs "'" => [[ cs ast-string boa ]]
|
||||||
RegExpFlags = NameRest* => [[ >string ]]
|
RegExpFlags = NameRest* => [[ >string ]]
|
||||||
NonTerminator = !("\n" | "\r") .
|
NonTerminator = !([\n\r]) .
|
||||||
BackslashSequence = "\\" NonTerminator => [[ second ]]
|
BackslashSequence = "\\" NonTerminator => [[ second ]]
|
||||||
RegExpFirstChar = !("*" | "\\" | "/") NonTerminator
|
RegExpFirstChar = !([*\\/]) NonTerminator
|
||||||
| BackslashSequence
|
| BackslashSequence
|
||||||
RegExpChar = !("\\" | "/") NonTerminator
|
RegExpChar = !([\\/]) NonTerminator
|
||||||
| BackslashSequence
|
| BackslashSequence
|
||||||
RegExpChars = RegExpChar*
|
RegExpChars = RegExpChar*
|
||||||
RegExpBody = RegExpFirstChar RegExpChars => [[ first2 swap prefix >string ]]
|
RegExpBody = RegExpFirstChar RegExpChars => [[ first2 swap prefix >string ]]
|
||||||
|
@ -75,5 +75,5 @@ Special = "(" | ")" | "{" | "}" | "[" | "]" | "," |
|
||||||
| "||" | "." | "!" | "&=" | "&" | "|=" | "|" | "^="
|
| "||" | "." | "!" | "&=" | "&" | "|=" | "|" | "^="
|
||||||
| "^"
|
| "^"
|
||||||
Tok = Spaces (Name | Keyword | Number | Str | RegExp | Special )
|
Tok = Spaces (Name | Keyword | Number | Str | RegExp | Special )
|
||||||
Toks = Tok* Spaces
|
Toks = Tok* Spaces
|
||||||
;EBNF
|
;EBNF
|
||||||
|
|
|
@ -71,7 +71,7 @@ exponent =
|
||||||
sign =
|
sign =
|
||||||
"+" => [[ f ]] | "-"
|
"+" => [[ f ]] | "-"
|
||||||
digit-sequence = [0-9]+ => [[ >string ]]
|
digit-sequence = [0-9]+ => [[ >string ]]
|
||||||
wsp = (" " | "\t" | "\r" | "\n")
|
wsp = [ \t\r\n]
|
||||||
|
|
||||||
transform-list = wsp* transforms?:t wsp*
|
transform-list = wsp* transforms?:t wsp*
|
||||||
=> [[ t [ identity-transform ] unless* ]]
|
=> [[ t [ identity-transform ] unless* ]]
|
||||||
|
@ -214,7 +214,7 @@ fractional-constant = digit-sequence? "." digit-sequence | digit-sequence "."
|
||||||
exponent = ( "e" | "E" ) sign? digit-sequence
|
exponent = ( "e" | "E" ) sign? digit-sequence
|
||||||
sign = "+" => [[ drop f ]] | "-"
|
sign = "+" => [[ drop f ]] | "-"
|
||||||
digit-sequence = [0-9]+ => [[ >string ]]
|
digit-sequence = [0-9]+ => [[ >string ]]
|
||||||
wsp = (" " | "\t" | "\r" | "\n")
|
wsp = [ \t\r\n]
|
||||||
|
|
||||||
svg-path = wsp* moveto-drawto-command-groups?:x wsp* => [[ x ]]
|
svg-path = wsp* moveto-drawto-command-groups?:x wsp* => [[ x ]]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue