Implement FOR 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 "for a in b do end"
@ ProgramNode (location: (1,0)-(1,17))
+-- locals: [:a]
+-- statements:
    @ StatementsNode (location: (1,0)-(1,17))
    +-- body: (length: 1)
        +-- @ ForNode (location: (1,0)-(1,17))
            +-- index:
            |   @ LocalVariableTargetNode (location: (1,4)-(1,5))
            |   +-- name: :a
            |   +-- depth: 0
            +-- collection:
            |   @ CallNode (location: (1,9)-(1,10))
            |   +-- CallNodeFlags: variable_call, ignore_visibility
            |   +-- receiver: nil
            |   +-- call_operator_loc: nil
            |   +-- name: :b
            |   +-- message_loc: (1,9)-(1,10) = "b"
            |   +-- opening_loc: nil
            |   +-- arguments: nil
            |   +-- closing_loc: nil
            |   +-- block: nil
            +-- statements: nil
            +-- for_keyword_loc: (1,0)-(1,3) = "for"
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            +-- in_keyword_loc: (1,6)-(1,8) = "in"
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            +-- do_keyword_loc: (1,11)-(1,13) = "do"
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            +-- end_keyword_loc: (1,14)-(1,17) = "end"
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
This commit is contained in:
ydah 2024-11-11 01:00:05 +09:00 committed by Yudai Takada
parent 841555245d
commit c721301132
5 changed files with 56 additions and 14 deletions

View file

@ -341,7 +341,18 @@ typedef struct RNode_ITER {
struct RNode *nd_body;
struct RNode *nd_iter;
} rb_node_iter_t, rb_node_for_t;
} rb_node_iter_t;
typedef struct RNode_FOR {
NODE node;
struct RNode *nd_body;
struct RNode *nd_iter;
rb_code_location_t for_keyword_loc;
rb_code_location_t in_keyword_loc;
rb_code_location_t do_keyword_loc;
rb_code_location_t end_keyword_loc;
} rb_node_for_t;
typedef struct RNode_FOR_MASGN {
NODE node;