Only show mismatch hints for fn+do/end

This commit is contained in:
José Valim
2018-06-21 14:08:30 +02:00
parent 4ee414e835
commit 22245a44fe
2 changed files with 21 additions and 9 deletions
+8 -5
View File
@@ -1105,7 +1105,11 @@ handle_terminator(Token, #elixir_tokenizer{terminators=Terminators} = Scope) ->
end.
check_terminator({Start, {Line, _, _}}, Terminators, Scope)
when Start == 'fn'; Start == 'do'; Start == '('; Start == '['; Start == '{'; Start == '<<' ->
when Start == '('; Start == '['; Start == '{'; Start == '<<' ->
Indentation = Scope#elixir_tokenizer.indentation,
Scope#elixir_tokenizer{terminators=[{Start, Line, Indentation} | Terminators]};
check_terminator({Start, {Line, _, _}}, Terminators, Scope) when Start == 'fn'; Start == 'do' ->
Indentation = Scope#elixir_tokenizer.indentation,
NewScope =
@@ -1156,8 +1160,8 @@ check_terminator({'end', {Line, Column, _}}, [], #elixir_tokenizer{mismatch_hint
Suffix =
case lists:keyfind('end', 1, Hints) of
{'end', HintLine, _Identation} ->
io_lib:format("\n\n HINT: we found what looks like a mismatched \"end\",\n"
" you may have forgotten to define a \"do\" somewhere above line ~B\n", [HintLine]);
io_lib:format("\n\n HINT: it looks like the \"end\" on line ~B "
"does not have a matching \"do\" defined before it\n", [HintLine]);
false ->
""
end,
@@ -1174,8 +1178,7 @@ check_terminator(_, _, Scope) ->
missing_terminator_hint(Start, End, #elixir_tokenizer{mismatch_hints=Hints}) ->
case lists:keyfind(Start, 1, Hints) of
{Start, HintLine, _} ->
io_lib:format("\n\n HINT: we found what looks like a non-terminated \"~ts\" on line ~B,\n"
" you may have forgotten to define a \"~ts\" somewhere below it\n",
io_lib:format("\n\n HINT: it looks like the \"~ts\" on line ~B does not have a matching \"~ts\"\n",
[Start, HintLine, End]);
false ->
""
+13 -4
View File
@@ -180,7 +180,16 @@ defmodule Kernel.ErrorsTest do
assert_eval_raise SyntaxError, "nofile:1: unexpected token: end", '1 end'
assert_eval_raise SyntaxError,
~r"you may have forgotten to define a \"do\" somewhere above line 3",
~r" HINT: it looks like the \"end\" on line 2 does not have a matching \"do\" defined before it",
'''
defmodule MyApp do
def one end
def two do end
end
'''
assert_eval_raise SyntaxError,
~r" HINT: it looks like the \"end\" on line 3 does not have a matching \"do\" defined before it",
'''
defmodule MyApp do
def one
@@ -192,7 +201,7 @@ defmodule Kernel.ErrorsTest do
'''
assert_eval_raise SyntaxError,
~r"you may have forgotten to define a \"do\" somewhere above line 6",
~r" HINT: it looks like the \"end\" on line 6 does not have a matching \"do\" defined before it",
'''
defmodule MyApp do
def one do
@@ -210,7 +219,7 @@ defmodule Kernel.ErrorsTest do
'foo do 1'
assert_eval_raise TokenMissingError,
~r"we found what looks like a non-terminated \"do\" on line 2",
~r"HINT: it looks like the \"do\" on line 2 does not have a matching \"end\"",
'''
defmodule MyApp do
def one do
@@ -222,7 +231,7 @@ defmodule Kernel.ErrorsTest do
'''
assert_eval_raise SyntaxError,
~r"we found what looks like a non-terminated \"do\" on line 3",
~r"HINT: it looks like the \"do\" on line 3 does not have a matching \"end\"",
'''
defmodule MyApp do
(