peg.javascript.tokenizer: allow escaped quotes in strings

Previously, the tokenizer didn't understand
escaped quotes in string literals. Also added was
a test to ensure the escaping works.
locals-and-roots
catb0t 2016-06-11 17:36:14 -04:00 committed by John Benediktsson
parent 6984bae7ca
commit 385cf35e7f
2 changed files with 11 additions and 6 deletions

View File

@ -23,3 +23,7 @@ IN: peg.javascript.tokenizer.tests
{ V{ T{ ast-regexp f "<(w+)[^>]*?)/>" "g" } } } [
"/<(\\w+)[^>]*?)\\/>/g" tokenize-javascript
] unit-test
{
V{ T{ ast-string { value "abc\"def\"" } } }
} [ "\"abc\\\"def\\\"\"" tokenize-javascript ] unit-test

View File

@ -8,7 +8,7 @@ IN: peg.javascript.tokenizer
USE: prettyprint
EBNF: tokenize-javascript
EBNF: tokenize-javascript
Letter = [a-zA-Z]
Digit = [0-9]
Digits = Digit+
@ -43,14 +43,15 @@ Keyword = ("break"
| "var"
| "void"
| "while"
| "with") !(NameRest)
| "with") !(NameRest)
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 ]]
| Digits => [[ >string string>number ast-number boa ]]
EscapeChar = "\\n" => [[ 10 ]]
| "\\r" => [[ 13 ]]
| "\\t" => [[ 9 ]]
EscapeChar = "\\n" => [[ CHAR: \n ]]
| "\\r" => [[ CHAR: \r ]]
| "\\t" => [[ CHAR: \t ]]
| "\\\"" => [[ CHAR: \" ]]
StringChars1 = (EscapeChar | !('"""') .)* => [[ >string ]]
StringChars2 = (EscapeChar | !('"') .)* => [[ >string ]]
StringChars3 = (EscapeChar | !("'") .)* => [[ >string ]]