Kevin Newton
75568d23e9
[ruby/prism] Disallow &. after endless range
...
https://github.com/ruby/prism/commit/498dd922d4
2024-10-01 12:57:00 +00:00
Kevin Newton
6c9b5c1615
Sync Prism with latest main branch
2024-09-30 11:36:29 -04:00
Kevin Newton
c1c9ba77ca
[ruby/prism] Require a delimiter for singleton classes
...
https://github.com/ruby/prism/commit/fd58d6a9ea
2024-09-30 14:33:58 +00:00
Kevin Newton
1f431b63a2
[ruby/prism] Reject non-assoc ranges with subsequent operators
...
https://github.com/ruby/prism/commit/976a3cd0a5
2024-09-26 14:57:02 +00:00
Kevin Newton
be331c0eeb
[ruby/prism] Fix up more error messages to more closely match parse.y
...
https://github.com/ruby/prism/commit/988ac82187
2024-09-25 19:19:18 +00:00
Kevin Newton
12cf9f2ae5
[ruby/prism] Fix up void value expression checking for rescue
...
https://github.com/ruby/prism/commit/509ff88e92
2024-09-25 18:34:51 +00:00
Kevin Newton
768ceceb12
[ruby/prism] Disallow label in parentheses
...
https://github.com/ruby/prism/commit/b624e09cc6
2024-09-25 17:33:51 +00:00
Kevin Newton
414a848cc6
[ruby/prism] Accept version shorthand like 3.4
...
https://github.com/ruby/prism/commit/098f1c4607
2024-09-24 13:21:36 +00:00
Benoit Daloze
ed4a55fc4d
[ruby/prism] Accept all 3.3.x and 3.4.x Ruby versions for Prism.parse
...
https://github.com/ruby/prism/commit/a4fcd5339a
2024-09-24 12:24:19 +00:00
Koichi ITO
75ed086348
[ruby/prism] Fix `kDO_LAMBDA` token incompatibility for `Prism::Translation::Parser::Lexer`
...
## Summary
This PR fixes `kDO_LAMBDA` token incompatibility between Parser gem and `Prism::Translation::Parser` for lambda `do` block.
### Parser gem (Expected)
Returns `kDO_LAMBDA` token:
```console
$ bundle exec ruby -Ilib -rparser/ruby33 -ve \
'buf = Parser::Source::Buffer.new("example.rb"); buf.source = "-> do end"; p Parser::Ruby33.new.tokenize(buf)[2]'
ruby 3.4.0dev (2024-09-01T11:00:13Z master https://github.com/ruby/prism/commit/eb144ef91e ) [x86_64-darwin23]
[[:tLAMBDA, ["->", #<Parser::Source::Range example.rb 0...2>]], [:kDO_LAMBDA, ["do", #<Parser::Source::Range example.rb 3...5>]],
[:kEND, ["end", #<Parser::Source::Range example.rb 6...9>]]]
```
### `Prism::Translation::Parser` (Actual)
Previously, the parser returned `kDO` token when parsing the following:
```console
$ bundle exec ruby -Ilib -rprism -rprism/translation/parser33 -ve \
'buf = Parser::Source::Buffer.new("example.rb"); buf.source = "-> do end"; p Prism::Translation::Parser33.new.tokenize(buf)[2]'
ruby 3.4.0dev (2024-09-01T11:00:13Z master https://github.com/ruby/prism/commit/eb144ef91e ) [x86_64-darwin23]
[[:tLAMBDA, ["->", #<Parser::Source::Range example.rb 0...2>]], [:kDO, ["do", #<Parser::Source::Range example.rb 3...5>]],
[:kEND, ["end", #<Parser::Source::Range example.rb 6...9>]]]
```
After the update, the parser now returns `kDO_LAMBDA` token for the same input:
```console
$ bundle exec ruby -Ilib -rprism -rprism/translation/parser33 -ve \
'buf = Parser::Source::Buffer.new("example.rb"); buf.source = "-> do end"; p Prism::Translation::Parser33.new.tokenize(buf)[2]'
ruby 3.4.0dev (2024-09-01T11:00:13Z master https://github.com/ruby/prism/commit/eb144ef91e ) [x86_64-darwin23]
[[:tLAMBDA, ["->", #<Parser::Source::Range example.rb 0...2>]], [:kDO_LAMBDA, ["do", #<Parser::Source::Range example.rb 3...5>]],
[:kEND, ["end", #<Parser::Source::Range example.rb 6...9>]]]
```
## Additional Information
Unfortunately, this kind of edge case doesn't work as expected; `kDO` is returned instead of `kDO_LAMBDA`.
However, since `kDO` is already being returned in this case, there is no change in behavior.
### Parser gem
Returns `tLAMBDA` token:
```console
$ bundle exec ruby -Ilib -rparser/ruby33 -ve \
'buf = Parser::Source::Buffer.new("example.rb"); buf.source = "-> (foo = -> (bar) {}) do end"; p Parser::Ruby33.new.tokenize(buf)[2]'
ruby 3.3.5 (2024-09-03 revision https://github.com/ruby/prism/commit/ef084cc8f4 ) [x86_64-darwin23]
[[:tLAMBDA, ["->", #<Parser::Source::Range example.rb 0...2>]], [:tLPAREN2, ["(", #<Parser::Source::Range example.rb 3...4>]],
[:tIDENTIFIER, ["foo", #<Parser::Source::Range example.rb 4...7>]], [:tEQL, ["=", #<Parser::Source::Range example.rb 8...9>]],
[:tLAMBDA, ["->", #<Parser::Source::Range example.rb 10...12>]], [:tLPAREN2, ["(", #<Parser::Source::Range example.rb 13...14>]],
[:tIDENTIFIER, ["bar", #<Parser::Source::Range example.rb 14...17>]], [:tRPAREN, [")", #<Parser::Source::Range example.rb 17...18>]],
[:tLAMBEG, ["{", #<Parser::Source::Range example.rb 19...20>]], [:tRCURLY, ["}", #<Parser::Source::Range example.rb 20...21>]],
[:tRPAREN, [")", #<Parser::Source::Range example.rb 21...22>]], [:kDO_LAMBDA, ["do", #<Parser::Source::Range example.rb 23...25>]],
[:kEND, ["end", #<Parser::Source::Range example.rb 26...29>]]]
```
### `Prism::Translation::Parser`
Returns `kDO` token:
```console
$ bundle exec ruby -Ilib -rprism -rprism/translation/parser33 -ve \
'buf = Parser::Source::Buffer.new("example.rb"); buf.source = "-> (foo = -> (bar) {}) do end"; p Prism::Translation::Parser33.new.tokenize(buf)[2]'
ruby 3.3.5 (2024-09-03 revision https://github.com/ruby/prism/commit/ef084cc8f4 ) [x86_64-darwin23]
[[:tLAMBDA, ["->", #<Parser::Source::Range example.rb 0...2>]], [:tLPAREN2, ["(", #<Parser::Source::Range example.rb 3...4>]],
[:tIDENTIFIER, ["foo", #<Parser::Source::Range example.rb 4...7>]], [:tEQL, ["=", #<Parser::Source::Range example.rb 8...9>]],
[:tLAMBDA, ["->", #<Parser::Source::Range example.rb 10...12>]], [:tLPAREN2, ["(", #<Parser::Source::Range example.rb 13...14>]],
[:tIDENTIFIER, ["bar", #<Parser::Source::Range example.rb 14...17>]], [:tRPAREN, [")", #<Parser::Source::Range example.rb 17...18>]],
[:tLAMBEG, ["{", #<Parser::Source::Range example.rb 19...20>]], [:tRCURLY, ["}", #<Parser::Source::Range example.rb 20...21>]],
[:tRPAREN, [")", #<Parser::Source::Range example.rb 21...22>]], [:kDO, ["do", #<Parser::Source::Range example.rb 23...25>]],
[:kEND, ["end", #<Parser::Source::Range example.rb 26...29>]]]
```
As the intention is not to address such special cases at this point, a comment has been left indicating that this case still returns `kDO`.
In other words, `kDO_LAMBDA` will now be returned except for edge cases after this PR.
https://github.com/ruby/prism/commit/2ee480654c
2024-09-20 17:17:21 +00:00
Kevin Newton
f515a1ab4b
[ruby/prism] Introduce partial_script option
...
https://github.com/ruby/prism/commit/b28877fa4f
2024-09-20 15:42:12 +00:00
Kevin Newton
96da3f16a0
[ruby/prism] Allow returns in default parameter values
...
https://github.com/ruby/prism/commit/e98ea15596
2024-09-18 11:52:27 -04:00
Hiroshi SHIBATA
c0116860ba
Removed accidentally commit for snapshot file of prism
2024-09-17 15:37:20 +09:00
Kevin Newton
2ea1950510
[ruby/prism] Do not leak explicit encoding
...
Fixes [Bug #20744 ]
https://github.com/ruby/prism/commit/f1b8b1b2a2
2024-09-16 18:57:54 +00:00
Kevin Newton
d57bc870ac
[PRISM] Remove snapshot testing from Prism sync
2024-09-16 08:44:19 -04:00
Kevin Newton
ddbd644001
[ruby/prism] Stat file first to check directory
...
https://github.com/ruby/prism/commit/4ed7de537b
2024-09-13 19:30:57 +00:00
Kevin Newton
77521afac1
[PRISM] Do not warn ambiguous ampersand when symbol literal
...
Fixes [Bug #20735 ]
2024-09-13 14:09:02 -04:00
Kevin Newton
9afc6a981d
[PRISM] Only parse shebang on main script
...
Fixes [Bug #20730 ]
2024-09-13 12:51:53 -04:00
Kevin Newton
d42d19059d
[PRISM] Allow case/when to be indented with no warning
...
Fixes [Bug #20731 ]
2024-09-13 12:51:36 -04:00
Kevin Newton
f0dcbbe9b9
[ruby/prism] Reverse-sync numbered reference range handling
...
https://github.com/ruby/prism/commit/a2f57ef6e3
2024-09-13 13:17:56 +00:00
Kevin Newton
05e02783a5
[PRISM] Ignore test_parse_directory if error is nil
2024-09-12 15:07:04 -04:00
Kevin Newton
38ba15beed
[ruby/prism] Check errno for parsing directory
...
https://github.com/ruby/prism/commit/d68ea29d04
2024-09-12 13:43:04 -04:00
Kevin Newton
15135030e5
[ruby/prism] Do not warn \r in shebang on windows
...
https://github.com/ruby/prism/commit/e8c862ca1f
2024-09-12 15:50:34 +00:00
Kevin Newton
d4d6f1de83
[ruby/prism] UTF-8 characters in file name
...
https://github.com/ruby/prism/commit/487f0ffe78
2024-09-11 19:17:12 +00:00
Kevin Newton
1be9a99837
[ruby/prism] Add a flag for arguments that contain forwarding
...
https://github.com/ruby/prism/commit/ebd2889bee
2024-09-11 16:35:10 +00:00
Kevin Newton
886fc69b1c
[ruby/prism] Parse tempfile
...
https://github.com/ruby/prism/commit/31154a389a
2024-09-11 15:39:22 +00:00
Koichi ITO
7a65334528
[ruby/prism] Fix a token incompatibility for `Prism::Translation::Parser::Lexer`
...
This PR fixes a token incompatibility between Parser gem and `Prism::Translation::Parser` for double splat argument.
## Parser gem (Expected)
Returns `tDSTAR` token:
```console
$ bundle exec ruby -Ilib -rparser/ruby33 -ve \
'buf = Parser::Source::Buffer.new("example.rb"); buf.source = "def f(**foo) end"; p Parser::Ruby33.new.tokenize(buf)[2]'
ruby 3.4.0dev (2024-09-01T11:00:13Z master https://github.com/ruby/prism/commit/eb144ef91e ) [x86_64-darwin23]
[[:kDEF, ["def", #<Parser::Source::Range example.rb 0...3>]], [:tIDENTIFIER, ["f", #<Parser::Source::Range example.rb 4...5>]],
[:tLPAREN2, ["(", #<Parser::Source::Range example.rb 5...6>]], [:tDSTAR, ["**", #<Parser::Source::Range example.rb 6...8>]],
[:tIDENTIFIER, ["foo", #<Parser::Source::Range example.rb 8...11>]], [:tRPAREN, [")", #<Parser::Source::Range example.rb 11...12>]],
[:kEND, ["end", #<Parser::Source::Range example.rb 13...16>]]]
```
## `Prism::Translation::Parser` (Actual)
Previously, the parser returned `tPOW` token when parsing the following:
```console
$ bundle exec ruby -Ilib -rprism -rprism/translation/parser33 -ve \
'buf = Parser::Source::Buffer.new("example.rb"); buf.source = "def f(**foo) end"; p Prism::Translation::Parser33.new.tokenize(buf)[2]'
ruby 3.4.0dev (2024-09-01T11:00:13Z master https://github.com/ruby/prism/commit/eb144ef91e ) [x86_64-darwin23]
[[:kDEF, ["def", #<Parser::Source::Range example.rb 0...3>]], [:tIDENTIFIER, ["f", #<Parser::Source::Range example.rb 4...5>]],
[:tLPAREN2, ["(", #<Parser::Source::Range example.rb 5...6>]], [:tPOW, ["**", #<Parser::Source::Range example.rb 6...8>]],
[:tIDENTIFIER, ["foo", #<Parser::Source::Range example.rb 8...11>]], [:tRPAREN, [")", #<Parser::Source::Range example.rb 11...12>]],
[:kEND, ["end", #<Parser::Source::Range example.rb 13...16>]]]
```
After the update, the parser now returns `tDSTAR` token for the same input:
```console
$ bundle exec ruby -Ilib -rprism -rprism/translation/parser33 -ve \
'buf = Parser::Source::Buffer.new("example.rb"); buf.source = "def f(**foo) end"; p Prism::Translation::Parser33.new.tokenize(buf)[2]'
ruby 3.4.0dev (2024-09-01T11:00:13Z master https://github.com/ruby/prism/commit/eb144ef91e ) [x86_64-darwin23]
[[:kDEF, ["def", #<Parser::Source::Range example.rb 0...3>]], [:tIDENTIFIER, ["f", #<Parser::Source::Range example.rb 4...5>]],
[:tLPAREN2, ["(", #<Parser::Source::Range example.rb 5...6>]], [:tDSTAR, ["**", #<Parser::Source::Range example.rb 6...8>]],
[:tIDENTIFIER, ["foo", #<Parser::Source::Range example.rb 8...11>]], [:tRPAREN, [")", #<Parser::Source::Range example.rb 11...12>]],
[:kEND, ["end", #<Parser::Source::Range example.rb 13...16>]]]
```
With this change, the following code could be removed from test/prism/ruby/parser_test.rb:
```diff
- when :tPOW
- actual_token[0] = expected_token[0] if expected_token[0] == :tDSTAR
```
`tPOW` is the token type for the behavior of `a ** b`, and its behavior remains unchanged:
```console
$ bundle exec ruby -Ilib -rprism -rprism/translation/parser33 -ve \
'buf = Parser::Source::Buffer.new("example.rb"); buf.source = "a ** b"; p Prism::Translation::Parser33.new.tokenize(buf)[2]'
ruby 3.4.0dev (2024-09-01T11:00:13Z master https://github.com/ruby/prism/commit/eb144ef91e ) [x86_64-darwin23]
[[:tIDENTIFIER, ["a", #<Parser::Source::Range example.rb 0...1>]], [:tPOW, ["**", #<Parser::Source::Range example.rb 2...4>]],
[:tIDENTIFIER, ["b", #<Parser::Source::Range example.rb 5...6>]]]
```
https://github.com/ruby/prism/commit/66bde35a44
2024-09-09 19:01:30 +00:00
Koichi ITO
4774284124
[ruby/prism] Fix a token incompatibility for `Prism::Translation::Parser::Lexer`
...
This PR fixes a token incompatibility between Parser gem and `Prism::Translation::Parser` for left parenthesis.
## Parser gem (Expected)
Returns `tLPAREN2` token:
```console
$ bundle exec ruby -Ilib -rparser/ruby33 \
-ve 'buf = Parser::Source::Buffer.new("example.rb"); buf.source = "foo(:bar)"; p Parser::Ruby33.new.tokenize(buf)[2]'
ruby 3.4.0dev (2024-09-01T11:00:13Z master https://github.com/ruby/prism/commit/eb144ef91e ) [x86_64-darwin23]
[[:tIDENTIFIER, ["foo", #<Parser::Source::Range example.rb 0...3>]], [:tLPAREN2, ["(", #<Parser::Source::Range example.rb 3...4>]],
[:tSYMBOL, ["bar", #<Parser::Source::Range example.rb 4...8>]], [:tRPAREN, [")", #<Parser::Source::Range example.rb 8...9>]]]
```
## `Prism::Translation::Parser` (Actual)
Previously, the parser returned `tLPAREN` token when parsing the following:
```console
$ bundle exec ruby -Ilib -rprism -rprism/translation/parser33 -ve \
'buf = Parser::Source::Buffer.new("example.rb"); buf.source = "foo(:bar)"; p Prism::Translation::Parser33.new.tokenize(buf)[2]'
ruby 3.4.0dev (2024-09-01T11:00:13Z master https://github.com/ruby/prism/commit/eb144ef91e ) [x86_64-darwin23]
[[:tIDENTIFIER, ["foo", #<Parser::Source::Range example.rb 0...3>]], [:tLPAREN, ["(", #<Parser::Source::Range example.rb 3...4>]],
[:tSYMBOL, ["bar", #<Parser::Source::Range example.rb 4...8>]], [:tRPAREN, [")", #<Parser::Source::Range example.rb 8...9>]]]
```
After the update, the parser now returns `tLPAREN2` token for the same input:
```console
$ bundle exec ruby -Ilib -rprism -rprism/translation/parser33 -ve \
'buf = Parser::Source::Buffer.new("example.rb"); buf.source = "foo(:bar)"; p Prism::Translation::Parser33.new.tokenize(buf)[2]'
ruby 3.4.0dev (2024-09-01T11:00:13Z master https://github.com/ruby/prism/commit/eb144ef91e ) [x86_64-darwin23]
[[:tIDENTIFIER, ["foo", #<Parser::Source::Range example.rb 0...3>]], [:tLPAREN2, ["(", #<Parser::Source::Range example.rb 3...4>]],
[:tSYMBOL, ["bar", #<Parser::Source::Range example.rb 4...8>]], [:tRPAREN, [")", #<Parser::Source::Range example.rb 8...9>]]]
```
The `PARENTHESIS_LEFT` token in Prism is classified as either `tLPAREN` or `tLPAREN2` in the Parser gem.
The tokens that were previously all classified as `tLPAREN` are now also classified to `tLPAREN2`.
With this change, the following code could be removed from `test/prism/ruby/parser_test.rb`:
```diff
- when :tLPAREN
- actual_token[0] = expected_token[0] if expected_token[0] == :tLPAREN2
```
https://github.com/ruby/prism/commit/04d6f3478d
2024-09-07 22:36:38 +00:00
Kevin Newton
d25833b81a
[ruby/prism] Multi-splat flag for arguments
...
https://github.com/ruby/prism/commit/21cb9b78ae
2024-08-28 21:10:39 +00:00
Kevin Newton
417bb8d4fd
[PRISM] Field renaming
...
Rename some fields that do not quite make sense.
* CaseMatchNode#consequent -> CaseMatchNode#else_clause
* CaseNode#consequent -> CaseNode#else_clause
* IfNode#consequent -> IfNode#subsequent
* RescueNode#consequent -> RescueNode#subsequent
* UnlessNode#consequent -> UnlessNode#else_clause
2024-08-28 15:06:53 -04:00
eileencodes
2157dcb568
[ruby/prism] Add `contains_splat` flag
...
If we have a splat, add a flag for it named `contains_splat`.
https://github.com/ruby/prism/commit/5be97a75c8
2024-08-27 20:53:11 +00:00
Alexander Momchilov
2fbaff5351
[ruby/prism] Fix warning when `#!` ends with carriage return
...
https://github.com/ruby/prism/commit/5753fb6260
2024-08-27 16:46:44 +00:00
Kevin Newton
3eb42054d9
[ruby/prism] Pass Unicode escapes on to onigmo
...
When we encounter an invalid unicode escape within a regular
expression, we now pass that error on to Onigmo as if it didn't
exist in the parser (which matches the upstream parser's behavior).
We do this because there are tests that specify that you are
allowed to have invalid Unicode escapes if they are within the
context of a regular expression comment for a regular expression
in extended mode. That looks like:
/# \u /x
Note that this _only_ applies to Unicode escapes (as opposed to
applying to hex or meta/control escapes as well). Importantly it
also only applies if the regular expression is terminated. An
unterminated regular expression will still get error handling done
in the parser. That would look like:
/# \u
that would result in the same error handling we have today.
https://github.com/ruby/prism/commit/fb98034806
2024-08-23 19:18:14 +00:00
Kevin Newton
d57486cb10
[ruby/prism] Turn off extended mode when parsing extended group
...
https://github.com/ruby/prism/commit/098b3f08bc
2024-08-22 14:43:35 +00:00
Kevin Newton
5cb6954baa
[ruby/prism] Fix up lex result constants
...
https://github.com/ruby/prism/commit/084baca463
2024-08-15 16:50:00 +00:00
Kevin Newton
cbf508da58
[ruby/prism] Special error for too short unicode errors
...
https://github.com/ruby/prism/commit/9f1f7d08bd
2024-08-15 16:40:05 +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
Nobuyoshi Nakada
e642ddf7ae
[Bug #20647 ] Disallow `return` directly within a singleton class
2024-07-24 14:44:32 +09:00
Kevin Newton
cb863907d8
[ruby/prism] Single line method bodies should not be marked as newline
...
https://github.com/ruby/prism/commit/18a8597276
2024-07-23 18:44:31 +00:00
Kevin Newton
2effa98b6f
[ruby/prism] Implement mismatched indentation warning
...
https://github.com/ruby/prism/commit/5d5bf92be8
2024-07-22 18:57:10 +00:00
Kevin Newton
e77e4aa608
[ruby/prism] Have parse_stream handle NUL bytes
...
https://github.com/ruby/prism/commit/4a41d298c8
2024-07-17 19:44:32 +00:00
Nobuyoshi Nakada
644424941a
[Bug #20457 ] [Prism] Remove redundant return flag
2024-07-17 14:06:11 -04:00
Kevin Newton
c06f79c575
[ruby/prism] Fix up implicit flags
...
https://github.com/ruby/prism/commit/f4152c1f50
2024-07-15 18:12:37 +00:00
Kevin Newton
6298667ff5
[ruby/prism] When parsing an invalid write, still add to the local table
...
https://github.com/ruby/prism/commit/a54abc4d1b
2024-07-12 13:50:00 +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
2bf9ae3fa1
[ruby/prism] Add node ids to nodes
...
https://github.com/ruby/prism/commit/bf16ade7f9
2024-07-11 14:25:54 -04:00
Kevin Newton
39dcfe26ee
[ruby/prism] Move Node#type and Node::type documentation
...
https://github.com/ruby/prism/commit/08a71f6259
2024-07-11 14:25:54 -04:00
Kevin Newton
32090e2b8d
[ruby/prism] Add Node#breadth_first_search
...
https://github.com/ruby/prism/commit/1ffb141199
2024-07-11 14:25:54 -04:00
Kevin Newton
aca42a2478
[ruby/prism] Expose common flags in inspect output
...
https://github.com/ruby/prism/commit/d0143865c2
2024-07-11 14:25:54 -04:00
Kevin Newton
687be43c79
[ruby/prism] Expose flags on every node type
...
https://github.com/ruby/prism/commit/9f12a56fd6
2024-07-11 14:25:54 -04:00