From 7900b66c7034e34eed5a2301c53e15f0aa42bbd3 Mon Sep 17 00:00:00 2001 From: David Majda Date: Mon, 7 May 2012 09:46:53 +0200 Subject: [PATCH] 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). --- spec/parser.spec.js | 8 ++++---- src/parser.js | 4 ++-- src/parser.pegjs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/parser.spec.js b/spec/parser.spec.js index 14774dc..c637a0b 100644 --- a/spec/parser.spec.js +++ b/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. */ diff --git a/src/parser.js b/src/parser.js index 8d20221..c2cdbcd 100644 --- a/src/parser.js +++ b/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) { diff --git a/src/parser.pegjs b/src/parser.pegjs index 6b3c77b..c9c44b5 100644 --- a/src/parser.pegjs +++ b/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("") + "}"; }