feat(parser): Phase 152-A - Grouped assignment expression (箱化モジュール化)
Implement Stage-3 grouped assignment expression `(x = expr)` following the 箱化モジュール化 (modular box) pattern established in Phase 133/134. **Implementation**: - AssignmentExprParser module (Rust: 183 lines) - src/parser/stage3/assignment_expr_parser.rs (+183 lines) - src/parser/stage3/mod.rs (+9 lines) - AST node addition: GroupedAssignmentExpr - src/ast.rs (+7 lines) - src/ast/utils.rs (+9 lines) - MIR lowering via 1-line delegation - src/mir/builder/exprs.rs (+5 lines) - src/mir/builder/vars.rs (+4 lines) - Parser integration via 1-line delegation - src/parser/expr/primary.rs (+6 lines) - src/parser/mod.rs (+1 line) **Test Results**: 3/3 PASS - assignment_expr_simple.hako: RC 1 ✅ - assignment_expr_shortcircuit.hako: RC 1 ✅ - shortcircuit_and_phi_skip.hako: RC 1 ✅ (updated to use expression context) **Stage-3 Gate**: No impact on Stage-2/legacy - NYASH_FEATURES=stage3 required - Pattern: '(' IDENT '=' expr ')' - Value/type same as rhs, side effect assigns to lhs **箱化モジュール化パターン**: - Dedicated module for assignment expression parsing - Clear responsibility separation - 1-line delegation for integration - Testability improvement - Follows Phase 133/134-A/134-B pattern 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
12
apps/tests/assignment_expr_shortcircuit.hako
Normal file
12
apps/tests/assignment_expr_shortcircuit.hako
Normal file
@ -0,0 +1,12 @@
|
||||
// Phase 152-A: Grouped assignment expression with shortcircuit
|
||||
// Test: (x = expr) can be used in conditional expressions
|
||||
|
||||
static box Main {
|
||||
main() {
|
||||
local x = 0
|
||||
if ((x = 1) > 0) and true {
|
||||
return x // Expected: RC 1
|
||||
}
|
||||
return -1
|
||||
}
|
||||
}
|
||||
11
apps/tests/assignment_expr_simple.hako
Normal file
11
apps/tests/assignment_expr_simple.hako
Normal file
@ -0,0 +1,11 @@
|
||||
// Phase 152-A: Grouped assignment expression simple test
|
||||
// Test: (x = expr) returns value and assigns to x
|
||||
|
||||
static box Main {
|
||||
main() {
|
||||
local x = 0
|
||||
local y = (x = x + 1)
|
||||
// x should be 1, y should be 1
|
||||
return y // Expected: RC 1
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,8 @@
|
||||
static box Main {
|
||||
main(args) {
|
||||
local x = 0
|
||||
((x = x + 1) < 0) && ((x = x + 1) < 0)
|
||||
// Phase 152-A: Use grouped assignment in expression context
|
||||
local result = ((x = x + 1) < 0) && ((x = x + 1) < 0)
|
||||
// LHS が false → RHS は評価されず x は 1 のまま
|
||||
return x
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user