Remove the |startRule| property from the AST

It's redundant.
redux
David Majda 11 years ago
parent 3981433984
commit 5942988f66

@ -6,7 +6,7 @@ module.exports = function(ast, options) {
options = utils.clone(options); options = utils.clone(options);
utils.defaults(options, { utils.defaults(options, {
cache: false, cache: false,
allowedStartRules: [ast.startRule], allowedStartRules: [ast.rules[0].name],
optimize: "speed" optimize: "speed"
}); });

@ -58,7 +58,7 @@ module.exports = function(ast, options) {
var indices = [], var indices = [],
allowedStartRules = options.allowedStartRules !== undefined allowedStartRules = options.allowedStartRules !== undefined
? options.allowedStartRules ? options.allowedStartRules
: [ast.startRule]; : [ast.rules[0].name];
utils.each(ast.rules, function(rule, i) { utils.each(ast.rules, function(rule, i) {
if (isProxyRule(rule)) { if (isProxyRule(rule)) {

@ -77,8 +77,7 @@ module.exports = (function() {
return { return {
type: "grammar", type: "grammar",
initializer: initializer !== "" ? initializer : null, initializer: initializer !== "" ? initializer : null,
rules: rules, rules: rules
startRule: rules[0].name
}; };
}, },
peg$c4 = function(code) { peg$c4 = function(code) {

@ -34,8 +34,7 @@ describe("PEG.js grammar parser", function() {
name: "start", name: "start",
expression: expression expression: expression
} }
], ]
startRule: "start"
}; };
} }
@ -170,20 +169,17 @@ describe("PEG.js grammar parser", function() {
expect('a = "abcd"').toParseAs({ expect('a = "abcd"').toParseAs({
type: "grammar", type: "grammar",
initializer: null, initializer: null,
rules: [ruleA], rules: [ruleA]
startRule: "a"
}); });
expect('{ code } a = "abcd"').toParseAs({ expect('{ code } a = "abcd"').toParseAs({
type: "grammar", type: "grammar",
initializer: { type: "initializer", code: " code " }, initializer: { type: "initializer", code: " code " },
rules: [ruleA], rules: [ruleA]
startRule: "a"
}); });
expect('a = "abcd"; b = "efgh"; c = "ijkl"').toParseAs({ expect('a = "abcd"; b = "efgh"; c = "ijkl"').toParseAs({
type: "grammar", type: "grammar",
initializer: null, initializer: null,
rules: [ruleA, ruleB, ruleC], rules: [ruleA, ruleB, ruleC]
startRule: "a"
}); });
}); });

@ -7,8 +7,7 @@ grammar
return { return {
type: "grammar", type: "grammar",
initializer: initializer !== "" ? initializer : null, initializer: initializer !== "" ? initializer : null,
rules: rules, rules: rules
startRule: rules[0].name
}; };
} }

Loading…
Cancel
Save