Skip to content

Commit b08ea1d

Browse files
committed
now gathering statistics for PEG rules (for autocomplete)
1 parent b6aad02 commit b08ea1d

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

Diff for: src/speg_visitor.js

+21-2
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,31 @@ SPEG_actions.prototype.parsing_body = function(node) {
3434

3535
SPEG_actions.prototype.parsing_rule = function(node) {
3636
var rule = node.children[4];
37+
var ruleName = node.children[0].match;
3738
return {
38-
name: node.children[0].match,
39+
name: ruleName,
3940
parser: function(state) {
41+
var start = state.position;
4042
var ast = rule(state);
4143
if (ast) {
42-
ast.rule = node.children[0].match;
44+
ast.rule = ruleName;
45+
if (!state.succesfullRules) {
46+
state.succesfullRules = [];
47+
}
48+
state.succesfullRules.push({
49+
rule: ast.rule,
50+
match: ast.match,
51+
start_position: ast.start_position,
52+
end_position: ast.end_position
53+
});
54+
} else {
55+
if (!state.failedRules) {
56+
state.failedRules = [];
57+
}
58+
state.failedRules.push({
59+
rule: ruleName,
60+
start_position: start
61+
});
4362
}
4463
return ast;
4564
}

0 commit comments

Comments
 (0)