Commit graph

302 commits

Author SHA1 Message Date
Haldun Bayhantopcu
0d1917aead [ruby/prism] Remove no-op assignment
4b3079d9e8
2023-11-30 17:42:24 +00:00
sid-707
2c64041ed5 [ruby/prism] Fix typo in comment
eb1a6ba263
2023-11-30 14:10:28 +00:00
Matt Boldt
9fc40d2b26 [ruby/prism] Add MacJapanese encoding
MacJapanese (also aliased as MacJapan) is a modified Shift_JIS
encoding, but is implemented identically in Ruby

9e0a097699
2023-11-29 12:08:15 -05:00
Dhaval
9fada99cb2 [ruby/prism] added CP950 encoding
9c2d1cf4ba
2023-11-29 11:15:50 -05:00
Jemma Issroff
b632732bcf [ruby/prism] Fixed comment on pm_parser_numbered_parameters_set
ceae5727b8
2023-11-29 15:24:41 +00:00
Jean Boussier
2af82e2316 [ruby/prism] Convert start line to signed integers
Ruby allows for 0 or negative line start, this is often used
with `eval` calls to get a correct offset when prefixing a snippet.

e.g.

```ruby
caller = caller_locations(1, 1).first
class_eval <<~RUBY, caller.path, caller.line - 2
  # frozen_string_literal: true
  def some_method
    #{caller_provided_code_snippet}
  end
RUBY
```

0d14ed1452
2023-11-29 13:56:19 +00:00
Jean Boussier
2653404840 [ruby/prism] Rename varint as varuint
Line numbers may be negative, so we need to introduce signed varint,
so renaming unsigned ones first avoid confusion.

90d862361e
2023-11-29 13:56:18 +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
Kevin Newton
4938390177 [ruby/prism] Implicit rest nodes
Fundamentally, `foo { |bar,| }` is different from `foo { |bar, *| }`
because of arity checks. This PR introduces a new node to handle
that, `ImplicitRestNode`, which goes in the `rest` slot of parameter
nodes instead of `RestParameterNode` instances.

This is also used in a couple of other places, namely:

* pattern matching: `foo in [bar,]`
* multi target: `for foo, in bar do end`
* multi write: `foo, = bar`

Now the only splat nodes with a `NULL` value are when you're
forwarding, as in: `def foo(*) = bar(*)`.

dba2a3b652
2023-11-28 22:33:50 +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
c11dd34753 [ruby/prism] Reset current_param_name around closed scopes
It is for supporting `def foo(bar = (def baz(bar) = bar; 1)) = 2` case.

c789a833c5
2023-11-28 17:27:10 +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
TSUYUSATO Kitsune
9365b78d49 [ruby/prism] Fix to parse * as forwarding in foo[*] case
Fix https://github.com/ruby/prism/pull/1924

7cde900065
2023-11-28 13:25:59 +00:00
Kevin Newton
c798943a4a [ruby/prism] Move DATA parsing into its own parse result field
42b60b6e95
2023-11-28 13:25:48 +00:00
Haldun Bayhantopcu
32b5f5be7c [ruby/prism] Introduce char_is_identifier_utf8
5f43e57b0f
2023-11-28 02:53:31 +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
Kevin Newton
285a41d793 [ruby/prism] Remove blank line
6e5258938a
2023-11-23 14:39:30 +00:00
TSUYUSATO Kitsune
7b20dd9f91 [ruby/prism] Fix LocalVariableTargetNode depth in patterns
Fix https://github.com/ruby/prism/pull/1821

7d023a26b4
2023-11-23 14:39:30 +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
Kevin Newton
8f707e8030 [ruby/prism] Join range checks into the main parse_expression switch
ed4523464b
2023-11-22 14:53:29 +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
Kevin Newton
2aefbbaab9 [ruby/prism] Combine expression checks into a single switch
825d5d7bd4
2023-11-22 14:53:28 +00:00
TSUYUSATO Kitsune
cdd07781b0 [ruby/prism] Remove TODO
d6d718487d
2023-11-22 14:53:27 +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
TSUYUSATO Kitsune
cc7a5dcd06 [ruby/prism] Add and use pm_parser_local_depth_constant_id
https://github.com/ruby/prism/pull/1877#discussion_r1398974248

0f545fe636
2023-11-22 14:53:27 +00:00
heyogrady
e3ef05a434 [ruby/prism] Add CP949 encoding
9e78dfdf69
2023-11-22 09:12:35 -05:00
Patrick O'Grady
e9ccceab11 [ruby/prism] Add KOI8-U encoding
(https://github.com/ruby/prism/pull/1906)

* Add test for KOI8-U

* Rename koi8 char_width function

- Rename function for use with any KOI8-based encoding

* Add KOI8-U encoding

* Add encoding to encoding.md

6cad4552f7
2023-11-22 13:21:15 +00:00
Jemma Issroff
8e80cad9e9 [ruby/prism] Add SPLAT flag on ArrayNode indicating if it contains splat element(s)
This commit puts a SPLAT flag on any ArrayNodes which contain
SplatNode elements

2fc1e7f181
2023-11-21 22:30:53 +00:00
Jemma Issroff
3db21d2d4c [PRISM] Rename flag to CONTAINS_KEYWORD_SPLAT
We need to do this change first on ruby/ruby before merging to
ruby/prism to avoid breaking ruby/ruby CI
2023-11-21 17:29:07 -05:00
Haldun Bayhantopcu
f397650cda [ruby/prism] Fix lex_state_beg_p
(https://github.com/ruby/prism/pull/1591)

46b8576dd0
2023-11-21 17:22:18 +00:00
Thiago Araujo
91685c01d3 [ruby/prism] feat: adds encoding for TIS-620
(https://github.com/ruby/prism/pull/1901)

2c308e6697
2023-11-21 17:12:00 +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
Kevin Newton
ddacc08528 [ruby/prism] Remove string concat in favor of a flat list
Right now when you have a lot of string concats it ends up being
difficult to work with because of the depth of the tree. You end
up descending very far for every string literal that is part of the
concat.

There are already times when we use an interpolated string node to
group together two string segments that are part of the same string
(like when they are interupted by the contents of a heredoc). This
commit takes the same approach and replaces string concats with
interpolated string nodes.

Now that they're a flat list, they should be much easier to work
with. There's still some missing information here that would be
useful to consumers: whether or not there is _actually_ any
interpolation contained in the list. We could remedy this with
another node type that is named something like string list, or we
could add a flag to interpolated string node indicating that there
is interpolation. Either way I want to solve that in a follow-up
commit, since this commit is valuable on its own.

1e7ae3ad1b
2023-11-21 11:35:46 -05: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
Kevin Newton
5299b4a362 [ruby/prism] Build the ability to format errors
(https://github.com/ruby/prism/pull/1796)

Previously, we only supported error messages that were constant
strings. This works for the most part, but there are some times
where we want to include some part of the source in the error
message to make it better.

For example, instead of "Token is reserved" it's better to write
"_1 is reserved".

To do this, we now support allocating error messages at runtime
that are built around format strings.

7e6aa17deb
2023-11-21 02:43:18 +00:00
Kevin Newton
9fa524dd41 [ruby/prism] Split up CaseNode and CaseMatchNode
(https://github.com/ruby/prism/pull/1801)

4c1391ea56
2023-11-21 02:38:07 +00:00
Ryan Garver
e16ff17374 Rename the big5-hkscs stuff to something more generic and add UAO sharing common code.
Merge the Big5 extensions into pm_big5.c
2023-11-20 21:18:31 -05:00
Haldun Bayhantopcu
36afc11ece [ruby/prism] Fix locations derived from arguments.
(https://github.com/ruby/prism/pull/1897)

00b76ef254
2023-11-20 23:03:23 +00:00
Kevin Newton
e269096d15 [ruby/prism] Replace match write locals with match write targets
eec1862967
2023-11-20 18:00:44 -05:00
Lynne Ashminov
307a5cb20b [ruby/prism] adds encodings for ibm869
(https://github.com/ruby/prism/pull/1886)

41462400b7
2023-11-20 20:06:14 +00:00
Maple Ong
9fbdb26f06 [ruby/prism] Add and test ibm863 encoding
(https://github.com/ruby/prism/pull/1853)

* Add and test ibm863

* Remove dup encoding and add alias

* Update test/prism/encoding_test.rb

Co-authored-by: Kevin Newton <kddnewton@gmail.com>

* Readd bitfield table lol

---------

4cd756d7ff

Co-authored-by: Kevin Newton <kddnewton@gmail.com>
2023-11-20 20:06:00 +00:00
Kevin Newton
5b0256e3c4 [ruby/prism] Disallow defining a numbered parameter method
(https://github.com/ruby/prism/pull/1797)

c13165e6aa
2023-11-20 16:12:50 +00:00
David Wessman
f9fb05f9d0 [ruby/prism] feat: Adds macCroatian encoding
(https://github.com/ruby/prism/pull/1880)

* feat: Adds macCroatian encoding

- Based on:
https://en.wikipedia.org/wiki/Mac_OS_Croatian_encoding
https://www.unicode.org/Public/MAPPINGS/VENDORS/APPLE/CROATIAN.TXT

Co-authored-by: Josefine Rost <nijrost@gmail.com>

* Use output from bin/encodings and adds to docs/encoding.md

---------

019a82d8f3

Co-authored-by: Josefine Rost <nijrost@gmail.com>
2023-11-20 16:07:19 +00:00
Hiroya Fujinami
adee7dab3e [ruby/prism] Correctly parse the resuce modifier in the rhs of the
assignments
(https://github.com/ruby/prism/pull/1879)

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

9fb276e1f4
2023-11-20 15:58:19 +00:00
Hiroya Fujinami
caa9ae7804 [ruby/prism] Fix parsing ... in arguments
(https://github.com/ruby/prism/pull/1882)

* Fix parsing `...` in arguments

Fix https://github.com/ruby/prism/pull/1830
Fix https://github.com/ruby/prism/pull/1831

* Rename the constant name to PM_ERR_ARGUMENT_FORWARDING_UNBOUND

https://github.com/ruby/prism/pull/1882#discussion_r1398461156

519653aec2
2023-11-20 15:52:44 +00:00
Derek Moore
701b0650de [ruby/prism] feat: add encoding for IBM865
(https://github.com/ruby/prism/pull/1884)

* feat: add encoding for IBM865

* style: fix incorrect autoformat

14c6ae0182
2023-11-20 02:02:55 +00:00
Hiroya Fujinami
8b4b0b7177 [ruby/prism] Don't add an invalid identifier capture to locals
(https://github.com/ruby/prism/pull/1836)

* Don't add an invalid identifier capture to locals

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

* Delay creating a MatchWriteNode

https://github.com/ruby/prism/pull/1836#discussion_r1393716600

635f595a36
2023-11-19 02:05:21 +00:00