Allow trailing semicolon (";") for rules
This commit is contained in:
parent
7d4911ec53
commit
95735f2c97
2373
lib/metagrammar.js
2373
lib/metagrammar.js
File diff suppressed because it is too large
Load diff
|
@ -6,7 +6,7 @@ grammar
|
||||||
}
|
}
|
||||||
|
|
||||||
rule
|
rule
|
||||||
= name:identifier displayName:(literal / "") equals expression:expression {
|
= name:identifier displayName:(literal / "") equals expression:expression semicolon? {
|
||||||
return {
|
return {
|
||||||
type: "rule",
|
type: "rule",
|
||||||
name: name,
|
name: name,
|
||||||
|
@ -138,6 +138,7 @@ nonBraceCharacter
|
||||||
|
|
||||||
equals = "=" __ { return "="; }
|
equals = "=" __ { return "="; }
|
||||||
colon = ":" __ { return ":"; }
|
colon = ":" __ { return ":"; }
|
||||||
|
semicolon = ";" __ { return ";"; }
|
||||||
slash = "/" __ { return "/"; }
|
slash = "/" __ { return "/"; }
|
||||||
and = "&" __ { return "&"; }
|
and = "&" __ { return "&"; }
|
||||||
not = "!" __ { return "!"; }
|
not = "!" __ { return "!"; }
|
||||||
|
|
|
@ -240,7 +240,7 @@ test("buildParser reports left recursion", function() {
|
||||||
'start = start { }',
|
'start = start { }',
|
||||||
|
|
||||||
/* Indirect */
|
/* Indirect */
|
||||||
'start = stop\nstop = start'
|
'start = stop; stop = start'
|
||||||
];
|
];
|
||||||
|
|
||||||
PEG.ArrayUtils.each(grammars, function(grammar) {
|
PEG.ArrayUtils.each(grammars, function(grammar) {
|
||||||
|
|
|
@ -144,11 +144,11 @@ function actionGrammar(action) {
|
||||||
return oneRuleGrammar(action_(literal("a"), 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() {
|
test("parses grammar", function() {
|
||||||
grammarParserParses('a = "abcd"', { a: rule("a", null, literalAbcd) });
|
grammarParserParses('a = "abcd"', { a: rule("a", null, literalAbcd) });
|
||||||
grammarParserParses(
|
grammarParserParses(
|
||||||
'a = "abcd"\nb = "efgh"\nc = "ijkl"',
|
'a = "abcd"; b = "efgh"; c = "ijkl"',
|
||||||
{
|
{
|
||||||
a: rule("a", null, literalAbcd),
|
a: rule("a", null, literalAbcd),
|
||||||
b: rule("b", null, literalEfgh),
|
b: rule("b", null, literalEfgh),
|
||||||
|
@ -169,6 +169,10 @@ test("parses rule", function() {
|
||||||
start: rule("start", "start rule", choiceLiterals)
|
start: rule("start", "start rule", choiceLiterals)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
grammarParserParses(
|
||||||
|
'start = "abcd" / "efgh" / "ijkl";',
|
||||||
|
oneRuleGrammar(choiceLiterals)
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
/* Canonical expression is "\"abcd\" / \"efgh\" / \"ijkl\"". */
|
/* Canonical expression is "\"abcd\" / \"efgh\" / \"ijkl\"". */
|
||||||
|
|
Loading…
Reference in a new issue