Граф коммитов

2461 Коммитов

Автор SHA1 Сообщение Дата
yui-knk 5537a41059 Remove not used fields from CASE, CASE2, CASE3 2023-09-29 17:31:34 +09:00
yui-knk b9bf419aa3 Remove not used fields from ALIAS, VALIAS, UNDEF 2023-09-29 11:43:04 +09:00
yui-knk 52f8b347a0 Remove not used fields from DOT2, DOT3, FLIP2, FLIP3 2023-09-29 10:09:04 +09:00
yui-knk 37a783a30c Merge RNode_OP_ASGN2 and RNode_OP_ASGN22 2023-09-29 08:36:39 +09:00
yui-knk 23bcdda377 Remove not used fields from SELF, NIL, TRUE, FALSE 2023-09-29 07:43:29 +09:00
Nobuyoshi Nakada eaa0fbf9b9 Fix `retry` in nested `rescue` blocks
Restore `rescue`-context from the outer context.
`retry` targets the next outer block except for between `rescue` and
`else` or `ensure`, otherwise, if there is no enclosing block, it
should be syntax error.
2023-09-29 03:14:17 +09:00
Nobuyoshi Nakada b5e23d3e3b
Syntax check of `yield` in the parser 2023-09-28 16:23:51 +09:00
Nobuyoshi Nakada ad96962173
Jumps are possible in the top-level loop 2023-09-28 15:12:27 +09:00
yui-knk 74c6781153 Change RNode structure from union to struct
All kind of AST nodes use same struct RNode, which has u1, u2, u3 union members
for holding different kind of data.
This has two problems.

1. Low flexibility of data structure

Some nodes, for example NODE_TRUE, don’t use u1, u2, u3. On the other hand,
NODE_OP_ASGN2 needs more than three union members. However they use same
structure definition, need to allocate three union members for NODE_TRUE and
need to separate NODE_OP_ASGN2 into another node.
This change removes the restriction so make it possible to
change data structure by each node type.

2. No compile time check for union member access

It’s developer’s responsibility for using correct member for each node type when it’s union.
This change clarifies which node has which type of fields and enables compile time check.

This commit also changes node_buffer_elem_struct buf management to handle
different size data with alignment.
2023-09-28 11:58:10 +09:00
Nobuyoshi Nakada 5b36c11e21 Out of place jumps are valid in `defined?` 2023-09-27 21:53:01 +09:00
Nobuyoshi Nakada 29e5fca718 Syntax check of `retry` in the parser 2023-09-27 21:53:01 +09:00
Nobuyoshi Nakada ff8278e52c Fix error token location 2023-09-27 21:53:01 +09:00
Nobuyoshi Nakada e1250a5f97 Syntax check of block exits in the parser 2023-09-27 21:53:01 +09:00
Nobuyoshi Nakada e2a5f0469c Use named references for method/class/module definitions 2023-09-25 23:04:09 +09:00
Nobuyoshi Nakada 03ef85bee7 Extract class/module context checks 2023-09-25 23:04:09 +09:00
Nobuyoshi Nakada 56604c7a3b Split the build of `RESBODY` nodes 2023-09-25 23:04:09 +09:00
Nobuyoshi Nakada 4449dcac15 Reduce stack usage in `string_content` 2023-09-25 23:04:09 +09:00
Nobuyoshi Nakada dd292640bf Remove `escape_Qundef`
Ripper dispatcher methods always escape `Qundef` by `get_value`.
2023-09-25 23:04:09 +09:00
Nobuyoshi Nakada 963d12722e Name midrules in complex rules 2023-09-25 23:04:09 +09:00
yui-knk 34d802f32f Refactor to use ripper_new_yylval2 2023-09-24 12:58:01 +09:00
yui-knk f38f8d4f4a The first arg of NEW_OPT_ARG is always 0 2023-09-24 09:08:39 +09:00
yui-knk fb7a2ddb4b Directly free structure managed by imemo tmpbuf
NODE_ARGS, NODE_ARYPTN, NODE_FNDPTN manage memory of their
structure by imemo tmpbuf Object.
However rb_ast_struct has reference to NODE. Then these
memory can be freed directly when rb_ast_struct is freed.

This commit reduces parser's dependency on CRuby functions.
2023-09-22 11:25:53 +09:00
Nobuyoshi Nakada e9a36f8abe
Tag `p_lparen` and `p_lbracket` as `tbl`
Remove tagging to the component for each reference.
2023-09-17 16:22:01 +09:00
Nobuyoshi Nakada 69d7871b02
ripper: Preprocess ripper-dispatchable types only
Keep the other types, which not having setter macros for ripper.
2023-09-17 16:22:01 +09:00
yui-knk df316be401 nd_aid of NODE_OP_ASGN_OR is not used then no need to set it 2023-09-17 16:04:42 +09:00
Nobuyoshi Nakada e6ce490337
Align comments [ci skip] 2023-09-16 22:13:18 +09:00
Nobuyoshi Nakada 89802078f9
[Bug #19882] Reject tokens invalid as symbols 2023-09-15 17:27:36 +09:00
Nobuyoshi Nakada 9cb33aad55
[Bug #19877] Fix flip-flop in block 2023-09-15 01:09:07 +09:00
Nobuyoshi Nakada 864bb8680c
[Bug #19877] Named captures should take place from regexps in block 2023-09-15 01:09:06 +09:00
Nobuyoshi Nakada e8896a31d4
[Bug #19877] Literals cannot have singleton methods even in blocks 2023-09-15 01:09:06 +09:00
Nobuyoshi Nakada 3f492921c8
Reuse `rb_reg_named_capture_assign_iter_impl` 2023-09-15 01:09:06 +09:00
Nobuyoshi Nakada b55785579c
Restore `in_defined` flag at nested `defined?` 2023-09-12 22:02:48 +09:00
Nobuyoshi Nakada 1ae5dd6f32
Rename `NODE_NEW_TEMPORAL` as `NODE_NEW_INTERNAL` 2023-09-12 02:09:22 +09:00
Nobuyoshi Nakada b8d0ab80bb
Declare `k_class` and `k_module` as `ctxt`
So that it is not ncessary to specify the type each time.
2023-09-10 21:37:44 +09:00
Yuichiro Kaneko 16882d4ebb
Add a new line between function definitions [ci skip] 2023-09-10 19:46:12 +09:00
Nobuyoshi Nakada bd046764e3
[Bug #19549] Check for variables to be interpolated 2023-09-07 13:41:13 +09:00
yui-knk 45cd011d73 [Bug #19281] Allow semicolon in parenthesis at the first argument of command call
Allow compstmt in the first argument of command call wrapped with parenthesis
like following arguments with parenthesis.
2023-09-01 12:55:09 +09:00
Nobuyoshi Nakada 9930363aab [Bug-18878] Parse qualified const with brace block as method call 2023-09-01 04:26:31 +09:00
yui-knk 2e648bfee4 [DOC] Detailed explanation when one line pattern matching is a void value expression 2023-08-30 12:47:09 +09:00
yui-knk cfdbbd6726 kw_rest_arg nd_cflag has not been used since 9720136 2023-08-26 08:45:02 +09:00
Nobuyoshi Nakada 40efbc7e40 [Bug #19851] Ripper: Hide internal block argument ID 2023-08-26 02:08:53 +09:00
Nobuyoshi Nakada fe73f9f24b
Replace only use of `snprintf` in parser 2023-08-25 23:34:02 +09:00
Nobuyoshi Nakada 1f76e42b85 [Bug #19848] Flush BOM
The token just after BOM needs to position at column 0, so that the
indentation matches closing line.
2023-08-25 20:07:10 +09:00
Nobuyoshi Nakada 6aa16f9ec1 Move SCRIPT_LINES__ away from parse.y 2023-08-25 18:23:05 +09:00
卜部昌平 26cb3b5617 config.h has to be the very beginning
This header defines several essential macros.
2023-08-25 17:27:53 +09:00
yui-knk ce79887da0 The first arg of NEW_KW_ARG macro is always 0 2023-08-24 07:47:52 +09:00
Nobuyoshi Nakada 0d7e847153
Consider the special node when printing
Appreciation to the reporter, Huichiao Tsai <hctsai.cs10@nycu.edu.tw>.
2023-08-16 23:52:04 +09:00
Peter Zhu 0b8f15575a Fix memory leak for incomplete lambdas
[Bug #19836]

The parser does not free the chain of `struct vtable`, which causes
memory leaks.

The following script reproduces this issue:

```
10.times do
  100_000.times do
    Ripper.parse("-> {")
  end

  puts `ps -o rss= -p #{$$}`
end
```
2023-08-09 14:06:58 -04:00
Peter Zhu 5bc8fceca8 Fix memory leak in parser for incomplete tokens
[Bug #19835]

The parser does not free the `tbl` of the `struct vtable` when there are
leftover `lvtbl` in the parser. This causes a memory leak.

The following script reproduces this issue:

```
10.times do
  100_000.times do
    Ripper.parse("class Foo")
  end

  puts `ps -o rss= -p #{$$}`
end
```
2023-08-09 14:06:58 -04:00
Nobuyoshi Nakada 382678d411 [Bug #19788] Use the result of `tCOLON2` event 2023-08-01 19:00:31 +09:00
Koichi Sasada 6a5c548218 remove strange line event
```ruby
  def helper_cant_rescue
    begin
      raise SyntaxError
    rescue
      cant_rescue # here
    end
  end
```

on this case, a line event is reported on `cant_rescue` line
because of node structure. it should not be reported.
2023-08-01 18:06:25 +09:00
Nobuyoshi Nakada 26aef1c736 Use `lex_eol_p` family 2023-07-26 11:39:29 +09:00
S-H-GAMELINKS 76ea8ecbf3 Supress warning that variable may be used uninitialized with ripper building 2023-07-20 21:55:44 +09:00
yui-knk 82cd70ef93 Use functions defined by parser_st.c to reduce dependency on st.c 2023-07-15 12:50:40 +09:00
S-H-GAMELINKS acd9c208d5 Move some macro for universal parser 2023-07-09 15:00:52 +09:00
S-H-GAMELINKS 8b2a0ec8df Move ISASCII defination to parse.y 2023-07-08 15:26:55 +09:00
Nobuyoshi Nakada 8ddfc17720 Use `uint_least32_t`
The elements of `ruby_global_name_punct_bits` table are 32-bit masks.
2023-07-04 21:30:44 +09:00
S-H-GAMELINKS 3fd1968d6f Introduce script_lines function for refactor script_lines_defined and script_lines_get functions 2023-07-01 23:17:57 +09:00
Jeremy Evans 1bc8838d60
Handle unterminated unicode escapes in regexps
This fixes an infinite loop possible after ec3542229b.
For \u{} escapes in regexps, skip validation in the parser, and rely on the regexp
code to handle validation. This is necessary so that invalid unicode escapes in
comments in extended regexps are allowed.

Fixes [Bug #19750]

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
2023-06-30 19:37:53 -07:00
Peter Zhu 58386814a7 Don't check for null pointer in calls to free
According to the C99 specification section 7.20.3.2 paragraph 2:

> If ptr is a null pointer, no action occurs.

So we do not need to check that the pointer is a null pointer.
2023-06-30 09:13:31 -04:00
Nobuyoshi Nakada 1344de5621
[Bug #19743] All but EOF can be read again after push-back 2023-06-22 20:10:13 +09:00
Nobuyoshi Nakada 6be402e172
[Bug #19736] Recover after unterminated interpolation 2023-06-20 20:10:46 +09:00
yui-knk 4f79c83a6a Remove coverage_enabled from parser_params
`yyparse` never changes the value of `coverage_enabled`.
`coverage_enabled` depends on only return value of `e_option_supplied`.
Therefore `parser_params` doesn't need to have `coverage_enabled.
2023-06-18 10:10:52 +09:00
yui-knk d444f1b1fa Specify int bitfield as signed int bitfield
sunc treats int bitfield as unsigned int.
This commit will fix build failure on sunc.

* http://rubyci.s3.amazonaws.com/solaris10-sunc/ruby-master/log/20230617T100003Z.fail.html.gz
* http://rubyci.s3.amazonaws.com/solaris11-sunc/ruby-master/log/20230617T090011Z.fail.html.gz
2023-06-17 22:02:13 +09:00
yui-knk 19c62b400d Replace parser & node compile_option from Hash to bit field
This commit reduces dependency to CRuby object.
2023-06-17 16:41:08 +09:00
Nobuyoshi Nakada 81836c6cb9
Fix duplicate symbol errors when statically linking ripper 2023-06-12 20:22:01 +09:00
yui-knk b481b673d7 [Feature #19719] Universal Parser
Introduce Universal Parser mode for the parser.
This commit includes these changes:

* Introduce `UNIVERSAL_PARSER` macro. All of CRuby related functions
  are passed via `struct rb_parser_config_struct` when this macro is enabled.
* Add CI task with 'cppflags=-DUNIVERSAL_PARSER' for ubuntu.
2023-06-12 18:23:48 +09:00
yui-knk 5f65e8c5d5 Rename `rb_node_name` to the original name
98637d421d changes the name of
the function. However this function is exported as global,
then change the name to origin one for keeping compatibility.
2023-05-24 20:54:48 +09:00
yui-knk 98637d421d Move `ruby_node_name` to node.c and rename prefix of the function 2023-05-23 18:05:35 +09:00
Nobuyoshi Nakada 91c004885f
[Bug #19025] Numbered parameter names are always local variables 2023-05-14 22:16:15 +09:00
Nobuyoshi Nakada bdaa491565 Add user argument to some macros used by bison 2023-05-14 15:38:48 +09:00
S-H-GAMELINKS b632566f7e Introduce anddot_multiple_assignment_check function 2023-05-14 10:32:25 +09:00
Nobuyoshi Nakada b15e88e0fc
[Bug #19619] Preserve numbered parameters context
Preserve numbered parameters context across method definitions
2023-05-02 17:39:18 +09:00
Nobuyoshi Nakada b82c06a711
Handle private AREF call in compile.c 2023-04-30 23:21:59 +09:00
Takashi Kokubun 4af9bd52cb Get rid of a breakpoint left in parse.y 2023-04-10 11:22:12 -07:00
Nobuyoshi Nakada ac8a16237c
[Bug #19563] Yield words separators per lines
So that newlines across a here-doc terminator will be separated
tokens.

Cf. https://github.com/ruby/irb/pull/558
2023-04-07 23:13:56 +09:00
Kazuki Tsujimoto 4ac8d11724
`*` in an array pattern should not be parsed as nil in ripper
After 6c0925ba70, it was impossible
to distinguish between the presence or absence of `*`.

    # Before the commit
    Ripper.sexp('0 in []')[1][0][2][1]  #=> [:aryptn, nil, nil, nil, nil]
    Ripper.sexp('0 in [*]')[1][0][2][1] #=> [:aryptn, nil, nil, [:var_field, nil], nil]

    # After the commit
    Ripper.sexp('0 in []')[1][0][2][1]  #=> [:aryptn, nil, nil, nil, nil]
    Ripper.sexp('0 in [*]')[1][0][2][1] #=> [:aryptn, nil, nil, nil, nil]

This commit reverts it.
2023-04-01 16:35:24 +09:00
yui-knk 3488eda41d Fix gc_verify_internal_consistency error for pattern_matching in ripper
`gc_verify_internal_consistency` reports "found internal inconsistency"
for "test_pattern_matching.rb".

http://ci.rvm.jp/results/trunk-gc-asserts@ruby-sp2-docker/4501173

Ruby's parser manages objects by two different ways.

1. For parser

* markable node holds objects
* call `RB_OBJ_WRITTEN` with `p->ast` as parent
* `mark_ast_value` marks objects

2. For ripper

* unmarkable node, NODE_RIPPER/NODE_CDECL, holds objects
* call `rb_ast_add_mark_object`. This function calls `rb_hash_aset` then
  `RB_OBJ_WRITTEN` is called with `mark_hash` as parent
* `mark_hash` marks objects

However in current pattern_matching implementation

* markable node holds objects
* call `rb_ast_add_mark_object`

This commit fix it to be #2.

This was inconsistency however always `mark_hash` is
made young by `rb_ast_add_mark_object` call then objects
are not collected.
2023-03-31 09:38:34 +09:00
Nobuyoshi Nakada 6f122965cf [Bug #19547] Add token for unescaped backslash
This token is exposed only when `RubyVM::AbstractSyntaxTree` with
`keep_tokens` option.
2023-03-30 19:47:36 +09:00
Kazuki Tsujimoto d51529244f
[Bug #19175] p_kw without a sub pattern should be `assignable' 2023-03-26 18:57:34 +09:00
Kazuki Tsujimoto 6c0925ba70
[Bug #19175] p_rest should be `assignable'
It should also check for duplicate names.
2023-03-26 18:56:21 +09:00
Nobuyoshi Nakada 67dd52d59c
[Bug #19539] Match heredoc identifier from end of line
Not to ignore leading spaces in indented heredoc identifier.
2023-03-19 01:35:21 +09:00
Takashi Kokubun c5e9af9c9d Expand tabs in parse.y
I used the same script as https://github.com/ruby/ruby/pull/6094 but
for a .y file.
2023-03-09 09:32:11 -08:00
Nobuyoshi Nakada 538c3b9ab7
Suppress -Wunused-but-set-variable warning 2023-02-14 19:26:41 +09:00
Nobuyoshi Nakada 7b343d9c67 Extract body rules from endless method definitions 2023-02-01 16:17:12 +09:00
yui-knk e82cef1762 Remove not used argument from tokenize_ident
This has not been used since 5e59be3edd
2023-01-25 10:52:37 +09:00
Nobuyoshi Nakada 41fbcc5193
Fix format specifiers for pointer differences 2023-01-07 11:47:50 +09:00
Nobuyoshi Nakada cee5beab1d [Bug #19312] Return end-of-input at `__END__` 2023-01-06 13:13:07 +01:00
Nobuyoshi Nakada 3becc4a105
[Bug #19291] Rewind to the previous line
When rewinding looking ahead after newline token, also reset the last
line string, the pointers to it, and the location, not only the line
number.
2023-01-02 16:12:08 +09:00
yui-knk adc29351f7 EXPR_DOT is set when next token is tANDDOT ("&.") [ci skip] 2022-12-26 17:34:57 +09:00
Shugo Maeda 2581de112c Disallow mixed usage of ... and */**
[Feature #19134]
2022-12-15 18:56:24 +09:00
Nobuyoshi Nakada 764da87ab0 [Bug #19195] Allow optional newlines before closing parenthesis 2022-12-13 18:06:11 +09:00
Shugo Maeda 04311008b6
Use loc to fix a failure of test_ast.rb
```
    1) Failure:
  TestAst#test_ranges:test/fiber/scheduler.rb [/home/runner/work/ruby/ruby/src/test/ruby/test_ast.rb:122]:
  <[]> expected but was
  <[{:type=>:max_validation_error,
    :max=>
     #<RubyVM::AbstractSyntaxTree::Node::CodePosition:0x00007f80d630b598
      @column=20,
      @lineno=203>,
    :end_pos=>
     #<RubyVM::AbstractSyntaxTree::Node::CodePosition:0x00007f80d630b778
      @column=19,
      @lineno=203>,
    :node=>
     (BLOCK_PASS@203:15-203:19
        (ARGSPUSH@203:15-203:20 (SPLAT@203:16-203:19 (LVAR@203:16-203:19 :*))
           (HASH@203:16-203:19
              (LIST@203:16-203:19 nil (LVAR@203:16-203:19 :**) nil)))
        (LVAR@203:16-203:19 :&))}]>.
```
2022-12-05 15:54:21 +09:00
Shugo Maeda 2649055c98
Should use argsloc for the last argument for arg_append() 2022-12-05 15:10:15 +09:00
S-H-GAMELINKS 1a64d45c67 Introduce encoding check macro 2022-12-02 01:31:27 +09:00
yui-knk 8be62f06c8 Remove ruby2_keywords related to args forwarding
This was introduced by b609bdeb53
to suppress warnings. However these warngins were deleted by
beae6cbf0f. Therefore these codes
are not needed anymore.
2022-11-29 15:39:56 +09:00
Shugo Maeda a0e4dc52b0 Use idFWD_* instead of ANON_*_ID 2022-11-29 11:22:09 +09:00
Shugo Maeda 4fc668a4f3 Allow ** in def foo(...)
[Feature #19134]
2022-11-29 11:22:09 +09:00
Jeremy Evans f5d73da806 Fix the position of rescue clause without exc_list
If the rescue clause has only exc_var and not exc_list, use the
exc_var position instead of the rescue body position.

This issue appears to have been introduced in
688169fd83 when "opt_list" was split
into "exc_list exc_var".

Fixes [Bug #18974]
2022-11-24 14:26:08 -08:00
yui-knk 854312eede Refactor to use has_delayed_token macro 2022-11-21 16:32:13 +09:00
yui-knk d8601621ed Enhance keep_tokens option for RubyVM::AbstractSyntaxTree parsing methods
Implementation for Language Server Protocol (LSP) sometimes needs token information.
For example both `m(1)` and `m(1, )` has same AST structure other than node locations
then it's impossible to check the existence of `,` from AST. However in later case,
it might be better to suggest variables list for the second argument.
Token information is important for such case.

This commit adds these methods.

* Add `keep_tokens` option for `RubyVM::AbstractSyntaxTree.parse`, `.parse_file` and `.of`
* Add `RubyVM::AbstractSyntaxTree::Node#tokens` which returns tokens for the node including tokens for descendants nodes.
* Add `RubyVM::AbstractSyntaxTree::Node#all_tokens` which returns all tokens for the input script regardless the receiver node.

[Feature #19070]

Impacts on memory usage and performance are below:

Memory usage:

```
$ cat test.rb
root = RubyVM::AbstractSyntaxTree.parse_file(File.expand_path('../test/ruby/test_keyword.rb', __FILE__), keep_tokens: true)

$ /usr/bin/time -f %Mkb /usr/local/bin/ruby -v
ruby 3.2.0dev (2022-11-19T09:41:54Z 19070-keep_tokens d3af1b8057) [x86_64-linux]
11408kb

# keep_tokens :false
$ /usr/bin/time -f %Mkb /usr/local/bin/ruby test.rb
17508kb

# keep_tokens :true
$ /usr/bin/time -f %Mkb /usr/local/bin/ruby test.rb
30960kb
```

Performance:

```
$ cat ../ast_keep_tokens.yml
prelude: |
  src = <<~SRC
    module M
      class C
        def m1(a, b)
          1 + a + b
        end
      end
    end
  SRC
benchmark:
  without_keep_tokens: |
    RubyVM::AbstractSyntaxTree.parse(src, keep_tokens: false)
  with_keep_tokens: |
    RubyVM::AbstractSyntaxTree.parse(src, keep_tokens: true)

$ make benchmark COMPARE_RUBY="./ruby" ARGS=../ast_keep_tokens.yml
/home/kaneko.y/.rbenv/shims/ruby --disable=gems -rrubygems -I../benchmark/lib ../benchmark/benchmark-driver/exe/benchmark-driver \
            --executables="compare-ruby::./ruby -I.ext/common --disable-gem" \
            --executables="built-ruby::./miniruby -I../lib -I. -I.ext/common  ../tool/runruby.rb --extout=.ext  -- --disable-gems --disable-gem" \
            --output=markdown --output-compare -v ../ast_keep_tokens.yml
compare-ruby: ruby 3.2.0dev (2022-11-19T09:41:54Z 19070-keep_tokens d3af1b8057) [x86_64-linux]
built-ruby: ruby 3.2.0dev (2022-11-19T09:41:54Z 19070-keep_tokens d3af1b8057) [x86_64-linux]
warming up..

|                     |compare-ruby|built-ruby|
|:--------------------|-----------:|---------:|
|without_keep_tokens  |     21.659k|   21.303k|
|                     |       1.02x|         -|
|with_keep_tokens     |      6.220k|    5.691k|
|                     |       1.09x|         -|
```
2022-11-21 09:01:34 +09:00
yui-knk f0ce118662 Make anonymous rest arg (*) and block arg (&) accessible from ARGS node 2022-11-18 18:25:42 +09:00
Shugo Maeda ddd62fadaf Allow anonymous keyword rest parameter with other keyword parameters
Fixes [Bug #19132]
2022-11-18 18:23:06 +09:00
S-H-GAMELINKS 1f4f6c9832 Using UNDEF_P macro 2022-11-16 18:58:33 +09:00
Nobuyoshi Nakada 230267d1a8 Now bison 3.0 or later is required 2022-11-09 21:34:02 +09:00
yui-knk f7db1affd1 Set default %printer for NODE nterms
Before:

```
Reducing stack by rule 639 (line 5062):
   $1 = token "integer literal" (1.0-1.1: 1)
-> $$ = nterm simple_numeric (1.0-1.1: )
```

After:

```
Reducing stack by rule 641 (line 5078):
   $1 = token "integer literal" (1.0-1.1: 1)
-> $$ = nterm simple_numeric (1.0-1.1: NODE_LIT)
```

`"<*>"` is supported by Bison 2.3b (2008-05-27) or later.
https://git.savannah.gnu.org/cgit/bison.git/commit/?id=12e3584054c16ab255672c07af0ffc7bb220e8bc

Therefore developers need to install Bison 2.3b+ to build ruby from
source codes if their Bison is older.

Minimum version requirement for Bison is changed to 3.0.

See: https://bugs.ruby-lang.org/issues/19068 [Feature #19068]
2022-11-08 12:30:03 +09:00
Nobuyoshi Nakada 546566d34b
Do not set `$!` to `SyntaxError` when error tolerant 2022-10-09 19:07:21 +09:00
yui-knk 8483737bbf Fix typos 2022-10-08 23:29:36 +09:00
yui-knk 50f5223236 Fix SEGV of dump parsetree
Assign internal_id to semantic value so that dump parsetree option
can render the tree for these codes without SEGV.

* `def m(&); end`
* `def m(*); end`
* `def m(**); end`
2022-10-08 22:30:50 +09:00
yui-knk 3531086095 "expr_value" can be error
So that "IF" node is kept in the case below

```
def m
  if
end
```

[Feature #19013]
2022-10-08 17:59:11 +09:00
yui-knk 4bfdf6d06d Move `error` from top_stmts and top_stmt to stmt
By this change, syntax error is recovered smaller units.
In the case below, "DEFN :bar" is same level with "CLASS :Foo"
now.

```
module Z
  class Foo
    foo.
  end

  def bar
  end
end
```

[Feature #19013]
2022-10-08 17:59:11 +09:00
yui-knk 4f24f3ea94 Treat "end" as reserved word with consideration of indent
"end" after "." or "::" is treated as local variable or method,
see `EXPR_DOT_bit` for detail.
However this "changes" where `bar` method is defined. In the example
below it is not module Z but class Foo.

```
module Z
  class Foo
    foo.
  end

  def bar
  end
end
```

[Feature #19013]
2022-10-08 17:59:11 +09:00
yui-knk 342d4c16d9 Generates "end" tokens if parser hits end of input
but "end" tokens are needed for correct language.

[Feature #19013]
2022-10-08 17:59:11 +09:00
yui-knk fbbdbdd891 Add error_tolerant option to RubyVM::AST
If this option is enabled, SyntaxError is not raised and Node is
returned even if passed script is broken.

[Feature #19013]
2022-10-08 17:59:11 +09:00
Shugo Maeda a8ad22d926
Suppress a warning on clang
The following warning appears without this fix:

```
parse.y:78:1: warning: unknown warning group '-Wpsabi', ignored
      [-Wunknown-warning-option]
RBIMPL_WARNING_IGNORED(-Wpsabi)
^
./include/ruby/internal/warning_push.h:103:39: note: expanded from macro
      'RBIMPL_WARNING_IGNORED'
                                      ^
./include/ruby/internal/warning_push.h:99:39: note: expanded from macro
      'RBIMPL_WARNING_PRAGMA2'
                                      ^
./include/ruby/internal/warning_push.h:98:39: note: expanded from macro
      'RBIMPL_WARNING_PRAGMA1'
                                      ^
./include/ruby/internal/warning_push.h:97:39: note: expanded from macro
      'RBIMPL_WARNING_PRAGMA0'
                                      ^
<scratch space>:49:27: note: expanded from here
 clang diagnostic ignored "-Wpsabi"
                          ^
1 warning generated.
```
2022-09-26 14:44:54 +09:00
S.H 960db13c47
Reuse `opt_arg_append` function 2022-09-14 23:10:21 +09:00
Kazuki Tsujimoto db0e0dad11
Fix unexpected "duplicated key name" error in paren-less one line pattern matching
[Bug #18990]
2022-09-09 14:00:27 +09:00
Nobuyoshi Nakada ace2eee544
[Bug #18963] Separate string contents by here document terminator 2022-08-28 09:29:24 +09:00
S.H 13d31331c8
Reuse `nonlocal_var` patterns 2022-08-22 18:52:36 +09:00
S-H-GAMELINKS 3541f32951 Reuse opt_nl rule 2022-08-19 09:51:06 +09:00
S-H-GAMELINKS f095361758 Repalce to NIL_P macro 2022-08-19 09:47:43 +09:00
Nobuyoshi Nakada 844a0edbae [Bug #18962] Do not read again once reached EOF
`Ripper::Lexer#parse` re-parses the source code with syntax errors
when `raise_errors: false`.

Co-Authored-By: tompng <tomoyapenguin@gmail.com>
2022-08-12 15:58:18 +09:00
Kevin Backhouse 8c1808151f
Fix some UBSAN false positives (#6115)
* Fix some UBSAN false positives.
* ruby tool/update-deps --fix
2022-07-12 11:48:10 -07:00
Nobuyoshi Nakada eaeb130b11 [Bug #18890] newline should be insignificant after pattern label 2022-07-06 08:32:36 +09:00
Nobuyoshi Nakada 982cda9a3e [Bug #18877] Let `lex_ctxt` not to eat escaped whitespace 2022-06-30 16:31:51 +09:00
Nobuyoshi Nakada 685efac059
[Bug #18884] `class` cannot be just followed by modifiers 2022-06-29 14:13:15 +09:00
Nobuyoshi Nakada 961543945f
Suppress notes for old gcc 2022-06-23 22:52:45 +09:00
S-H-GAMELINKS 420f3ced4d Using is_ascii_string to check encoding 2022-06-17 12:02:50 +09:00
Nobuyoshi Nakada cd5cafa4a3 Respect the encoding of the source [Bug #18827]
Do not override the input string encoding at the time of preparation,
the source encoding is not determined from the input yet.
2022-06-17 01:48:52 +09:00
Nobuyoshi Nakada bb12aa4d15
Remove unnecessary condition
`no_blockarg` is called for non-null `node` only.
2022-06-15 22:17:23 +09:00
Nobuyoshi Nakada 1a70973f75 ripper: Check if anonymous parameters defined [Bug #18828] 2022-06-14 20:41:41 +09:00
Jeremy Evans ec3542229b
Ignore invalid escapes in regexp comments
Invalid escapes are handled at multiple levels.  The first level
is in parse.y, so skip invalid unicode escape checks for regexps
in parse.y.

Make rb_reg_preprocess and unescape_nonascii accept the regexp
options.  In unescape_nonascii, if the regexp is an extended
regexp, when "#" is encountered, ignore all characters until the
end of line or end of regexp.

Unfortunately, in extended regexps, you can use "#" as a non-comment
character inside a character class, so also parse "[" and "]"
specially for extended regexps, and only skip comments if "#" is
not inside a character class. Handle nested character classes as well.

This issue doesn't just affect extended regexps, it also affects
"(#?" comments inside all regexps.  So for those comments, scan
until trailing ")" and ignore content inside.

I'm not sure if there are other corner cases not handled.  A
better fix would be to redesign the regexp parser so that it
unescaped during parsing instead of before parsing, so you already
know the current parsing state.

Fixes [Bug #18294]

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
2022-06-06 13:50:03 -07:00
Nobuyoshi Nakada 3ddf6ad4d2
Private local variables should shadow outer variables [Bug #18629] 2022-04-21 16:04:36 +09:00
Nobuyoshi Nakada 08b6aacc1a
Fix the wrong index of the previous component [Bug #18739] 2022-04-18 18:37:09 +09:00
Jeremy Evans 3bb70a6924 Fix using anonymous block in method accepting explicit keywords
Record block ID before vtable_pop, so the incorrect one doesn't
override it.

Fixes [Bug #18673]
2022-04-05 07:35:25 -07:00
Kazuki Tsujimoto db6b23c76c
Find pattern is no longer experimental [Feature #18585] 2022-02-19 18:45:49 +09:00
Kazuki Tsujimoto 3200d97e95
Fix location of NODE_LIT in p_kw 2022-02-19 18:45:36 +09:00
S-H-GAMELINKS e6b537e605 Reuse operation rule for operation2 2022-02-12 12:28:07 +09:00
S-H-GAMELINKS c0651b4ae1 Reuse p_kwnorest rule for f_no_kwarg 2022-02-12 12:27:49 +09:00
Vladimir Dementyev b633c9ac1c
Reduce p_args rules with p_rest 2022-01-11 19:58:57 +09:00
Nobuyoshi Nakada 6baa78bb78 Use chomp: option when chomp mode
Get rid of depending on using $/ internally in String#chomp!, and
chomp the separator at once.
2022-01-07 09:23:38 +09:00
Nobuyoshi Nakada 83b987054a Explicitly pass $/ when loop mode
Get rid of depending on using $/ internally in ARGF.gets.
2022-01-07 09:23:38 +09:00
Jeremy Evans f53dfab95c Add support for anonymous rest and keyword rest argument forwarding
This allows for the following syntax:

```ruby
def foo(*)
  bar(*)
end
def baz(**)
  quux(**)
end
```

This is a natural addition after the introduction of anonymous
block forwarding.  Anonymous rest and keyword rest arguments were
already supported in method parameters, this just allows them to
be used as arguments to other methods.  The same advantages of
anonymous block forwarding apply to rest and keyword rest argument
forwarding.

This has some minor changes to #parameters output.  Now, instead
of `[:rest], [:keyrest]`, you get `[:rest, :*], [:keyrest, :**]`.
These were already used for `...` forwarding, so I think it makes
it more consistent to include them in other cases.  If we want to
use `[:rest], [:keyrest]` in both cases, that is also possible.

I don't think the previous behavior of `[:rest], [:keyrest]` in
the non-... case and `[:rest, :*], [:keyrest, :**]` in the ...
case makes sense, but if we did want that behavior, we'll have to
make more substantial changes, such as using a different ID in the
... forwarding case.

Implements [Feature #18351]
2021-12-30 14:37:42 -08:00
S.H 9b187fec58
Add `rb_parser_set_pos` function
Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
Co-authored-by: Marivaldo Cavalheiro <marivaldo@gmail.com>
2021-12-16 20:03:44 +09:00
Nobuyoshi Nakada aa7c4c37d7 Fix arg_forward without parentheses [Bug #18267] 2021-12-15 07:01:20 +09:00
Nobuyoshi Nakada 3a6b79d0c0 Revert "Rename `in_kwarg` as `in_argdef` as unrelated to keywords"
This reverts commit b7f7117bdc, to
separate `in_argdef` from `in_kwarg`.
2021-12-15 07:01:20 +09:00
Nobuyoshi Nakada 637c3cfc5d Turn SET_LEX_STATE macro into an inline function call 2021-12-15 01:52:15 +09:00
Nobuyoshi Nakada a3934cd1e5
Fix indent [ci skip] 2021-12-15 00:50:39 +09:00
Nobuyoshi Nakada 54f0e63a8c Remove `NODE_DASGN_CURR` [Feature #18406]
This `NODE` type was used in pre-YARV implementation, to improve
the performance of assignment to dynamic local variable defined at
the innermost scope.  It has no longer any actual difference with
`NODE_DASGN`, except for the node dump.
2021-12-13 12:53:03 +09:00
S.H ec7f14d9fa
Add `nd_type_p` macro 2021-12-04 00:01:24 +09:00
Nobuyoshi Nakada c14f230b26 Assign temporary ID to anonymous ID [Bug #18250]
Dumped iseq binary can not have unnamed symbols/IDs, and ID 0 is
stored instead.  As `struct rb_id_table` disallows ID 0, also for
the distinction, re-assign a new temporary ID based on the local
variable table index when loading from the binary, as well as the
parser.
2021-11-23 21:03:19 +09:00
Yusuke Endoh feda058531 Refactor hacky ID tables to struct rb_ast_id_table_t
The implementation of a local variable tables was represented as `ID*`,
but it was very hacky: the first element is not an ID but the size of
the table, and, the last element is (sometimes) a link to the next local
table only when the id tables are a linked list.

This change converts the hacky implementation to a normal struct.
2021-11-21 08:59:24 +09:00
Jeremy Evans 4adb012926 Anonymous block forwarding allows a method to forward a passed
block to another method without having to provide a name for the
block parameter.

Implements [Feature #11256]

Co-authored-by: Yusuke Endoh mame@ruby-lang.org
Co-authored-by: Nobuyoshi Nakada nobu@ruby-lang.org
2021-11-18 14:17:57 -08:00
Yusuke Endoh 415671a282 parse.y: Fix memory leak at parse error
Local variable tables might leak at the parse error.
2021-11-12 17:36:39 +09:00
Peter Zhu aeae6e2842 [Feature #18290] Remove all usages of rb_gc_force_recycle
This commit removes usages of rb_gc_force_recycle since it is a burden
to maintain and makes changes to the GC difficult.
2021-11-08 14:05:54 -05:00
Nobuyoshi Nakada 13a9597c7c Argument forwarding definition without parentheses [Bug #18267] 2021-10-31 18:27:55 +09:00
Nobuyoshi Nakada b7f7117bdc
Rename `in_kwarg` as `in_argdef` as unrelated to keywords 2021-10-31 13:55:14 +09:00
Nobuyoshi Nakada 1b59ad57ae
Reduce parser stack usage at pattern matching 2021-10-31 13:49:21 +09:00
Nobuyoshi Nakada e1ecda297e
Make new object for negated float as `Float` is always frozen now 2021-10-26 20:17:00 +09:00
Yusuke Endoh 09fa773e04
ast.c: Use kept script_lines data instead of re-opening the source file (#5019)
ast.c: Use kept script_lines data instead of re-open the source file
2021-10-26 01:58:01 +09:00
Koichi Sasada c7550537f1 `RubyVM.keep_script_lines`
`RubyVM.keep_script_lines` enables to keep script lines
for each ISeq and AST. This feature is for debugger/REPL
support.

```ruby
RubyVM.keep_script_lines = true
RubyVM::keep_script_lines = true

eval("def foo = nil\ndef bar = nil")
pp RubyVM::InstructionSequence.of(method(:foo)).script_lines
```
2021-10-21 16:17:39 +09:00
Jeremy Evans fac2c0f73c
Fix evaluation order of hash values for duplicate keys
Fixes [Bug #17719]

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
Co-authored-by: Ivo Anjo <ivo@ivoanjo.me>
2021-10-18 09:09:07 -07:00
Nobuyoshi Nakada 8057129da6
Remove duplicate value checks on `mrhs` which always has the value 2021-10-08 00:11:22 +09:00
Nobuyoshi Nakada a15996c752
Split parser_yyerror0 from parser_yyerror
The former uses the current location, while the latter takes a
non-null location.
2021-10-05 16:59:35 +09:00
Nobuyoshi Nakada 1f544d6715
Show the last line at unexpected end-of-input error 2021-10-05 16:44:43 +09:00
Nobuyoshi Nakada 126122bb6c
Replace inaccurate error messages
When Bison reports "memory exhausted", it means the parser stack
depth reached the limit `YYMAXDEPTH` which is defaulted to 10_000,
but not memory allocation failed.
2021-10-05 15:00:02 +09:00
Nobuyoshi Nakada 28392d3045
The same warning for static symbol literal 2021-10-04 12:16:31 +09:00
Nobuyoshi Nakada da139317a5
Fix the warning message for dynamic symbol literal in condition 2021-10-04 12:16:31 +09:00
Nobuyoshi Nakada fa05697e48 Use `%printer` directive for Bison 3.8 2021-09-14 18:51:38 +09:00
Shugo Maeda 7686776c05
Hash values should be omitted in Ripper results 2021-09-11 22:03:10 +09:00
Shugo Maeda c60dbcd1c5
Allow value omission in Hash literals
`{x:, y:}` is a syntax sugar of `{x: x, y: y}`.
2021-09-11 18:52:25 +09:00
S-H-GAMELINKS bdd6d8746f Replace RBOOL macro 2021-09-05 23:01:27 +09:00
Nobuyoshi Nakada c38c2d8ee2 Moved exported symbols in internal/util.h to ruby/util.h
[Feature #18051]
2021-08-24 10:37:41 +09:00
Yusuke Endoh cad83fa3c4 ast.c: Rename "save_script_lines" to "keep_script_lines"
... as per ko1's preference. He is preparing to extend this feature to
ISeq for his new debugger. He prefers "keep" to "save" for this wording.
This API is internal and not included in any released version, so I
change it in advance.
2021-08-20 16:18:36 +09:00
Kazuki Tsujimoto ecb6d6a4ef
Allow omission of parentheses in one line pattern matching [Feature #16182] 2021-08-19 17:07:58 +09:00
Nobuyoshi Nakada 2aa6826e81 Extract the wrapped value when yydebug [Bug #18075] 2021-08-15 11:40:06 +09:00
eileencodes b940a45357 Fix interpolated heredoc
This fixes https://bugs.ruby-lang.org/issues/18038. The provided
reproduction showed that this happens in heredocs with double
interpolation. In this case `DSTR` was getting returned but needs to be
convered to a `EVSTR` which is what is returned by the function. There
may be an additional bug here that we weren't able to produce. It seems
odd that `STR` returns `DSTR` while everything else should return
`EVSTR` since the function is `new_evstr`.

[Bug #18038][ruby-core:104597]

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2021-07-21 10:06:33 -07:00
Kazuki Tsujimoto eed5e8f796
One-line pattern matching is no longer experimental
https://github.com/ruby/dev-meeting-log/blob/master/DevelopersMeeting20210715Japan.md#feature-17724-make-the-pin-operator-support-instanceclassglobal-variables-jeremyevans0
2021-07-17 11:13:52 +09:00
Jeremy Evans fa87f72e1e Add pattern matching pin support for instance/class/global variables
Pin matching for local variables and constants is already supported,
and it is fairly simple to add support for these variable types.

Note that pin matching for method calls is still not supported
without wrapping in parentheses (pin expressions).  I think that's
for the best as method calls are far more complex (arguments/blocks).

Implements [Feature #17724]
2021-07-15 09:56:02 -07:00
Yusuke Endoh fb01411ae8 node.h: Reduce struct size to fit with Ruby object size (five VALUEs)
by merging `rb_ast_body_t#line_count` and `#script_lines`.

Fortunately `line_count == RARRAY_LEN(script_lines)` was always
satisfied. When script_lines is saved, it has an array of lines, and
when not saved, it has a Fixnum that represents the old line_count.
2021-06-18 02:34:27 +09:00
Yusuke Endoh acae5f363d ast.rb: RubyVM::AST.parse and .of accepts `save_script_lines: true`
This option makes the parser keep the original source as an array of
the original code lines. This feature exploits the mechanism of
`SCRIPT_LINES__` but records only the specified code that is passed to
RubyVM::AST.of or .parse, instead of recording all parsed program texts.
2021-06-18 02:34:27 +09:00
Nobuyoshi Nakada e4f891ce8d
Adjust styles [ci skip]
* --braces-after-func-def-line
* --dont-cuddle-else
* --procnames-start-lines
* --space-after-for
* --space-after-if
* --space-after-while
2021-06-17 10:13:40 +09:00
Yusuke Endoh 70313ec01a parse.y: Fix the location of a target constant of OP_CDECL
```
p RubyVM::AbstractSyntaxTree.parse("::Foo += 1").children
 #=> before: [[], nil, (OP_CDECL@1:0-1:10 (COLON3@1:0-1:10 :Foo) :+ (LIT@1:9-1:10 1))]
 #=> after:  [[], nil, (OP_CDECL@1:0-1:10 (COLON3@1:0-1:5 :Foo) :+ (LIT@1:9-1:10 1))]
```
2021-06-14 10:02:02 +09:00
Nobuyoshi Nakada 9f3888d6a3 Warn more duplicate literal hash keys
Following non-special_const literals:
* T_REGEXP
2021-06-03 15:11:18 +09:00
Nobuyoshi Nakada 37eb5e7439 Warn more duplicate literal hash keys
Following non-special_const literals:
* T_BIGNUM
* T_FLOAT (non-flonum)
* T_RATIONAL
* T_COMPLEX
2021-06-03 15:11:18 +09:00
Nobuyoshi Nakada 50a534a152 ripper: wrap endless method in bodystmt [Bug #17869] 2021-05-21 18:28:24 +09:00
Nobuyoshi Nakada 110f242ef9
Also `\U` after control/meta is invalid [Bug #17861]
As well as `\u`, `\U` should be invalid there too.
And highlight including `u`/`U` not only the backslash before it.
2021-05-13 12:54:56 +09:00
Jeremy Evans 11ae581a4a Fix handling of control/meta escapes in literal regexps
Ruby uses a recursive algorithm for handling control/meta escapes
in strings (read_escape).  However, the equivalent code for regexps
(tokadd_escape) in did not use a recursive algorithm.  Due to this,
Handling of control/meta escapes in regexp did not have the same
behavior as in strings, leading to behavior such as the following
returning nil:

```ruby
/\c\xFF/ =~ "\c\xFF"
```

Switch the code for handling \c, \C and \M in literal regexps to
use the same code as for strings (read_escape), to keep behavior
consistent between the two.

Fixes [Bug #14367]
2021-05-12 18:55:43 -07:00
Yusuke Endoh 31794d2e73 parse.y: Allow "command" syntax in endless method definition
This change allows `def hello = puts "Hello"` without parentheses.

Note that `private def hello = puts "Hello"` does not parse for
technical reason.

[Feature #17398]
2021-05-13 00:14:50 +09:00
Yusuke Endoh d405b1a878 Make imemo_ast WB-protected again
by firing the write barrier of imemo_ast after nd_lit is modified.
This will fix the issue of https://github.com/ruby/ruby/pull/4416 more
gracefully.
2021-04-27 17:05:19 +09:00
Nobuyoshi Nakada 607aa11711
Ignore useless separators preceding a file encoding comment 2021-03-23 17:20:19 +09:00
Kazuki Tsujimoto 21863470d9
Pattern matching pin operator against expression [Feature #17411]
This commit is based on the patch by @nobu.
2021-03-21 15:14:31 +09:00
Takashi Tamura 990b54054d Add a missing semicolon. 2021-02-15 10:46:29 +09:00
Nobuyoshi Nakada b091889ed6 Removed YYUSE [Bug #17582]
Although it was used just to suppress an "unsed argument" warning
in the same manner as other bison-provided functions, it has been
dropped since Bision 3.7.5.  And we always suppress that
warnings.
2021-01-26 21:57:09 +09:00
Nobuyoshi Nakada 6bcc4664bd
Return new NODE_LIT
As NODE_ZLIST/NODE_LIST are not markable, cannot be reused as
NODE_LIT.
2021-01-14 16:15:25 +09:00
Nobuyoshi Nakada bb40c5cbe9
Ensure symbol list node is either NODE_STR or NODE_DSTR 2021-01-14 16:13:26 +09:00
Nobuyoshi Nakada 0036648a42
Capture to reserved name variables if already defined [Bug #17533] 2021-01-13 21:16:00 +09:00
Nobuhiro IMAI 7ff0e93f96
parse.y: handle "duplicated argument name" appropriately on ripper.y
refs: 733ed1e184
2021-01-09 13:33:33 +09:00
Nobuyoshi Nakada 35c3a24c8c
Fixed error message when % at EOF 2021-01-04 12:11:37 +09:00
Masataka Pocke Kuwabara de5f8a92d5
Make args info for RubyVM::AST to available on endless method without parens
Problem
===

Arguments information is missing for endless method without parens.
For example:

```ruby
# ok
pp RubyVM::AbstractSyntaxTree.parse(<<~RUBY).children[2]
  def x() = 42
RUBY
# => (DEFN@1:0-1:12
#     mid: :x
#     body:
#       (SCOPE@1:0-1:12
#        tbl: []
#        args:
#          (ARGS@1:5-1:6
#           pre_num: 0
#           pre_init: nil
#           opt: nil
#           first_post: nil
#           post_num: 0
#           post_init: nil
#           rest: nil
#           kw: nil
#           kwrest: nil
#           block: nil)
#        body: (LIT@1:10-1:12 42)))

# ok
pp RubyVM::AbstractSyntaxTree.parse(<<~RUBY).children[2]
  def x() 42 end
RUBY
# => (DEFN@1:0-1:14
#     mid: :x
#     body:
#       (SCOPE@1:0-1:14
#        tbl: []
#        args:
#          (ARGS@1:5-1:6
#           pre_num: 0
#           pre_init: nil
#           opt: nil
#           first_post: nil
#           post_num: 0
#           post_init: nil
#           rest: nil
#           kw: nil
#           kwrest: nil
#           block: nil)
#        body: (LIT@1:8-1:10 42)))

# It has a problem, the `args` is nil
pp RubyVM::AbstractSyntaxTree.parse(<<~RUBY).children[2]
  def x = 42
RUBY
# => (DEFN@1:0-1:10
#     mid: :x
#     body: (SCOPE@1:0-1:10 tbl: [] args: nil body: (LIT@1:8-1:10 42)))
```

It causes an error if a program expects `args` node exists.
For example: https://github.com/ruby/rbs/issues/551

Solution
====

Call `new_args` on this case.
2021-01-01 14:25:08 +09:00