77require "pathname"
88require "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
1214require "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-
3016module 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]
0 commit comments