Commit 78616c98
78616c983f8eMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
Merge pull request #141 from ryanseys/rs-parse-rightward-assign
feat(parse): support rightward assignment (expr => var)
Details
- Commit
- 78616c983f8e
- Parent
- ee5c05b72d03
- Merge parent
- 5e9d5a9571d7
spinel_parse.cmodifiedView file
@@ -743,6 +743,26 @@
743743
R("call", n->call);744744
break;745745
}746+
case PM_MATCH_REQUIRED_NODE: {747+
/* Rightward assignment: `expr => var` (Ruby 3.0+). When the748+
pattern is a single LocalVariableTargetNode, this is just749+
`var = expr` and we lower it to a LocalVariableWriteNode so750+
the codegen reuses the regular assignment path. Full pattern751+
matching (array / hash patterns, pinned vars) is out of scope752+
and falls through to the unknown-node passthrough. */753+
pm_match_required_node_t *n = (pm_match_required_node_t *)node;754+
if (n->pattern && PM_NODE_TYPE_P(n->pattern, PM_LOCAL_VARIABLE_TARGET_NODE)) {755+
pm_local_variable_target_node_t *t = (pm_local_variable_target_node_t *)n->pattern;756+
N("LocalVariableWriteNode");757+
NAME("name", t->name);758+
R("value", n->value);759+
} else {760+
N("MatchRequiredNode");761+
R("value", n->value);762+
R("pattern", n->pattern);763+
}764+
break;765+
}746766
case PM_ALTERNATION_PATTERN_NODE: {747767
pm_alternation_pattern_node_t *n = (pm_alternation_pattern_node_t *)node;748768
N("AlternationPatternNode");test/rightward_assign.rbaddedView file
Loading diff…