From 4c192011422dc04902ddf930ff22be223325a35d Mon Sep 17 00:00:00 2001 From: ydah Date: Mon, 4 Nov 2024 23:32:00 +0900 Subject: Implement EVSTR NODE locations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The following Location information has been added This is the information required for parse.y to be a universal parser: ``` ❯ ruby --parser=prism --dump=parsetree -e '"#{foo}"' @ ProgramNode (location: (1,0)-(1,8)) +-- locals: [] +-- statements: @ StatementsNode (location: (1,0)-(1,8)) +-- body: (length: 1) +-- @ InterpolatedStringNode (location: (1,0)-(1,8)) +-- InterpolatedStringNodeFlags: nil +-- opening_loc: (1,0)-(1,1) = "\"" +-- parts: (length: 1) | +-- @ EmbeddedStatementsNode (location: (1,1)-(1,7)) | +-- opening_loc: (1,1)-(1,3) = "\#{" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | +-- statements: | | @ StatementsNode (location: (1,3)-(1,6)) | | +-- body: (length: 1) | | +-- @ CallNode (location: (1,3)-(1,6)) | | +-- CallNodeFlags: variable_call, ignore_visibility | | +-- receiver: nil | | +-- call_operator_loc: nil | | +-- name: :foo | | +-- message_loc: (1,3)-(1,6) = "foo" | | +-- opening_loc: nil | | +-- arguments: nil | | +-- closing_loc: nil | | +-- block: nil | +-- closing_loc: (1,6)-(1,7) = "}" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +-- closing_loc: (1,7)-(1,8) = "\"" ``` --- test/ruby/test_ast.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test') diff --git a/test/ruby/test_ast.rb b/test/ruby/test_ast.rb index 58d22149b7..4e449410f1 100644 --- a/test/ruby/test_ast.rb +++ b/test/ruby/test_ast.rb @@ -1376,6 +1376,14 @@ dummy assert_locations(node.children[-1].locations, [[1, 0, 1, 17], [1, 0, 1, 4], [1, 14, 1, 17]]) end + def test_evstr_locations + node = ast_parse('"#{foo}"') + assert_locations(node.children[-1].children[1].locations, [[1, 0, 1, 8], [1, 1, 1, 3], [1, 6, 1, 7]]) + + node = ast_parse('"#$1"') + assert_locations(node.children[-1].children[1].locations, [[1, 0, 1, 5], [1, 1, 1, 2], nil]) + end + def test_if_locations node = ast_parse("if cond then 1 else 2 end") assert_locations(node.children[-1].locations, [[1, 0, 1, 25], [1, 0, 1, 2], [1, 8, 1, 12], [1, 22, 1, 25]]) -- cgit v1.2.3