Rename |_element| to |_expression| in AST

All nodes which have one subexpression store it in the |_expression| property
now.
redux
David Majda 15 years ago
parent 7d1261c0fc
commit f28c52fde2

@ -216,11 +216,11 @@ PEG.Grammar.Choice = function(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) {
this._expression = expression;
@ -264,13 +264,13 @@ PEG.Grammar.extendNodes("checkReferencedRulesExist", {
},
Optional:
function(grammar) { this._element.checkReferencedRulesExist(grammar); },
function(grammar) { this._expression.checkReferencedRulesExist(grammar); },
ZeroOrMore:
function(grammar) { this._element.checkReferencedRulesExist(grammar); },
function(grammar) { this._expression.checkReferencedRulesExist(grammar); },
OneOrMore:
function(grammar) { this._element.checkReferencedRulesExist(grammar); },
function(grammar) { this._expression.checkReferencedRulesExist(grammar); },
AndPredicate:
function(grammar) { this._expression.checkReferencedRulesExist(grammar); },
@ -320,17 +320,17 @@ PEG.Grammar.extendNodes("checkNoLeftRecursion", {
Optional:
function(grammar, appliedRules) {
this._element.checkNoLeftRecursion(grammar, appliedRules);
this._expression.checkNoLeftRecursion(grammar, appliedRules);
},
ZeroOrMore:
function(grammar, appliedRules) {
this._element.checkNoLeftRecursion(grammar, appliedRules);
this._expression.checkNoLeftRecursion(grammar, appliedRules);
},
OneOrMore:
function(grammar, appliedRules) {
this._element.checkNoLeftRecursion(grammar, appliedRules);
this._expression.checkNoLeftRecursion(grammar, appliedRules);
},
AndPredicate:
@ -891,55 +891,55 @@ PEG.Grammar.Choice.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(
"${elementCode}",
"var ${resultVar} = ${elementResultVar} !== null ? ${elementResultVar} : '';",
"${expressionCode}",
"var ${resultVar} = ${expressionResultVar} !== null ? ${expressionResultVar} : '';",
{
elementCode: this._element.compile(elementResultVar),
elementResultVar: elementResultVar,
resultVar: resultVar
expressionCode: this._expression.compile(expressionResultVar),
expressionResultVar: expressionResultVar,
resultVar: resultVar
}
);
};
PEG.Grammar.ZeroOrMore.prototype.compile = function(resultVar) {
var elementResultVar = PEG.Compiler.generateUniqueIdentifier("result");
var expressionResultVar = PEG.Compiler.generateUniqueIdentifier("result");
return PEG.Compiler.formatCode(
"var ${resultVar} = [];",
"${elementCode}",
"while (${elementResultVar} !== null) {",
" ${resultVar}.push(${elementResultVar});",
" ${elementCode}",
"${expressionCode}",
"while (${expressionResultVar} !== null) {",
" ${resultVar}.push(${expressionResultVar});",
" ${expressionCode}",
"}",
{
elementCode: this._element.compile(elementResultVar),
elementResultVar: elementResultVar,
resultVar: resultVar
expressionCode: this._expression.compile(expressionResultVar),
expressionResultVar: expressionResultVar,
resultVar: resultVar
}
);
};
PEG.Grammar.OneOrMore.prototype.compile = function(resultVar) {
var elementResultVar = PEG.Compiler.generateUniqueIdentifier("result");
var expressionResultVar = PEG.Compiler.generateUniqueIdentifier("result");
return PEG.Compiler.formatCode(
"${elementCode}",
"if (${elementResultVar} !== null) {",
"${expressionCode}",
"if (${expressionResultVar} !== null) {",
" var ${resultVar} = [];",
" while (${elementResultVar} !== null) {",
" ${resultVar}.push(${elementResultVar});",
" ${elementCode}",
" while (${expressionResultVar} !== null) {",
" ${resultVar}.push(${expressionResultVar});",
" ${expressionCode}",
" }",
"} else {",
" var ${resultVar} = null;",
"}",
{
elementCode: this._element.compile(elementResultVar),
elementResultVar: elementResultVar,
resultVar: resultVar
expressionCode: this._expression.compile(expressionResultVar),
expressionResultVar: expressionResultVar,
resultVar: resultVar
}
);
};

Loading…
Cancel
Save