|
|
|
@ -38,6 +38,9 @@ PEG.buildParser = function(grammar, startRule) {
|
|
|
|
|
throw new PEG.Grammar.GrammarError("Grammar must be object or string.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (var key in ast) {
|
|
|
|
|
ast[key].checkReferencedRulesExist(ast);
|
|
|
|
|
}
|
|
|
|
|
if (ast[startRule] === undefined) {
|
|
|
|
|
throw new PEG.Grammar.GrammarError("Missing \"" + startRule + "\" rule.");
|
|
|
|
|
}
|
|
|
|
@ -97,6 +100,46 @@ PEG.Grammar.Action = function(expression, action) {
|
|
|
|
|
this._action = action;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* ===== Referenced Rule Existence Checks ===== */
|
|
|
|
|
|
|
|
|
|
PEG.Grammar.Rule.prototype.checkReferencedRulesExist = function(grammar) {
|
|
|
|
|
this._expression.checkReferencedRulesExist(grammar);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PEG.Grammar.Literal.prototype.checkReferencedRulesExist = function(grammar) {};
|
|
|
|
|
|
|
|
|
|
PEG.Grammar.Any.prototype.checkReferencedRulesExist = function(grammar) {};
|
|
|
|
|
|
|
|
|
|
PEG.Grammar.Sequence.prototype.checkReferencedRulesExist = function(grammar) {
|
|
|
|
|
PEG.ArrayUtils.each(this._elements, function(element) {
|
|
|
|
|
element.checkReferencedRulesExist(grammar);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PEG.Grammar.Choice.prototype.checkReferencedRulesExist = function(grammar) {
|
|
|
|
|
PEG.ArrayUtils.each(this._alternatives, function(alternative) {
|
|
|
|
|
alternative.checkReferencedRulesExist(grammar);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PEG.Grammar.ZeroOrMore.prototype.checkReferencedRulesExist = function(grammar) {
|
|
|
|
|
this._element.checkReferencedRulesExist(grammar);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PEG.Grammar.NotPredicate.prototype.checkReferencedRulesExist = function(grammar) {
|
|
|
|
|
this._expression.checkReferencedRulesExist(grammar);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PEG.Grammar.RuleRef.prototype.checkReferencedRulesExist = function(grammar) {
|
|
|
|
|
if (grammar[this._name] === undefined) {
|
|
|
|
|
throw new PEG.Grammar.GrammarError("Referenced rule \"" + this._name + "\" does not exist.");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PEG.Grammar.Action.prototype.checkReferencedRulesExist = function(grammar) {
|
|
|
|
|
this._expression.checkReferencedRulesExist(grammar);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* ===== PEG.Compiler ===== */
|
|
|
|
|
|
|
|
|
|
PEG.Compiler = {
|
|
|
|
|