2738 Commits

Author SHA1 Message Date
Shugo Maeda
da37301f08 Keep room in the token buffer for the terminator
tokspace stops doubling as soon as the buffer reaches the token's length,
so a copy that lands exactly on the end leaves tokfix writing its
terminator one byte past it.  No caller passes a large enough n to reach
that today, but the invariant tokfix relies on is worth holding.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-20 22:49:27 +09:00
Nobuyoshi Nakada
db7fba3217
Make __VA_ARGS__ check mandatory
Since we already require C99 compilers, and autoconf 2.67 or later.
`__VA_ARGS__` is always available.
2026-07-13 20:03:55 +09:00
Nobuyoshi Nakada
3f7d4bc859 [Bug #22183] Preserve lpar_beg across interpolation
Fix unexpected `keyword_do_LAMBDA` inside string interpolation within
default argument of lambda.
2026-07-07 21:07:12 +09:00
Earlopain
7ea07dd74d [Bug #21994] Drop warning for ambiguous regexp use
https://bugs.ruby-lang.org/issues/21994
2026-07-06 09:38:14 -04:00
Nobuyoshi Nakada
d8444812f4
[Bug #22124] Add block to the proper node 2026-06-23 20:44:57 +09:00
Earlopain
11de89ca1a Reject END { next } as well
Followup for https://bugs.ruby-lang.org/issues/20409
2026-05-15 19:58:27 +09:00
Nobuyoshi Nakada
2f9432d211
[Bug #20409] Make break and redo in END syntax error 2026-05-12 20:04:00 +09:00
Nobuyoshi Nakada
803b3169e0
Show "END in method" warning immediately 2026-05-12 20:04:00 +09:00
Nobuyoshi Nakada
4644e4f2fa
[Bug #21986] Fix location of numeric literal
When checking for suffixes, do not flush the numeric literal token
even if no suffix is found.
2026-04-09 13:32:31 +09:00
Nobuyoshi Nakada
24a2ba09af [Bug #21985] Include the - in the negative numbers location 2026-04-08 14:50:30 +09:00
Jean Boussier
53099633e2 Make ruby_xfree_sized and ruby_xrealloc_sized public
[Feature #21861]
2026-04-01 08:10:07 +01:00
Nobuyoshi Nakada
ae9b60f189
[Feature #19107] parse.y: Allow trailing comma in method signature 2026-03-30 22:14:09 +09:00
Nobuyoshi Nakada
55694ad7ef
[Bug #21945] Correctly handle and? and similar 2026-03-07 10:39:46 +09:00
Nobuyoshi Nakada
d5d144c149
parse.y: Split forwarding argument in method and lambda
Eliminate the lambda argument conditions from the action.
2026-03-06 18:25:08 +09:00
Nobuyoshi Nakada
7a3940e8b6
Unify rb_node_list_new and rb_node_list_new2
The former is the specialized case of the latter.
2026-03-03 23:05:00 +09:00
Nobuyoshi Nakada
45dce19e22
parse.y: Parameterize argument list rules
Parametrize `block_param` and `f_args` into `arg-list` and
`tail-only-args`.  Since the pattern for `pre_args` alone differs
between `opt_comma` and `excessed_comma`, retain it within each rule.
2026-03-01 19:44:59 +09:00
Nobuyoshi Nakada
0980de4c1a
parse.y: Extract new_empty_args_tail macro 2026-03-01 12:10:06 +09:00
Nobuyoshi Nakada
504cf455fb
parse.y: Extract f_empty_arg 2026-03-01 12:04:38 +09:00
Nobuyoshi Nakada
851a10bcb5
Revert "parse.y: narrow excessed_comma to block_param_def"
This reverts commit 2239d54348d9f1f7768860efc9e76876f85766d8.
At first glance, it seemed like a good idea, but it wasn't all that
great.
2026-03-01 09:20:18 +09:00
Nobuyoshi Nakada
68080febee parse.y: Unify to use only tagged references
Unify references in rules that mix positional references and tagged
references.  Leave the positional reference-only rules unchanged.
2026-02-28 01:01:46 +09:00
Nobuyoshi Nakada
486f7fcc27 parse.y: prefer @$ over @0 in empty-rule actions 2026-02-27 23:47:11 +09:00
Nobuyoshi Nakada
2239d54348 parse.y: narrow excessed_comma to block_param_def 2026-02-27 13:10:04 +09:00
Nobuyoshi Nakada
116d402067 [Feature #19979] Method definition with &nil
Allow methods to declare that they don't accept a block via `&nil`.
2026-02-15 14:12:15 -05:00
Nobuyoshi Nakada
cb303ff4b8
[Bug #21669] Fix void value expression check for pattern-matching
If the all `in` and `else` branches are void, the `case` is also void.
2026-02-04 13:28:34 +09:00
Nobuyoshi Nakada
baaf0ccb9c
[Bug #21669] Fix void value expression check for block
A block containing a void statement that is not contained in a branch
is also void.
2026-02-04 13:28:34 +09:00
Nobuyoshi Nakada
932ce048fe
[Bug #21669] Implement void value expression check for case/when
If the all `when` and `else` branches are void, the `case` is also
void.
2026-02-04 13:28:33 +09:00
Nobuyoshi Nakada
4f36010738
[Bug #21669] Fix void value expression check for rescue-else
If `rescue`-else node is void, the `rescue`-body is also void.
2026-02-04 13:28:33 +09:00
Nobuyoshi Nakada
c8b2a453d0
[Bug #21669] Fix void value expression check for rescue
If any `rescue` node is non-void, the enclosing block is also
non-void.
2026-02-04 13:28:33 +09:00
Jean Boussier
9be01bc70d gc.c: also verify sized_xrealloc old size 2026-01-30 15:24:48 +01:00
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