Commit graph

39 commits

Author SHA1 Message Date
Kevin Newton
50e999c56d [ruby/prism] Command line options as a bitset
369ffbd57e
2024-02-29 12:05:19 -05:00
Kevin Newton
3ca8b4aee0 [ruby/prism] Support -p, -n, -a, and -l command line options
959eb506ca
2024-02-27 04:22:39 +00:00
Kevin Newton
90c5393f9f [ruby/prism] Support ItParametersNode
So that compilers know they need to add to add an anonymous
variable to the local table.

7f1aadd057
2024-02-21 17:55:11 -05:00
Kevin Newton
8e4d1ff5da [ruby/prism] Disallow numbered parameters within given scopes
a218a0f265
2024-02-16 17:50:32 +00:00
Kevin Newton
332d2c92d8 [PRISM] Emit parse warnings 2024-02-01 15:52:19 -05:00
Kevin Newton
e9f1324464 Sync to latest prism 2024-02-01 12:52:16 -05:00
Aaron Patterson
8e708e4a07 Update forwarding locals for prism 2024-01-30 13:19:06 -05:00
Kevin Newton
ba06a8259a [ruby/prism] Better error messages for unexpected tokens in prefix
a35b8e45ee
2024-01-30 16:10:08 +00:00
Kevin Newton
80da9b1547 [ruby/prism] Clarify __END__ comment
3e36d5eabc
2024-01-09 19:02:26 +00:00
Kevin Newton
23beceedb7 [ruby/prism] IndexTargetNode should always have ATTRIBUTE_WRITE
Because this is a user-facing change, we also need to deal with the
fact that CRuby 3.3.0 was just released.

In order to support workflows that want to parse exactly as CRuby
parses in a specific version, this PR introduces a new option to
the options struct that is "version". This allows you to specify
that you want "3.3.0" parsing.

I'm not sure if this is the correct solution. Another solution is
to just fork and keep around the old branch for security patches.
Or we could keep around a copy of the source files within this
repository as another directory and only update when necessary.
There are a lot of potential solutions here.

Because this change is so small and the check for it is so minimal,
I've decided to go with this enum. If this ends up entirely
cluttering the codebase with version checks, we'll come up with
another solution. But for now this works, so we're going to go in
this direction for a bit until we determine it's no longer working.

d8c7e6bd10
2024-01-02 18:51:18 +00:00
Hiroshi SHIBATA
fa251d60aa Revert "Revert all of commits after Prism 0.19.0 release"
This reverts commit d242e8416e.
2023-12-25 21:12:49 +09:00
Hiroshi SHIBATA
d242e8416e
Revert all of commits after Prism 0.19.0 release
We should bundle released version of Prism for Ruby 3.3.0
2023-12-16 11:08:51 +08:00
Ufuk Kayserilioglu
0a31cb1a37 [ruby/prism] Finish keyword hash node flag refactor by renaming flag
7f812389f8
2023-12-15 18:45:36 +00:00
Ufuk Kayserilioglu
01f21d5729 [ruby/prism] Fix the implementation of the flag on keyword hash nodes
The previous implementation was incorrect since it was just checking for all keys in assoc nodes to be static literals but the actual check is that all keys in assoc nodes must be symbol nodes.

This commit fixes that implementation, and, also, aliases the flag to `PM_KEYWORD_HASH_NODE_FLAGS_SYMBOL_KEYS` so that ruby/ruby can start using the new flag name.

I intend to later change the real flag name to `PM_KEYWORD_HASH_NODE_FLAGS_SYMBOL_KEYS` and remove the alias.

f5099c79ce
2023-12-14 18:05:54 +00:00
Kevin Newton
82f18baa21 [ruby/prism] Provide flags for changing encodings
e838eaff6f
2023-12-06 14:23:38 -05:00
Lily Lyons
1227b6d912 [ruby/prism] Refactor pm_diagnostic_t and pm_comment_t to use pm_location_t
115b6a2fc6
2023-12-04 14:33:44 +00:00
Kevin Newton
cdb74d74af [ruby/prism] Change numbered parameters
Previously numbered parameters were a field on blocks and lambdas
that indicated the maximum number of numbered parameters in either
the block or lambda, respectively. However they also had a
parameters field that would always be nil in these cases.

This changes it so that we introduce a NumberedParametersNode that
goes in place of parameters, which has a single uint8_t maximum
field on it. That field contains the maximum numbered parameter in
either the block or lambda.

As a part of the PR, I'm introducing a new UInt8Field type that
can be used on nodes, which is just to make it a little more
explicit what the maximum values can be (the maximum is actually 9,
since it only goes up to _9). Plus we can do a couple of nice
things in serialization like just read a single byte.

2d87303903
2023-12-01 12:03:09 -05:00
Matt Valentine-House
ce5f5ca1d6 [PRISM] Remove transparent scope nodes 2023-12-01 15:04:13 +00:00
Kevin Newton
ea409958b3 [ruby/prism] Remove ability to decode other encodings
98e218d989
2023-11-30 21:37:56 -05:00
Kevin Newton
abb1fe2868 [PRISM] Consolidate prism encoding files 2023-11-30 21:37:56 -05: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
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
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
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
Kevin Newton
c798943a4a [ruby/prism] Move DATA parsing into its own parse result field
42b60b6e95
2023-11-28 13:25:48 +00:00
Mike Dalessio
d6d1a1839a [ruby/prism] fix: nested heredoc dedentation use-after-free
Because the lex mode may be freed when popped, we need to store off
this value for dedentation.

64007322f5

Co-authored-by: Kevin Newton <kddnewton@gmail.com>
2023-11-14 14:11:55 +00:00
Kevin Newton
d7d3243364
[ruby/prism] Properly support the start line option
33cc75a4b7
2023-11-03 10:13:50 -04:00
Kevin Newton
95d3f2eaec
[ruby/prism] Properly support the suppress_warnings option
84229529d7
2023-11-03 10:13:49 -04:00
Kevin Newton
690f3bbf5d [ruby/prism] Last remaining missing C comments
e327449db6
2023-11-01 13:10:29 -04:00
Kevin Newton
17923cc876 [ruby/prism] Even more C file documentation
9c648ce615
2023-11-01 13:10:29 -04:00
Kevin Newton
7c8d939680 [ruby/prism] Start better documenting C API
2b6e661bbc
2023-11-01 13:10:29 -04:00
Kevin Newton
82acca915a [ruby/prism] Ensure no extra multi-target nodes are created
ec31fd827f
2023-10-26 14:58:55 -04:00
Kevin Newton
5523a23469 [ruby/prism] Attach magic comments to the parse result
c7ef25a79a
2023-10-16 15:40:19 -07:00
Kevin Newton
ad46fc093b [ruby/prism] Calculate heredoc common whitespace while lexing
c3f43b64a3
2023-10-13 15:31:30 -04:00
Kevin Newton
1a941c70e4 [ruby/prism] Track current_string to pass forward for character literals
be1d8ae8bb
2023-10-13 15:31:30 -04:00
Matt Valentine-House
7db4ce13ed [ruby/prism] Introduce transparent scopes.
A transparent scope is a scope that cannot have local variables added to
it's local table. When a local is added to it's table, it instead gets
added to the first non-transparent parent scope.

This is used in for loops to ensure the correct depth for local
variables inside the body

ddb8e82253

Co-Authored-By: Kevin Newton <kddnewton@gmail.com>
2023-10-06 12:21:03 +00:00
Kevin Newton
4f73a7c2f7 Sync to prism rename commits 2023-09-27 13:57:38 -04:00
Kevin Newton
8ab56869a6 Rename YARP filepaths to prism filepaths 2023-09-27 13:57:38 -04:00
Renamed from yarp/parser.h (Browse further)