WIP: BREAKING CHANGE: Store byte offset in Error
instead of TextPos
.
#141
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.
This adds support for error handling scenarios where callers need the byte offset where an error occurred rather than the
TextPos
. SinceTextPos
is calculated from a byte offset (and the source string), the best way to provide support for both situations is to store the byte offset inError
and then supply an easy way for the caller to translate it into aTextPos
.FIX: Callers that want to continue displaying the
TextPos
(i.e. line/col) for an error will need to refactor their error handling code to create thatTextPos
by calling the newtext_pos
free function, passing the original XML string and the result fromError::pos()
(which is now ausize
instead of aTextPos
).Breakdown of changes:
TextPos
data inError
tousize
.Error
variants without position data to return0
frompos
method.Error
Display
strings, allowing the caller to provide position info in the manner of their choosing. Rephrase a few error strings where the position was in the middle of the string.Stream::gen_text_pos[_from]
andDocument::text_pos_at
into new lib-level free functiontext_pos
.text_pos_*
tests intokenizer_tests
to just test the newtext_pos
function. Move them to theapi
tests and renumber them to not conflict with the text pos tests already in that file.Token::Error
intokenizer_tests
so that expected error positions are still verified even though they're not included in theDisplay
strings anymore.ast
test function to concat error strings and theirTextPos
before comparing to the expected file/message.Questions:
ast
tests were the minimal needed to get them working without losing functionality. I suggest that it might be preferable to store the expected byte position separately from the message in the yaml file, but I'm not sure what the preferred way to do that would be.