diff options
author | ydah <[email protected]> | 2024-11-03 23:52:50 +0900 |
---|---|---|
committer | Yudai Takada <[email protected]> | 2025-03-08 18:26:40 +0900 |
commit | eae0fe37c08b568c0a7cbf904caba4faca517746 (patch) | |
tree | 166c20e6046a3be3f5428eda36b848ea0fae0a98 /ast.c | |
parent | 98790faae3cbbe67a5335df30f6e9000f3a83ad9 (diff) |
Implement CLASS 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 "class A < B; end"
@ ProgramNode (location: (1,0)-(1,16))
+-- locals: []
+-- statements:
@ StatementsNode (location: (1,0)-(1,16))
+-- body: (length: 1)
+-- @ ClassNode (location: (1,0)-(1,16))
+-- locals: []
+-- class_keyword_loc: (1,0)-(1,5) = "class"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+-- constant_path:
| @ ConstantReadNode (location: (1,6)-(1,7))
| +-- name: :A
+-- inheritance_operator_loc: (1,8)-(1,9) = "<"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+-- superclass:
| @ ConstantReadNode (location: (1,10)-(1,11))
| +-- name: :B
+-- body: nil
+-- end_keyword_loc: (1,13)-(1,16) = "end"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+-- name: :A
```
Diffstat (limited to 'ast.c')
-rw-r--r-- | ast.c | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -787,7 +787,6 @@ node_locations(VALUE ast_value, const NODE *node) return rb_ary_new_from_args(2, location_new(nd_code_loc(node)), location_new(&RNODE_BLOCK_PASS(node)->operator_loc)); - case NODE_BREAK: return rb_ary_new_from_args(2, location_new(nd_code_loc(node)), @@ -807,6 +806,12 @@ node_locations(VALUE ast_value, const NODE *node) location_new(nd_code_loc(node)), location_new(&RNODE_CASE3(node)->case_keyword_loc), location_new(&RNODE_CASE3(node)->end_keyword_loc)); + case NODE_CLASS: + return rb_ary_new_from_args(4, + location_new(nd_code_loc(node)), + location_new(&RNODE_CLASS(node)->class_keyword_loc), + location_new(&RNODE_CLASS(node)->inheritance_operator_loc), + location_new(&RNODE_CLASS(node)->end_keyword_loc)); case NODE_DOT2: return rb_ary_new_from_args(2, location_new(nd_code_loc(node)), |