diff --git a/lib/parser.js b/lib/parser.js index 9177884..e1a244e 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -1383,17 +1383,6 @@ module.exports = (function(){ matchFailed("\"_\""); } } - if (r3 === null) { - if (input.charCodeAt(pos) === 36) { - r3 = "$"; - pos++; - } else { - r3 = null; - if (reportFailures === 0) { - matchFailed("\"$\""); - } - } - } } if (r3 !== null) { r4 = []; @@ -1410,17 +1399,6 @@ module.exports = (function(){ matchFailed("\"_\""); } } - if (r5 === null) { - if (input.charCodeAt(pos) === 36) { - r5 = "$"; - pos++; - } else { - r5 = null; - if (reportFailures === 0) { - matchFailed("\"$\""); - } - } - } } } while (r5 !== null) { @@ -1438,17 +1416,6 @@ module.exports = (function(){ matchFailed("\"_\""); } } - if (r5 === null) { - if (input.charCodeAt(pos) === 36) { - r5 = "$"; - pos++; - } else { - r5 = null; - if (reportFailures === 0) { - matchFailed("\"$\""); - } - } - } } } } diff --git a/spec/parser.spec.js b/spec/parser.spec.js index 34e9227..d8726a0 100644 --- a/spec/parser.spec.js +++ b/spec/parser.spec.js @@ -349,11 +349,9 @@ describe("PEG.js grammar parser", function() { it("parses identifier", function() { expect('start = a' ).toParseAs(ruleRefGrammar("a")); expect('start = _' ).toParseAs(ruleRefGrammar("_")); - expect('start = $' ).toParseAs(ruleRefGrammar("$")); expect('start = aa' ).toParseAs(ruleRefGrammar("aa")); expect('start = a0' ).toParseAs(ruleRefGrammar("a0")); expect('start = a_' ).toParseAs(ruleRefGrammar("a_")); - expect('start = a$' ).toParseAs(ruleRefGrammar("a$")); expect('start = abcd').toParseAs(ruleRefGrammar("abcd")); expect('start = a\n').toParseAs(ruleRefGrammar("a")); diff --git a/src/parser.pegjs b/src/parser.pegjs index 86b2c43..a37475b 100644 --- a/src/parser.pegjs +++ b/src/parser.pegjs @@ -190,9 +190,12 @@ dot = "." __ { return "."; } * * The simplifications were made just to make the implementation little bit * easier, there is no "philosophical" reason behind them. + * + * Contrary to ECMA 262, the "$" character is not valid because it serves other + * purpose in the grammar. */ identifier "identifier" - = head:(letter / "_" / "$") tail:(letter / digit / "_" / "$")* __ { + = head:(letter / "_") tail:(letter / digit / "_")* __ { return head + tail.join(""); }