diff options
author | ydah <[email protected]> | 2024-11-06 12:14:01 +0900 |
---|---|---|
committer | Yudai Takada <[email protected]> | 2025-01-04 07:34:49 +0900 |
commit | 607b1b3d7628b1f94f086ce1dfe67789179cf906 (patch) | |
tree | 5929a66656adf7d2064cd1423e4e95ed08ee6fe4 /ast.c | |
parent | 4c192011422dc04902ddf930ff22be223325a35d (diff) |
Implement YIELD 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 'def foo; yield end'
@ ProgramNode (location: (1,0)-(1,18))
+-- locals: []
+-- statements:
@ StatementsNode (location: (1,0)-(1,18))
+-- body: (length: 1)
+-- @ DefNode (location: (1,0)-(1,18))
+-- name: :foo
+-- name_loc: (1,4)-(1,7) = "foo"
+-- receiver: nil
+-- parameters: nil
+-- body:
| @ StatementsNode (location: (1,9)-(1,14))
| +-- body: (length: 1)
| +-- @ YieldNode (location: (1,9)-(1,14))
| +-- keyword_loc: (1,9)-(1,14) = "yield"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| +-- lparen_loc: nil
^^^^^^^^^^^^^^^^^^^
| +-- arguments: nil
| +-- rparen_loc: nil
^^^^^^^^^^^^^^^^^^^
+-- locals: []
+-- def_keyword_loc: (1,0)-(1,3) = "def"
+-- operator_loc: nil
+-- lparen_loc: nil
+-- rparen_loc: nil
+-- equal_loc: nil
+-- end_keyword_loc: (1,15)-(1,18) = "end"
```
Diffstat (limited to 'ast.c')
-rw-r--r-- | ast.c | 6 |
1 files changed, 6 insertions, 0 deletions
@@ -886,6 +886,12 @@ node_locations(VALUE ast_value, const NODE *node) location_new(nd_code_loc(node)), location_new(&RNODE_UNTIL(node)->keyword_loc), location_new(&RNODE_UNTIL(node)->closing_loc)); + case NODE_YIELD: + return rb_ary_new_from_args(4, + location_new(nd_code_loc(node)), + location_new(&RNODE_YIELD(node)->keyword_loc), + location_new(&RNODE_YIELD(node)->lparen_loc), + location_new(&RNODE_YIELD(node)->rparen_loc)); case NODE_ARGS_AUX: case NODE_LAST: break; |