lark-parser / lark

Lark is a parsing toolkit for Python, built with a focus on ergonomics, performance and modularity.
MIT License
4.75k stars 401 forks source link

How to turn "RBRACE", "__ANON_n" into "{"? #1316

Closed aspizu closed 10 months ago

aspizu commented 1 year ago

I want to get the value of the terminal from UnexpectedInput errors.

erezsh commented 1 year ago

I think you mean UnexpectedToken. Did you try e.token.value?

aspizu commented 1 year ago
if isinstance(err, UnexpectedCharacters):
    expected = ", ".join(err.allowed)
    return Diagnostic(
        range,
        f"Expected one of: {expected}",
        DiagnosticSeverity.Error,
        "UnexpectedCharacters",
    )

err.allowed is Set[str]

I want to get the string which was defined in the grammar file from this list.

erezsh commented 1 year ago

Did you try lark_instance.terminals ?