|
|
|
@ -56,6 +56,24 @@ PEG.buildParser = function(grammar, startRule) {
|
|
|
|
|
/* Array manipulation utility functions. */
|
|
|
|
|
|
|
|
|
|
PEG.ArrayUtils = {
|
|
|
|
|
/*
|
|
|
|
|
* The code needs to be in sync with a code template in
|
|
|
|
|
* PEG.Grammar.Action.prototype.compile.
|
|
|
|
|
*/
|
|
|
|
|
contains: function(array, value) {
|
|
|
|
|
/*
|
|
|
|
|
* Stupid IE does not have Array.prototype.indexOf, otherwise this function
|
|
|
|
|
* would be a one-liner.
|
|
|
|
|
*/
|
|
|
|
|
var length = array.length;
|
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
|
|
|
if (array[i] === value) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
each: function(array, callback) {
|
|
|
|
|
var length = array.length;
|
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
|
|
@ -289,7 +307,7 @@ PEG.Grammar.extendNodes("checkNoLeftRecursion", {
|
|
|
|
|
|
|
|
|
|
RuleRef:
|
|
|
|
|
function(grammar, appliedRules) {
|
|
|
|
|
if (appliedRules.indexOf(this._name) !== -1) {
|
|
|
|
|
if (PEG.ArrayUtils.contains(appliedRules, this._name)) {
|
|
|
|
|
throw new PEG.Grammar.GrammarError("Left recursion detected for rule \"" + this._name + "\".");
|
|
|
|
|
}
|
|
|
|
|
grammar[this._name].checkNoLeftRecursion(grammar, appliedRules);
|
|
|
|
@ -443,13 +461,28 @@ PEG.Compiler = {
|
|
|
|
|
" + '\"';",
|
|
|
|
|
" },",
|
|
|
|
|
" ",
|
|
|
|
|
/* This needs to be in sync with PEG.ArrayUtils.contains. */
|
|
|
|
|
" _arrayContains: function(array, value) {",
|
|
|
|
|
" /*",
|
|
|
|
|
" * Stupid IE does not have Array.prototype.indexOf, otherwise this function",
|
|
|
|
|
" * would be a one-liner.",
|
|
|
|
|
" */",
|
|
|
|
|
" var length = array.length;",
|
|
|
|
|
" for (var i = 0; i < length; i++) {",
|
|
|
|
|
" if (array[i] === value) {",
|
|
|
|
|
" return true;",
|
|
|
|
|
" }",
|
|
|
|
|
" }",
|
|
|
|
|
" return false;",
|
|
|
|
|
" },",
|
|
|
|
|
" ",
|
|
|
|
|
" _matchFailed: function(failure) {",
|
|
|
|
|
" if (this._pos > this._rightmostMatchFailuresPos) {",
|
|
|
|
|
" this._rightmostMatchFailuresPos = this._pos;",
|
|
|
|
|
" this._rightmostMatchFailuresExpected = [];",
|
|
|
|
|
" }",
|
|
|
|
|
" ",
|
|
|
|
|
" if (this._rightmostMatchFailuresExpected.indexOf(failure) === -1) {",
|
|
|
|
|
" if (!this._arrayContains(this._rightmostMatchFailuresExpected, failure)) {",
|
|
|
|
|
" this._rightmostMatchFailuresExpected.push(failure);",
|
|
|
|
|
" }",
|
|
|
|
|
" },",
|
|
|
|
|