Skip to content

Commit

Permalink
[ruby/irb] Reorder ruby lex clauses for unrecoverable first
Browse files Browse the repository at this point in the history
(ruby/irb#956)

When a syntax error includes multiple error messages, we want to
check for unrecoverable messages first so that we do not
accidentally match a recoverable error later in the message.

ruby/irb@2f42b2360d
  • Loading branch information
kddnewton authored and matzbot committed May 17, 2024
1 parent 761b907 commit 84d2bac
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions lib/irb/ruby-lex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,27 +219,6 @@ def check_code_syntax(code, local_variables:)
:unrecoverable_error
rescue SyntaxError => e
case e.message
when /unterminated (?:string|regexp) meets end of file/
# "unterminated regexp meets end of file"
#
# example:
# /
#
# "unterminated string meets end of file"
#
# example:
# '
return :recoverable_error
when /unexpected end-of-input/
# "syntax error, unexpected end-of-input, expecting keyword_end"
#
# example:
# if true
# hoge
# if false
# fuga
# end
return :recoverable_error
when /unexpected keyword_end/
# "syntax error, unexpected keyword_end"
#
Expand All @@ -262,6 +241,27 @@ def check_code_syntax(code, local_variables:)
# example:
# method / f /
return :unrecoverable_error
when /unterminated (?:string|regexp) meets end of file/
# "unterminated regexp meets end of file"
#
# example:
# /
#
# "unterminated string meets end of file"
#
# example:
# '
return :recoverable_error
when /unexpected end-of-input/
# "syntax error, unexpected end-of-input, expecting keyword_end"
#
# example:
# if true
# hoge
# if false
# fuga
# end
return :recoverable_error
else
return :other_error
end
Expand Down

0 comments on commit 84d2bac

Please sign in to comment.