Skip to content

Commit c9cad6e

Browse files
amomchilovegiurleo
authored andcommitted
Implement translation for local variable reads
1 parent 57da27c commit c9cad6e

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

parser/prism/Translator.cc

+8-1
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,14 @@ std::unique_ptr<parser::Node> Translator::translate(pm_node_t *node) {
282282

283283
return make_unique<parser::Kwrestarg>(parser.translateLocation(loc), gs.enterNameUTF8(name));
284284
}
285+
case PM_LOCAL_VARIABLE_READ_NODE: {
286+
auto localVarReadNode = reinterpret_cast<pm_local_variable_read_node *>(node);
287+
pm_location_t *loc = &localVarReadNode->base.location;
288+
289+
std::string_view name = parser.resolveConstant(localVarReadNode->name);
290+
291+
return make_unique<parser::LVar>(parser.translateLocation(loc), gs.enterNameUTF8(name));
292+
}
285293
case PM_LOCAL_VARIABLE_WRITE_NODE: {
286294
auto localVarWriteNode = reinterpret_cast<pm_local_variable_write_node *>(node);
287295
pm_location_t *loc = &localVarWriteNode->base.location;
@@ -631,7 +639,6 @@ std::unique_ptr<parser::Node> Translator::translate(pm_node_t *node) {
631639
case PM_LOCAL_VARIABLE_AND_WRITE_NODE:
632640
case PM_LOCAL_VARIABLE_OPERATOR_WRITE_NODE:
633641
case PM_LOCAL_VARIABLE_OR_WRITE_NODE:
634-
case PM_LOCAL_VARIABLE_READ_NODE:
635642
case PM_LOCAL_VARIABLE_TARGET_NODE:
636643
case PM_MATCH_LAST_LINE_NODE:
637644
case PM_MATCH_PREDICATE_NODE:

test/prism_regression/local_variables.parse-tree.exp

+8
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,13 @@ Begin {
1919
]
2020
}
2121
}
22+
Assign {
23+
lhs = LVarLhs {
24+
name = <U local_variable2>
25+
}
26+
rhs = LVar {
27+
name = <U local_variable1>
28+
}
29+
}
2230
]
2331
}

test/prism_regression/local_variables.rb

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44

55
local_variable2 = this_is_a_method_call
66
# ^^^^^^^^^^^^^^^^^^^^^ error: Method `this_is_a_method_call` does not exist on `T.class_of(<root>)`
7+
8+
local_variable2 = local_variable1 # should parse as local variable lookup

0 commit comments

Comments
 (0)