2661 Commits

Author SHA1 Message Date
ydah
2b1db0faec Remove unnecessary assignments to local variables in f_arg_asgn
Local variables are not reassigned and are not needed.
2025-01-21 20:25:38 +09:00
ydah
3260b0b647 Remove unnecessary assignments to local variables in strings
Local variables are not reassigned and are not needed.
2025-01-21 20:25:38 +09:00
Nobuyoshi Nakada
073c4e1cc7
[Feature #6012] Extend source_location for end position and columns 2025-01-09 20:21:41 +09:00
ydah
6069e8fea5 Refactor for loop handling to simplify do keyword location assignment 2025-01-09 18:24:56 +09:00
ydah
7790aa89f9 Use Named Reference 2025-01-09 18:24: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
ydah
36b6625ba9 Refactor parse_isalnum and parse_isxdigit to use macro 2025-01-09 02:33:48 +09:00
ydah
18f756e4af Remove unnecessary semantic actions
If you don’t specify an action for a rule, Lrama supplies a default: `$$ = $1`.
2025-01-08 10:48:07 +09:00
ydah
de8deb5f9c Remove unused token definitions for tRPAREN in Ripper and parser files 2025-01-07 07:17:55 +09:00
Peter Zhu
dfc9e978fb [Bug #21004] Fix memory leak with "it" in parse.y
Parsing `-> do it end` in parse.y leaks memory. We can see this in the
Valgrind output:

    56 bytes in 1 blocks are definitely lost in loss record 1 of 6
        at 0x484E0DC: calloc (vg_replace_malloc.c:1675)
        by 0x188970: calloc1 (default.c:1472)
        by 0x188970: rb_gc_impl_calloc (default.c:8208)
        by 0x188970: ruby_xcalloc_body (gc.c:4598)
        by 0x18B8BC: ruby_xcalloc (gc.c:4592)
        by 0x21DCCA70: new_locations_lambda_body (ripper.y:12844)
        by 0x21DCCA70: ripper_yyparse (ripper.y:5194)
        by 0x21DDA521: rb_ruby_ripper_parse0 (ripper.y:15798)
2025-01-05 09:06:12 +09:00
Peter Zhu
78d7dde21c Remove unused loc in rb_locations_lambda_body_t 2025-01-05 09:06:12 +09:00
ydah
61c4907458 Implement DOT3 NODE locations 2025-01-04 20:27:40 +09:00
ydah
88da6856a3 Implement DOT2 NODE locations 2025-01-04 20:27:40 +09:00
ydah
a1f010b8e4 Use user defined parameterizing rules compstmt(stmts) 2025-01-04 18:59:30 +09:00
ydah
bb66b42a7f Use user defined parameterizing rules op_asgn(rhs) 2025-01-04 18:58:44 +09:00
ydah
2efa78099c Use user defined parameterizing rules def_endless_method(bodystmt) 2025-01-04 18:58:44 +09:00
ydah
4fa68953fb Use user defined parameterizing rules asgn(lhs, rhs) 2025-01-04 18:58:44 +09:00
ydah
1e330dd5ec Use p_primitive_value 2025-01-04 18:07:27 +09:00
ydah
f00c5102c0 Use command_call_value 2025-01-04 18:07:27 +09:00
ydah
0eb63c410e Use user defined parameterizing rules value_expr 2025-01-04 18:07:27 +09:00
ydah
f2454aa2c2 Use user defined parameterizing rules f_kw(value) 2025-01-04 13:55:44 +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
5cc4240dda Refactor parse.y to replace tIDENTIFIER and tCONSTANT with ident_or_const inline rules 2025-01-03 22:13:20 +09:00
ydah
fd2f66e3c0 Use Named Reference for RHS of def_name 2025-01-03 21:21:52 +09:00
ydah
aa892378a1 Use callee side tag specification of parameterizing rules 2025-01-03 21:20:15 +09:00
ydah
1e2ed31cc2 Change the reference to the RHS in the Parameterizing rules action to a Named Reference 2025-01-03 21:19:41 +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
Nobuyoshi Nakada
6bbb470dc7
[Bug #20504] Move dynamic regexp concatenation to iseq compiler 2025-01-03 10:25:15 +09:00
S-H-GAMELINKS
3eebc81041 Rename to backref_with 2025-01-02 17:11:32 +09:00
S-H-GAMELINKS
1686c6b787 Introduce backref_with_rhs parameterizing rules 2025-01-02 17:11:32 +09:00
S-H-GAMELINKS
03b37fb342 Introduce inline_operation rule 2025-01-02 17:10:31 +09:00
Nobuyoshi Nakada
e4ec2128ae
[Bug #20990] Reject escaped multibyte char with control/meta prefix 2024-12-28 18:40:37 +09:00
Nobuyoshi Nakada
0ccc7657f3
Ripper: Fix duplicate regexp errors 2024-12-28 11:35:00 +09:00
Nobuyoshi Nakada
fb18bb183c
[Bug #20989] Ripper: Pass compile_error
For the universal parser, `rb_parser_reg_fragment_check` function is
shared between the parser and ripper.  However `parser_params` struct
is partially different, and `compile_error` function depends on that
part indirectly.
2024-12-28 11:25:57 +09:00
Takashi Kokubun
667a0f9f92
Revert "[Bug #20965] Define it like an ordinary argument" (#12418)
Revert "[Bug #20965] Define `it` like an ordinary argument (#12398)"

Reverts ruby/ruby#12398 as per https://bugs.ruby-lang.org/issues/20970#note-6 and https://bugs.ruby-lang.org/issues/20965#note-7.
We need more time to design the intended behavior, and it's too late for Ruby 3.4.
2024-12-23 04:46:50 +00: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
Nobuyoshi Nakada
46fec0f62a
[Bug #20965] Define it like an ordinary argument (#12398)
Also fixes [Bug #20955]
2024-12-18 23:12:16 -08:00
ydah
ce2f398386 Remove unused macros from parse.y 2024-12-10 12:21:19 +09:00
ydah
bfb7571d24 Remove minimum Bison version requirement from parse.y
How about removing `%require “version”` since it is a definition to specify the minimum version of Bison and is not needed now that we have completely moved to Lrama?

see: https://www.gnu.org/software/bison/manual/html_node/Require-Decl.html
2024-12-10 11:50:36 +09:00
S.H.
d278d352f9
Introduce inline_primary rule
Introduce inline_primary rule to merge the same BNF pattern
2024-10-25 22:26:29 +09:00
ydah
1c762d9566 [Bug #20789] Fix an invalid syntax error when ->a=1...{}
https://bugs.ruby-lang.org/issues/20789
2024-10-09 23:58:19 +09:00
Nobuyoshi Nakada
f37e6d7f7b
Merge rb_parser_enc_compatible_latter into rb_parser_enc_compatible 2024-10-05 16:07:57 +09:00
Nobuyoshi Nakada
9dbbd0181f
Parser string encoding is always ASCII-compatible 2024-10-05 15:59:44 +09:00
tompng
6743e6285a [Bug #20784] Fix incomplete character syntax followed by EOF 2024-10-05 15:59:01 +09:00
ydah
169a5ee99e Use user defined inline rules user_or_keyword_variable 2024-10-01 23:59:58 +09:00
Nobuyoshi Nakada
86ae409467
[Bug #20764] Refactor argument forwarding in lambda
Reject argument forwarding in lambda:
- without parentheses
- after optional argument(s)
2024-10-01 20:00:22 +09:00