✨ feat(parser): support index assignment for arrays and dicts#1235
Merged
✨ feat(parser): support index assignment for arrays and dicts#1235
Conversation
Desugar `arr[idx] = rhs` into `arr = set(arr, idx, rhs)` and support compound assignment operators (`+=`, `-=`, etc.) on indexed targets.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds parsing + desugaring support for indexed assignment targets so expressions like arr[idx] = rhs are lowered into arr = set(arr, idx, rhs), including compound assignment operators on indexed targets.
Changes:
- Extend AST assignment construction to recognize indexed LHS (represented as
get(base, idx)) and desugar intoset(...). - Add
SETAST constant for the new desugaring target. - Add CST/AST/HIR/formatter tests covering indexed assignment and some compound forms.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/mq-lang/src/cst/parser.rs | Adds CST-level test cases for index assignment and index compound assignment tokens/shape. |
| crates/mq-lang/src/ast/parser.rs | Implements indexed-target handling in assignment creation + adds AST tests for =, +=, and //= on indexed targets. |
| crates/mq-lang/src/ast/constants.rs | Introduces SET constant used by the new desugaring. |
| crates/mq-hir/src/hir.rs | Adds HIR smoke tests ensuring indexed assignment parses/lower without errors and produces expected symbols. |
| crates/mq-formatter/src/formatter.rs | Adds formatter test cases for indexed assignment and += on indexed targets. |
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.
Desugar
arr[idx] = rhsintoarr = set(arr, idx, rhs)and support compound assignment operators (+=,-=, etc.) on indexed targets.