summaryrefslogtreecommitdiff
path: root/lib/syntax_suggest/explain_syntax.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/syntax_suggest/explain_syntax.rb')
-rw-r--r--lib/syntax_suggest/explain_syntax.rb22
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/syntax_suggest/explain_syntax.rb b/lib/syntax_suggest/explain_syntax.rb
index 142ed2e269..0d80c4d869 100644
--- a/lib/syntax_suggest/explain_syntax.rb
+++ b/lib/syntax_suggest/explain_syntax.rb
@@ -2,7 +2,21 @@
require_relative "left_right_lex_count"
+if !SyntaxSuggest.use_prism_parser?
+ require_relative "ripper_errors"
+end
+
module SyntaxSuggest
+ class GetParseErrors
+ def self.errors(source)
+ if SyntaxSuggest.use_prism_parser?
+ Prism.parse(source).errors.map(&:message)
+ else
+ RipperErrors.new(source).call.errors
+ end
+ end
+ end
+
# Explains syntax errors based on their source
#
# example:
@@ -15,8 +29,8 @@ module SyntaxSuggest
# # => "Unmatched keyword, missing `end' ?"
#
# When the error cannot be determined by lexical counting
- # then ripper is run against the input and the raw ripper
- # errors returned.
+ # then the parser is run against the input and the raw
+ # errors are returned.
#
# Example:
#
@@ -91,10 +105,10 @@ module SyntaxSuggest
# Returns an array of syntax error messages
#
# If no missing pairs are found it falls back
- # on the original ripper error messages
+ # on the original error messages
def errors
if missing.empty?
- return RipperErrors.new(@code_lines.map(&:original).join).call.errors
+ return GetParseErrors.errors(@code_lines.map(&:original).join).uniq
end
missing.map { |miss| why(miss) }