diff --git a/lib/compiler.js b/lib/compiler.js index 0800727..44c794d 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -182,43 +182,71 @@ PEG.Grammar.GrammarError.prototype = Error.prototype; /* ===== PEG.Grammar.* ===== */ PEG.Grammar.Rule = function(name, displayName, expression) { + this.type = "rule"; this.name = name; this.displayName = displayName; this.expression = expression; }; PEG.Grammar.Choice = function(alternatives) { + this.type = "choice"; this.alternatives = alternatives; }; -PEG.Grammar.Sequence = function(elements) { this.elements = elements; }; +PEG.Grammar.Sequence = function(elements) { + this.type = "sequence"; + this.elements = elements; +}; PEG.Grammar.AndPredicate = function(expression) { + this.type = "and_predicate"; this.expression = expression; }; PEG.Grammar.NotPredicate = function(expression) { + this.type = "not_predicate"; this.expression = expression; }; -PEG.Grammar.Optional = function(expression) { this.expression = expression; }; +PEG.Grammar.Optional = function(expression) { + this.type = "optional"; + this.expression = expression; +}; -PEG.Grammar.ZeroOrMore = function(expression) { this.expression = expression; }; +PEG.Grammar.ZeroOrMore = function(expression) { + this.type = "zero_or_more"; + this.expression = expression; +}; -PEG.Grammar.OneOrMore = function(expression) { this.expression = expression; }; +PEG.Grammar.OneOrMore = function(expression) { + this.type = "one_or_more"; + this.expression = expression; +}; PEG.Grammar.Action = function(expression, action) { + this.type = "action"; this.expression = expression; this.action = action; }; -PEG.Grammar.RuleRef = function(name) { this.name = name; }; +PEG.Grammar.RuleRef = function(name) { + this.type = "rule_ref"; + this.name = name; +}; -PEG.Grammar.Literal = function(value) { this.value = value; }; +PEG.Grammar.Literal = function(value) { + this.type = "literal"; + this.value = value; +}; -PEG.Grammar.Any = function() {}; +PEG.Grammar.Any = function() { + this.type = "any"; +}; -PEG.Grammar.Class = function(characters) { this.characters = characters; }; +PEG.Grammar.Class = function(characters) { + this.type = "class"; + this.characters = characters; +}; /* ===== Referenced Rule Existence Checks ===== */ @@ -967,7 +995,7 @@ PEG.Grammar.Action.prototype.compile = function(resultVar) { var expressionResultVar = PEG.Compiler.generateUniqueIdentifier("result"); - if (this.expression instanceof PEG.Grammar.Sequence) { + if (this.expression.type === "sequence") { var params = PEG.ArrayUtils.map( PEG.ArrayUtils.range(1, this.expression.elements.length + 1), function(n) { return "$" + n; }