Skip to content

Commit

Permalink
Reorder ruby lex clauses for unrecoverable first (#956)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kddnewton committed May 17, 2024
1 parent 7d60349 commit 2f42b23
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 2f42b23

Please sign in to comment.