We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 93a4a0f commit 5bec091Copy full SHA for 5bec091
lib/eex/lib/eex/compiler.ex
@@ -304,7 +304,7 @@ defmodule EEx.Compiler do
304
source: source,
305
line: line,
306
quoted: [],
307
- parser_options: parser_options,
+ parser_options: [indentation: indentation] ++ parser_options,
308
indentation: indentation
309
}
310
lib/eex/test/eex_test.exs
@@ -502,6 +502,59 @@ defmodule EExTest do
502
end
503
504
505
+ test "from Elixir parser" do
506
+ line = __ENV__.line + 6
507
+
508
+ message =
509
+ assert_raise TokenMissingError, fn ->
510
+ EEx.compile_string(
511
+ """
512
+ <li>
513
+ <strong>Some:</strong>
514
+ <%= true && @some[ %>
515
+ </li>
516
+ """,
517
+ file: __ENV__.file,
518
+ line: line,
519
+ indentation: 12
520
+ )
521
+ end
522
523
+ assert message |> Exception.message() |> strip_ansi() =~ """
524
+ │
525
+ 514 │ true && @some[\s
526
+ │ │ └ missing closing delimiter (expected "]")
527
+ │ └ unclosed delimiter
528
529
530
531
+ test "from Elixir parser with line breaks" do
532
533
534
535
536
537
538
539
540
+ <%= true &&
541
+ @some[ %>
542
543
544
545
546
547
548
549
550
551
552
+ #{line + 3} │ @some[\s
553
554
555
556
557
558
test "honor line numbers" do
559
assert_raise EEx.SyntaxError,
560
"nofile:100:6: expected closing '%>' for EEx expression",
@@ -948,6 +1001,12 @@ defmodule EExTest do
948
1001
949
1002
950
1003
1004
+ @strip_ansi [IO.ANSI.green(), IO.ANSI.red(), IO.ANSI.reset()]
1005
1006
+ defp strip_ansi(doc) do
1007
+ String.replace(doc, @strip_ansi, "")
1008
1009
951
1010
defp assert_eval(expected, actual, binding \\ [], opts \\ []) do
952
1011
opts = Keyword.merge([file: __ENV__.file, engine: opts[:engine] || EEx.Engine], opts)
953
1012
result = EEx.eval_string(actual, binding, opts)
lib/elixir/src/elixir.erl
@@ -490,10 +490,14 @@ parser_location(Meta) ->
490
{ok, Forms} ->
491
Forms;
492
{error, {Meta, Error, Token}} ->
493
- elixir_errors:parse_error(Meta, File, Error, Token, {String, StartLine, StartColumn})
+ Indentation = proplists:get_value(indentation, Opts, 0),
494
+ Input = {String, StartLine, StartColumn, Indentation},
495
+ elixir_errors:parse_error(Meta, File, Error, Token, Input)
496
end;
497
498
499
500
501
end.
to_binary(List) when is_list(List) -> elixir_utils:characters_to_binary(List);
lib/elixir/src/elixir_errors.erl
@@ -446,11 +446,12 @@ cut_snippet(Location, Input) ->
446
nil
447
448
449
-cut_snippet({InputString, StartLine, StartColumn}, Line, Span) ->
+cut_snippet({InputString, StartLine, StartColumn, Indentation}, Line, Span) ->
450
%% In case the code is indented, we need to add the indentation back
451
%% for the snippets to match the reported columns.
452
- Indent = binary:copy(<<" ">>, StartColumn - 1),
453
- Lines = string:split(InputString, "\n", all),
+ Prelude = lists:duplicate(max(StartColumn - Indentation - 1, 0), " "),
+ Lines = string:split(Prelude ++ InputString, "\n", all),
454
+ Indent = binary:copy(<<" ">>, Indentation),
455
[Head | Tail] = lists:nthtail(Line - StartLine, Lines),
456
IndentedTail = indent_n(Tail, Span - 1, <<"\n", Indent/binary>>),
457
elixir_utils:characters_to_binary([Indent, Head, IndentedTail]).
lib/elixir/src/elixir_tokenizer.erl
@@ -130,9 +130,11 @@ tokenize(String, Line, Column, Opts) ->
130
Acc#elixir_tokenizer{preserve_comments=PreserveComments};
131
({unescape, Unescape}, Acc) when is_boolean(Unescape) ->
132
Acc#elixir_tokenizer{unescape=Unescape};
133
+ ({indentation, Indentation}, Acc) when Indentation >= 0 ->
134
+ Acc#elixir_tokenizer{column=Indentation+1};
135
(_, Acc) ->
136
Acc
- end, #elixir_tokenizer{identifier_tokenizer=IdentifierTokenizer, column=Column}, Opts),
137
+ end, #elixir_tokenizer{identifier_tokenizer=IdentifierTokenizer}, Opts),
138
139
tokenize(String, Line, Column, Scope, []).
140
0 commit comments