Commit graph

337 commits

Author SHA1 Message Date
Max Prokopiev
8e5bc8f7c2 [ruby/prism] Change binding power for modifiers in case-in nodes
c31eeba54c
2024-01-26 18:32:02 +00:00
Kevin Newton
ebf803aa19 [ruby/prism] Fix Ruby head build
149e2ff7f6
2024-01-25 13:58:07 +00:00
Max Prokopiev
6a63aaade9 [ruby/prism] Use char_is_identifier_start() to check for valid method name
alnum_char() only checks for alphanumeric characters while
ignoring other valid cases (like emoji codepoints for example)

d15958fd28
2024-01-24 20:32:01 +00:00
Kevin Newton
455fb32038 [ruby/prism] Add an implicit node for the target of a hash pattern
This simplifies compiling it, since you can now compile the value
as if it were always there.

bcfc74aacb
2024-01-24 18:37:36 +00:00
Kevin Newton
5906ce42fe [ruby/prism] Static literal flag for string hash keys
26a2d774cd
2024-01-22 16:23:11 +00:00
Kevin Newton
e00f42e5d3 [ruby/prism] Return 1-indexed line numbers
ad17f58729
2024-01-22 16:13:36 +00:00
Matt Valentine-House
b8495048fb [ruby/prism] Unescape method name for unary methods.
4386a4c0da
2024-01-22 13:19:57 +00:00
Kevin Newton
d29cd972f7 [ruby/prism] Use inttypes for more accurate printf formatting
2a22b9b72f
2024-01-19 14:49:09 +00:00
Takashi Kokubun
27d81b9282 [ruby/prism] Guard 3.3.0 for pinned it
9778377b12

Co-authored-by: Kevin Newton <kddnewton@gmail.com>
2024-01-17 17:47:34 +00:00
Takashi Kokubun
e0d60a833b [ruby/prism] Fix => ^it
24a2872b4e
2024-01-17 17:47:34 +00:00
Takashi Kokubun
603f2ca730 [ruby/prism] Parse it default parameter
a0c5361b9f
2024-01-17 17:47:33 +00:00
Kevin Newton
3f23cb1a43 [ruby/prism] Remove flag gating for 3.3.0 bug fixes
64baf94271
2024-01-17 15:51:36 +00:00
git
67a545b3d2 * expand tabs. [ci skip]
Please consider using misc/expand_tabs.rb as a pre-commit hook.
2024-01-17 13:26:15 +00:00
Adam Hess
13879fea69 [ruby/prism] Fix prism brace association for constant-like method/local calls
8ca24f263e
2024-01-17 13:26:05 +00:00
TSUYUSATO Kitsune
c5e43da426 [ruby/prism] Correct the "ambiguous first argument" condition
Fix https://github.com/ruby/prism/pull/2182

This change reflects this line:
6283ae8d36/parse.y (L11124).

a52588ff37
2024-01-16 15:51:09 +00:00
Kevin Newton
76a207e542 [ruby/prism] Fix nested default value error
ef26b283de
2024-01-11 20:52:48 +00:00
Kevin Newton
72be786017 [ruby/prism] Allow fsl comment to set to false
b4db7bb703
2024-01-11 19:27:14 +00:00
Kevin Newton
6ff9f1aa51 [ruby/prism] Provide ability to format errors
27985b0e7e
2024-01-11 18:36:32 +00:00
Kevin Newton
8333845b0b [ruby/prism] Unary symbols that cannot be binary should drop @
d139af033f
2024-01-10 20:24:31 +00:00
Aaron Patterson
f165fa09e7 [ruby/prism] address feedback
ed183ad30c
2024-01-10 15:24:26 +00:00
Aaron Patterson
881c5a1846 [ruby/prism] Add a "repeated flag" to parameter nodes
It's possible to repeat parameters in method definitions like so:

```ruby
def foo(_a, _a)
end
```

The compiler needs to know to adjust the local table size to account for
these duplicate names.  We'll use the repeated parameter flag to account
for the extra stack space required

b443cb1f60

Co-Authored-By: Kevin Newton <kddnewton@gmail.com>
Co-Authored-By: Jemma Issroff <jemmaissroff@gmail.com>
2024-01-10 15:24:26 +00:00
Kevin Newton
88d7838445 [ruby/prism] Fix assertion on spanning heredocs
e190308845
2024-01-09 15:15:52 +00:00
Kevin Newton
d1d50a0505 [ruby/prism] Handle parsing a line break in a receiver of a method
4d5f43ecbc
2024-01-08 14:34:59 +00:00
TSUYUSATO Kitsune
a25329e0da [ruby/prism] Fix parsing pinned local variable pattern for numbered parameter
Fix https://github.com/ruby/prism/pull/2094

The part of `parse_variable_call` for variables was split into a new
function `parse_variable` and used it.

4c5fd1a746
2024-01-03 17:20:33 +00:00
Kevin Newton
0215965df4 [ruby/prism] Better error recovery for content after unterminated heredoc
c2d325a886
2024-01-03 16:46:08 +00:00
Kevin Newton
adbfbd822f [ruby/prism] Ignore visibility flag
55b049ddac
2024-01-02 20:59:19 +00:00
Kevin Newton
380c218bfa [ruby/prism] Do not add error for forwarding in CRuby 3.3.0
a28e57c650
2024-01-02 19:10:43 +00:00
TSUYUSATO Kitsune
0ee625ceae [ruby/prism] Fix to check multiple block arguments for forwarding arg
Fix https://github.com/ruby/prism/pull/2111

21ca243d0a
2024-01-02 19:08:15 +00:00
Kevin Newton
23beceedb7 [ruby/prism] IndexTargetNode should always have ATTRIBUTE_WRITE
Because this is a user-facing change, we also need to deal with the
fact that CRuby 3.3.0 was just released.

In order to support workflows that want to parse exactly as CRuby
parses in a specific version, this PR introduces a new option to
the options struct that is "version". This allows you to specify
that you want "3.3.0" parsing.

I'm not sure if this is the correct solution. Another solution is
to just fork and keep around the old branch for security patches.
Or we could keep around a copy of the source files within this
repository as another directory and only update when necessary.
There are a lot of potential solutions here.

Because this change is so small and the check for it is so minimal,
I've decided to go with this enum. If this ends up entirely
cluttering the codebase with version checks, we'll come up with
another solution. But for now this works, so we're going to go in
this direction for a bit until we determine it's no longer working.

d8c7e6bd10
2024-01-02 18:51:18 +00:00
Hiroshi SHIBATA
fa251d60aa Revert "Revert all of commits after Prism 0.19.0 release"
This reverts commit d242e8416e.
2023-12-25 21:12:49 +09:00
Hiroshi SHIBATA
d242e8416e
Revert all of commits after Prism 0.19.0 release
We should bundle released version of Prism for Ruby 3.3.0
2023-12-16 11:08:51 +08:00
eileencodes
2e8cfcac91 [ruby/prism] String literal hash keys should be frozen
String literal hash keys can't be mutated by the user so we should mark
them as frozen. We were seeing instructions for hashes with string
literal keys using two `putstring` instructions when it should be a
`putobject` and `putstring`.

Code example:

```ruby
{ "a" => "b" }
```

Instructions before:

```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(2,14)>
0000 putobject                              "a"                       (   2)[Li]
0002 putstring                              "b"
0004 newhash                                2
0006 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(1,14)>
0000 putstring                              "a"                       (   1)[Li]
0002 putstring                              "b"
0004 newhash                                2
0006 leave
```

Instructions after:

```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(2,14)>
0000 putobject                              "a"                       (   2)[Li]
0002 putstring                              "b"
0004 newhash                                2
0006 leave

"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(1,14)>
0000 putobject                              "a"                       (   1)[Li]
0002 putstring                              "b"
0004 newhash                                2
0006 leave
```

b14ae55385
2023-12-15 20:55:13 +00:00
Kevin Newton
f38814564b [ruby/prism] Fix eval parsing depth
89bf7a4948
2023-12-15 15:19:50 +00:00
Kevin Newton
fe9b42f024 [ruby/prism] Invalid pinned locals in pattern matching
3a67b37a56
2023-12-15 15:03:49 +00:00
Kevin Newton
854ff25f4f [ruby/prism] Add TODO comment
885d1d78cb
2023-12-15 13:26:40 +00:00
TSUYUSATO Kitsune
16830a4783 [ruby/prism] Add an error for in keyword in arguments
Fix https://github.com/ruby/prism/pull/2026

c4b41cd477
2023-12-15 13:25:54 +00:00
Kevin Newton
019fff3a86 [ruby/prism] Fix parse result for nesting pattern matching
ee6fc9ee87
2023-12-14 18:54:46 +00:00
Ufuk Kayserilioglu
01f21d5729 [ruby/prism] Fix the implementation of the flag on keyword hash nodes
The previous implementation was incorrect since it was just checking for all keys in assoc nodes to be static literals but the actual check is that all keys in assoc nodes must be symbol nodes.

This commit fixes that implementation, and, also, aliases the flag to `PM_KEYWORD_HASH_NODE_FLAGS_SYMBOL_KEYS` so that ruby/ruby can start using the new flag name.

I intend to later change the real flag name to `PM_KEYWORD_HASH_NODE_FLAGS_SYMBOL_KEYS` and remove the alias.

f5099c79ce
2023-12-14 18:05:54 +00:00
TSUYUSATO Kitsune
3658798dbb [ruby/prism] Make equality operators non-associative
Fix https://github.com/ruby/prism/pull/2073

0f747d9240
2023-12-14 16:39:05 +00:00
Kevin Newton
b7e89d4b17 [ruby/prism] Fix hash pattern rest
43c4232cfc
2023-12-14 02:43:32 +00:00
Ufuk Kayserilioglu
e96f6126f2 [ruby/prism] Fix hash deopt based on contents
The previous implementation of hash deopt was based on clearing the static literal flag on a hash node if the element that was being added was an array, hash or range node, or if the element was not a static literal in the first place.

However, this is not correct. First of all, the elements added to a hash node will primarily be assoc nodes, but never array, hash or range nodes. Secondly, the static literal flag is set on assoc nodes, only if the value in an assoc node is a static literal, so the key is never checked. As a result, the static literal flag on a hash node would never be cleared if the key wasn't a static literal.

This commit fixes this by clearing the static literal flag if:
1. the element is not an assoc node,
2. the element is an assoc node, but the key is not a static literal, or
3. the element is an assoc node, the key is a static literal, but assoc node (and thus the value in assoc node) is not a static literal.

7f67109b36
2023-12-13 00:21:42 +00:00
Kevin Newton
f61df27b4c [ruby/prism] Use new flag setters for attribute write
1e07832778
2023-12-12 18:43:59 +00:00
Ufuk Kayserilioglu
1f22245ed5 [ruby/prism] Start using flag macros/methods exclusively
5f05a6fe83
2023-12-12 17:35:53 +00:00
Ufuk Kayserilioglu
bdb38dd9f2 [ruby/prism] Add methods for setting/unsetting and macros for testing a flags
e5f37d1407
2023-12-12 17:35:52 +00:00
Kevin Newton
278ce27ee4 [ruby/prism] Flag for attribute write on calls
465731969c
2023-12-12 15:55:54 +00:00
Ufuk Kayserilioglu
43229d531f [ruby/prism] Start KeywordHashNodes with STATIC_KEYS set, until hit an element that should clear it
7c7c486507
2023-12-12 13:05:09 +00:00
Kevin Newton
4095e7d2be [ruby/prism] Regexp terminator escapes
42a48a2ba9
2023-12-11 16:34:55 +00:00
Kevin Newton
c65de63913 [ruby/prism] Handle a non-interpolated dsym spanning a heredoc
b23136ebfd
2023-12-11 16:34:41 +00:00
Kevin Newton
261e8f28a0 [ruby/prism] Correct escapes when ctrl+meta+escape
ee68b17c01
2023-12-11 16:34:27 +00:00
Kevin Newton
b673b5b432 [ruby/prism] Split up CallNode in target position
In this commit we're splitting up the call nodes that were in target
positions (that is, for loop indices, rescue error captures, and
multi assign targets).

Previously, we would simply leave the call nodes in place. This had
the benefit of keeping the AST relatively simple, but had the
downside of not being very explicit. If a static analysis tool wanted
to only look at call nodes, it could easily be confused because the
method would have 1 fewer argument than it would actually be called
with.

This also brings some consistency to the AST. All of the nodes in
a target position are now *TargetNode nodes. These should all be
treated the same, and the call nodes can now be treated the same.

Finally, there is benefit to memory. Because being in a target
position ensures we don't have some fields, we can strip down the
number of fields on these nodes.

So this commit introduces two new nodes: CallTargetNode and
IndexTargetNode. For CallTargetNode we get to drop the opening_loc,
closing_loc, arguments, and block. Those can never be present. We
also get to mark their fields as non-null, so they will always be
seen as present.

The IndexTargetNode keeps around most of its fields but gets to
drop both the name (because it will always be []=) and the
message_loc (which was always super confusing because it included
the arguments by virtue of being inside the []).

Overall, this adds complexity to the AST at the expense of memory
savings and explicitness. I believe this tradeoff is worth it in
this case, especially because these are very much not common nodes
in the first place.

3ef71cdb45
2023-12-11 15:32:31 +00:00