Skip to content

Commit a40a2ae

Browse files
committed
Making state open to access
1 parent 3d903cd commit a40a2ae

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Diff for: src/speg.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ function SPEG() {
77
this.parser = new SPEG_parser();
88
this.visitor = new SPEG_actions_visitor();
99
this.speg_parser = null;
10+
this.state = null;
1011
}
1112

1213
SPEG.prototype.parse_grammar = function(grammar) {
@@ -24,12 +25,12 @@ SPEG.prototype.parse_text = function(text) {
2425
var rules = this.speg_parser.children;
2526
var first_rule = rules[0];
2627
var first_rule_parser = first_rule.parser;
27-
var state = { text: text, position: 0, rules: rules };
28-
var ast = first_rule_parser(state);
28+
this.state = { text: text, position: 0, rules: rules };
29+
var ast = first_rule_parser(this.state);
2930
if (ast) {
3031
return ast;
3132
} else {
32-
throw new ex.TextParseError('Failed to parse text: \n\n' + rd.get_last_error(state))
33+
throw new ex.TextParseError('Failed to parse text: \n\n' + rd.get_last_error(this.state))
3334
}
3435
} else {
3536
throw Error('You need grammar to parse text. Call parseGrammar first');
@@ -43,12 +44,12 @@ SPEG.prototype.parse = function(grammar, text) {
4344
var rules = generated_parser.children;
4445
var first_rule = rules[0];
4546
var first_rule_parser = first_rule.parser;
46-
var state = { text: text, position: 0, rules: rules };
47-
var ast = first_rule_parser(state);
47+
this.state = { text: text, position: 0, rules: rules };
48+
var ast = first_rule_parser(this.state);
4849
if (ast) {
4950
return ast;
5051
} else {
51-
throw new ex.TextParseError('Failed to parse text: \n\n' + rd.get_last_error(state))
52+
throw new ex.TextParseError('Failed to parse text: \n\n' + rd.get_last_error(this.state))
5253
}
5354
} else {
5455
throw new ex.GrammarParseError('Failed to parse grammar: \n\n' + this.parser.get_last_error())

0 commit comments

Comments
 (0)