Skip to content

Commit 2f42b23

Browse files
authored
Reorder ruby lex clauses for unrecoverable first (#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.
1 parent 7d60349 commit 2f42b23

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

lib/irb/ruby-lex.rb

+21-21
Original file line numberDiff line numberDiff line change
@@ -219,27 +219,6 @@ def check_code_syntax(code, local_variables:)
219219
:unrecoverable_error
220220
rescue SyntaxError => e
221221
case e.message
222-
when /unterminated (?:string|regexp) meets end of file/
223-
# "unterminated regexp meets end of file"
224-
#
225-
# example:
226-
# /
227-
#
228-
# "unterminated string meets end of file"
229-
#
230-
# example:
231-
# '
232-
return :recoverable_error
233-
when /unexpected end-of-input/
234-
# "syntax error, unexpected end-of-input, expecting keyword_end"
235-
#
236-
# example:
237-
# if true
238-
# hoge
239-
# if false
240-
# fuga
241-
# end
242-
return :recoverable_error
243222
when /unexpected keyword_end/
244223
# "syntax error, unexpected keyword_end"
245224
#
@@ -262,6 +241,27 @@ def check_code_syntax(code, local_variables:)
262241
# example:
263242
# method / f /
264243
return :unrecoverable_error
244+
when /unterminated (?:string|regexp) meets end of file/
245+
# "unterminated regexp meets end of file"
246+
#
247+
# example:
248+
# /
249+
#
250+
# "unterminated string meets end of file"
251+
#
252+
# example:
253+
# '
254+
return :recoverable_error
255+
when /unexpected end-of-input/
256+
# "syntax error, unexpected end-of-input, expecting keyword_end"
257+
#
258+
# example:
259+
# if true
260+
# hoge
261+
# if false
262+
# fuga
263+
# end
264+
return :recoverable_error
265265
else
266266
return :other_error
267267
end

0 commit comments

Comments
 (0)