Allow trailing semicolon (";") for rules

redux
David Majda 14 years ago
parent 7d4911ec53
commit 95735f2c97

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,
@ -136,17 +136,18 @@ nonBraceCharacters
nonBraceCharacter nonBraceCharacter
= [^{}] = [^{}]
equals = "=" __ { return "="; } equals = "=" __ { return "="; }
colon = ":" __ { return ":"; } colon = ":" __ { return ":"; }
slash = "/" __ { return "/"; } semicolon = ";" __ { return ";"; }
and = "&" __ { return "&"; } slash = "/" __ { return "/"; }
not = "!" __ { return "!"; } and = "&" __ { return "&"; }
question = "?" __ { return "?"; } not = "!" __ { return "!"; }
star = "*" __ { return "*"; } question = "?" __ { return "?"; }
plus = "+" __ { return "+"; } star = "*" __ { return "*"; }
lparen = "(" __ { return "("; } plus = "+" __ { return "+"; }
rparen = ")" __ { return ")"; } lparen = "(" __ { return "("; }
dot = "." __ { return "."; } rparen = ")" __ { return ")"; }
dot = "." __ { return "."; }
/* /*
* Modelled after ECMA-262, 5th ed., 7.6, but much simplified: * Modelled after ECMA-262, 5th ed., 7.6, but much simplified:

@ -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…
Cancel
Save