diff --git a/spec/compiler/parser/parser_spec.cr b/spec/compiler/parser/parser_spec.cr index b6f3676b1a46..7837819c97fe 100644 --- a/spec/compiler/parser/parser_spec.cr +++ b/spec/compiler/parser/parser_spec.cr @@ -1598,6 +1598,9 @@ describe "Parser" do assert_syntax_error %(case x; when /x/; 2; when /x/; end), "duplicate when /x/ in case" assert_syntax_error %(case x; when X; 2; when X; end), "duplicate when X in case" + assert_syntax_error "%w(", "Unterminated String array literal" + assert_syntax_error "%i(", "Unterminated Symbol array literal" + it "gets corrects of ~" do node = Parser.parse("\n ~1") loc = node.location.not_nil! diff --git a/src/compiler/crystal/syntax/lexer.cr b/src/compiler/crystal/syntax/lexer.cr index cec64ed9c3ea..42d11d0ec8f3 100644 --- a/src/compiler/crystal/syntax/lexer.cr +++ b/src/compiler/crystal/syntax/lexer.cr @@ -2438,6 +2438,11 @@ module Crystal next_char end + if start == current_pos + @token.type = :EOF + return @token + end + @token.type = :STRING @token.value = string_range(start) set_token_raw_from_start(start) diff --git a/src/compiler/crystal/syntax/parser.cr b/src/compiler/crystal/syntax/parser.cr index b0fb71f64672..ce436ff52e03 100644 --- a/src/compiler/crystal/syntax/parser.cr +++ b/src/compiler/crystal/syntax/parser.cr @@ -2049,8 +2049,8 @@ module Crystal when :STRING_ARRAY_END next_token break - when :EOF - raise "Unterminated symbol array literal" + else + raise "Unterminated #{elements_type} array literal" end end