Skip to content

Commit 63a90d2

Browse files
Earlopainmatzbot
authored andcommitted
[ruby/syntax_suggest] Prism is always present on Ruby 3.3
Allows to remove some compatibility code with ripper ruby/syntax_suggest@3f2e9a7657
1 parent 76016cc commit 63a90d2

4 files changed

Lines changed: 9 additions & 93 deletions

File tree

lib/syntax_suggest/api.rb

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,12 @@
77
require "pathname"
88
require "timeout"
99

10+
# Prism is the new parser, replacing Ripper
11+
require "prism"
1012
# We need Ripper loaded for `Prism.lex_compat` even if we're using Prism
1113
# for lexing and parsing
1214
require "ripper"
1315

14-
# Prism is the new parser, replacing Ripper
15-
#
16-
# We need to "dual boot" both for now because syntax_suggest
17-
# supports older rubies that do not ship with syntax suggest.
18-
#
19-
# We also need the ability to control loading of this library
20-
# so we can test that both modes work correctly in CI.
21-
if (value = ENV["SYNTAX_SUGGEST_DISABLE_PRISM"])
22-
warn "Skipping loading prism due to SYNTAX_SUGGEST_DISABLE_PRISM=#{value}"
23-
else
24-
begin
25-
require "prism"
26-
rescue LoadError
27-
end
28-
end
29-
3016
module SyntaxSuggest
3117
# Used to indicate a default value that cannot
3218
# be confused with another input.
@@ -35,14 +21,6 @@ module SyntaxSuggest
3521
class Error < StandardError; end
3622
TIMEOUT_DEFAULT = ENV.fetch("SYNTAX_SUGGEST_TIMEOUT", 1).to_i
3723

38-
# SyntaxSuggest.use_prism_parser? [Private]
39-
#
40-
# Tells us if the prism parser is available for use
41-
# or if we should fallback to `Ripper`
42-
def self.use_prism_parser?
43-
defined?(Prism)
44-
end
45-
4624
# SyntaxSuggest.handle_error [Public]
4725
#
4826
# Takes a `SyntaxError` exception, uses the
@@ -152,20 +130,11 @@ def self.valid_without?(without_lines:, code_lines:)
152130
# SyntaxSuggest.invalid? [Private]
153131
#
154132
# Opposite of `SyntaxSuggest.valid?`
155-
if defined?(Prism)
156-
def self.invalid?(source)
157-
source = source.join if source.is_a?(Array)
158-
source = source.to_s
133+
def self.invalid?(source)
134+
source = source.join if source.is_a?(Array)
135+
source = source.to_s
159136

160-
Prism.parse(source).failure?
161-
end
162-
else
163-
def self.invalid?(source)
164-
source = source.join if source.is_a?(Array)
165-
source = source.to_s
166-
167-
Ripper.new(source).tap(&:parse).error?
168-
end
137+
Prism.parse(source).failure?
169138
end
170139

171140
# SyntaxSuggest.valid? [Private]

lib/syntax_suggest/explain_syntax.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,10 @@
22

33
require_relative "left_right_lex_count"
44

5-
if !SyntaxSuggest.use_prism_parser?
6-
require_relative "ripper_errors"
7-
end
8-
95
module SyntaxSuggest
106
class GetParseErrors
117
def self.errors(source)
12-
if SyntaxSuggest.use_prism_parser?
13-
Prism.parse(source).errors.map(&:message)
14-
else
15-
RipperErrors.new(source).call.errors
16-
end
8+
Prism.parse(source).errors.map(&:message)
179
end
1810
end
1911

lib/syntax_suggest/lex_all.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,8 @@ def initialize(source:, source_lines: nil)
4040
}
4141
end
4242

43-
if SyntaxSuggest.use_prism_parser?
44-
def self.lex(source, line_number)
45-
Prism.lex_compat(source, line: line_number).value.sort_by { |values| values[0] }
46-
end
47-
else
48-
def self.lex(source, line_number)
49-
Ripper::Lexer.new(source, "-", line_number).parse.sort_by(&:pos)
50-
end
43+
def self.lex(source, line_number)
44+
Prism.lex_compat(source, line: line_number).value.sort_by { |values| values[0] }
5145
end
5246

5347
def to_a

lib/syntax_suggest/ripper_errors.rb

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)