PEG.js grammar: Fix line continuation handling

Before this commit, a line continuation (backslash followed by a line
terminator character) contributed a character to a string or a character
class it was used in. In JavaScript and many other languages, line
continuation doesn't contribute anything.

This commit aligns PEG.js line continuation behavior with JavaScript.
redux
David Majda 11 years ago committed by David Majda
parent 3dbec0b30d
commit fb72c430e6

@ -281,7 +281,7 @@ module.exports = (function() {
},
peg$c111 = "\\u",
peg$c112 = { type: "literal", value: "\\u", description: "\"\\\\u\"" },
peg$c113 = function(eol) { return eol; },
peg$c113 = function(eol) { return ""; },
peg$c114 = /^[0-9]/,
peg$c115 = { type: "class", value: "[0-9]", description: "[0-9]" },
peg$c116 = /^[0-9a-fA-F]/,

@ -392,7 +392,7 @@ describe("PEG.js grammar parser", function() {
expect('start = "\\0"' ).toParseAs(literalGrammar("\x00"));
expect('start = "\\xFF"' ).toParseAs(literalGrammar("\xFF"));
expect('start = "\\uFFFF"').toParseAs(literalGrammar("\uFFFF"));
expect('start = "\\\n"' ).toParseAs(literalGrammar("\n"));
expect('start = "\\\n"' ).toParseAs(literalGrammar(""));
});
/* Canonical simpleDoubleQuotedCharacter is "a". */
@ -418,7 +418,7 @@ describe("PEG.js grammar parser", function() {
expect("start = '\\0'" ).toParseAs(literalGrammar("\x00"));
expect("start = '\\xFF'" ).toParseAs(literalGrammar("\xFF"));
expect("start = '\\uFFFF'").toParseAs(literalGrammar("\uFFFF"));
expect("start = '\\\n'" ).toParseAs(literalGrammar("\n"));
expect("start = '\\\n'" ).toParseAs(literalGrammar(""));
});
/* Canonical simpleSingleQuotedCharacter is "a". */
@ -471,7 +471,7 @@ describe("PEG.js grammar parser", function() {
expect('start = [\\0]' ).toParseAs(classGrammar(["\x00"], "[\\0]"));
expect('start = [\\xFF]' ).toParseAs(classGrammar(["\xFF"], "[\\xFF]"));
expect('start = [\\uFFFF]').toParseAs(classGrammar(["\uFFFF"], "[\\uFFFF]"));
expect('start = [\\\n]' ).toParseAs(classGrammar(["\n"], "[\\\n]"));
expect('start = [\\\n]' ).toParseAs(classGrammar([""], "[\\\n]"));
});
/* Canonical simpleBracketDelimiedCharacter is "a". */
@ -518,11 +518,7 @@ describe("PEG.js grammar parser", function() {
/* Canonical eolEscapeSequence is "\\\n". */
it("parses eolEscapeSequence", function() {
expect('start = "\\\n"' ).toParseAs(literalGrammar("\n"));
expect('start = "\\\r\n"' ).toParseAs(literalGrammar("\r\n"));
expect('start = "\\\r"' ).toParseAs(literalGrammar("\r"));
expect('start = "\\\u2028"').toParseAs(literalGrammar("\u2028"));
expect('start = "\\\u2029"').toParseAs(literalGrammar("\u2029"));
expect('start = "\\\n"' ).toParseAs(literalGrammar(""));
});
/* Trivial character class rules are not tested. */

@ -308,7 +308,7 @@ unicodeEscapeSequence
}
eolEscapeSequence
= "\\" eol:eol { return eol; }
= "\\" eol:eol { return ""; }
digit
= [0-9]

Loading…
Cancel
Save