From 48717e57466f4705c27dc13d24080cd3fa7dc4e8 Mon Sep 17 00:00:00 2001 From: Marc Worrell Date: Wed, 25 Mar 2026 22:15:34 +0100 Subject: [PATCH] Fix an issue where in translit tokens the line count was not incremented --- src/template_compiler_scanner.erl | 8 ++++++++ test/template_compiler_quote_SUITE.erl | 14 ++++++++++++++ test/template_compiler_trans_SUITE.erl | 7 +++++++ 3 files changed, 29 insertions(+) diff --git a/src/template_compiler_scanner.erl b/src/template_compiler_scanner.erl index 37e5f59..f425c51 100644 --- a/src/template_compiler_scanner.erl +++ b/src/template_compiler_scanner.erl @@ -220,6 +220,14 @@ scan(<<"_}-->", T/binary>>, Scanned, {SourceRef, Row, Column}, {in_trans, <<"_}- scan(<<"_}", T/binary>>, Scanned, {SourceRef, Row, Column}, {in_trans, <<"_}">>}) -> scan(T, [{close_trans, {SourceRef, Row, Column}, <<"_}">>} | Scanned], {SourceRef, Row, Column + 2}, in_text); +scan(<<"\r\n", T/binary>>, Scanned, {SourceRef, Row, _Column}, {in_trans, Closer}) -> + Scanned1 = append_char(Scanned, $\r), + Scanned2 = append_char(Scanned1, $\n), + scan(T, Scanned2, {SourceRef, Row + 1, 1}, {in_trans, Closer}); + +scan(<<"\n", T/binary>>, Scanned, {SourceRef, Row, _Column}, {in_trans, Closer}) -> + scan(T, append_char(Scanned, $\n), {SourceRef, Row + 1, 1}, {in_trans, Closer}); + scan(<<"">>}); diff --git a/test/template_compiler_quote_SUITE.erl b/test/template_compiler_quote_SUITE.erl index 3cbbd65..3fb34b9 100644 --- a/test/template_compiler_quote_SUITE.erl +++ b/test/template_compiler_quote_SUITE.erl @@ -24,6 +24,8 @@ groups() -> ,back_quote_test ,back_quote_slash_test ,multiline_string_token_position_test + ,multiline_trans_literal_token_position_test + ,multiline_comment_token_position_test ]}]. init_per_suite(Config) -> @@ -76,6 +78,18 @@ multiline_string_token_position_test(_Config) -> {identifier, {undefined, 2, 6}, <<"x">>} = lists:nth(4, Tokens), ok. +multiline_trans_literal_token_position_test(_Config) -> + Template = <<"{% print _\"foo\nbar\" x %}">>, + {ok, Tokens} = template_compiler_scanner:scan(Template), + {identifier, {undefined, 2, 6}, <<"x">>} = lists:nth(4, Tokens), + ok. + +multiline_comment_token_position_test(_Config) -> + Template = <<"{# foo\n#}{% print x %}">>, + {ok, Tokens} = template_compiler_scanner:scan(Template), + {identifier, {undefined, 2, 12}, <<"x">>} = lists:nth(3, Tokens), + ok. + test_data_dir(Config) -> filename:join([ filename:dirname(filename:dirname(?config(data_dir, Config))), diff --git a/test/template_compiler_trans_SUITE.erl b/test/template_compiler_trans_SUITE.erl index 37b82d9..671c273 100644 --- a/test/template_compiler_trans_SUITE.erl +++ b/test/template_compiler_trans_SUITE.erl @@ -20,6 +20,7 @@ groups() -> [trans_test ,trans_escape_test ,trans_string_test + ,multiline_trans_text_token_position_test ]}]. init_per_suite(Config) -> @@ -54,6 +55,12 @@ trans_string_test(_Config) -> <<"Hello">> = iolist_to_binary(Bin1), ok. +multiline_trans_text_token_position_test(_Config) -> + Template = <<"{_ foo\nbar _}{% print x %}">>, + {ok, Tokens} = template_compiler_scanner:scan(Template), + {identifier, {undefined, 2, 16}, <<"x">>} = lists:nth(6, Tokens), + ok. + test_data_dir(Config) -> filename:join([ filename:dirname(filename:dirname(?config(data_dir, Config))),