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