Commit graph

132 commits

Author SHA1 Message Date
Kevin Newton
494778c663 [ruby/prism] Remove locals_body_index
We're not using this anymore, and it doesn't make a lot of sense
outside the context of a compiler anyway, and in anyway it's wrong
when you have local variables written in default values.

5edbd9c25b
2024-02-01 16:48:55 +00:00
Haldun Bayhantopcu
67c5690a6d [ruby/prism] Check literals for receiver
56441b08e7
2024-02-01 16:48:09 +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
e337c9478a [ruby/prism] Error follow-up
Split up the diagnostic levels so that error and warning levels
aren't mixed. Also fix up deconstruct_keys implementation.

bd3eeb308d

Co-authored-by: Benoit Daloze <eregontp@gmail.com>
2024-01-27 18:46:16 +00:00
Benoit Daloze
de135bc247 [ruby/prism] Add level to warnings and errors to categorize them
* Fixes https://github.com/ruby/prism/issues/2082

7a74576357
2024-01-26 21:34:34 +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
Takashi Kokubun
603f2ca730 [ruby/prism] Parse it default parameter
a0c5361b9f
2024-01-17 17:47:33 +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
d1d50a0505 [ruby/prism] Handle parsing a line break in a receiver of a method
4d5f43ecbc
2024-01-08 14:34:59 +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
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
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
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
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
Ufuk Kayserilioglu
d313c82f79 [ruby/prism] Update tests and snapshots
0663e2bcfa
2023-12-12 13:05:09 +00:00
TSUYUSATO Kitsune
48cb70fee9 [ruby/prism] Fix parsing unterminated empty string "
Fix https://github.com/ruby/prism/pull/2034

8280e577fa
2023-12-11 13:36:37 +00:00
TSUYUSATO Kitsune
a860e3605c [ruby/prism] Fix to parse a (endless-)range with binary operators
Fix https://github.com/ruby/prism/pull/2022
Fix https://github.com/ruby/prism/pull/2030

b78d8b6525
2023-12-11 13:34:48 +00:00
Alex Koval
04eb1b6f26 [ruby/prism] fix: escape newline
a28b427dcc
2023-12-10 03:06:36 +00:00
Kevin Newton
98e3552cfb [ruby/prism] Add necessary encoding flags for symbols and regex
This doesn't actually fix the encodings for symbols and regex,
unfortunately. But I wanted to get this change in because it is
the last AST change we're going to make before 3.3 is released.

So, if consumers want, they can start to check these flags to
determine the encoding, even though it will be wrong. Then once we
actually set them correctly, everything should work.

9b35f7e891
2023-12-08 18:59:52 +00:00
Kevin Newton
892b5f10d5 [ruby/prism] More closely match CRuby error messages
1ed07a0c6d
2023-12-08 14:34:34 +00:00
Haldun Bayhantopcu
ce094e8556 [ruby/prism] Emit error for constant assignments in defs
864b06f90e
2023-12-06 22:15:16 +00:00
Kevin Newton
c5a4409f20 [ruby/prism] Simplify unterminated string
ef512ca914
2023-12-06 21:34:48 +00:00
Kevin Newton
fe6ee5e921 [ruby/prism] Move flag position consistently to front
6e69a81737
2023-12-06 20:50:02 +00:00
TSUYUSATO Kitsune
cbb941f58a [ruby/prism] Fix closing loc for string literals
Fix https://github.com/ruby/prism/pull/1974

453d403593
2023-12-06 20:48:11 +00:00
Kevin Newton
82f18baa21 [ruby/prism] Provide flags for changing encodings
e838eaff6f
2023-12-06 14:23:38 -05:00
Jemma Issroff
018dbf18d5 [ruby/prism] Add locals_body_index to DefNode, BlockNode, LambdaNode
The locals_body_index gives the index in the locals array where
the locals from the body start. This allows compilers to easily
index past the parameters in the locals array.

5d4627b890
2023-12-06 09:55:48 -05:00
TSUYUSATO Kitsune
3260ed7e5e [ruby/prism] Add test cases
e91f8dbb99
2023-12-05 15:16:42 +00:00
TSUYUSATO Kitsune
3d4a4b2529 [ruby/prism] Fix some corner cases
d5453f168e
2023-12-05 15:16:41 +00:00
TSUYUSATO Kitsune
dcd75fd49d [ruby/prism] Fix to parse command-style method calls more correctly
Fix https://github.com/ruby/prism/pull/1468
Fix https://github.com/ruby/prism/pull/1575

To decide command-style method calls are allowed, this introduce a new
parameter `accepts_command_call` to `parse_expression` and some
functions.

Although one think this can be solved by operator precedence, it is
hard or impossible, because the precedence of command-style calls is skewed
(e.g. `! bar 1 ` is accepted, but `foo = ! bar 1` is rejected.)

One of the most complex examples is that:
(1) even though `foo = bar = baz 1` and `foo, bar = baz 1` is accepted,
(2) `foo, bar = baz = fuzz 1` is rejected.
To implement this behavior, this introduces a new binding power
`PM_BINDING_POWER_MULTI_ASSIGNMENT` and uses it for distinguish which single
assignments or multi assignments at their RHS.

d4dd49ca81
2023-12-05 15:16:40 +00:00
TSUYUSATO Kitsune
2a65d83707 [ruby/prism] Check "void value expression" for array literals
Fix https://github.com/ruby/prism/pull/1978

194c997d0a
2023-12-04 14:00:23 +00:00
Kevin Newton
cdb74d74af [ruby/prism] Change numbered parameters
Previously numbered parameters were a field on blocks and lambdas
that indicated the maximum number of numbered parameters in either
the block or lambda, respectively. However they also had a
parameters field that would always be nil in these cases.

This changes it so that we introduce a NumberedParametersNode that
goes in place of parameters, which has a single uint8_t maximum
field on it. That field contains the maximum numbered parameter in
either the block or lambda.

As a part of the PR, I'm introducing a new UInt8Field type that
can be used on nodes, which is just to make it a little more
explicit what the maximum values can be (the maximum is actually 9,
since it only goes up to _9). Plus we can do a couple of nice
things in serialization like just read a single byte.

2d87303903
2023-12-01 12:03:09 -05:00
TSUYUSATO Kitsune
417d700406 [ruby/prism] Improve to handle unterminated strings
Fix https://github.com/ruby/prism/pull/1946

This fixes to set an error position for unterminated strings to the
opening delimiters. Previously, the error position was set to the end
of the delimiter.

The same fix applies to other string-like literals.

Additionally, this fixes https://github.com/ruby/prism/pull/1946; that is, it adds the last part of the
string even though the string literal does not terminate.

c1240baafd
2023-12-01 15:15:01 +00:00
TSUYUSATO Kitsune
a908cef53f [ruby/prism] Reject class/module defs in method params/rescue/ensure/else
Fix https://github.com/ruby/prism/pull/1936

232e77a003
2023-11-29 02:03:06 +00:00
Jemma Issroff
04cbcd37b1 [ruby/prism] Add numbered_parameters field to BlockNode and LambdaNode
We are aware at parse time how many numbered parameters we have
on a BlockNode or LambdaNode, but prior to this commit, did not
store that information anywhere in its own right.

The numbered parameters were stored as locals, but this does not
distinguish them from other locals that have been set, for example
in `a { b = 1; _1 }` there is nothing on the AST that distinguishes
b from _1.

Consumers such as the compiler need to know information about how
many numbered parameters exist to set up their own tables around
parameters. Since we have this information at parse time, we should
compute it here, instead of deferring the work later on.

bf4a1e124d
2023-11-28 21:08:46 +00:00
TSUYUSATO Kitsune
55f34d4745 [ruby/prism] Fix tests
1e6ecbaf04
2023-11-28 17:27:11 +00:00
TSUYUSATO Kitsune
f6fbb9fec5 [ruby/prism] Use 0 for the default valie of current_param_name
896915de24
2023-11-28 17:27:10 +00:00
TSUYUSATO Kitsune
b5796d7b11 [ruby/prism] Check circular references in default values of params
Fix https://github.com/ruby/prism/pull/1637

0172d69cba
2023-11-28 17:27:09 +00:00
Kevin Newton
0164da68c1 [ruby/prism] Use un-capitalized error messages
I don't prefer this style, but it appears that a plurality of syntax
error messages between with un-capitalized messages in CRuby, so
we'll go with that for consistency, for now.

b02df68954
2023-11-28 02:53:44 +00:00
TSUYUSATO Kitsune
3af56e87ca [ruby/prism] Check void expressions for constant paths
Fix https://github.com/ruby/prism/pull/1920

ee8e03bac7
2023-11-27 17:35:38 +00:00
TSUYUSATO Kitsune
8654859dbd [ruby/prism] Fix and reuse pm_call_node_index_p
Fix https://github.com/ruby/prism/pull/1925
Fix https://github.com/ruby/prism/pull/1927

Previously pm_call_node_index_p does not check about a block argument
correctly and is not used in parse_write to check an index call node.

This commit fixes these problems.

92bab044ff
2023-11-27 17:33:31 +00:00
TSUYUSATO Kitsune
6968b289e7 [ruby/prism] Check void values in singleton class (class <<)
Follow up the ruby/ruby#8917 change.

f6bac4d3bf
2023-11-22 15:45:33 +00:00
TSUYUSATO Kitsune
8794836bf2 [ruby/prism] Fix associativity of binary range with begin-less range
Fix https://github.com/ruby/prism/pull/1828

22c0640e48
2023-11-22 14:53:28 +00:00
TSUYUSATO Kitsune
76f9abced7 [ruby/prism] Reject statements at non-statement posisions
Fix https://github.com/ruby/prism/pull/1547

cdb643aeab
2023-11-22 14:53:27 +00:00
Benoit Daloze
018e6abf85 [ruby/prism] Move CallNode#name field between receiver and arguments
* The same order as in source code.
* CallOrWriteNode, CallOperatorWriteNode, CallAndWriteNode already have
  the correct order so it was also inconsistent with them.

4434e4bc22
2023-11-22 12:15:20 +00:00
Hiroya Fujinami
ad25313ca8 [ruby/prism] Fix .. and ... to be non-associative
(https://github.com/ruby/prism/pull/1837)

Fix https://github.com/ruby/prism/pull/1829

90b0b1974c

Co-authored-by: Kevin Newton <kddnewton@gmail.com>
2023-11-21 17:03:33 +00:00
Haldun Bayhantopcu
8966d06b96 [ruby/prism] Warning for ENDs in methods
(https://github.com/ruby/prism/pull/1899)

1b41c2d56c
2023-11-21 16:36:12 +00:00
Hiroya Fujinami
b6b31f673d [ruby/prism] Check a token after targets more strictly
(https://github.com/ruby/prism/pull/1878)

Fix https://github.com/ruby/prism/pull/1832

060bcc81a8
2023-11-21 02:45:12 +00:00