Commit graph

2684 commits

Author SHA1 Message Date
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