diff options
author | ydah <[email protected]> | 2025-01-03 19:51:58 +0900 |
---|---|---|
committer | Yudai Takada <[email protected]> | 2025-01-03 20:34:19 +0900 |
commit | 0643f081877ea19f8dd6610dd67b2606ecf4c880 () | |
tree | e9a13921b5d5fd633a1eaaeaf5a3b2c3129154a5 /node_dump.c | |
parent | 23018c2fb48ac7ada1ead79e3c896605c1b8bae6 (diff) |
Implement IF 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 -y -e "if a; elsif b; else end" @ ProgramNode (location: (1,0)-(1,23)) +-- locals: [] +-- statements: @ StatementsNode (location: (1,0)-(1,23)) +-- body: (length: 1) +-- @ IfNode (location: (1,0)-(1,23)) +-- if_keyword_loc: (1,0)-(1,2) = "if" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +-- predicate: | @ CallNode (location: (1,3)-(1,4)) | +-- CallNodeFlags: variable_call, ignore_visibility | +-- receiver: nil | +-- call_operator_loc: nil | +-- name: :a | +-- message_loc: (1,3)-(1,4) = "a" | +-- opening_loc: nil | +-- arguments: nil | +-- closing_loc: nil | +-- block: nil +-- then_keyword_loc: nil ^^^^^^^^^^^^^^^^^^^^^^^^^ +-- statements: nil +-- subsequent: | @ IfNode (location: (1,6)-(1,23)) | +-- if_keyword_loc: (1,6)-(1,11) = "elsif" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | +-- predicate: | | @ CallNode (location: (1,12)-(1,13)) | | +-- CallNodeFlags: variable_call, ignore_visibility | | +-- receiver: nil | | +-- call_operator_loc: nil | | +-- name: :b | | +-- message_loc: (1,12)-(1,13) = "b" | | +-- opening_loc: nil | | +-- arguments: nil | | +-- closing_loc: nil | | +-- block: nil | +-- then_keyword_loc: nil ^^^^^^^^^^^^^^^^^^^^^^^^^ | +-- statements: nil | +-- subsequent: | | @ ElseNode (location: (1,15)-(1,23)) | | +-- else_keyword_loc: (1,15)-(1,19) = "else" | | +-- statements: nil | | +-- end_keyword_loc: (1,20)-(1,23) = "end" | +-- end_keyword_loc: (1,20)-(1,23) = "end" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +-- end_keyword_loc: (1,20)-(1,23) = "end" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ```
-rw-r--r-- | node_dump.c | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -239,8 +239,11 @@ dump_node(VALUE buf, VALUE indent, int comment, const NODE * node) ANN("example: if x == 1 then foo else bar end"); F_NODE(nd_cond, RNODE_IF, "condition expr"); F_NODE(nd_body, RNODE_IF, "then clause"); - LAST_NODE; F_NODE(nd_else, RNODE_IF, "else clause"); return; case NODE_UNLESS: |