Fix: Parse slice range indexing (e.g. buffer[..n], buffer[..=n]) - #201
Draft
jaybosamiya-ms with Copilot wants to merge 2 commits into
Draft
jaybosamiya-ms with Copilot wants to merge 2 commits into
jaybosamiya-ms with Copilot wants to merge 2 commits into
Conversation
Copilot
AI
changed the title
[WIP] Fix fail to parse slice range indexing in verusfmt
Fix: Parse slice range indexing (e.g. May 30, 2026
buffer[..n], buffer[..=n])
|
@jaybosamiya-ms i tested this out and it does work. Thank you |
Collaborator
|
The fix that the agent came up with is (at least at first glance) not the best, and might cause maintenance troubles in the future, so I'd like to write a cleaner one before merging; until then, if this is a blocker, as a workaround I think you can use |
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.
verusfmtfailed to parse range-indexed slices like&buffer[..n]because the PEG grammar had noexpr_innerproduction for prefix range expressions (..n,..,..=n). A secondary bug caused..=to be tokenized as..+=(formatted asx.. = y) due to wrong alternation ordering.Changes
src/verus.pest..=operator ordering: swap(dot_dot_str | dot_dot_eq_str)→(dot_dot_eq_str | dot_dot_str)inexpr_outerandexpr_outer_no_structso the longer token winsrange_expr_inner/range_expr_inner_no_structto represent prefix range expressions; insert intoexpr_inner/expr_inner_no_structrecord_expr_field: change fromattr* ~ (name ~ colon_str)? ~ exprtoattr* ~ (name ~ colon_str ~ expr | !".." ~ expr)— prevents a leading-..shorthand field from consuming the struct update base (..base), while still allowing named fields with range-to values (x: ..5)src/lib.rsRule::range_expr_inner/Rule::range_expr_inner_no_structto the exhaustive match (silent rules never createPairnodes at runtime, but Rust requires allRulevariants to be covered)tests/verus-consistency.rsverus_range_index_exprcovering[..n],[..],[..=n],[n..],[n..n]By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.