fix(parser)!: track byte offsets instead of char counts in source locations#1144
fix(parser)!: track byte offsets instead of char counts in source locations#1144lu-zero wants to merge 1 commit into
Conversation
|
@reubeno not sure if it this alone warrants bumping to 0.5 but staying API-compatible would be more churn ... |
Public API changes for crate: brush-parserRemoved itemsAdded itemsPerformance Benchmark Report
Code Coverage Report: Only Changed Files listed
Minimum allowed coverage is Test Summary: bash-completion test suite
|
|
@lu-zero What do you think about changing the field name to reflect the meaning change? That seems like something we ought to do so that all downstream consumers are forced to reevaluate whether their logic is still correct. |
|
if you prefer we can, but the new release is already breaking enough that... |
…ations SourcePosition.offset now tracks byte offsets rather than UTF-8 character counts. Previously, any multi-byte character caused the reported index to drift by (len_utf8() - 1), breaking downstream consumers that use the index to slice the original source (diagnostics, syntax highlighting, LSP, etc.). SourcePosition.index is removed to force downstreams to be aware of the change. Closes reubeno#1127
|
using |
Sure. My main concern is avoiding a situation where the meaning of a field has changed but its name hasn't. Even if there are other breaking API changes, I'd want to lean on a compile break to at least give callers a chance to consider whether they need to change their logic. |
Summary
SourcePosition.indexnow tracks byte offsets rather than UTF-8 character counts, fixing off-by-one drift per multi-byte character that broke any downstream use of the index for source slicing (diagnostics, syntax highlighting, LSP, etc.)next_char()increments bych.len_utf8()instead of1, and the whitespace-skip branch does the sameSourcePosition,SourcePositionOffset, andSourceSpan::length()to reflect byte semanticsCloses #1127
Breaking change
SourcePosition.indexpreviously documented as a "character index" now returns a byte offset. Any downstream consumer relying on character-count semantics will need to adjust.