summaryrefslogtreecommitdiff
path: root/parse.y
AgeCommit message (Collapse)Author
2021-11-23Assign temporary ID to anonymous ID [Bug #18250]Nobuyoshi Nakada
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. Notes: Merged: https://github.com/ruby/ruby/pull/5157
2021-11-21Refactor hacky ID tables to struct rb_ast_id_table_tYusuke Endoh
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. Notes: Merged: https://github.com/ruby/ruby/pull/5136
2021-11-18Anonymous block forwarding allows a method to forward a passedJeremy Evans
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 Notes: Merged: https://github.com/ruby/ruby/pull/5051
2021-11-12parse.y: Fix memory leak at parse errorYusuke Endoh
Local variable tables might leak at the parse error. Notes: Merged: https://github.com/ruby/ruby/pull/5111
2021-11-08[Feature #18290] Remove all usages of rb_gc_force_recyclePeter Zhu
This commit removes usages of rb_gc_force_recycle since it is a burden to maintain and makes changes to the GC difficult. Notes: Merged: https://github.com/ruby/ruby/pull/4363
2021-10-31Argument forwarding definition without parentheses [Bug #18267]Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/5065
2021-10-31Rename `in_kwarg` as `in_argdef` as unrelated to keywordsNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/5064
2021-10-31Reduce parser stack usage at pattern matchingNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/5064
2021-10-26Make new object for negated float as `Float` is always frozen nowNobuyoshi Nakada
2021-10-26ast.c: Use kept script_lines data instead of re-opening the source file (#5019)Yusuke Endoh
ast.c: Use kept script_lines data instead of re-open the source file Notes: Merged-By: mame <mame@ruby-lang.org>
2021-10-21`RubyVM.keep_script_lines`Koichi Sasada
`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 ``` Notes: Merged: https://github.com/ruby/ruby/pull/4913
2021-10-18Fix evaluation order of hash values for duplicate keysJeremy Evans
Fixes [Bug #17719] Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org> Co-authored-by: Ivo Anjo <ivo@ivoanjo.me> Notes: Merged: https://github.com/ruby/ruby/pull/4969 Merged-By: jeremyevans <code@jeremyevans.net>
2021-10-08Remove duplicate value checks on `mrhs` which always has the valueNobuyoshi Nakada
2021-10-05Split parser_yyerror0 from parser_yyerrorNobuyoshi Nakada
The former uses the current location, while the latter takes a non-null location.
2021-10-05Show the last line at unexpected end-of-input errorNobuyoshi Nakada
2021-10-05Replace inaccurate error messagesNobuyoshi Nakada
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-04The same warning for static symbol literalNobuyoshi Nakada
2021-10-04Fix the warning message for dynamic symbol literal in conditionNobuyoshi Nakada
2021-09-14Use `%printer` directive for Bison 3.8Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/4836
2021-09-11Hash values should be omitted in Ripper resultsShugo Maeda
2021-09-11Allow value omission in Hash literalsShugo Maeda
`{x:, y:}` is a syntax sugar of `{x: x, y: y}`.
2021-09-05Replace RBOOL macroS-H-GAMELINKS
Notes: Merged: https://github.com/ruby/ruby/pull/4791
2021-08-24Moved exported symbols in internal/util.h to ruby/util.hNobuyoshi Nakada
[Feature #18051] Notes: Merged: https://github.com/ruby/ruby/pull/4763
2021-08-20ast.c: Rename "save_script_lines" to "keep_script_lines"Yusuke Endoh
... 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-19Allow omission of parentheses in one line pattern matching [Feature #16182]Kazuki Tsujimoto
2021-08-15Extract the wrapped value when yydebug [Bug #18075]Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/4742
2021-07-21Fix interpolated heredoceileencodes
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> Notes: Merged: https://github.com/ruby/ruby/pull/4664
2021-07-17One-line pattern matching is no longer experimentalKazuki Tsujimoto
https://github.com/ruby/dev-meeting-log/blob/master/DevelopersMeeting20210715Japan.md#feature-17724-make-the-pin-operator-support-instanceclassglobal-variables-jeremyevans0
2021-07-15Add pattern matching pin support for instance/class/global variablesJeremy Evans
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] Notes: Merged: https://github.com/ruby/ruby/pull/4502
2021-06-18node.h: Reduce struct size to fit with Ruby object size (five VALUEs)Yusuke Endoh
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. Notes: Merged: https://github.com/ruby/ruby/pull/4581
2021-06-18ast.rb: RubyVM::AST.parse and .of accepts `save_script_lines: true`Yusuke Endoh
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. Notes: Merged: https://github.com/ruby/ruby/pull/4581
2021-06-17Adjust styles [ci skip]Nobuyoshi Nakada
* --braces-after-func-def-line * --dont-cuddle-else * --procnames-start-lines * --space-after-for * --space-after-if * --space-after-while
2021-06-14parse.y: Fix the location of a target constant of OP_CDECLYusuke Endoh
``` 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-03Warn more duplicate literal hash keysNobuyoshi Nakada
Following non-special_const literals: * T_REGEXP Notes: Merged: https://github.com/ruby/ruby/pull/4548
2021-06-03Warn more duplicate literal hash keysNobuyoshi Nakada
Following non-special_const literals: * T_BIGNUM * T_FLOAT (non-flonum) * T_RATIONAL * T_COMPLEX Notes: Merged: https://github.com/ruby/ruby/pull/4548
2021-05-21ripper: wrap endless method in bodystmt [Bug #17869]Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/4516
2021-05-13Also `\U` after control/meta is invalid [Bug #17861]Nobuyoshi Nakada
As well as `\u`, `\U` should be invalid there too. And highlight including `u`/`U` not only the backslash before it.
2021-05-12Fix handling of control/meta escapes in literal regexpsJeremy Evans
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] Notes: Merged: https://github.com/ruby/ruby/pull/4495
2021-05-13parse.y: Allow "command" syntax in endless method definitionYusuke Endoh
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-04-27Make imemo_ast WB-protected againYusuke Endoh
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. Notes: Merged: https://github.com/ruby/ruby/pull/4419
2021-03-23Ignore useless separators preceding a file encoding commentNobuyoshi Nakada
2021-03-21Pattern matching pin operator against expression [Feature #17411]Kazuki Tsujimoto
This commit is based on the patch by @nobu.
2021-02-15Add a missing semicolon.Takashi Tamura
Notes: Merged: https://github.com/ruby/ruby/pull/4180
2021-01-26Removed YYUSE [Bug #17582]Nobuyoshi Nakada
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. Notes: Merged: https://github.com/ruby/ruby/pull/4121
2021-01-14Return new NODE_LITNobuyoshi Nakada
As NODE_ZLIST/NODE_LIST are not markable, cannot be reused as NODE_LIT. Notes: Merged: https://github.com/ruby/ruby/pull/4069
2021-01-14Ensure symbol list node is either NODE_STR or NODE_DSTRNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/4069
2021-01-13Capture to reserved name variables if already defined [Bug #17533]Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/4059
2021-01-09parse.y: handle "duplicated argument name" appropriately on ripper.yNobuhiro IMAI
refs: 733ed1e184
2021-01-04Fixed error message when % at EOFNobuyoshi Nakada
2021-01-01Make args info for RubyVM::AST to available on endless method without parensMasataka Pocke Kuwabara
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. Notes: Merged: https://github.com/ruby/ruby/pull/4016 Merged-By: nobu <nobu@ruby-lang.org>