Skip to content

Commit

Permalink
Fix charclass parser to ignore whitespace and quote backslash
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurkov committed Jun 23, 2015
1 parent 6ac6007 commit 6a98c09
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions priv/neotoma_parse.peg
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,9 @@ single_quoted_string <- "'" string:(!"'" ("\\\\" / "\\'" / .))* "'" ~;
character_class <- '[' characters:(!']' ('\\\\' . / !'\\\\' .))+ ']'
`
used_combinator(p_charclass),
Data = re:replace(proplists:get_value(characters, Node), "\\s", "", [{return, binary}, global]),
["p_charclass(<<\"[",
escape_string(unicode:characters_to_list(proplists:get_value(characters, Node))),
re:replace(Data, "\"|\\\\", "\\\\&", [{return, binary}, global]),
"]\">>)"]
`;

Expand All @@ -189,7 +190,7 @@ space <- (white / comment_to_eol)+ ~;

comment_to_eol <- !'%{' '%' (!"\n" .)* ~;

white <- [ \t\n\r] ~;
white <- [ \s \t \n \r ] ~;

code_block <- ( '%{' code:('\\%' / '$%' / !'%}' .)+ '%}' ) /
('`' code:('\\`' / '$`' / !'`' .)+ '`') /
Expand Down
5 changes: 3 additions & 2 deletions src/neotoma_parse.erl
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,9 @@ end
'character_class'(Input, Index) ->
p(Input, Index, 'character_class', fun(I,D) -> (p_seq([p_string(<<"[">>), p_label('characters', p_one_or_more(p_seq([p_not(p_string(<<"]">>)), p_choose([p_seq([p_string(<<"\\\\">>), p_anything()]), p_seq([p_not(p_string(<<"\\\\">>)), p_anything()])])]))), p_string(<<"]">>)]))(I,D) end, fun(Node, _Idx) ->
used_combinator(p_charclass),
Data = re:replace(proplists:get_value(characters, Node), "\\s", "", [{return, binary}, global]),
["p_charclass(<<\"[",
escape_string(unicode:characters_to_list(proplists:get_value(characters, Node))),
re:replace(Data, "\"|\\\\", "\\\\&", [{return, binary}, global]),
"]\">>)"]
end).

Expand All @@ -357,7 +358,7 @@ end

-spec 'white'(input(), index()) -> parse_result().
'white'(Input, Index) ->
p(Input, Index, 'white', fun(I,D) -> (p_charclass(<<"[\s\t\n\r]">>))(I,D) end, fun(Node, _Idx) ->Node end).
p(Input, Index, 'white', fun(I,D) -> (p_charclass(<<"[\\s\\t\\n\\r]">>))(I,D) end, fun(Node, _Idx) ->Node end).

-spec 'code_block'(input(), index()) -> parse_result().
'code_block'(Input, Index) ->
Expand Down

0 comments on commit 6a98c09

Please sign in to comment.