diff options
Diffstat (limited to 'lib/syntax_suggest/explain_syntax.rb')
| -rw-r--r-- | lib/syntax_suggest/explain_syntax.rb | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/syntax_suggest/explain_syntax.rb b/lib/syntax_suggest/explain_syntax.rb index 142ed2e269..d7f5262ddb 100644 --- a/lib/syntax_suggest/explain_syntax.rb +++ b/lib/syntax_suggest/explain_syntax.rb @@ -1,8 +1,14 @@ # frozen_string_literal: true -require_relative "left_right_lex_count" +require_relative "left_right_token_count" module SyntaxSuggest + class GetParseErrors + def self.errors(source) + Prism.parse(source).errors.map(&:message) + end + end + # Explains syntax errors based on their source # # example: @@ -15,8 +21,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: # @@ -39,14 +45,14 @@ module SyntaxSuggest def initialize(code_lines:) @code_lines = code_lines - @left_right = LeftRightLexCount.new + @left_right = LeftRightTokenCount.new @missing = nil end def call @code_lines.each do |line| - line.lex.each do |lex| - @left_right.count_lex(lex) + line.tokens.each do |token| + @left_right.count_token(token) end end @@ -91,10 +97,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) } |
