Commit graph

20 commits

Author SHA1 Message Date
Kevin Newton
198d197aeb [ruby/prism] Allow block exits in defined? and fix modifier while/until
2752f0b8df
2024-04-03 17:34:12 -04:00
Kevin Newton
664a5082cb [ruby/prism] Check for syntax errors using RubyVM
9e200dd1c1
2024-04-03 17:34:12 -04:00
Kevin Newton
e454cf2202 [ruby/prism] Update fixtures to be all valid Ruby
a0b978d25b
2024-04-03 17:34:12 -04:00
Koichi ITO
52cf6ec46b [ruby/prism] Fix typos
After finding the "if if" typo, some additional typos identified by running `codespell` are also being corrected:
https://github.com/codespell-project/codespell

e6a34cfeeb
2024-03-26 10:51:12 +00:00
Kevin Newton
af7bf9e0d8 [ruby/prism] Provide options for reducing size
592128de4d
2024-03-20 17:32:03 -04:00
yui-knk
2a4b6ed37c Workaround for Prism::ParseTest#test_filepath for "unparser/corpus/literal/def.txt"
See the discussion on https://github.com/ruby/ruby/pull/9923
2024-02-20 17:33:58 +09:00
yui-knk
20dbc7a5f4 Skip test_filepath of "unparser/corpus/literal/def.txt"
The previous commit changes Ripper lex state behavior of `tLABEL`.
For example, Ripper lex state for the second `bar` was changed
by the previous commit.

```
def foo(bar: bar())
end
```

Before the commit, Ripper didn’t add label `bar` id to `vtable`
because `formal_argument` function for Ripper didn’t return id
but returned `VALUE lhs`.
Therefore Ripper didn’t `SET_LEX_STATE(EXPR_END|EXPR_LABEL)` for following `bar`
in `parse_ident` because `lvar_defined` for following `bar` was not true.

Currently Ripper does `SET_LEX_STATE(EXPR_END|EXPR_LABEL)` then
the result of this test case is changed like below.

```
Prism::ParseTest#test_filepath_unparser/corpus/literal/def.txt [ruby/test/prism/parse_test.rb:280]:
<[[80, 13], :on_ident, “bar”, END|LABEL]> expected but was
<[[80, 13], :on_ident, “bar”, ARG]>.
```

Parser sets lex state to `END|LABEL` on master branch.
Therefore previous commit makes Ripper’s behavior aligned with parser’s behavior.

```
$ ruby -v -y -e "def foo(bar: bar())" -e "end"
ruby 3.4.0dev (2024-02-11T23:52:05Z master 697ade7bda) [arm64-darwin21]
...
Reading a token
parser_dispatch_scan_event:11210 (1: 12|1|7)
lex_state: ARG|LABELED -> ARG at line 11113
lex_state: ARG -> END|LABEL at line 11128
parser_dispatch_scan_event:11877 (1: 13|3|4)
Next token is token “local variable or method” (1.13-1.16: bar)
Shifting token “local variable or method” (1.13-1.16: bar)
```
2024-02-20 17:33:58 +09:00
Benoit Daloze
c2d8d6eba6 Initialize the Prism::Source directly with all 3 fields for the C extension
* Faster that way:
  $ ruby -Ilib -rprism -rbenchmark/ips -e 'Benchmark.ips { |x| x.report("parse") { Prism.parse("1 + 2") } }'
  195.722k (± 0.5%) i/s
  rb_iv_set():
  179.609k (± 0.5%) i/s
  rb_funcall():
  190.030k (± 0.3%) i/s
  before this PR:
  183.319k (± 0.4%) i/s
2024-02-14 15:48:33 +00:00
eileencodes
936c0ab5e8 [ruby/prism] Implement file parsing error handling
This PR implements proper file parsing error handling. Previously
`file_options` would call `pm_string_mapped_init` which would print an
error from `perror`. However this wouldn't raise a proper Ruby error so
it was just a string output. I've done the following:

- Raise an error from `rb_syserr_fail` with the filepath in
`file_options`.
- No longer return `Qnil` if `file_options` returns false (because now
it will raise)
- Update `file_options` to return `static void` instead of `static
bool`.
- Update `file_options` and `profile_file` to check the type so when
passing `nil` we see a `TypeError`.
- Delete `perror` from `pm_string_mapped_init`
- Update `FFI` backend to raise appropriate errors when calling
`pm_string_mapped_init`.
- Add tests for `dump_file`, `lex_file`, `parse_file`,
`parse_file_comments`, `parse_lex_file`, and `parse_file_success?`
when a file doesn't exist and for `nil`.
- Updates the `bin/parse` script to no longer raise it's own
`ArgumentError` now that we raise a proper error.

Fixes: ruby/prism#2207

b2f7494ff5
2024-02-06 20:49:33 +00:00
Max Prokopiev
e9f936df71 [ruby/prism] Extract snippet into its own file and skip in TruffleRuby
12649ee74c
2024-01-24 20:32:02 +00:00
Kevin Newton
88d7838445 [ruby/prism] Fix assertion on spanning heredocs
e190308845
2024-01-09 15:15:52 +00:00
Haldun Bayhantopcu
562d949e02 [ruby/prism] Fix parsing heredoc ends
aa8c702271
2023-12-01 20:10:58 +00: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
Kevin Newton
ca7297efd3
[ruby/prism] Wire up options through the Ruby API
8582d372a3
2023-11-03 10:13:49 -04:00
Kevin Newton
9f16f07cf1 [ruby/prism] Additionally handle encoding comments in vim mode
bf9bdb9d82
2023-10-16 15:40:19 -07:00
Nobuyoshi Nakada
9059dfce12
yield cannot be placed outside methods even in blocks 2023-10-02 23:20:03 +09:00
Nobuyoshi Nakada
b5e23d3e3b
Syntax check of yield in the parser 2023-09-28 16:23:51 +09:00
Kevin Newton
224e76ada7 Include recently added parse_test code in rename 2023-09-27 13:57:38 -04: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 test/yarp/parse_test.rb (Browse further)