From ba759a98b093715fc680122aca93e2154736333b Mon Sep 17 00:00:00 2001 From: Mikl Kurkov Date: Fri, 19 Jun 2015 20:52:21 +0300 Subject: [PATCH] Fix charclass parser to ignore whitespace and quote backslash --- priv/neotoma_parse.peg | 5 +++-- src/neotoma_parse.erl | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/priv/neotoma_parse.peg b/priv/neotoma_parse.peg index 49d9fda..87f66b5 100644 --- a/priv/neotoma_parse.peg +++ b/priv/neotoma_parse.peg @@ -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]), "]\">>)"] `; @@ -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:('\\`' / '$`' / !'`' .)+ '`') / diff --git a/src/neotoma_parse.erl b/src/neotoma_parse.erl index 1bffaf8..e1a4111 100644 --- a/src/neotoma_parse.erl +++ b/src/neotoma_parse.erl @@ -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). @@ -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) ->