Skip to content

Commit 1abc076

Browse files
committed
Make parser accessible in postprocessing rules
As first suggested here: #203
1 parent 6e24450 commit 1abc076

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/nearley.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@
6363
return children;
6464
};
6565

66-
State.prototype.finish = function() {
66+
State.prototype.finish = function(parser) {
6767
if (this.rule.postprocess) {
68-
this.data = this.rule.postprocess(this.data, this.reference, Parser.fail);
68+
this.data = this.rule.postprocess(this.data, this.reference, Parser.fail, parser);
6969
}
7070
};
7171

@@ -80,7 +80,7 @@
8080
}
8181

8282

83-
Column.prototype.process = function(nextColumn) {
83+
Column.prototype.process = function(parser) {
8484
var states = this.states;
8585
var wants = this.wants;
8686
var completed = this.completed;
@@ -89,7 +89,7 @@
8989
var state = states[w];
9090

9191
if (state.isComplete) {
92-
state.finish();
92+
state.finish(parser);
9393
if (state.data !== Parser.fail) {
9494
// complete
9595
var wantedBy = state.wantedBy;
@@ -269,7 +269,7 @@
269269
column.wants[grammar.start] = [];
270270
column.predict(grammar.start);
271271
// TODO what if start rule is nullable?
272-
column.process();
272+
column.process(this);
273273
this.current = 0; // token index
274274
}
275275

@@ -335,7 +335,7 @@
335335
// To prevent duplication, we also keep track of rules we have already
336336
// added
337337

338-
nextColumn.process();
338+
nextColumn.process(this);
339339

340340
// If needed, throw an error:
341341
if (nextColumn.states.length === 0) {

0 commit comments

Comments
 (0)