Skip to content

Commit

Permalink
Merge branch 'fix/loop-tag-newline'
Browse files Browse the repository at this point in the history
  • Loading branch information
soranoba committed May 19, 2015
2 parents 476004d + d0962b8 commit 13b4c7d
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 19 deletions.
2 changes: 0 additions & 2 deletions ct/mustache_SUITE_data/delimiter.result
@@ -1,5 +1,3 @@
* tag1

* tag2

* tag3
1 change: 0 additions & 1 deletion ct/mustache_SUITE_data/false_values.result
@@ -1,2 +1 @@
Shown.

2 changes: 0 additions & 2 deletions ct/mustache_SUITE_data/invarted.result
@@ -1,3 +1 @@


No repos :(
2 changes: 1 addition & 1 deletion ct/mustache_SUITE_data/lambdas.result
@@ -1 +1 @@
<b>Willy is awesome.</b>
<b>Willy is awesome.</b>
4 changes: 0 additions & 4 deletions ct/mustache_SUITE_data/non-empty.result
@@ -1,7 +1,3 @@

<b>resque</b>

<b>hub</b>

<b>rip</b>

2 changes: 0 additions & 2 deletions ct/mustache_SUITE_data/non-false.result
@@ -1,3 +1 @@

Hi Jon!

1 change: 0 additions & 1 deletion ct/mustache_SUITE_data/partial.result
@@ -1,4 +1,3 @@
<h2>Names</h2>
<strong>alice</strong>
<strong>bob</strong>

23 changes: 17 additions & 6 deletions src/mustache.erl
Expand Up @@ -184,6 +184,17 @@ parse1(#state{start = Start, stop = Stop} = State, Bin, Result) ->
[B1, B2] -> parse3(State, binary:split(B2, Stop), [B1 | Result])
end.

%% @doc Part of the `parse/1'
%%
%% ATTENTION: The result is a list that is inverted.
-spec parse4(state(), Input :: binary(), Result :: [tag()]) -> {state(), [tag()]} | endtag().
parse4(State, <<"\r\n", Rest/binary>>, Result) ->
parse1(State, Rest, Result);
parse4(State, <<"\n", Rest/binary>>, Result) ->
parse1(State, Rest, Result);
parse4(State, Input, Result) ->
parse1(State, Input, Result).

%% @doc Part of the `parse/1'
%%
%% 2nd Argument: [TagBinary(may exist unnecessary spaces to the end), RestBinary]
Expand Down Expand Up @@ -229,12 +240,12 @@ parse3(_, _, _) ->
%% `{{# Tag}}' or `{{^ Tag}}' corresponds to this.
-spec parse_loop(state(), '#' | '^', Tag :: binary(), Input :: binary(), Result :: [tag()]) -> [tag()] | endtag().
parse_loop(State0, Mark, Tag, Input, Result0) ->
case parse1(State0, Input, []) of
case parse4(State0, Input, []) of
{endtag, {State, Tag, LastTagSize, Rest, Result1}} ->
case Mark of
'#' -> Source = binary:part(Input, 0, byte_size(Input) - byte_size(Rest) - LastTagSize),
parse1(State, Rest, [{'#', Tag, lists:reverse(Result1), Source} | Result0]);
'^' -> parse1(State, Rest, [{'^', Tag, lists:reverse(Result1)} | Result0])
parse4(State, Rest, [{'#', Tag, lists:reverse(Result1), Source} | Result0]);
'^' -> parse4(State, Rest, [{'^', Tag, lists:reverse(Result1)} | Result0])
end;
{endtag, {_, OtherTag, _, _, _}} ->
error({?PARSE_ERROR, {section_is_incorrect, OtherTag}});
Expand All @@ -249,9 +260,9 @@ parse_jump(#state{dirname = Dirname} = State0, Tag, NextBin, Result0) ->
Filename = ?COND(Dirname =:= <<>>, Filename0, filename:join([Dirname, Filename0])),
case file:read_file(Filename) of
{ok, Bin} ->
case parse1(State0, Bin, Result0) of
case parse4(State0, Bin, Result0) of
{endtag, {_, Tag, _, _, _}} -> error({?PARSE_ERROR, {section_begin_tag_not_found, <<"#", Tag/binary>>}});
{State, Result} -> parse1(State, NextBin, Result)
{State, Result} -> parse4(State, NextBin, Result)
end;
_ ->
error(?FILE_ERROR, [Filename])
Expand All @@ -265,7 +276,7 @@ parse_delimiter(State0, ParseDelimiterBin, NextBin, Result) ->
case binary:match(ParseDelimiterBin, <<"=">>) of
nomatch ->
case [X || X <- binary:split(ParseDelimiterBin, <<" ">>, [global]), X =/= <<>>] of
[Start, Stop] -> parse1(State0#state{start = Start, stop = Stop}, NextBin, Result);
[Start, Stop] -> parse4(State0#state{start = Start, stop = Stop}, NextBin, Result);
_ -> error({?PARSE_ERROR, delimiters_may_not_contain_whitespaces})
end;
_ ->
Expand Down

0 comments on commit 13b4c7d

Please sign in to comment.