lark icon indicating copy to clipboard operation
lark copied to clipboard

TypeError: Parser.parse() got an unexpected keyword argument 'on_error'

Open aspizu opened this issue 2 years ago • 4 comments

ERROR:root:parser raised exception
Traceback (most recent call last):
  File "/home/aspizu/Projects/goboscript-lsp/goboscript-lsp/diag.py", line 32, in get_diagnostics
    parser.parse(doctext, on_error=on_error)
  File "/usr/lib/python3.11/site-packages/lark/lark.py", line 645, in parse
    return self.parser.parse(text, start=start, on_error=on_error)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/lark/parser_frontends.py", line 96, in parse
    return self.parser.parse(stream, chosen_start, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Parser.parse() got an unexpected keyword argument 'on_error'

aspizu avatar Jul 25 '23 08:07 aspizu

on_error is only supported for parser='lalr'. Can you provide an actual reproducer script please?

MegaIng avatar Jul 25 '23 10:07 MegaIng

yes was using earley, this should be reported

aspizu avatar Jul 25 '23 11:07 aspizu

another suggestion is that instead of a string definiing what parser to use just impor the parser class and pass it to Lark so you can use typing to convey that earley doesnt support on_error

aspizu avatar Jul 25 '23 11:07 aspizu

I agree, a better error is warranted.

If we want to be type-friendly, we can define different interfaces for each parser, and use @overload to return the correct one based on the parser name (using Literal etc.).

erezsh avatar Jul 25 '23 11:07 erezsh