Commit graph

182 commits

Author SHA1 Message Date
S-H-GAMELINKS
4775d1ffa8 Add NODE IN locations
Add locations to struct `RNode_IN`.

memo:

```bash
> ruby -e 'case 1; in 2 then 3; end' --parser=prism --dump=parsetree
@ ProgramNode (location: (1,0)-(1,24))
+-- locals: []
+-- statements:
    @ StatementsNode (location: (1,0)-(1,24))
    +-- body: (length: 1)
        +-- @ CaseMatchNode (location: (1,0)-(1,24))
            +-- predicate:
            |   @ IntegerNode (location: (1,5)-(1,6))
            |   +-- IntegerBaseFlags: decimal
            |   +-- value: 1
            +-- conditions: (length: 1)
            |   +-- @ InNode (location: (1,8)-(1,19))
            |       +-- pattern:
            |       |   @ IntegerNode (location: (1,11)-(1,12))
            |       |   +-- IntegerBaseFlags: decimal
            |       |   +-- value: 2
            |       +-- statements:
            |       |   @ StatementsNode (location: (1,18)-(1,19))
            |       |   +-- body: (length: 1)
            |       |       +-- @ IntegerNode (location: (1,18)-(1,19))
            |       |           +-- IntegerBaseFlags: decimal
            |       |           +-- value: 3
            |       +-- in_loc: (1,8)-(1,10) = "in"
            |       +-- then_loc: (1,13)-(1,17) = "then"
            +-- else_clause: nil
            +-- case_keyword_loc: (1,0)-(1,4) = "case"
            +-- end_keyword_loc: (1,21)-(1,24) = "end"
```
2025-08-11 22:25:47 +09:00
S-H-GAMELINKS
bcd21053f7 Add MODULE NODE locations
Add `keyword_module` amd `keyword_end` locations to struct `RNode_MODULE`.

memo:
```
>ruby --dump=parsetree -e 'module A end'
@ ProgramNode (location: (1,0)-(1,12))
+-- locals: []
+-- statements:
    @ StatementsNode (location: (1,0)-(1,12))
    +-- body: (length: 1)
        +-- @ ModuleNode (location: (1,0)-(1,12))
            +-- locals: []
            +-- module_keyword_loc: (1,0)-(1,6) = "module"
            +-- constant_path:
            |   @ ConstantReadNode (location: (1,7)-(1,8))
            |   +-- name: :A
            +-- body: nil
            +-- end_keyword_loc: (1,9)-(1,12) = "end"
            +-- name: :A
```
2025-08-07 01:07:16 +09:00
S-H-GAMELINKS
fd492a45eb Add DEFINED NODE locations
Add keyword_defined locations to struct RNode_DEFINED
2025-07-24 23:30:23 +09:00
ydah
d60144a490 Implement COLON3 NODE locations 2025-06-15 22:37:20 +09:00
ydah
c584790bde Implement COLON2 NODE locations 2025-06-15 22:37:20 +09:00
Jean Boussier
15084fbc3c Get rid of FL_EXIVAR
Now that the shape_id gives us all the same information, it's no
longer needed.
2025-06-13 23:50:30 +02:00
ydah
eae0fe37c0 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
```
2025-03-08 18:26:40 +09:00
ydah
a47e686cb6 Implement POSTEXE 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 "END {  }"
@ ProgramNode (location: (1,0)-(1,8))
+-- locals: []
+-- statements:
    @ StatementsNode (location: (1,0)-(1,8))
    +-- body: (length: 1)
        +-- @ PostExecutionNode (location: (1,0)-(1,8))
            +-- statements: nil
            +-- keyword_loc: (1,0)-(1,3) = "END"
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            +-- opening_loc: (1,4)-(1,5) = "{"
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            +-- closing_loc: (1,7)-(1,8) = "}"
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
2025-03-03 11:17:14 +09:00
S-H-GAMELINKS
23c4ac9559 Remove rb_enc_associate for Parser 2025-02-15 15:37:09 +09:00
S-H-GAMELINKS
ace39a3ed4 Remove rb_exc_raise for Parser 2025-02-02 16:58:15 +09:00
S-H-GAMELINKS
baf22a0578 Remove rb_usascii_encoding for Parser 2025-01-28 18:22:35 +09:00
S-H-GAMELINKS
5c95898e93 Remove rb_obj_as_string for Parser
Ruby Parser not used rb_obj_as_string.
And obj_as_string property can be removed from Universal Parser.
2025-01-20 23:52:56 +09:00
ydah
c721301132 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"
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
2025-01-09 18:24:56 +09:00
S-H-GAMELINKS
975461bf88 Remove SYM2ID for Parser
Ruby Parser not used SYM2ID.
And sym2id property can be removed from Universal Parser.
2025-01-06 20:17:47 +09:00
ydah
88da6856a3 Implement DOT2 NODE locations 2025-01-04 20:27:40 +09:00
ydah
5fcc3ab534 Implement REGX 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 '/foo/'
@ ProgramNode (location: (1,0)-(1,5))
+-- locals: []
+-- statements:
    @ StatementsNode (location: (1,0)-(1,5))
    +-- body: (length: 1)
        +-- @ RegularExpressionNode (location: (1,0)-(1,5))
            +-- RegularExpressionFlags: forced_us_ascii_encoding
            +-- opening_loc: (1,0)-(1,1) = "/"
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            +-- content_loc: (1,1)-(1,4) = "foo"
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            +-- closing_loc: (1,4)-(1,5) = "/"
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            +-- unescaped: "foo"
```
2025-01-04 13:53:13 +09:00
ydah
fa2517451e 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)
```
2025-01-04 13:52:35 +09:00
ydah
607b1b3d76 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"
```
2025-01-04 07:34:49 +09:00
ydah
4c19201142 Implement EVSTR 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 '"#{foo}"'
@ ProgramNode (location: (1,0)-(1,8))
+-- locals: []
+-- statements:
    @ StatementsNode (location: (1,0)-(1,8))
    +-- body: (length: 1)
        +-- @ InterpolatedStringNode (location: (1,0)-(1,8))
            +-- InterpolatedStringNodeFlags: nil
            +-- opening_loc: (1,0)-(1,1) = "\""
            +-- parts: (length: 1)
            |   +-- @ EmbeddedStatementsNode (location: (1,1)-(1,7))
            |       +-- opening_loc: (1,1)-(1,3) = "\#{"
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            |       +-- statements:
            |       |   @ StatementsNode (location: (1,3)-(1,6))
            |       |   +-- body: (length: 1)
            |       |       +-- @ CallNode (location: (1,3)-(1,6))
            |       |           +-- CallNodeFlags: variable_call, ignore_visibility
            |       |           +-- receiver: nil
            |       |           +-- call_operator_loc: nil
            |       |           +-- name: :foo
            |       |           +-- message_loc: (1,3)-(1,6) = "foo"
            |       |           +-- opening_loc: nil
            |       |           +-- arguments: nil
            |       |           +-- closing_loc: nil
            |       |           +-- block: nil
            |       +-- closing_loc: (1,6)-(1,7) = "}"
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            +-- closing_loc: (1,7)-(1,8) = "\""
```
2025-01-04 07:34:25 +09:00
ydah
c22b0598b0 Implement SUPER NODE locations 2025-01-03 23:03:04 +09:00
ydah
0643f08187 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"
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
2025-01-03 20:34:19 +09:00
S-H-GAMELINKS
ba82399558 Remove rb_ary_push for parser 2025-01-02 17:11:45 +09:00
Nobuyoshi Nakada
7b2ae8df90
[Bug #20969] Pass assignable from ripper
For the universal parser, `rb_reg_named_capture_assign_iter_impl`
function is shared between the parser and ripper.  However
`parser_params` struct is partially different, and `assignable`
function depends on that part indirectly.
2024-12-19 23:20:09 +09:00
S-H-GAMELINKS
5c1e43277e Remove rb_ary_new for parser
rb_ary_new function was not used by the parser and could be removed.
2024-10-25 22:32:38 +09:00
ydah
044e57ed7c Implement SPLAT NODE keyword locations 2024-09-30 18:04:41 +09:00
ydah
8f678d6989 Implement OP_ASGN2 NODE locations 2024-09-28 20:53:09 +09:00
Nobuyoshi Nakada
7e19904c88 Remove on RSTRING_END dependency from parser 2024-09-28 01:59:33 +09:00
S-H-GAMELINKS
7f83bd3732 Reduce is_ascii_string function dependency for parser
Changed to use `rb_parser_is_ascii_string` function instead of `is_ascii_string` function
2024-09-27 19:34:35 +09:00
ydah
eff16d9302 Implement OP_ASGN1 NODE locations 2024-09-27 18:20:00 +09:00
S-H-GAMELINKS
3e742579bb Remove rb_str_cat for parser 2024-09-26 19:20:57 +09:00
ydah
509b577e01 Implement BLOCK_PASS NODE keyword locations 2024-09-25 09:15:43 +09:00
ydah
31a88d1554 Implement RETURN NODE keyword locations 2024-09-25 09:06:42 +09:00
ydah
b811a9a097 Implement CASE3 NODE keyword locations 2024-09-23 09:19:37 +09:00
ydah
5334766beb Implement CASE2 NODE keyword locations 2024-09-23 09:19:37 +09:00
ydah
feac2b4b77 Implement CASE NODE keyword locations 2024-09-23 09:19:37 +09:00
S-H-GAMELINKS
95d26ee41e Reuse dedent_string function in rb_ruby_ripper_dedent_string function
This change is reduce Ruby C API dependency for Universal Parser.
Reuse dedent_string functions in rb_ruby_ripper_dedent_string functions and remove dependencies on rb_str_modify and rb_str_set_len from the parser.
2024-09-22 12:22:20 +09:00
ydah
d03e0d1c35 Implement BREAK, NEXT and REDO NODE locations 2024-09-11 18:01:16 +09:00
ydah
4e6091ce09 Implement WHILE and UNTIL NODE locations 2024-09-11 09:28:55 +09:00
ydah
d52e599538 Implement WHEN NODE locations 2024-09-09 10:34:02 +09:00
ydah
32680f543c Implement AND/OR NODE operator locations 2024-09-05 13:03:28 +09:00
ydah
ab18b1b4f5 Implement VALIAS NODE keyword locations 2024-09-04 14:36:35 +09:00
ydah
a2243ee48b Implement ALIAS NODE keyword locations 2024-09-03 22:09:08 +09:00
ydah
af143d8a74 Implement UNDEF NODE keyword locations 2024-09-03 21:15:12 +09:00
yui-knk
52c4d0e048 Remove enc_coderange_broken field from struct rb_parser_config_struct
It has not been used since fcc55dc226.
2024-08-27 09:59:43 +09:00
yui-knk
2e07c13049 Remove nonexist declarations
These functions were removed by 33c1e082d0.
2024-08-26 09:08:53 +09:00
Nobuyoshi Nakada
995b4c329b
Make same structures same 2024-08-20 12:26:02 +09:00
yui-knk
2c76bb7ec0 Remove struct RNode_VALUES
This was removed by a5cc6341c0.
2024-07-26 10:29:26 +09:00
yui-knk
f2728c3393 Change RESBODY Node structure
Extracrt exception variable into `nd_exc_var` field
to keep the original grammar structure.

For example:

```
begin
rescue Error => e1
end
```

Before:

```
@ NODE_RESBODY (id: 8, line: 2, location: (2,0)-(2,18))
+- nd_args:
|   @ NODE_LIST (id: 2, line: 2, location: (2,7)-(2,12))
|   +- as.nd_alen: 1
|   +- nd_head:
|   |   @ NODE_CONST (id: 1, line: 2, location: (2,7)-(2,12))
|   |   +- nd_vid: :Error
|   +- nd_next:
|       (null node)
+- nd_body:
|   @ NODE_BLOCK (id: 6, line: 2, location: (2,13)-(2,18))
|   +- nd_head (1):
|   |   @ NODE_LASGN (id: 3, line: 2, location: (2,13)-(2,18))
|   |   +- nd_vid: :e1
|   |   +- nd_value:
|   |       @ NODE_ERRINFO (id: 5, line: 2, location: (2,13)-(2,18))
|   +- nd_head (2):
|       @ NODE_BEGIN (id: 4, line: 2, location: (2,18)-(2,18))
|       +- nd_body:
|           (null node)
+- nd_next:
    (null node)
```

After:

```
@ NODE_RESBODY (id: 6, line: 2, location: (2,0)-(2,18))
+- nd_args:
|   @ NODE_LIST (id: 2, line: 2, location: (2,7)-(2,12))
|   +- as.nd_alen: 1
|   +- nd_head:
|   |   @ NODE_CONST (id: 1, line: 2, location: (2,7)-(2,12))
|   |   +- nd_vid: :Error
|   +- nd_next:
|       (null node)
+- nd_exc_var:
|   @ NODE_LASGN (id: 3, line: 2, location: (2,13)-(2,18))
|   +- nd_vid: :e1
|   +- nd_value:
|       @ NODE_ERRINFO (id: 5, line: 2, location: (2,13)-(2,18))
+- nd_body:
|   @ NODE_BEGIN (id: 4, line: 2, location: (2,18)-(2,18))
|   +- nd_body:
|       (null node)
+- nd_next:
    (null node)
```
2024-07-26 07:29:32 +09:00
yui-knk
57b11be15a Implement UNLESS NODE keyword locations 2024-07-23 14:35:23 +09:00
yui-knk
6be539aab5 Change UNDEF Node structure
Change UNDEF Node to hold their items to keep the original grammar
structure.

For example:

```
undef a, b
```

Before:

```
@ NODE_BLOCK (id: 4, line: 1, location: (1,6)-(1,10))*
+- nd_head (1):
|   @ NODE_UNDEF (id: 1, line: 1, location: (1,6)-(1,7))
|   +- nd_undef:
|       @ NODE_SYM (id: 0, line: 1, location: (1,6)-(1,7))
|       +- string: :a
+- nd_head (2):
    @ NODE_UNDEF (id: 3, line: 1, location: (1,9)-(1,10))
    +- nd_undef:
        @ NODE_SYM (id: 2, line: 1, location: (1,9)-(1,10))
        +- string: :b
```

After:

```
@ NODE_UNDEF (id: 1, line: 1, location: (1,6)-(1,10))*
+- nd_undefs:
    +- length: 2
    +- element (0):
    |   @ NODE_SYM (id: 0, line: 1, location: (1,6)-(1,7))
    |   +- string: :a
    +- element (1):
        @ NODE_SYM (id: 2, line: 1, location: (1,9)-(1,10))
        +- string: :b
```
2024-07-20 11:25:26 +09:00