From 5942988f66ce79d4784348831b9fb0105ca0e5bf Mon Sep 17 00:00:00 2001 From: David Majda Date: Sun, 6 Jan 2013 10:21:12 +0100 Subject: [PATCH] Remove the |startRule| property from the AST It's redundant. --- lib/compiler/passes/generate-javascript.js | 2 +- lib/compiler/passes/remove-proxy-rules.js | 2 +- lib/parser.js | 3 +-- spec/parser.spec.js | 12 ++++-------- src/parser.pegjs | 3 +-- 5 files changed, 8 insertions(+), 14 deletions(-) diff --git a/lib/compiler/passes/generate-javascript.js b/lib/compiler/passes/generate-javascript.js index 719c93b..1784db2 100644 --- a/lib/compiler/passes/generate-javascript.js +++ b/lib/compiler/passes/generate-javascript.js @@ -6,7 +6,7 @@ module.exports = function(ast, options) { options = utils.clone(options); utils.defaults(options, { cache: false, - allowedStartRules: [ast.startRule], + allowedStartRules: [ast.rules[0].name], optimize: "speed" }); diff --git a/lib/compiler/passes/remove-proxy-rules.js b/lib/compiler/passes/remove-proxy-rules.js index 6c59570..9b4d629 100644 --- a/lib/compiler/passes/remove-proxy-rules.js +++ b/lib/compiler/passes/remove-proxy-rules.js @@ -58,7 +58,7 @@ module.exports = function(ast, options) { var indices = [], allowedStartRules = options.allowedStartRules !== undefined ? options.allowedStartRules - : [ast.startRule]; + : [ast.rules[0].name]; utils.each(ast.rules, function(rule, i) { if (isProxyRule(rule)) { diff --git a/lib/parser.js b/lib/parser.js index 8427ad3..d8ad3b5 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -77,8 +77,7 @@ module.exports = (function() { return { type: "grammar", initializer: initializer !== "" ? initializer : null, - rules: rules, - startRule: rules[0].name + rules: rules }; }, peg$c4 = function(code) { diff --git a/spec/parser.spec.js b/spec/parser.spec.js index b6b908a..4c5570f 100644 --- a/spec/parser.spec.js +++ b/spec/parser.spec.js @@ -34,8 +34,7 @@ describe("PEG.js grammar parser", function() { name: "start", expression: expression } - ], - startRule: "start" + ] }; } @@ -170,20 +169,17 @@ describe("PEG.js grammar parser", function() { expect('a = "abcd"').toParseAs({ type: "grammar", initializer: null, - rules: [ruleA], - startRule: "a" + rules: [ruleA] }); expect('{ code } a = "abcd"').toParseAs({ type: "grammar", initializer: { type: "initializer", code: " code " }, - rules: [ruleA], - startRule: "a" + rules: [ruleA] }); expect('a = "abcd"; b = "efgh"; c = "ijkl"').toParseAs({ type: "grammar", initializer: null, - rules: [ruleA, ruleB, ruleC], - startRule: "a" + rules: [ruleA, ruleB, ruleC] }); }); diff --git a/src/parser.pegjs b/src/parser.pegjs index 39ed65a..dba4f37 100644 --- a/src/parser.pegjs +++ b/src/parser.pegjs @@ -7,8 +7,7 @@ grammar return { type: "grammar", initializer: initializer !== "" ? initializer : null, - rules: rules, - startRule: rules[0].name + rules: rules }; }