Rename |_element| to |_expression| in AST
All nodes which have one subexpression store it in the |_expression| property now.
This commit is contained in:
parent
7d1261c0fc
commit
f28c52fde2
|
@ -216,11 +216,11 @@ PEG.Grammar.Choice = function(alternatives) {
|
||||||
this._alternatives = alternatives;
|
this._alternatives = alternatives;
|
||||||
};
|
};
|
||||||
|
|
||||||
PEG.Grammar.Optional = function(element) { this._element = element; };
|
PEG.Grammar.Optional = function(expression) { this._expression = expression; };
|
||||||
|
|
||||||
PEG.Grammar.ZeroOrMore = function(element) { this._element = element; };
|
PEG.Grammar.ZeroOrMore = function(expression) { this._expression = expression; };
|
||||||
|
|
||||||
PEG.Grammar.OneOrMore = function(element) { this._element = element; };
|
PEG.Grammar.OneOrMore = function(expression) { this._expression = expression; };
|
||||||
|
|
||||||
PEG.Grammar.AndPredicate = function(expression) {
|
PEG.Grammar.AndPredicate = function(expression) {
|
||||||
this._expression = expression;
|
this._expression = expression;
|
||||||
|
@ -264,13 +264,13 @@ PEG.Grammar.extendNodes("checkReferencedRulesExist", {
|
||||||
},
|
},
|
||||||
|
|
||||||
Optional:
|
Optional:
|
||||||
function(grammar) { this._element.checkReferencedRulesExist(grammar); },
|
function(grammar) { this._expression.checkReferencedRulesExist(grammar); },
|
||||||
|
|
||||||
ZeroOrMore:
|
ZeroOrMore:
|
||||||
function(grammar) { this._element.checkReferencedRulesExist(grammar); },
|
function(grammar) { this._expression.checkReferencedRulesExist(grammar); },
|
||||||
|
|
||||||
OneOrMore:
|
OneOrMore:
|
||||||
function(grammar) { this._element.checkReferencedRulesExist(grammar); },
|
function(grammar) { this._expression.checkReferencedRulesExist(grammar); },
|
||||||
|
|
||||||
AndPredicate:
|
AndPredicate:
|
||||||
function(grammar) { this._expression.checkReferencedRulesExist(grammar); },
|
function(grammar) { this._expression.checkReferencedRulesExist(grammar); },
|
||||||
|
@ -320,17 +320,17 @@ PEG.Grammar.extendNodes("checkNoLeftRecursion", {
|
||||||
|
|
||||||
Optional:
|
Optional:
|
||||||
function(grammar, appliedRules) {
|
function(grammar, appliedRules) {
|
||||||
this._element.checkNoLeftRecursion(grammar, appliedRules);
|
this._expression.checkNoLeftRecursion(grammar, appliedRules);
|
||||||
},
|
},
|
||||||
|
|
||||||
ZeroOrMore:
|
ZeroOrMore:
|
||||||
function(grammar, appliedRules) {
|
function(grammar, appliedRules) {
|
||||||
this._element.checkNoLeftRecursion(grammar, appliedRules);
|
this._expression.checkNoLeftRecursion(grammar, appliedRules);
|
||||||
},
|
},
|
||||||
|
|
||||||
OneOrMore:
|
OneOrMore:
|
||||||
function(grammar, appliedRules) {
|
function(grammar, appliedRules) {
|
||||||
this._element.checkNoLeftRecursion(grammar, appliedRules);
|
this._expression.checkNoLeftRecursion(grammar, appliedRules);
|
||||||
},
|
},
|
||||||
|
|
||||||
AndPredicate:
|
AndPredicate:
|
||||||
|
@ -891,55 +891,55 @@ PEG.Grammar.Choice.prototype.compile = function(resultVar) {
|
||||||
};
|
};
|
||||||
|
|
||||||
PEG.Grammar.Optional.prototype.compile = function(resultVar) {
|
PEG.Grammar.Optional.prototype.compile = function(resultVar) {
|
||||||
var elementResultVar = PEG.Compiler.generateUniqueIdentifier("result");
|
var expressionResultVar = PEG.Compiler.generateUniqueIdentifier("result");
|
||||||
|
|
||||||
return PEG.Compiler.formatCode(
|
return PEG.Compiler.formatCode(
|
||||||
"${elementCode}",
|
"${expressionCode}",
|
||||||
"var ${resultVar} = ${elementResultVar} !== null ? ${elementResultVar} : '';",
|
"var ${resultVar} = ${expressionResultVar} !== null ? ${expressionResultVar} : '';",
|
||||||
{
|
{
|
||||||
elementCode: this._element.compile(elementResultVar),
|
expressionCode: this._expression.compile(expressionResultVar),
|
||||||
elementResultVar: elementResultVar,
|
expressionResultVar: expressionResultVar,
|
||||||
resultVar: resultVar
|
resultVar: resultVar
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
PEG.Grammar.ZeroOrMore.prototype.compile = function(resultVar) {
|
PEG.Grammar.ZeroOrMore.prototype.compile = function(resultVar) {
|
||||||
var elementResultVar = PEG.Compiler.generateUniqueIdentifier("result");
|
var expressionResultVar = PEG.Compiler.generateUniqueIdentifier("result");
|
||||||
|
|
||||||
return PEG.Compiler.formatCode(
|
return PEG.Compiler.formatCode(
|
||||||
"var ${resultVar} = [];",
|
"var ${resultVar} = [];",
|
||||||
"${elementCode}",
|
"${expressionCode}",
|
||||||
"while (${elementResultVar} !== null) {",
|
"while (${expressionResultVar} !== null) {",
|
||||||
" ${resultVar}.push(${elementResultVar});",
|
" ${resultVar}.push(${expressionResultVar});",
|
||||||
" ${elementCode}",
|
" ${expressionCode}",
|
||||||
"}",
|
"}",
|
||||||
{
|
{
|
||||||
elementCode: this._element.compile(elementResultVar),
|
expressionCode: this._expression.compile(expressionResultVar),
|
||||||
elementResultVar: elementResultVar,
|
expressionResultVar: expressionResultVar,
|
||||||
resultVar: resultVar
|
resultVar: resultVar
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
PEG.Grammar.OneOrMore.prototype.compile = function(resultVar) {
|
PEG.Grammar.OneOrMore.prototype.compile = function(resultVar) {
|
||||||
var elementResultVar = PEG.Compiler.generateUniqueIdentifier("result");
|
var expressionResultVar = PEG.Compiler.generateUniqueIdentifier("result");
|
||||||
|
|
||||||
return PEG.Compiler.formatCode(
|
return PEG.Compiler.formatCode(
|
||||||
"${elementCode}",
|
"${expressionCode}",
|
||||||
"if (${elementResultVar} !== null) {",
|
"if (${expressionResultVar} !== null) {",
|
||||||
" var ${resultVar} = [];",
|
" var ${resultVar} = [];",
|
||||||
" while (${elementResultVar} !== null) {",
|
" while (${expressionResultVar} !== null) {",
|
||||||
" ${resultVar}.push(${elementResultVar});",
|
" ${resultVar}.push(${expressionResultVar});",
|
||||||
" ${elementCode}",
|
" ${expressionCode}",
|
||||||
" }",
|
" }",
|
||||||
"} else {",
|
"} else {",
|
||||||
" var ${resultVar} = null;",
|
" var ${resultVar} = null;",
|
||||||
"}",
|
"}",
|
||||||
{
|
{
|
||||||
elementCode: this._element.compile(elementResultVar),
|
expressionCode: this._expression.compile(expressionResultVar),
|
||||||
elementResultVar: elementResultVar,
|
expressionResultVar: expressionResultVar,
|
||||||
resultVar: resultVar
|
resultVar: resultVar
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue