Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
aspizu opened this issue Jul 25, 2023 · 5 comments
Closed
Labels
Earley Issues regarding the Earley parser

Comments

@aspizu
Copy link
Contributor

aspizu commented Jul 25, 2023

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'
@MegaIng
Copy link
Member

MegaIng commented Jul 25, 2023

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

@aspizu
Copy link
Contributor Author

aspizu commented Jul 25, 2023

yes was using earley, this should be reported

@aspizu
Copy link
Contributor Author

aspizu commented Jul 25, 2023

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

@erezsh
Copy link
Member

erezsh commented Jul 25, 2023

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 erezsh added the Earley Issues regarding the Earley parser label Aug 23, 2023
erezsh added a commit that referenced this issue Sep 1, 2024
Better error in Lark.parse when using on_error when parser!=lalr (issue #1311)
@erezsh
Copy link
Member

erezsh commented Sep 1, 2024

Error is now fixed.

If anyone wants to suggest a PR to improve the API or make it more type-friendly, they are welcome to do so.

@erezsh erezsh closed this as completed Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Earley Issues regarding the Earley parser
Projects
None yet
Development

No branches or pull requests

3 participants