146 Commits
Author SHA1 Message Date
Kevin Newton 51f2767aa0 [ruby/prism] Avoid vsnprintf when possible
When formatting error messages, first try to format into a fixed
buffer instead of formatting once to get the length then a second
time to get the actual format.

https://github.com/ruby/prism/commit/557cffe23e
2026-10-26 15:38:14 +00:00
Yusuke EndohandClaude Opus 5.5 9b23d39c44 [ruby/prism] Resync prism as Ruby::Prism
This is the output of

    ruby tool/sync_default_gems.rb prism
    git rm -r lib/prism.rb lib/prism

at https://github.com/ruby/prism/commit/0a5f9c9, with the new mapping:
lib/prism is now lib/ruby/prism, the namespace is rewritten to
Ruby::Prism, and lib/prism/prism.gemspec is no longer imported, so
prism is no longer installed as a default gem.

prism/srcs.mk.in (excluded from the sync) follows the template engine,
now Ruby::Prism::Template: it defines the Ruby module, which does not
exist in BASERUBY older than Ruby 4.0, before loading
templates/template.rb.

Ruby::Prism is the very parser that parsed the running code, no
matter which version of the prism gem is installed; the two can be
loaded side by side (the ruby binary is built with -fvisibility=hidden,
so the gem's pm_* and rb_cPrism* symbols do not collide with the
built-in ones).

[Bug #22379]

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 04:27:15 +09:00
Earlopain 558c104139 [ruby/prism] Reject END { break } for Ruby 4.0
For [Bug #20409]

https://github.com/ruby/prism/commit/4848eb344e
2026-04-27 14:01:26 +00:00
Kevin Newton b5f3f7c504 [ruby/prism] Refine continuable? with algorithm in C
https://github.com/ruby/prism/commit/c28810fe93
2026-03-09 18:42:31 +00:00
Kevin Newton 6533b101e3 [ruby/prism] Fix precedence of infix operators after command
https://github.com/ruby/prism/commit/35470bb90d
2026-03-06 21:26:44 +00:00
Kevin Newton 2b8c10075e [ruby/prism] Prism::ParseResult#continuable?
An API to determine if more input could fix the existing syntax errors.

https://github.com/ruby/prism/commit/6701ffe0f5
2026-03-02 19:48:18 +00:00
Earlopain bf1ac3f4af [ruby/prism] Fix lexing for unterminated strings/heredocs etc.
When we hit EOF and still have lex modes left, it means some content was unterminated.
Heredocs specifically have logic that needs to happen when the body finished lexing.
If we don't reset the mode back to how it was before, it will not continue lexing at the correct place.

Followup to https://github.com/ruby/prism/pull/3918.
We can't call into `parser_lex` since it resets token locations.

https://github.com/ruby/prism/commit/27c24fdc0d
2026-02-13 16:38:48 +00:00
Earlopain 03090e2e72 [ruby/prism] Change bin/prism errors to take source and print errors
This is more akin to how all the other ones work.
Instead I added most of this to the errors test like focusing
a few specifically and creating new expectations.

https://github.com/ruby/prism/commit/b21922b0a1
2026-02-02 18:26:54 +00:00
Kevin Newton af4a1ca021 Use slices instead of locations
In the C API, we want to use slices instead of locations in the
AST. In this case a "slice" is effectively the same thing as the
location, expect it is represented using a 32-bit offset and a
32-bit length. This will cut down on half of the space of all of
the locations in the AST.

Note that from the Ruby/Java/JavaScript side, this is effectively
an invisible change. This only impacts the C/Rust side.
2026-01-27 15:30:45 -05:00
Earlopain c34c7def5a [ruby/prism] Fix locations for invalid syntax when using expect1_opening
Followup to https://github.com/ruby/prism/pull/3827

It sets the start to the opening but it should instead just
continue on as usual.
Fixes https://github.com/ruby/prism/issues/3851

Notice how the AST actually contains "123" in both the body and end keyword.

https://github.com/ruby/prism/commit/8f69c5af08
2026-01-15 21:15:34 +00:00
Earlopain 17bcd71e42 [ruby/prism] Clean up test excludes
Mostly not having to list version-specific excludes when testing against ripper/parse.y

Also don't test new syntax additions against the parser gems. The version support
for them may (or may not) be expanded but we shouldn't bother while the ruby version
hasn't even released yet.
(ruby_parser translation is not versioned, so let as is for now)

I also removed excludes that have since been implemented by parse.y

https://github.com/ruby/prism/commit/e5a0221c37
2025-12-02 16:20:43 +00:00
Thiago Araujo ba47c2f033 [ruby/prism] Add tests to regexp_encoding_option_mismatch
related to #2667

https://github.com/ruby/prism/commit/44f075bae4
2025-11-20 20:09:19 +00:00
Earlopain 6047eada20 [ruby/prism] Make error and snapshot tests multi-version aware
This one has been on my mind for a while now.

Currently, there are only tests against the latest syntax version.

This changes the snapshot structure as follows:
* Snapshots at their current location are tested against all syntax versions
* Snapshots inside a version folder like "3.3" are tested against all versions starting from that version
* Snapshots inside a version folder like "3.3-4.2" are tested against all versions in the given range.

This makes sure that as new syntax is added, older versions still work as expected.
I also added a few tests for now valid syntax that should be invalid in older versions (and the other way around as well)

These tests run really fast. So even though it does 3x the work for these, I am still able to run the whole test suite in just 11 seconds.

https://github.com/ruby/prism/commit/5191b1aa68
2025-10-22 14:50:11 +00:00
Earlopain f2dbc4ec82 [ruby/prism] [Bug #17398] Allow private def hello = puts "Hello"
This was a limitation of parse.y that prism intentionally replicated.

https://github.com/ruby/prism/commit/8fd12d594c
2025-09-12 15:00:01 -04: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
Matt Valentine-House 39d0ebb6e8 [ruby/prism] Blocks & kwargs are not valid in index assignments
Ruby feature: https://bugs.ruby-lang.org/issues/20952

https://github.com/ruby/prism/commit/e612df5f36
2024-12-16 15:00:27 +00:00
Aaron Patterson 6877c38866 [ruby/prism] Fix error messages for unterminated ( and {
If we hit an EOF token, and the character before the EOF is a newline,
we should make EOF token start at the previous newline.  That way any
errors reported will occur on that line.

For example "foo(\n" should report an error on line 1 even though the
EOF technically occurs on line 2.

[Bug #20918]
https://bugs.ruby-lang.org/issues/20918

https://github.com/ruby/prism/commit/60bc43de8e
2024-12-05 18:42:01 +00:00
Kevin Newton 24770c30f8 [ruby/prism] Sync from ruby/ruby
https://github.com/ruby/prism/commit/280517c325
2024-07-25 18:59:10 +00:00
Kevin Newton aa473489a2 [ruby/prism] Various cleanup for initializers and typechecks
https://github.com/ruby/prism/commit/86cf82794a
2024-07-11 14:25:54 -04:00
Kevin Newton 678dd769e5 [ruby/prism] Reconfigure error tests
https://github.com/ruby/prism/commit/fb7e1ebb7f
2024-07-11 14:25:54 -04:00
Kevin Newton ce7299d09a [ruby/prism] Handle block exits under modifiers
https://github.com/ruby/prism/commit/6b78f5309b
2024-06-26 20:46:27 +00:00
Kevin Newton 7529591df1 [ruby/prism] Ensure ranges are non-associative
https://github.com/ruby/prism/commit/f59295938b
2024-06-14 19:22:54 +00:00
Kevin Newton 47322b592a [ruby/prism] Match CRuby error message for unknown regexp options
https://github.com/ruby/prism/commit/73669b59f6
2024-06-11 12:34:00 +00:00
Kevin Newton cbc83c4a92 Remove circular parameter syntax error
https://bugs.ruby-lang.org/issues/20478
2024-06-06 16:29:50 -04:00
Kevin Newton 72452f4387 [ruby/prism] Tests overhaul
https://github.com/ruby/prism/commit/6f886be0a4
2024-05-30 15:18:20 -04:00
eileencodes c96b5791ef [ruby/prism] Raise void value expression in begin clauses
In some cases Prism was either not raising an appropriate `void value
expression` error, or raising that error when the syntax is considered
valid.

To fix this Prism needs to check whether we have other clauses on the
`begin` rather than just returning `cast->statements`.

* If the `cast->statements` are null and the `cast->ensure_clause` is
not null, set the code to `cast->ensure_clause`
* else
  * If there is a `cast->rescue_clause`
    * Check if `cast->statements` are null and `cast->rescue_clause->statements`
    are null, and return `NULL`
    * Check if there is an `else_clause`, and set the node to
      `cast->else_clause`.
    * Otherwise return `cast->statements` as the node
  * return `cast->statements` as the node

See tests for test cases. Note I took these directly from CRuby so if
desired I can delete them since the test will now pass. This only fixes
one test in the `test_parse` file, taking failures from 14 to 13.

This fixes `TestParse#test_void_value_in_rhs` and is related to
issue #2791.

https://github.com/ruby/prism/commit/398152b412
2024-05-23 19:30:03 +00:00
Kevin Newton e575954887 [ruby/prism] Fix support for 'it' implicit local variable
https://github.com/ruby/prism/commit/53bbcfe513
2024-05-22 16:34:04 -04:00
Kevin Newton ff43b4a28b [ruby/prism] Add error for numbered parameter used in inner block
https://github.com/ruby/prism/commit/c386ba6d48
2024-05-21 15:46:45 +00:00
Kevin Newton 98e1e610f6 [ruby/prism] Update more escape error messages to match CRuby
https://github.com/ruby/prism/commit/ab43b3ab66
2024-05-16 18:40:20 +00:00
Kevin Newton 910bb49230 [ruby/prism] Update error message for invalid % at EOF
https://github.com/ruby/prism/commit/178d4f66fd
2024-05-16 14:52:34 +00:00
Kevin Newton 7a4b9d1614 [ruby/prism] Match CRuby error message for unknown % string
https://github.com/ruby/prism/commit/863197629c
2024-05-16 14:23:36 +00:00
Kevin Newton 011668883c [ruby/prism] Always go to string lex mode even if EOF
https://github.com/ruby/prism/commit/57d5c9be2c
2024-05-16 14:16:32 +00:00
Kevin Newton c4a5866798 [ruby/prism] Replace end of file with end-of-input
https://github.com/ruby/prism/commit/dd532ded95
2024-05-15 15:44:16 +00:00
Kevin Newton 83f481ebf0 [ruby/prism] Enhance parameter forwarding error messages
https://github.com/ruby/prism/commit/826657232e
2024-05-10 15:54:15 +00:00
Kevin Newton 21b94ae0d1 [ruby/prism] Extend error message for unterminated HEREDOC
https://github.com/ruby/prism/commit/c1b07ec11b
2024-05-07 18:03:03 +00:00
Kevin Newton 7caeff2bae [ruby/prism] Disallow keywords and blocks in index expressions
https://github.com/ruby/prism/commit/e950dc1e83
2024-05-03 13:01:40 -04:00
Kevin Newton f109a83ddf [PRISM] Fix up error message expectations 2024-05-01 19:19:07 -04:00
Kevin Newton fc8fb581cf [ruby/prism] CRuby error message for trailing underscore in number
https://github.com/ruby/prism/commit/4e34f236d3
2024-05-01 19:51:09 +00:00
Kevin Newton 6a296089c6 [ruby/prism] Add a flag on returns when they are redundant
https://github.com/ruby/prism/commit/450541d2c3
2024-04-26 18:10:42 +00:00
Kevin Newton 3c0756752c [ruby/prism] Better error message on statement inside argument list
https://github.com/ruby/prism/commit/3b1a99526a
2024-04-12 21:46:42 +00:00
Kevin Newton 1521af3259 [ruby/prism] Better error message on invalid def
https://github.com/ruby/prism/commit/d398e7d22c
2024-04-12 17:49:17 +00:00
Kevin Newton 52b862398d [ruby/prism] Syntax error for block argument on yield
https://github.com/ruby/prism/commit/9feeafbc67
2024-04-12 17:30:37 +00:00
Kevin Newton 0424c1fa7b [ruby/prism] Fix up embdoc lexing on EOF
https://github.com/ruby/prism/commit/8ee43be26d
2024-04-12 16:50:34 +00:00
Kevin Newton 0107954f25 [ruby/prism] Fix up invalid global variable error message
https://github.com/ruby/prism/commit/8ce9ae487f
2024-04-09 16:29:01 +00:00
Kevin Newton dcec1e0dc6 [ruby/prism] Replace old circular parameter definition detection
https://github.com/ruby/prism/commit/c739f8e194
2024-04-05 19:24:00 +00:00
Kevin Newton 440c63df31 [ruby/prism] Change forwarding error messages to match CRuby
https://github.com/ruby/prism/commit/6a15e475c9
2024-04-04 20:59:08 +00:00
Kevin Newton 198d197aeb [ruby/prism] Allow block exits in defined? and fix modifier while/until
https://github.com/ruby/prism/commit/2752f0b8df
2024-04-03 17:34:12 -04:00
Kevin Newton 664a5082cb [ruby/prism] Check for syntax errors using RubyVM
https://github.com/ruby/prism/commit/9e200dd1c1
2024-04-03 17:34:12 -04:00
Kevin Newton 1153bcde6b [ruby/prism] Fix up errors test
https://github.com/ruby/prism/commit/5f86742537
2024-04-03 17:34:12 -04:00
Kevin Newton 3147404d64 [ruby/prism] Match circular parameter error message
https://github.com/ruby/prism/commit/c0381b10e4
2024-04-03 17:34:12 -04:00