Skip to content

Commit

Permalink
Action AST node no longer accepts functions as actions (only strings).
Browse files Browse the repository at this point in the history
  • Loading branch information
dmajda committed Apr 21, 2010
1 parent b2f230f commit a1dcd24
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions lib/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -993,23 +993,19 @@ PEG.Grammar.RuleRef.prototype.compile = function(resultVar) {
PEG.Grammar.Action.prototype.compile = function(resultVar) {
var expressionResultVar = PEG.Compiler.generateUniqueIdentifier("result");

if (typeof(this._action) === "function") {
var actionFunction = this._action.toString();
} else {
var actionCode = this._action.replace(
/\$(\d+)/g,
function(match, digits) {
return PEG.Compiler.formatCode(
"(arguments[${index}])",
{ index: parseInt(digits) - 1 }
);
}
)
var actionFunction = PEG.Compiler.formatCode(
"function() { ${actionCode} }",
{ actionCode: actionCode }
);
}
var actionCode = this._action.replace(
/\$(\d+)/g,
function(match, digits) {
return PEG.Compiler.formatCode(
"(arguments[${index}])",
{ index: parseInt(digits) - 1 }
);
}
)
var actionFunction = PEG.Compiler.formatCode(
"function() { ${actionCode} }",
{ actionCode: actionCode }
);

/*
* In case of sequences, we splat their elements into function arguments one
Expand Down

0 comments on commit a1dcd24

Please sign in to comment.