diff options
| author | ydah <t.yudai92@gmail.com> | 2024-11-02 17:21:51 +0900 |
|---|---|---|
| committer | Yudai Takada <t.yudai92@gmail.com> | 2025-01-04 13:52:35 +0900 |
| commit | fa2517451ec265d5b273e864bc750a1b9ba2957f (patch) | |
| tree | bf2d88ec9a7e0d2deee331acba938ce5573c03d2 /test/ruby | |
| parent | 607b1b3d7628b1f94f086ce1dfe67789179cf906 (diff) | |
Implement LAMBDA NODE locations
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 "-> (a, b) do foo end"
@ ProgramNode (location: (1,0)-(1,20))
+-- locals: []
+-- statements:
@ StatementsNode (location: (1,0)-(1,20))
+-- body: (length: 1)
+-- @ LambdaNode (location: (1,0)-(1,20))
+-- locals: [:a, :b]
+-- operator_loc: (1,0)-(1,2) = "->"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+-- opening_loc: (1,10)-(1,12) = "do"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+-- closing_loc: (1,17)-(1,20) = "end"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
: (snip)
```
Diffstat (limited to 'test/ruby')
| -rw-r--r-- | test/ruby/test_ast.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/test/ruby/test_ast.rb b/test/ruby/test_ast.rb index e456f5b7b5..d509cc26c6 100644 --- a/test/ruby/test_ast.rb +++ b/test/ruby/test_ast.rb @@ -1384,6 +1384,14 @@ dummy assert_locations(node.children[-1].children[1].locations, [[1, 0, 1, 5], [1, 1, 1, 2], nil]) end + def test_lambda_locations + 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]]) + + node = ast_parse("-> (a, b) do foo end") + assert_locations(node.children[-1].locations, [[1, 0, 1, 20], [1, 0, 1, 2], [1, 10, 1, 12], [1, 17, 1, 20]]) + 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]]) |
