summaryrefslogtreecommitdiff
path: root/test/prism/fixtures
AgeCommit message (Collapse)Author
37 hours[ruby/prism] Fix ripper translator for `__END__`Earlopain
https://github.com/ruby/prism/commit/2792ac78ca
2025-12-18[ruby/prism] Reject `p(p a, &block => value)` and similarEarlopain
Redo of https://github.com/ruby/prism/pull/3669 with more tests https://github.com/ruby/prism/commit/48b403ea79
2025-12-04[ruby/prism] Fix `%Q` with newline delimiter and heredoc interpolationEarlopain
The lexer did not jump to the `heredoc_end`, causing the heredoc end delimiter to be parsed twice. Normally the heredocs get flushed when a newline is encountered. But because the newline is part of the string delimiter, that codepath is not taken. Fixes [Bug #21758] https://github.com/ruby/prism/commit/7440eb4b11
2025-11-23[ruby/prism] Revert "Reject `p(p a, &block => value)` and similar"Kevin Newton
https://github.com/ruby/prism/commit/fef2c20777
2025-11-23[ruby/prism] Reject `p(p a, &block => value)` and similarEarlopain
They were being parsed as `p((p a, &block) => value)`. When we get to this point, we must not just have parsed a command call, always consuming the `=>` is not correct. Closes [Bug #21622] https://github.com/ruby/prism/commit/796ab0edf4
2025-11-14[ruby/prism] Reject endless method as a block parameter defaultEarlopain
Fixes [Bug #21661] https://github.com/ruby/prism/commit/475fa46a82
2025-11-08[ruby/prism] Rename Ruby 3.5 to Ruby 4.0Earlopain
See https://github.com/ruby/ruby/commit/6d81969b475262aba251e99b518181bdf7c5a523 It leaves the old variant around. RuboCop for examples accesses `Prism::Translation::Parser35` to test against ruby-head. For now I left these simply as an alias https://github.com/ruby/prism/commit/d0a823f045
2025-10-30[ruby/prism] Unescape unary method callsEarlopain
Followup to https://github.com/ruby/prism/pull/2213 Before: ```sh $ ruby -ve "puts 42.~@" ruby 3.4.6 (2025-09-16 revision https://github.com/ruby/prism/commit/dbd83256b1) +PRISM [x86_64-linux] -e:1:in '<main>': undefined method '~@' for an instance of Integer (NoMethodError) Did you mean? ~ ``` After (matches parse.y): ```sh $ ./miniruby -ve "puts 42.~@" ruby 3.5.0dev (2025-10-16T03:40:45Z master https://github.com/ruby/prism/commit/1d95d75c3f) +PRISM [x86_64-linux] -43 ``` https://github.com/ruby/prism/commit/a755bf228f
2025-10-22[ruby/prism] Make error and snapshot tests multi-version awareEarlopain
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-06Sync Prism (#14751)Takashi Kokubun
to https://github.com/ruby/prism/commit/c89ca2af12ba20b4fd2c5ff43ebe25da1d81d8db
2025-09-19[ruby/prism] Reject argument command call taking a block with more trailing ↵Earlopain
arguments https://bugs.ruby-lang.org/issues/21168#note-5 The added code samples align with `parse.y`, except for `foo(bar baz do end)` which `parse.y` currently rejects but shouldn't. https://github.com/ruby/prism/commit/3a4e102d80
2025-09-15[ruby/prism] Fix character literal forced encodingKevin Newton
If a character literal was followed by a string concatenation, then the forced encoding of the string concatenation could accidentally overwrite the explicit encoding of the character literal. We now handle this properly. https://github.com/ruby/prism/commit/125c375d74
2025-09-12[ruby/prism] [Bug #17398] Allow `private def hello = puts "Hello"`Earlopain
This was a limitation of parse.y that prism intentionally replicated. https://github.com/ruby/prism/commit/8fd12d594c
2025-09-12[ruby/prism] Support leading logical operatorsKevin Newton
https://github.com/ruby/prism/commit/3f58fa7705
2025-09-11[ruby/prism] Reject some cases with `return` and command callsEarlopain
The same also applies to `break`/`next`. https://bugs.ruby-lang.org/issues/21540 https://github.com/ruby/prism/commit/3a38b192e3
2025-08-05[ruby/prism] Add it read and assignment testS-H-GAMELINKS
https://github.com/ruby/prism/commit/659d769621
2025-08-05[ruby/prism] Make `it = it` assign `nil` to match parse.y behavior [Bug #21139]S-H-GAMELINKS
Currently Prism returns `42` for code like this: ```ruby 42.tap { it = it; p it } # => 42 ``` But parse.y returns `nil`: ```ruby 42.tap { it = it; p it } # => nil ``` In parse.y, it on the right-hand side is parsed as a local variable. In Prism, it was parsed as the implicit block parameter it, which caused this inconsistent behavior. This change makes the right-hand side it to be parsed as a local variable, aligning with parse.y's behavior. Bug ticket: https://bugs.ruby-lang.org/issues/21139 https://github.com/ruby/prism/commit/cf3bbf9d2c
2025-08-05[ruby/prism] Ensure context terminators terminate expressionsKevin Newton
https://github.com/ruby/prism/commit/915f6b3ae9
2025-08-01[ruby/prism] RubyParser translation for stabby lambdas with `it`Justin Collins
https://github.com/ruby/prism/commit/c2e372a8d8
2025-07-29[ruby/prism] Allow command calls in endless method bodies within assignmentsStan Lo
Previously, endless method definitions in assignment contexts like `x = def f = p 1` would fail to parse because command calls (method calls without parentheses) were only accepted when the surrounding binding power was less than `PM_BINDING_POWER_COMPOSITION`. This fix specifically checks for assignment context and allows command calls in those cases while maintaining the existing behavior for other contexts. This ensures that: - `x = def f = p 1` parses correctly (previously failed) - `private def f = puts "Hello"` still produces the expected error https://github.com/ruby/prism/commit/722af59ba3
2025-07-17[ruby/prism] Revert "Merge pull request #3598 from Shopify/fix-3473"Aaron Patterson
This reverts commit https://github.com/ruby/prism/commit/bc446fb9795e, reversing changes made to https://github.com/ruby/prism/commit/71432af1eb49. https://github.com/ruby/prism/commit/e5ca485f4e
2025-07-17[ruby/prism] Allow command calls in endless method bodies regardless of contextStan Lo
Previously, endless method definitions like `x = def f = p 1` would fail to parse because command calls (method calls without parentheses) were only accepted when the surrounding binding power was less than `PM_BINDING_POWER_COMPOSITION` (8). In assignment contexts with binding power 18, this condition was false, causing parse errors. This fix ensures command calls are always accepted in endless method bodies by passing `true` for `accepts_command_call`, making the method body parse consistently regardless of where the method is defined. https://github.com/ruby/prism/commit/70413ed4dd
2025-06-30[ruby/prism] Fix parser translator with trailing backslash in `%W` /`%I` arrayEarlopain
https://docs.ruby-lang.org/en/master/syntax/literals_rdoc.html#label-25w+and+-25W-3A+String-Array+Literals > %W allow escape sequences described in Escape Sequences. However the continuation line <newline> is not usable because it is interpreted as the escaped newline described above. https://github.com/ruby/prism/commit/f5c7460ad5
2025-06-11[ruby/prism] Fix parser translator during string escaping with invalid utf-8Earlopain
Instead, prefer `scan_byte` over `get_byte` since that already returns the byte as an integer, sidestepping conversion issues. Fixes https://github.com/ruby/prism/issues/3582 https://github.com/ruby/prism/commit/7f3008b2b5
2025-04-12[ruby/prism] Fix parsing rescued exception via indexed assignmentviralpraxis
Given this code ```ruby begin raise '42' rescue => A[] end ``` Prism fails with this backtrace ``` Error: test_unparser/corpus/literal/rescue.txt(Prism::ParserTest): NoMethodError: undefined method `arguments' for nil prism/lib/prism/translation/parser/compiler.rb:1055:in `visit_index_target_node' prism/lib/prism/node.rb:9636:in `accept' prism/lib/prism/compiler.rb:30:in `visit' prism/lib/prism/translation/parser/compiler.rb:218:in `visit_begin_node' ``` Seems like ```diff - visit_all(node.arguments.arguments), + visit_all(node.arguments&.arguments || []), ``` fixes the problem. https://github.com/ruby/prism/commit/76d01aeb6c
2025-04-02[ruby/prism] Fix parser translator when splatting in pattern matching pinEarlopain
Because it ends up treating it as a local variable, and `a.x` is not a valid local variable name. I'm not big on pattern matching, but conceptually it makes sense to me to treat anything inside ^() to not be pattern matching syntax? https://github.com/ruby/prism/commit/80dbd85c45
2025-03-30[ruby/prism] Fix parser translator when pinning hash with string keysEarlopain
`StringNode` and `SymbolNode` don't have the same shape (`content` vs `value`) and that wasn't handled. I believe the logic for the common case can be reused. I simply left the special handling for implicit nodes in pattern matching and fall through otherwise. NOTE: patterns.txt is not actually tested at the moment, because it contains syntax that `parser` mistakenly rejects. But I checked manually that this doesn't introduce other failures. https://github.com/whitequark/parser/pull/1060 https://github.com/ruby/prism/commit/55adfaa895
2025-03-30[ruby/prism] Accept a newline after the defined? keywordKevin Newton
[Bug #21197] https://github.com/ruby/prism/commit/22be955ce9 Notes: Merged: https://github.com/ruby/ruby/pull/12999
2025-03-20[Bug #21026] no singleton method on pseudo variable literalNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12925
2025-03-18[ruby/prism] Add a multiple statements flag to parenthesesKevin Newton
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[ruby/prism] Only unnest parser mlhs nodes when no rest argument is providedEarlopain
``` (a,), = [] PARSER==================== s(:masgn, s(:mlhs, s(:mlhs, s(:lvasgn, :a))), s(:array)) PRISM==================== s(:masgn, s(:mlhs, s(:lvasgn, :a)), s(:array)) ``` https://github.com/ruby/prism/commit/8aa1f4690e
2025-03-18[ruby/prism] Fix parser translator multiline interpolated symbolsEarlopain
In https://github.com/ruby/prism/commit/26370079291a420c6b2b7be5cdbd5c609da62f21 I added tests but didn't modify them correctly https://github.com/ruby/prism/commit/de021e74de
2025-03-18[ruby/prism] Further refine string handling in the parser translatorEarlopain
Mostly around newlines and line continuation. * percent arrays need special backslash handling in the ast * Fix offset issue for heredocs with many line continuations (used wrong variable as index access) * More refined rules on when to simplify string tokens * Handle line continuations in squiggly heredocs * Correctly dedent squiggly heredocs with interpolation * Consider `':foo:` and `%s[foo]` to not be interpolation https://github.com/ruby/prism/commit/4edfe9d981
2025-03-18[ruby/prism] Further refine string handling in the parser translatorEarlopain
Mostly around newlines and line continuation. * percent arrays need special backslash handling in the ast * Fix offset issue for heredocs with many line continuations (used wrong variable as index access) * More refined rules on when to simplify string tokens * Handle line continuations in squiggly heredocs * Correctly dedent squiggly heredocs with interpolation * Consider `':foo:` and `%s[foo]` to not be interpolation https://github.com/ruby/prism/commit/4edfe9d981
2025-03-18[ruby/prism] Fix parser translator tokens for %-arrays with whitespace escapesEarlopain
Also fixes a token incompatibility for the word separator. parser only considers whitespace until the first newline https://github.com/ruby/prism/commit/bd3dd2b62a
2025-03-18[ruby/prism] Fix parser translator edge-case when multiline string ends with \nEarlopain
When the line contains no real newline but contains unescaped ones, then there will be one less entry https://github.com/ruby/prism/commit/4ef093b600
2025-03-18[ruby/prism] Better handle all kinds of multiline strings in the parser ↵Earlopain
translator This is a followup to #3373, where the implementation was extracted https://github.com/ruby/prism/commit/2637007929
2025-03-18[ruby/prism] Fix an incompatibility with the parser translatorEarlopain
The offset cache contains an entry for each byte so it can't be accessed via the string length. Adds tests for all variants except for this: ``` "fo o" "ba ’" ``` For some reason, this still has the wrong offset. https://github.com/ruby/prism/commit/a651126458
2025-03-18[ruby/prism] Fix parser translator rescue location with semicolon bodyEarlopain
There are a few other locations that should be included in that check. I think the end location must always be present but I left it in to be safe (maybe implicit begin somehow?) https://github.com/ruby/prism/commit/545d07ddc3
2025-03-18[ruby/prism] Further refine string handling in the parser translatorEarlopain
Mostly around newlines and line continuation. * percent arrays need special backslash handling in the ast * Fix offset issue for heredocs with many line continuations (used wrong variable as index access) * More refined rules on when to simplify string tokens * Handle line continuations in squiggly heredocs * Correctly dedent squiggly heredocs with interpolation * Consider `':foo:` and `%s[foo]` to not be interpolation https://github.com/ruby/prism/commit/4edfe9d981
2025-03-18[ruby/prism] Fix parser translator when unescaping invalid utf8Earlopain
1. The string starts out as binary 2. `ち` is appended, forcing it back into utf-8 3. Some invalid byte sequences are tried to append > incompatible character encodings: UTF-8 and BINARY (ASCII-8BIT) This makes use of my wish to use `append_as_bytes`. Unfortunatly that method is rather new so it needs a fallback https://github.com/ruby/prism/commit/e31e94a775
2025-02-14[ruby/prism] Fix up it indirect writesKevin Newton
Fixes [Bug #21137] https://github.com/ruby/prism/commit/ca493e6797
2025-01-22[ruby/prism] Fix rescue modifier precedenceKevin Newton
Fixes [Bug #21048] https://github.com/ruby/prism/commit/07202005cb
2025-01-14[ruby/prism] Fix block parameters and it for RubyParserJustin Collins
https://github.com/ruby/prism/commit/7a93a307ac
2025-01-12[ruby/prism] Fix parser translator tokens for comment-only fileEarlopain
In https://github.com/ruby/prism/pull/3393 I made a mistake. When there is no previous token, it wraps around to -1. Oops Additionally, if a comment has no newline then the offset should be kept as is https://github.com/ruby/prism/commit/3c266f1de4
2025-01-12[ruby/prism] Fix binary encoding for the parser translatorEarlopain
Skipping detecting the encoding is almost always right, just for binary it should actually happen. A symbol containing escapes that are invalid in utf-8 would fail to parse since symbols must be valid in the script encoding. Additionally, the parser gem would raise an exception somewhere during string handling https://github.com/ruby/prism/commit/fa0154d9e4
2025-01-11[ruby/prism] Better comment token handling for the parser translatorEarlopain
There appear to be a bunch of rules, changing behaviour for inline comments, multiple comments after another, etc. This seems to line up with reality pretty closely, token differences for RuboCop tests go from 1129 to 619 which seems pretty impressive https://github.com/ruby/prism/commit/2e1b92670c
2025-01-11[ruby/prism] Fix parser translator tokens for backslashes in single-quoted ↵Earlopain
strings and word arrays These are not line continuations. They either should be taken literally, or allow the word array to contain the following whitespace (newlines in this case) Before: ``` 0...1: tSTRING_BEG => "'" 1...12: tSTRING_CONTENT => "foobar\\\n" 12...16: tSTRING_CONTENT => "baz\n" 16...17: tSTRING_END => "'" 17...18: tNL => nil ``` After: ``` 0...1: tSTRING_BEG => "'" 1...6: tSTRING_CONTENT => "foo\\\n" 6...12: tSTRING_CONTENT => "bar\\\n" 12...16: tSTRING_CONTENT => "baz\n" 16...17: tSTRING_END => "'" 17...18: tNL => nil ``` https://github.com/ruby/prism/commit/b6554ad64e
2025-01-11[ruby/prism] Import code samples for Ruby 3.3 from the parser gemEarlopain
Slightly tweaking the import script becaues of backtrace format changes in Ruby 3.4 Most tests pass in all parsers, with only a handful of failures overall https://github.com/ruby/prism/commit/9b5b785aa4
2025-01-11[ruby/prism] Better handle all kinds of multiline strings in the parser ↵Earlopain
translator This is a followup to #3373, where the implementation was extracted https://github.com/ruby/prism/commit/2637007929