Browse Source

PEG.js grammar: Extract the |AnyMatcher| rule

This makes the |Primary| rule a bit more tidy. Also, matching the |.|
character really belongs to the lexical part of the grammar, next to
literals and character classes.
redux
David Majda 8 years ago
parent
commit
4ce7593f5f
  1. 568
      lib/parser.js
  2. 5
      spec/parser.spec.js
  3. 5
      src/parser.pegjs

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

5
spec/parser.spec.js

@ -561,6 +561,11 @@ describe("PEG.js grammar parser", function() {
/* Digit rules are not tested. */
/* Canonical AnyMatcher is ".". */
it("parses CodeAnymatcher", function() {
expect('start = .').toParseAs(oneRuleGrammar({ type: "any" }));
});
/* Canonical CodeBlock is "{ code }". */
it("parses CodeBlock", function() {
expect('start = "abcd" { code }').toParseAs(actionGrammar(" code "));

5
src/parser.pegjs

@ -166,7 +166,7 @@ Primary
}
/ LiteralMatcher
/ CharacterClassMatcher
/ "." { return { type: "any" }; }
/ AnyMatcher
/ "(" __ expression:Expression __ ")" { return expression; }
/* "Lexical" elements */
@ -394,6 +394,9 @@ DecimalDigit
HexDigit
= [0-9a-f]i
AnyMatcher
= "." { return { type: "any" }; }
CodeBlock "code block"
= "{" code:Code "}" { return code; }

Loading…
Cancel
Save