@@ -43,8 +43,13 @@ fn parse_escaped_char(input: &str) -> IResult<&str, char> {
4343 ) ( input)
4444}
4545
46- fn parse_literal ( input : & str ) -> IResult < & str , & str > {
47- let not_quote_slash = is_not ( "\' \" \\ " ) ;
46+ fn parse_literal ( sep : char , input : & str ) -> IResult < & str , & str > {
47+ let not_quote_slash = if sep == '\'' {
48+ is_not ( "\' \\ " )
49+ } else {
50+ is_not ( "\" \\ " )
51+ } ;
52+
4853 verify ( not_quote_slash, |s : & str | !s. is_empty ( ) ) ( input)
4954}
5055
@@ -65,17 +70,24 @@ impl StringFragment {
6570 }
6671}
6772
68- fn parse_fragment ( input : & str ) -> IResult < & str , StringFragment > {
73+ fn parse_fragment ( sep : char , input : & str ) -> IResult < & str , StringFragment > {
6974 alt ( (
70- map ( parse_literal, |x| StringFragment :: Literal ( x. len ( ) ) ) ,
75+ map (
76+ |x| parse_literal ( sep, x) ,
77+ |x| StringFragment :: Literal ( x. len ( ) ) ,
78+ ) ,
7179 map ( parse_escaped_char, |_| StringFragment :: EscapedChar ) ,
7280 value ( StringFragment :: EscapedWS , preceded ( char ( '\\' ) , multispace1) ) ,
7381 ) ) ( input)
7482}
7583
7684pub fn parse_string_literal ( sep : char ) -> impl for < ' a > Fn ( & ' a str ) -> IResult < & ' a str , & ' a str > {
7785 move |input| {
78- let build_string = fold_many0 ( parse_fragment, || 2 , |len, frag| frag. len ( ) + len) ;
86+ let build_string = fold_many0 (
87+ |x| parse_fragment ( sep, x) ,
88+ || 2 ,
89+ |len, frag| frag. len ( ) + len,
90+ ) ;
7991 let offset = delimited ( char ( sep) , build_string, char ( sep) ) ;
8092 map ( offset, |x| & input[ ..x] ) ( input)
8193 }
0 commit comments