Implement FLIP3 NODE locations

This commit is contained in:
ydah 2024-11-03 00:52:14 +09:00 committed by Yudai Takada
parent 24653430cd
commit c936699431
Notes: git 2025-01-04 11:27:58 +00:00
2 changed files with 12 additions and 0 deletions

4
ast.c
View File

@ -824,6 +824,10 @@ node_locations(VALUE ast_value, const NODE *node)
return rb_ary_new_from_args(2, return rb_ary_new_from_args(2,
location_new(nd_code_loc(node)), location_new(nd_code_loc(node)),
location_new(&RNODE_FLIP2(node)->operator_loc)); location_new(&RNODE_FLIP2(node)->operator_loc));
case NODE_FLIP3:
return rb_ary_new_from_args(2,
location_new(nd_code_loc(node)),
location_new(&RNODE_FLIP3(node)->operator_loc));
case NODE_LAMBDA: case NODE_LAMBDA:
return rb_ary_new_from_args(4, return rb_ary_new_from_args(4,
location_new(nd_code_loc(node)), location_new(nd_code_loc(node)),

View File

@ -1420,6 +1420,14 @@ dummy
assert_locations(node.children[-1].children[0].locations, [[1, 3, 1, 7], [1, 4, 1, 6]]) assert_locations(node.children[-1].children[0].locations, [[1, 3, 1, 7], [1, 4, 1, 6]])
end end
def test_flip3_locations
node = ast_parse("if 'a'...('z'); foo; end")
assert_locations(node.children[-1].children[0].locations, [[1, 3, 1, 14], [1, 6, 1, 9]])
node = ast_parse('if 1...5; foo; end')
assert_locations(node.children[-1].children[0].locations, [[1, 3, 1, 8], [1, 4, 1, 7]])
end
def test_lambda_locations def test_lambda_locations
node = ast_parse("-> (a, b) { foo }") node = ast_parse("-> (a, b) { foo }")
assert_locations(node.children[-1].locations, [[1, 0, 1, 17], [1, 0, 1, 2], [1, 10, 1, 11], [1, 16, 1, 17]]) assert_locations(node.children[-1].locations, [[1, 0, 1, 17], [1, 0, 1, 2], [1, 10, 1, 11], [1, 16, 1, 17]])