Commit a37df6cc
a37df6cc446cMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
Merge pull request #296 from ryanseys/rs-node-embedded-var
feat(parse): support EmbeddedVariableNode ("foo #@bar")
Details
- Commit
- a37df6cc446c
- Parent
- 59ff8d7a4f30
- Merge parent
- 4e5a78a89432
spinel_parse.cmodifiedView file
@@ -1033,6 +1033,27 @@
10331033
A("rights", &n->rights);10341034
break;10351035
}1036+
case PM_EMBEDDED_VARIABLE_NODE: {1037+
/* `"foo #@bar"` shorthand for `"foo #{@bar}"`. The cleanest1038+
implementation is parser-side lowering: synthesize an1039+
EmbeddedStatementsNode wrapping a StatementsNode whose single1040+
body element is the variable read. The existing interpolation1041+
path then handles it without any codegen change.1042+
1043+
Same lowering trick as PM_IT_LOCAL_VARIABLE_READ_NODE -- emit1044+
a different node type at the same `id` slot so parent walks1045+
(parts list of the surrounding InterpolatedString) keep the1046+
slot unchanged. The wrapped StatementsNode gets a fresh id1047+
allocated via node_counter++. */1048+
pm_embedded_variable_node_t *n = (pm_embedded_variable_node_t *)node;1049+
N("EmbeddedStatementsNode");1050+
int var_id = flatten(n->variable);1051+
int stmts_id = node_counter++;1052+
out_add("N %d StatementsNode", stmts_id);1053+
out_add("A %d body %d", stmts_id, var_id);1054+
out_add("R %d statements %d", id, stmts_id);1055+
break;1056+
}10361057
default: {10371058
/* Fallback: emit unknown node type */10381059
char buf[64];test/embedded_var.rbaddedView file
Loading diff…
test/embedded_var.rb.expectedaddedView file
Loading diff…