Skip to content

Commit

Permalink
now gathering statistics for PEG rules (for autocomplete)
Browse files Browse the repository at this point in the history
  • Loading branch information
obenjiro committed Jan 25, 2017
1 parent b6aad02 commit b08ea1d
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/speg_visitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,31 @@ SPEG_actions.prototype.parsing_body = function(node) {

SPEG_actions.prototype.parsing_rule = function(node) {
var rule = node.children[4];
var ruleName = node.children[0].match;
return {
name: node.children[0].match,
name: ruleName,
parser: function(state) {
var start = state.position;
var ast = rule(state);
if (ast) {
ast.rule = node.children[0].match;
ast.rule = ruleName;
if (!state.succesfullRules) {
state.succesfullRules = [];
}
state.succesfullRules.push({
rule: ast.rule,
match: ast.match,
start_position: ast.start_position,
end_position: ast.end_position
});
} else {
if (!state.failedRules) {
state.failedRules = [];
}
state.failedRules.push({
rule: ruleName,
start_position: start
});
}
return ast;
}
Expand Down

0 comments on commit b08ea1d

Please sign in to comment.