untwine icon indicating copy to clipboard operation
untwine copied to clipboard

Clarification on producing an “incomplete” AST for recoverable parsing

Open Germ210 opened this issue 2 months ago • 1 comments

I have a language here: https://github.com/Germ210/Crabstar/tree/main. The parser’s output implements recoverable, but I want high-quality errors, which requires a syntax tree even when the input is incomplete.

Is this possible in Untwine right now? If so, how? If not, will it be implemented?

Germ210 avatar Oct 25 '25 05:10 Germ210

Untwine can produce incomplete syntax trees, yes. Check out the JSON example, where the JSONValue type has an Error variant which will be inserted whenever there is an error that was recovered from. The Range indicates the position of the error. You shouldn't use untwine::parse or its variants for this if you want to recover the incomplete AST; instead construct a ParserContext and invoke the public parser function on it directly. You can take the output of that function call to get an AST, and you can use the methods on the ParserContext to inspect the errors.

boxbeam avatar Oct 25 '25 12:10 boxbeam