Skip to content

Commit

Permalink
fix: escape sequence literals
Browse files Browse the repository at this point in the history
  • Loading branch information
menduz committed Oct 29, 2022
1 parent 3b4b06d commit 8e637c2
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 30 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ build:
node dist/utils/packStdLib.js

GREP="."
TEST_FILE=*
TEST_FILE="test/*.spec.ts"

DEBUG_TYPES=0

just-test:
DEBUG_TYPES=$(DEBUG_TYPES) \
node ./node_modules/mocha/bin/_mocha --grep "$(GREP)" "test/$(TEST_FILE).spec.ts"
node ./node_modules/mocha/bin/_mocha --grep "$(GREP)" $(TEST_FILE)

test: | build just-test

Expand Down
33 changes: 7 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@webassemblyjs/wast-printer": "1.11.1",
"arg": "^4.1.3",
"binaryen": "^100.0.0",
"ebnf": "^1.7.4",
"ebnf": "^1.9.0",
"wabt": "^1.0.30"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ PostfixNumber ::= (HexLiteral | NumberLiteral) Reference? {pin=1,simplifyWhe
NumberLiteral ::= !('0x') ("0" | [1-9] [0-9]*) ("." [0-9]+)? (("e" | "E") ( "-" | "+" )? ("0" | [1-9] [0-9]*))? {pin=2}
NegNumberLiteral ::= '-'? NumberLiteral {pin=2}
HexLiteral ::= "0x" [0-9A-Fa-f]+ {pin=1}
StringLiteral ::= STRING_DELIMITER ((![\\\\"] [#x20-#xFFFF])* | ('\\' (STRING_DELIMITER | '\\' | '/' | 'b' | 'f' | 'n' | 'r' | 't' | 'u' HEXDIG HEXDIG HEXDIG HEXDIG)?))* STRING_DELIMITER {pin=1}
StringLiteral ::= STRING_DELIMITER ((![\\\\"] [#x20-#xFFFF])* | ([#x5c] (STRING_DELIMITER | [#x5c] | '/' | 'b' | 'f' | 'n' | 'r' | 't' | 'u' HEXDIG HEXDIG HEXDIG HEXDIG)?))* STRING_DELIMITER {pin=1}
Literal ::= StringLiteral
| PostfixNumber
| BooleanLiteral {fragment=true}
Expand Down
2 changes: 2 additions & 0 deletions test/Canonical.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ describe('Canonical', function() {
test`var a: Number = 0x0`;
test`var a: Number = 0x1facbeda0192830190238019283`;
test`var a: Number = -0x1facbeda0192830190238019283`;
test`var a = "\\u001B[2J"`;
test`var b = "\\u001b[H\\u001b[2J\\u001b[3J"`;
test`var a = false`;

test`
Expand Down
7 changes: 7 additions & 0 deletions test/Parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,13 @@ describe('Parser', () => {
testLiteral(JSON.stringify('A string'));
testLiteral(JSON.stringify("asdasd`\"`'''`\\\""));
testLiteral(JSON.stringify(213422342344234));
testLiteral(JSON.stringify("\\u001B[2J"));
testLiteral(JSON.stringify("\\u001b[H\\u001b[2J\\u001b[3J"));

test`
var a = "\\u001B[2J"
var b = "\\u001b[H\\u001b[2J\\u001b[3J"
`;

test`
var a = 1
Expand Down

0 comments on commit 8e637c2

Please sign in to comment.