Browse Source

PEG.js grammar: Improve the |Code| rule a bit

Instead of matching segments between blocks character by character,
match them as a whole. Also align the style with other similar rules
(e.g. the comment ones).
redux
David Majda 8 years ago
parent
commit
e78ffbba9c
  1. 134
      lib/parser.js
  2. 7
      spec/parser.spec.js
  3. 2
      src/parser.pegjs

134
lib/parser.js
File diff suppressed because it is too large
View File

7
spec/parser.spec.js

@ -595,9 +595,10 @@ describe("PEG.js grammar parser", function() {
/* Canonical Code is " code ". */
it("parses Code", function() {
expect('start = "abcd" {a}' ).toParseAs(actionGrammar("a"));
expect('start = "abcd" {{a}}').toParseAs(actionGrammar("{a}"));
expect('start = "abcd" {abc}').toParseAs(actionGrammar("abc"));
expect('start = "abcd" {a}' ).toParseAs(actionGrammar("a"));
expect('start = "abcd" {abc}' ).toParseAs(actionGrammar("abc"));
expect('start = "abcd" {{a}}' ).toParseAs(actionGrammar("{a}"));
expect('start = "abcd" {{a}{b}{c}}').toParseAs(actionGrammar("{a}{b}{c}"));
expect('start = "abcd" {{}').toFailToParse();
expect('start = "abcd" {}}').toFailToParse();

2
src/parser.pegjs

@ -414,7 +414,7 @@ CodeBlock "code block"
= "{" code:Code "}" { return code; }
Code
= $([^{}] / "{" Code "}")*
= $((![{}] SourceCharacter)+ / "{" Code "}")*
/*
* Unicode Character Categories

Loading…
Cancel
Save