Allow trailing semicolon (";") for rules
This commit is contained in:
parent
7d4911ec53
commit
95735f2c97
2221
lib/metagrammar.js
2221
lib/metagrammar.js
File diff suppressed because it is too large
Load diff
|
@ -6,7 +6,7 @@ grammar
|
|||
}
|
||||
|
||||
rule
|
||||
= name:identifier displayName:(literal / "") equals expression:expression {
|
||||
= name:identifier displayName:(literal / "") equals expression:expression semicolon? {
|
||||
return {
|
||||
type: "rule",
|
||||
name: name,
|
||||
|
@ -136,17 +136,18 @@ nonBraceCharacters
|
|||
nonBraceCharacter
|
||||
= [^{}]
|
||||
|
||||
equals = "=" __ { return "="; }
|
||||
colon = ":" __ { return ":"; }
|
||||
slash = "/" __ { return "/"; }
|
||||
and = "&" __ { return "&"; }
|
||||
not = "!" __ { return "!"; }
|
||||
question = "?" __ { return "?"; }
|
||||
star = "*" __ { return "*"; }
|
||||
plus = "+" __ { return "+"; }
|
||||
lparen = "(" __ { return "("; }
|
||||
rparen = ")" __ { return ")"; }
|
||||
dot = "." __ { return "."; }
|
||||
equals = "=" __ { return "="; }
|
||||
colon = ":" __ { return ":"; }
|
||||
semicolon = ";" __ { return ";"; }
|
||||
slash = "/" __ { return "/"; }
|
||||
and = "&" __ { return "&"; }
|
||||
not = "!" __ { return "!"; }
|
||||
question = "?" __ { return "?"; }
|
||||
star = "*" __ { return "*"; }
|
||||
plus = "+" __ { return "+"; }
|
||||
lparen = "(" __ { return "("; }
|
||||
rparen = ")" __ { return ")"; }
|
||||
dot = "." __ { return "."; }
|
||||
|
||||
/*
|
||||
* Modelled after ECMA-262, 5th ed., 7.6, but much simplified:
|
||||
|
|
|
@ -240,7 +240,7 @@ test("buildParser reports left recursion", function() {
|
|||
'start = start { }',
|
||||
|
||||
/* Indirect */
|
||||
'start = stop\nstop = start'
|
||||
'start = stop; stop = start'
|
||||
];
|
||||
|
||||
PEG.ArrayUtils.each(grammars, function(grammar) {
|
||||
|
|
|
@ -144,11 +144,11 @@ function actionGrammar(action) {
|
|||
return oneRuleGrammar(action_(literal("a"), action));
|
||||
}
|
||||
|
||||
/* Canonical grammar is "a: \"abcd\";\nb: \"efgh\";\nc: \"ijkl\";". */
|
||||
/* Canonical grammar is "a: \"abcd\"; b: \"efgh\"; c: \"ijkl\";". */
|
||||
test("parses grammar", function() {
|
||||
grammarParserParses('a = "abcd"', { a: rule("a", null, literalAbcd) });
|
||||
grammarParserParses(
|
||||
'a = "abcd"\nb = "efgh"\nc = "ijkl"',
|
||||
'a = "abcd"; b = "efgh"; c = "ijkl"',
|
||||
{
|
||||
a: rule("a", null, literalAbcd),
|
||||
b: rule("b", null, literalEfgh),
|
||||
|
@ -169,6 +169,10 @@ test("parses rule", function() {
|
|||
start: rule("start", "start rule", choiceLiterals)
|
||||
}
|
||||
);
|
||||
grammarParserParses(
|
||||
'start = "abcd" / "efgh" / "ijkl";',
|
||||
oneRuleGrammar(choiceLiterals)
|
||||
);
|
||||
});
|
||||
|
||||
/* Canonical expression is "\"abcd\" / \"efgh\" / \"ijkl\"". */
|
||||
|
|
Loading…
Reference in a new issue