Skip to content

Commit

Permalink
reinitialize ast after parse error; fixes #9
Browse files Browse the repository at this point in the history
  • Loading branch information
dchester committed Nov 21, 2015
1 parent d5722d2 commit 265773c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ var gparser = require('../generated/parser');
var Parser = function() {

var parser = new gparser.Parser();

var _parseError = parser.parseError;
parser.yy.parseError = function() {
parser.yy.ast.initialize();
_parseError.apply(parser, arguments);
}

return parser;

};
Expand Down
9 changes: 9 additions & 0 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ suite('parse', function() {
])
});

test('parser ast is reinitialized after parse() throws', function() {
assert.throws(function() { var path = jp.parse('store.book...') })
var path = jp.parse('$..price');
assert.deepEqual(path, [
{ "expression": { "type": "root", "value": "$" } },
{ "expression": { "type": "identifier", "value": "price" }, "operation": "member", "scope": "descendant"}
])
});

});

suite('parse-negative', function() {
Expand Down

0 comments on commit 265773c

Please sign in to comment.