parser: report the depth cap at a token index, like every other error - #45
Merged
Conversation
A parser reports a failure position RELATIVE to the range it was given, and for the token parser that position is a token index -- the resolver maps it back to file:line:col on the way out. too_deep() stored `in.front().byte_offset` instead, so a byte count landed in the slot the resolver reads as a token index. Both shapes ran off the end of the file: 60 nested messages in a 121-line file reported 122:1, and an option value with 51 nested '[' reported 3:1 for a bracket on line 2. The rejection itself was always correct; only its position was wrong. The fix is 0, not a computed index: every caller checks the depth BEFORE consuming anything, so the offending token is its range's first, and the sequential combinators lift the offset as it propagates. That makes the input parameter unnecessary. The tests assert the rendered diagnostic, since the position is the whole point. The first pins no line number -- it cannot see the cap and should not encode it -- and instead requires two files of DIFFERENT depth to report the same line, which is what a byte offset or a mis-lifted index breaks, plus that the line is inside the file and opens a message. The second pins column 62 exactly: "option x = " is 11 characters, so the 51st bracket -- the first one over the cap of 50 -- sits there.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A parser reports a failure position RELATIVE to the range it was given, and for the token parser that position is a token index -- the resolver maps it back to file:line:col on the way out. too_deep() stored
in.front().byte_offsetinstead, so a byte count landed in the slot the resolver reads as a token index.Both shapes ran off the end of the file: 60 nested messages in a 121-line file reported 122:1, and an option value with 51 nested '[' reported 3:1 for a bracket on line 2. The rejection itself was always correct; only its position was wrong.
The fix is 0, not a computed index: every caller checks the depth BEFORE consuming anything, so the offending token is its range's first, and the sequential combinators lift the offset as it propagates. That makes the input parameter unnecessary.
The tests assert the rendered diagnostic, since the position is the whole point. The first pins no line number -- it cannot see the cap and should not encode it -- and instead requires two files of DIFFERENT depth to report the same line, which is what a byte offset or a mis-lifted index breaks, plus that the line is inside the file and opens a message. The second pins column 62 exactly: "option x = " is 11 characters, so the 51st bracket -- the first one over the cap of 50 -- sits there.