h0tk3y / better-parse

A nice parser combinator library for Kotlin
Apache License 2.0
421 stars 42 forks source link

Fix reported range when an optional parser is lifted to an AST parser #48

Closed Thomvis closed 3 years ago

Thomvis commented 3 years ago

The range added to the SyntaxTree for an optional parser that is skipped, is reported as 0..0, as per this logic. This will affect the reported range of parent parsers as well, e.g. if the optional parser is the first in an "and combinator", the reported range of the "and combinator" as a whole will start at 0. This PR changes the fallback behavior to an empty range starting at the current token's offset. I think it can be debated if this is fully correct, but I like it because it's pragmatic.

Thanks for considering this PR. Let me know if you have any comments or things I should improve!

h0tk3y commented 3 years ago

Thanks a lot @Thomvis!