Browse Source

Fix |braced| rule in the PEG.js grammar

This fix does not change the behavior, it just makes the
|nonBraceCharacters| rule un-dead (as originally intended).
redux
David Majda 10 years ago
parent
commit
7900b66c70
  1. 8
      spec/parser.spec.js
  2. 4
      src/parser.js
  3. 2
      src/parser.pegjs

8
spec/parser.spec.js

@ -321,10 +321,10 @@ describe("PEG.js grammar parser", function() {
/* Canonical braced is "{ code }". */
it("parses braced", function() {
expect('start = "abcd" {}' ).toParseAs(actionGrammar(""));
expect('start = "abcd" {a}' ).toParseAs(actionGrammar("a"));
expect('start = "abcd" {{a}}').toParseAs(actionGrammar("{a}"));
expect('start = "abcd" {aaa}').toParseAs(actionGrammar("aaa"));
expect('start = "abcd" {}' ).toParseAs(actionGrammar(""));
expect('start = "abcd" {{a}}' ).toParseAs(actionGrammar("{a}"));
expect('start = "abcd" {abcd}' ).toParseAs(actionGrammar("abcd"));
expect('start = "abcd" {{a}{b}{c}}').toParseAs(actionGrammar("{a}{b}{c}"));
});
/* Trivial character rules are not tested. */

4
src/parser.js

@ -835,13 +835,13 @@ PEG.parser = (function(){
result1 = [];
result2 = parse_braced();
if (result2 === null) {
result2 = parse_nonBraceCharacter();
result2 = parse_nonBraceCharacters();
}
while (result2 !== null) {
result1.push(result2);
result2 = parse_braced();
if (result2 === null) {
result2 = parse_nonBraceCharacter();
result2 = parse_nonBraceCharacters();
}
}
if (result1 !== null) {

2
src/parser.pegjs

@ -144,7 +144,7 @@ action "action"
= braced:braced __ { return braced.substr(1, braced.length - 2); }
braced
= "{" parts:(braced / nonBraceCharacter)* "}" {
= "{" parts:(braced / nonBraceCharacters)* "}" {
return "{" + parts.join("") + "}";
}

Loading…
Cancel
Save