✨ feat(mq-lang): add value as name variable binding syntax#1781
Merged
Conversation
Implements jq-style `expr as name` binding across all language layers
Contributor
There was a problem hiding this comment.
Pull request overview
Adds jq-style expr as name bindings to the mq language, threading the new syntax through lexing, CST/AST parsing, evaluation, HIR lowering, and formatting so bindings can be introduced mid-pipeline and referenced later.
Changes:
- Introduces
asas a keyword/token and parses it into new CST/AST nodes (NodeKind::As/Expr::As). - Implements evaluation semantics for
asbindings by defining the name in the current environment while passing through the prior pipeline value. - Extends HIR lowering and the formatter to understand/print
asbindings, and adds integration/formatter/parser tests.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| crates/mq-lang/tests/property_based_tests.rs | Excludes as from generated identifiers to avoid keyword collisions. |
| crates/mq-lang/tests/integration_tests.rs | Adds eval-level integration coverage for expr as name usage in pipelines and defs. |
| crates/mq-lang/src/macro_expand.rs | Supports macro expansion/substitution for the new Expr::As node. |
| crates/mq-lang/src/lexer/token.rs | Adds TokenKind::As and display formatting. |
| crates/mq-lang/src/lexer.rs | Recognizes as as a keyword during lexing. |
| crates/mq-lang/src/eval.rs | Evaluates Expr::As by binding the evaluated value into the environment and returning the incoming pipeline value. |
| crates/mq-lang/src/cst/parser.rs | Parses as bindings into CST (NodeKind::As). |
| crates/mq-lang/src/cst/node.rs | Adds As to CST node kinds. |
| crates/mq-lang/src/ast/parser.rs | Parses as bindings into AST (Expr::As) and adds a unit test. |
| crates/mq-lang/src/ast/node.rs | Adds Expr::As and ensures range calculation covers the inner node consistently with similar constructs. |
| crates/mq-lang/src/ast/code.rs | Adds code formatting output for Expr::As. |
| crates/mq-hir/src/hir/lower.rs | Lowers CST As into HIR symbols (keyword + variable + initializer relationship). |
| crates/mq-formatter/src/formatter.rs | Formats as bindings and adds formatter tests. |
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.
Implements jq-style
expr as namebinding across all language layers