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

Misreported range in SyntaxTree for optional parser #47

Closed
Thomvis opened this issue Oct 22, 2021 · 1 comment
Closed

Misreported range in SyntaxTree for optional parser #47

Thomvis opened this issue Oct 22, 2021 · 1 comment

Comments

@Thomvis
Copy link
Contributor

Thomvis commented Oct 22, 2021

When an optional parser parses nothing, it's range becomes 0..0, because of the fallback here. This error will bubble up, e.g. when the optional is inside an "and" parser.

Example:

val integerExpression by (optional(MINUS) * INT)

If there is no - to parse, the start of the range of the SyntaxTree corresponding to a match of integerExpression will always start at 0, regardless of where the match happens. So if the input where Hello World! 5 (and imagine integerExpression is part of a larger parser that can also parse words), the actual range would be 0..14, while the expected range would be 13..14.

Do you have any pointers how this could be best resolved?

@h0tk3y
Copy link
Owner

h0tk3y commented Nov 1, 2021

Thanks for the report and the PR! I've merged it, so closing the issue now.

@h0tk3y h0tk3y closed this as completed Nov 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants