Skip to content

Commit a2ffec2

Browse files
committed
Fix Ruby 2.5 and 2.6 error detection
Apparently depending on the sub version of Ruby 2.6 and the specific syntax, the error may or may not include the comma. Ruby 2.5 has different cases for `Unexpected end` and `unexpected end`.
1 parent ace9eab commit a2ffec2

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

lib/dead_end/who_dis_syntax_error.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,20 @@ def on_parse_error(msg)
4545
@error = msg
4646
@unmatched_symbol = :unknown
4747

48-
if @error.match?(/unexpected end-of-input/)
48+
case @error
49+
when /unexpected end-of-input/
4950
@error_symbol = :missing_end
50-
elsif @error.match?(/expecting end-of-input/)
51+
when /expecting end-of-input/
5152
@error_symbol = :unmatched_syntax
5253
@unmatched_symbol = :end
53-
elsif @error.match?(/unexpected `end'/) || # Ruby 2.7 & 3.0
54-
@error.match?(/unexpected end,/) || # Ruby 2.6
55-
@error.match?(/unexpected keyword_end/) # Ruby 2.5
56-
57-
@error_symbol = :unmatched_syntax
54+
when /unexpected `end'/, # Ruby 2.7 and 3.0
55+
/unexpected end/, # Ruby 2.6
56+
/unexpected keyword_end/i # Ruby 2.5
5857

5958
match = @error.match(/expecting '(?<unmatched_symbol>.*)'/)
6059
@unmatched_symbol = match[:unmatched_symbol].to_sym if match
60+
61+
@error_symbol = :unmatched_syntax
6162
else
6263
@error_symbol = :unknown
6364
end

0 commit comments

Comments
 (0)