Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lark/lark.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,8 @@ def parse(self, text: str, start: Optional[str]=None, on_error: 'Optional[Callab
For convenience, these sub-exceptions also inherit from ``ParserError`` and ``LexerError``.

"""
if on_error is not None and self.options.parser != 'lalr':
raise NotImplementedError("The on_error option is only implemented for the LALR(1) parser.")
return self.parser.parse(text, start=start, on_error=on_error)


Expand Down
5 changes: 5 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2584,6 +2584,11 @@ def ignore_errors(e):
s = "[0 1, 2,@, 3,,, 4, 5 6 ]$"
tree = g.parse(s, on_error=ignore_errors)

@unittest.skipIf(PARSER == 'lalr', "test on_error only works with lalr")
def test_on_error_without_lalr(self):
p = _Lark(r"""start: "A" """)
self.assertRaises(NotImplementedError, p.parse, "", on_error=print)

@unittest.skipIf(PARSER != 'lalr', "interactive_parser error handling only works with LALR for now")
def test_iter_parse(self):
ab_grammar = '!start: "a"* "b"*'
Expand Down