Commit graph

346 commits

Author SHA1 Message Date
Benoit Daloze
9fdfdf4fca [ruby/prism] Always return the character width for char_is_identifier_start() and char_is_identifier_utf8()
* This is also faster than calling pm_encoding_utf_8_alpha_char/pm_encoding_utf_8_alnum_char
  as those compute the character width and do extra checks.

4cb276ac4c
2024-01-31 21:29:16 +00:00
Aaron Patterson
8e708e4a07 Update forwarding locals for prism 2024-01-30 13:19:06 -05:00
Kevin Newton
ba06a8259a [ruby/prism] Better error messages for unexpected tokens in prefix
a35b8e45ee
2024-01-30 16:10:08 +00:00
Kevin Newton
d39d9e066f [ruby/prism] Fix binding power for modifier rescue
f614863d79
2024-01-29 18:42:47 +00:00
Kevin Newton
bcafd28a3e [ruby/prism] Symbol encoding follow-up
Ensure we don't accidentally parse the symbol encoding twice, and
ensure we parse it in every circumstance we need to by requiring
it as a parameter.

9cea31c785
2024-01-26 21:14:59 +00:00
Kevin Menard
2a509787cb [ruby/prism] Track whether a Symbol should have its encoding changed from the source encoding.
Ruby sets a Symbol literal's encoding to US-ASCII if the symbols consists only of US ASCII code points. Character escapes can also lead a Symbol to have a different encoding than its source's encoding.

f315660b31
2024-01-26 20:15:19 +00:00
Kevin Newton
99d91838e0 [ruby/prism] Update src/prism.c
91b5550726
2024-01-26 18:35:54 +00:00
Haldun Bayhantopcu
7d356b8f0e [ruby/prism] Fix multiple assigns with newlines
b4ba41bdcd
2024-01-26 18:35:54 +00:00
Haldun Bayhantopcu
b0e10345d3 [ruby/prism] Fix parsing calls with labels
3db7849a31
2024-01-26 18:32:30 +00:00
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