From 0424b2223b5b1c21b6e234c665dabd0adf0d3b58 Mon Sep 17 00:00:00 2001 From: r00ster91 <35064754+r00ster91@users.noreply.github.com> Date: Thu, 29 Mar 2018 16:17:20 +0200 Subject: [PATCH] Fix HEREDOC error message grammar (#5887) * Fix HEREDOC error message grammar * Update parser_spec.cr --- spec/compiler/parser/parser_spec.cr | 12 ++++++------ src/compiler/crystal/syntax/parser.cr | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/compiler/parser/parser_spec.cr b/spec/compiler/parser/parser_spec.cr index 5cbb98306058..c7032ee5f943 100644 --- a/spec/compiler/parser/parser_spec.cr +++ b/spec/compiler/parser/parser_spec.cr @@ -1202,12 +1202,12 @@ describe "Parser" do it_parses "<<-HERE1; <<-HERE2\nHERE1\nHERE2", ["".string_interpolation, "".string_interpolation] of ASTNode it_parses "<<-HERE1; <<-HERE2\nhere1\nHERE1\nHERE2", ["here1".string_interpolation, "".string_interpolation] of ASTNode it_parses "<<-HERE1; <<-HERE2\nHERE1\nhere2\nHERE2", ["".string_interpolation, "here2".string_interpolation] of ASTNode - assert_syntax_error "<<-HERE\n One\nwrong\n Zero\n HERE", "heredoc line must have an indent greater or equal than 2", 3, 1 - assert_syntax_error "<<-HERE\n One\n wrong\n Zero\n HERE", "heredoc line must have an indent greater or equal than 2", 3, 1 - assert_syntax_error "<<-HERE\n One\n \#{1}\n Zero\n HERE", "heredoc line must have an indent greater or equal than 2", 3, 1 - assert_syntax_error "<<-HERE\n One\n \#{1}\n wrong\n HERE", "heredoc line must have an indent greater or equal than 2", 4, 1 - assert_syntax_error "<<-HERE\n One\n \#{1}\n wrong\#{1}\n HERE", "heredoc line must have an indent greater or equal than 2", 4, 1 - assert_syntax_error "<<-HERE\n One\n \#{1}\n HERE", "heredoc line must have an indent greater or equal than 2", 2, 1 + assert_syntax_error "<<-HERE\n One\nwrong\n Zero\n HERE", "heredoc line must have an indent greater than or equal to 2", 3, 1 + assert_syntax_error "<<-HERE\n One\n wrong\n Zero\n HERE", "heredoc line must have an indent greater than or equal to 2", 3, 1 + assert_syntax_error "<<-HERE\n One\n \#{1}\n Zero\n HERE", "heredoc line must have an indent greater than or equal to 2", 3, 1 + assert_syntax_error "<<-HERE\n One\n \#{1}\n wrong\n HERE", "heredoc line must have an indent greater than or equal to 2", 4, 1 + assert_syntax_error "<<-HERE\n One\n \#{1}\n wrong\#{1}\n HERE", "heredoc line must have an indent greater than or equal to 2", 4, 1 + assert_syntax_error "<<-HERE\n One\n \#{1}\n HERE", "heredoc line must have an indent greater than or equal to 2", 2, 1 assert_syntax_error %("\#{<<-HERE}"\nHERE), "heredoc cannot be used inside interpolation" assert_syntax_error %("foo" "bar") diff --git a/src/compiler/crystal/syntax/parser.cr b/src/compiler/crystal/syntax/parser.cr index 720b78568e49..50d61537a0f8 100644 --- a/src/compiler/crystal/syntax/parser.cr +++ b/src/compiler/crystal/syntax/parser.cr @@ -2022,7 +2022,7 @@ module Crystal if remove_indent line = current_line.to_s if (line.size < indent) || !line.each_char.first(indent).all?(&.ascii_whitespace?) - raise "heredoc line must have an indent greater or equal than #{indent}", line_number, 1 + raise "heredoc line must have an indent greater than or equal to #{indent}", line_number, 1 else line = line[indent..-1] end @@ -2071,7 +2071,7 @@ module Crystal line[indent..-1] end else - raise "heredoc line must have an indent greater or equal than #{indent}", line_number, 1 + raise "heredoc line must have an indent greater than or equal to #{indent}", line_number, 1 end end