1044 Commits

Author SHA1 Message Date
Dmitry Dygalo
4e5c8c19a7 [ruby/prism] fix: sigsegv on malformed shebang
Signed-off-by: Dmitry Dygalo <dmitry@dygalo.dev>

https://github.com/ruby/prism/commit/e23292120e
2025-06-30 12:31:53 +00:00
Tim Craft
e210a70e9a [ruby/prism] Fix typo in visitor example code
https://github.com/ruby/prism/commit/5aa963f8e6
2025-06-09 13:41:17 +00:00
harasho
5f247416b6 [ruby/prism] Document ClassNode fields - Adds documentation for the fields of the ClassNode. - Part of #2123
https://github.com/ruby/prism/commit/99615b43ac
2025-06-03 14:07:43 +00:00
Nobuyoshi Nakada
857b1ae786 [ruby/prism] [DOC] No RDoc in include/prism/ast.h
https://github.com/ruby/prism/commit/1cae6e3b02
2025-05-29 04:46:00 +00:00
Nobuyoshi Nakada
8aa21634d8 [ruby/prism] [DOC] Simply use String#ljust
https://github.com/ruby/prism/commit/ba019ab4b4
2025-05-29 04:45:59 +00:00
Nobuyoshi Nakada
82c74e4282 [ruby/prism] [DOC] Stop rdoc from processing non-rdoc comments
https://github.com/ruby/prism/commit/de1faa1680
2025-05-29 04:45:59 +00:00
Nobuyoshi Nakada
991cf2dd4d [ruby/prism] [DOC] Specify markdown mode to RDoc
https://github.com/ruby/prism/commit/12af4e144e
2025-05-29 04:45:58 +00:00
Ufuk Kayserilioglu
224a02f924 [ruby/prism] Monomorphise visitor methods
The current implementation of the visitor pattern in Prism uses
a single method (`visit_child_nodes`) to handle all node types. This can lead to performance issues since the `node` argument will end up being polymorphic, and will prevent effective use of inline caches, which in CRuby are monomorphic.

This commit generates an inlined version of the previous code for each node type, thus making the calls inside visitor methods monomorphic. This should improve performance, especially in cases where the visitor is called frequently.

https://github.com/ruby/prism/commit/60d324a701
2025-05-23 14:22:47 +00:00
Hiroshi SHIBATA
4d9a1d5b6f Handle to look up CGI::EscapeExt instead of using LoadError. cgi/escape is provided snce Ruby 2.3 2025-05-13 14:37:24 +09:00
Hiroshi SHIBATA
a61f51f66d Use cgi/escape instead of cgi/util 2025-05-09 14:27:28 +09:00
Hiroshi SHIBATA
a88c5b501c Use cgi/util if that uses like CGI.escape methods 2025-04-24 12:15:11 +09:00
Alexander Momchilov
0fad0ce35c [ruby/prism] Use xmalloc()/xfree()
https://github.com/ruby/prism/commit/bd9027f0ab
2025-03-31 19:57:33 +00:00
Kevin Newton
052794bfe1 [ruby/prism] Accept a newline after the defined? keyword
[Bug #21197]

https://github.com/ruby/prism/commit/22be955ce9
2025-03-30 13:22:41 -04:00
Kevin Newton
4b1fea81f9 [ruby/prism] Update Ruby deps
https://github.com/ruby/prism/commit/594e2a69ed
2025-03-23 22:16:45 +00:00
Benoit Daloze
13e6f715ef [ruby/prism] Include nodeId in Java Node only if necessary
* See https://github.com/ruby/prism/issues/3502

https://github.com/ruby/prism/commit/b7aedfe696
2025-03-22 17:06:46 +00:00
Kevin Newton
93ac342afc [ruby/prism] Add node_id to Java serialization
https://github.com/ruby/prism/commit/93e768bd18
2025-03-21 14:18:57 +00:00
Sam Bostock
f07af59a2f [ruby/prism] Dynamically register events to dispatch
Instead of requiring the consumer to provide a list of all events which
they wish to handle, we can give them to option of dynamically detecting
them, by scanning the listener's public methods.

This approach is similar to that used by Minitest (scanning for `test_`
methods) and Rails generators (running all public methods in the order
they are defined).

While this is slower than specifying a hard coded list, the penalty is
only during registration. There is no change the the behaviour of
dispatching the events.

https://github.com/ruby/prism/commit/781ebed743
2025-03-20 17:28:59 +00:00
Nobuyoshi Nakada
820c541671 [Bug #21026] no singleton method on pseudo variable literal 2025-03-20 17:32:26 +09:00
Kevin Newton
641f15b1c6 [ruby/prism] Mark Prism as ractor-safe
https://github.com/ruby/prism/commit/c02429765b
2025-03-19 21:11:57 +00:00
Kevin Newton
6e9568d202 [ruby/prism] Bump to v1.4.0
https://github.com/ruby/prism/commit/71d31db496
2025-03-18 19:06:34 +00:00
Kevin Newton
dc48c1aca3 [ruby/prism] Add a multiple statements flag to parentheses
This can get triggered even if the list of statements only contains
a single statement. This is necessary to properly support compiling

```ruby
defined? (;a)
defined? (a;)
```

as "expression". Previously these were parsed as statements lists
with single statements in them.

https://github.com/ruby/prism/commit/b63b5d67a9
2025-03-18 13:36:53 -04:00
Kevin Newton
12541d2cc0 [ruby/prism] Track then keyword on rescue nodes
https://github.com/ruby/prism/commit/bde8ccc038
2025-03-18 13:36:53 -04:00
Kevin Newton
3d6fc29169 [ruby/prism] Make xstrings concat syntax error
https://github.com/ruby/prism/commit/f734350499
2025-03-18 16:00:03 +00:00
Kevin Newton
af76b7f4d9 [ruby/prism] Revert "Mark extension as Ractor-safe"
https://github.com/ruby/prism/commit/56eaf53732
2025-03-12 19:56:22 +00:00
Kevin Newton
242e99eb0f [ruby/prism] Mark extension as Ractor-safe
https://github.com/ruby/prism/commit/10e5431b38
2025-03-12 19:15:03 +00:00
Kevin Newton
617e8608b2 [ruby/prism] Rename fgets parameter to fix NetBSD
Fixes [Bug #21165]

https://github.com/ruby/prism/commit/3f0acf7560
2025-03-02 18:14:36 +00:00
Jean Boussier
025832c385 [ruby/prism] Use a locale-insensitive version of tolower
[Bug #21161]

The `tolower` function provided by the libc is locale dependent
and can behave in ways you wouldn't expect for some value
of `LC_CTYPE`.

https://github.com/ruby/prism/commit/e3488256b4

Co-Authored-By: Nobuyoshi Nakada <nobu@ruby-lang.org>
2025-02-28 00:28:24 +00:00
Kevin Newton
2db365dc83 [ruby/prism] Fix escape unicode curly inline whitespace
Fixes [Bug #21145]

https://github.com/ruby/prism/commit/be2d845639
2025-02-17 18:12:03 +00:00
Kevin Newton
ee181d1bb7 [ruby/prism] Fix up it indirect writes
Fixes [Bug #21137]

https://github.com/ruby/prism/commit/ca493e6797
2025-02-14 16:49:52 +00:00
HASUMI Hitoshi
31162bf426 [ruby/prism] Handle zero-sized allocation in pm_constant_id_list_init_capacity
According to the calloc(3) man page, when nmemb or size is 0, `calloc()` can either return NULL or a unique pointer that can be passed to `free()`.
While gcc and clang typically return a unique pointer, mruby's `mrb_calloc()` returns NULL in this case.

Since `pm_constant_pool_init()` is commonly called with capacity=0 during normal operation of Prism, explicitly handle this case by setting `list->ids` to NULL when capacity is 0.
This approach is portable across different calloc implementations and avoids potential issues with mruby's allocation behavior.

This maintains compatibility with `free()` and `realloc()`, as passing NULL pointers to these functions is explicitly allowed by their specifications.

https://github.com/ruby/prism/commit/1c32252df7
2025-02-13 20:12:43 +00:00
Kevin Newton
127325a4ba [ruby/prism] No writing to numbered parameters
Fixes [Bug #21117]

https://github.com/ruby/prism/commit/19d4bab5a0
2025-02-13 20:04:02 +00:00
Kevin Newton
b21e1aed2e [ruby/prism] Fix infinite loop in error recovery
When recovering from a depth error that occurs at the end of the
file, we need to break out of parsing statements.

Fixes [Bug #21114]

https://github.com/ruby/prism/commit/a32e268787
2025-02-13 19:12:10 +00:00
Nobuyoshi Nakada
2b92172894 [ruby/prism] Split assertion per expressions
Expressions joined with `&&` are better asserted separately, so that
it is clear from the failure message which expression is false.

Also, `unsigned long` may not be enough for `ptrdiff_t`, e.g., Windows.
Saying that `ptrdiff_t` can be larger than `SIZE_MAX` means that
`PTRDIFF_MAX` is larger than `SIZE_MAX` and `ptrdiff_t` is sufficient
to represent `SIZE_MAX`, otherwise if `PTRDIFF_MAX` is smaller than
`SIZE_MAX`, `diff` will always be smaller than `SIZE_MAX` as well.
`diff` could be equal to `SIZE_MAX` only if `PTRDIFF_MAX` is equal to
`SIZE_MAX` and these assertions would pass, but I don't think there is
any platform where that is the case.

https://github.com/ruby/prism/commit/1fc6dfcada
2025-02-13 17:49:48 +00:00
Kevin Newton
c290861336 [ruby/prism] Fix rescue modifier precedence
Fixes [Bug #21048]

https://github.com/ruby/prism/commit/07202005cb
2025-01-22 19:58:27 +00:00
Kevin Newton
241ada7b1c [ruby/prism] Do not put empty statements in while because of -n
Fixes [Bug #21085]

https://github.com/ruby/prism/commit/ebb9c36a10
2025-01-22 19:09:42 +00:00
Earlopain
f27ed98eff [ruby/prism] Freeze Prism::VERSION
Closes https://github.com/ruby/prism/pull/3422

https://github.com/ruby/prism/commit/b488a84253
2025-01-19 12:44:20 +00:00
Benjamin Quorning
931a870606 [ruby/prism] Increase value of PRISM_DEPTH_MAXIMUM to 10000
The previous value of 1_000 was added with a reference to the Bison
parser[^1], but the value of YYMAXDEPTH in the Bison docs is 10_000,
not 1_000.

[^1]: https://www.gnu.org/software/bison/manual/html_node/Memory-Management.html

Fixes [Bug #21044]

https://github.com/ruby/prism/commit/e098533ab4

Co-authored-by: Nony Dutton <nonydutton@gmail.com>
2025-01-16 01:47:46 +00:00
Kevin Newton
51d3d6ac8c [ruby/prism] Support forwarding flags on scopes
When parent scopes around an eval are forwarding parameters (like
*, **, &, or ...) we need to know that information when we are in
the parser. As such, we need to support passing that information
into the scopes option. In order to do this, unfortunately we need
a bunch of changes.

The scopes option was previously an array of array of strings.
These corresponded to the names of the locals in the parent scopes.
We still support this, but now additionally support passing in a
Prism::Scope instance at each index in the array. This Prism::Scope
class holds both the names of the locals as well as an array of
forwarding parameter names (symbols corresponding to the forwarding
parameters). There is convenience function on the Prism module that
creates a Prism::Scope object using Prism.scope.

In JavaScript, we now additionally support an object much the same
as the Ruby side. In Java, we now have a ParsingOptions.Scope class
that holds that information. In the dump APIs, these objects in all
3 languages will add an additional byte for the forwarding flags in
the middle of the scopes serialization.

All of this is in service of properly parsing the following code:

```ruby
def foo(*) = eval("bar(*)")
```

https://github.com/ruby/prism/commit/21abb6b7c4
2025-01-14 20:31:38 +00:00
Kevin Newton
da93c9ae29 [ruby/prism] Refactor serializer
https://github.com/ruby/prism/commit/8ab2532f09
2025-01-14 15:32:41 +00:00
Kevin Newton
713f31872a [ruby/prism] Freeze AST option
To make it so that you can pass `freeze: true` to Prism parse
methods and get back a deeply-frozen AST that is Ractor-
shareable.

https://github.com/ruby/prism/commit/8e6a93b2d2
2025-01-14 15:32:39 +00:00
Kevin Newton
14b9098459 [ruby/prism] Frozen strings in the AST
https://github.com/ruby/prism/commit/8d9d429155
2025-01-12 18:41:42 +00:00
Kevin Newton
117d6e145a [ruby/prism] Fix not receiver
`not foo` should be `!foo`
`not()` should be `!nil`

Fixes [Bug #21027]

https://github.com/ruby/prism/commit/871ed4b462
2025-01-11 19:09:05 -05:00
Kevin Newton
d597118b3f [ruby/prism] Fallthrough fallback for unknown compilers
https://github.com/ruby/prism/commit/cc810b1e06
2025-01-11 19:09:05 -05:00
Alexander Momchilov
fa1427a63e [ruby/prism] Enable implicit fall-through errors
https://github.com/ruby/prism/commit/03797b84d3
2025-01-11 19:09:05 -05:00
Kevin Newton
b0e64fcde8 [ruby/prism] Bump to v1.3.0
https://github.com/ruby/prism/commit/a679ee0e5c
2025-01-11 19:09:05 -05:00
Kevin Newton
b79152fd22 [ruby/prism] Support 3.5 for version option
https://github.com/ruby/prism/commit/6b6aa05bfb
2025-01-11 19:09:05 -05:00
Kevin Newton
96f23306f0 [ruby/prism] Revert "Reject pattern match with unexpected double splat inside array"
https://github.com/ruby/prism/commit/51e7c84124
2025-01-08 20:42:35 +00:00
Kevin Newton
c4534c9fe8 [ruby/prism] Handle escapes in named capture names
https://github.com/ruby/prism/commit/b4b7a69ce7
2025-01-08 20:36:06 +00:00
ydah
500a87756f [ruby/prism] Reject pattern match with unexpected double splat inside array
`a => [-2**b]` should be SyntaxError

Fixes: https://github.com/ruby/prism/issues/3381

https://github.com/ruby/prism/commit/ae8e83b389
2025-01-08 17:23:51 +00:00
eileencodes
ad96c5a729 [ruby/prism] Throw syntax error for endless method with []=
Prism shoudld throw a syntax error for endless methods when the method
name uses brackets. Previously it would not. This matches the behavior
of parse.y.

Fixes https://bugs.ruby-lang.org/issues/21010

https://github.com/ruby/prism/commit/43c16a89ef
2025-01-07 19:35:01 +00:00