2709 Commits

Author SHA1 Message Date
Benoit Daloze
c970d2941d [Bug #21784] Fix the Proc#source_location start_column for stabby lambdas
* Consistent with plain `blocks` and `for` blocks and methods
  where the source_location covers their entire definition.
* Matches the documentation which mentions
  "where the definition starts/ends".
* Partially reverts d357d50f0a74409446f4cccec78593373f5adf2f
  which was a workaround to be compatible with parse.y.
2025-12-30 16:02:39 +01:00
yui-knk
f81c62be3d Terminate args_tail_basic rule with a semicolon
Semicolon is optional however it clarifies the end of the rule.
2025-12-19 13:39:12 +08:00
Nobuyoshi Nakada
711d14992e
Adjust indents [ci skip] 2025-12-14 16:11:02 +09:00
Yusuke Endoh
129d74c96b Binding#implicit_parameters, etc. support the implicit "it" parameter
[Bug #21049]
2025-12-12 23:24:50 +09:00
yui-knk
c5b51bdd8c [Bug #21712] Allow .() call for command with block
This commit allows codes like `a b do end.()` and `a b do end&.()`.
2025-12-11 17:35:39 +08:00
yui-knk
056997cbcd Remove needless ruby2_keywords field from struct rb_args_info
`ruby2_keywords` is set only to be `0` in parse.y.
However `args->ruby2_keywords` is initialized with `0` by `MEMZERO`
in `rb_node_args_new` function and `body->param.flags.ruby2_keywords`
is initialized with `0` by `ZALLOC` in `rb_iseq_constant_body_alloc` function,
so `args->ruby2_keywords` does nothing for `body->param.flags.ruby2_keywords`.
2025-12-09 09:09:00 +08:00
yui-knk
576acb9502 Remove FORWARD_ARGS_WITH_RUBY2_KEYWORDS check
Because `FORWARD_ARGS_WITH_RUBY2_KEYWORDS` definition was removed
by 4f77d8d3289ece0e3537d9273a5c745120bff59a.
2025-12-09 09:09:00 +08:00
yui-knk
e96bbd718e Remove needless parse.y new_nil macro
In the past parse.y and ripper had different `new_nil` definition
so that `new_nil` returns `nil` for ripper.

```c
// parse.y
#define new_nil(loc) NEW_NIL(loc)

// ripper
#define new_nil(loc) Qnil
```

However Rearchitect Ripper (89cfc1520717257073012ec07105c551e4b8af7c)
removed `new_nil` definition for ripper then this commit removes
needless parse.y macro and uses `NEW_NIL` directly.
2025-12-04 08:39:54 +08:00
yui-knk
b79ef73a3b Remove needless parse.y value_expr macro
In the past parse.y and ripper had different `value_expr` definition
so that `value_expr` does nothing for ripper.

```c
// parse.y
#define value_expr(node) value_expr_gen(p, (node))

// ripper
#define value_expr(node) ((void)(node))
```

However Rearchitect Ripper (89cfc1520717257073012ec07105c551e4b8af7c)
removed `value_expr` definition for ripper then this commit removes
needless parse.y macro and uses `value_expr_gen` directly.
2025-12-04 08:39:54 +08:00
yui-knk
dfdc5d40ec Check and raise semantics errors on nested variables captures in patterns
This commit makes these codes to be invalid.

```ruby
case 0
in [a] | 1
end

case 0
in { a: b } | 1
end

case 0
in [{ a: [{ b: [{ c: }] }] }] | 1
end
```
2025-12-03 09:18:22 +08:00
Nobuyoshi Nakada
f4b6a5191c [Feature #21572] Syntax error at capture in alternation pattern
Should fail even with `-c` option.
2025-11-14 21:03:04 +09:00
yui-knk
560ec9bfd2 Skip null check for brace_block
`brace_block` is `'{' brace_body '}'` or `k_do do_body k_end`.
Both of them are not null so no need to check `$5`.
2025-11-14 10:23:35 +08:00
ydah
5179b7fb3f Rename mlhs rule to mlhs_items for clarity in parse.y
Since `mlhs` is already defined as a nonterminal as follows, using the same name as a parameterizing rule is a bit confusing, so rename the parameterizing rule.

8d1c459783/parse.y (L3648-L3654)
2025-09-21 17:36:45 +09:00
Nobuyoshi Nakada
d2cea4b688
* adjust indents. [ci skip] 2025-09-13 20:10:42 +09:00
Nobuyoshi Nakada
618224adf6
[Feature #20925] Support leading logical operators 2025-09-13 15:42:26 +09:00
yui-knk
a8c829e7f0 [Bug #17398] Allow private def hello = puts "Hello" 2025-09-13 10:58:07 +08:00
S-H-GAMELINKS
dd4e7801f3 Add NODE SCLASS locations
Add locations to struct `RNode_SCLASS`.

memo:

```
@ ProgramNode (location: (1,0)-(1,18))
+-- locals: []
+-- statements:
    @ StatementsNode (location: (1,0)-(1,18))
    +-- body: (length: 1)
        +-- @ SingletonClassNode (location: (1,0)-(1,18))
            +-- locals: []
            +-- class_keyword_loc: (1,0)-(1,5) = "class"
            +-- operator_loc: (1,6)-(1,8) = "<<"
            +-- expression:
            |   @ SelfNode (location: (1,9)-(1,13))
            +-- body: nil
            +-- end_keyword_loc: (1,15)-(1,18) = "end"
```
2025-08-30 22:41:23 +09:00
Yusuke Endoh
2ccb2de677 Make RubyVM::AST.of return a parent node of NODE_SCOPE
This change makes `RubyVM::AST.of` and `.node_id_for_backtrace_location`
return a parent node of NODE_SCOPE (such as NODE_DEFN) instead of the
NODE_SCOPE node itself.
(In future, we may remove NODE_SCOPE, which is a bit hacky AST node.)

This is preparation for [Feature #21543].
2025-08-28 12:44:04 +09:00
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
S-H-GAMELINKS
f0649ab46a Make defined? (x;) return expression when using parse.y parser
Follow up [Bug #21029].

Currently,  `defined? (x;)` returns `expression` when using Prism parser.

See:
- https://github.com/ruby/ruby/pull/12949
- https://bugs.ruby-lang.org/issues/21029

However, `defined? (x;)` returns nil when using parse.y, as reported in bug ticket comment and test-all (when using parse.y parser) test result.

This change adds a context flag to track trailing semicolons in defined? scope.
When a trailing semicolon is detected within a defined? scope, the generated AST node is wrapped with NODE_BLOCK.
This change ensures consistent behavior with `defined? (;x)` .
2025-07-16 16:17:10 +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
Nobuyoshi Nakada
0e0008da0f
[Bug #21381] Refine error messages for it and numbered parameters 2025-06-05 19:21:02 +09:00
ydah
b68172caad Rename f_optarg to f_opt_arg for consistency in parser rules 2025-04-15 00:39:12 +09:00
ydah
1c8154e5c9 Use call_op2 instead of call_op and tCOLON2 2025-04-14 23:13:57 +09:00
ydah
e255964542 Use user defined parameterizing rules range_expr 2025-04-14 03:21:17 +09:00
ydah
088fd968ed Add a new non-terminal symbol ternary to tidy up 2025-04-14 03:01:01 +09:00
ydah
e996699820 Refactor assignment rules to remove unnecessary lhs parameter 2025-04-14 01:15:20 +09:00
ydah
a35a101b4c Change the indent after lhs in generation rules from spaces to tabs
Change the indent to match the characters used in other generation rules. This makes it easier to find lhs.
2025-04-13 01:23:39 +09:00
tomoya ishida
a4a6019550
[Bug #21202] Fix wrong token concat while tokenizing nested unterminated heredoc (#13000) 2025-03-29 20:46:43 +09:00
ydah
549c7fe29d Adjust indentation for user defined parameterized rule
This PR just fixing indentation.
2025-03-29 17:51:19 +09:00
Nobuyoshi Nakada
820c541671 [Bug #21026] no singleton method on pseudo variable literal 2025-03-20 17:32:26 +09:00
Nobuyoshi Nakada
1acfb29015 [Bug #21186] multibyte char literal should be a single letter word 2025-03-17 23:55:11 +09:00
ydah
dd7deef338 Organize block_param_def by defining opt_block_param for non-terminal symbols 2025-03-14 17:10:33 +09:00
ydah
f5f1951808 Refactor parse.y to replace tIDENTIFIER and tCONSTANT with ident_or_const inline rules 2025-03-14 12:32:03 +09:00
ydah
84f51eb02a Use user defined parameterizing rules args_tail_basic 2025-03-14 00:20:35 +09:00
ydah
5965978efb Merge the new_yield method into the rb_node_yield_new method 2025-03-09 11:26:56 +09:00
ydah
caa7eaecc5 Refactor parser rules to remove inline_operation 2025-03-09 02:56:26 +09:00
ydah
24945defa5 Remove redundant semantic action in bvar rule 2025-03-08 22:20:11 +09: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
ydah
c93f30ab67 Use user defined parameterizing rules mlhs 2025-03-02 23:10:45 +09:00
ydah
6c8cdc9c6b Change superclass rhs to use none 2025-03-02 23:10:17 +09:00
ydah
3198b46a36 s/TERMINTOR/TERMINATOR/ 2025-02-25 10:29:15 +09:00
Nobuyoshi Nakada
21ac0a3a64
[Bug #21153] Add missing op-assign to top const in command_asgn
It was defined in `arg` only; moved that pattern to `op_asgn` rule to
share it with `command_asgn`.
2025-02-24 23:20:12 +09:00
S-H-GAMELINKS
5cf146399f Merge NODE_LINE and NODE_ENCODING cases in cond0 function
NODE_LINE and NODE_ENCODING cases are used SWITCH_BY_COND_TYPE macro that is same to NODE_INTEGER and other cases.
NODE_LINE and NODE_ENCODING cases can be marge to NODE_INTEGER and other node cases.
2025-02-24 18:44:57 +09:00
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