@@ -172,13 +172,17 @@ fn optional_unquoted_string_with_spaces(i: &mut &str) -> ModalResult<Option<Comp
172172fn any_string ( i : & mut & str ) -> ModalResult < CompactString > {
173173 trace (
174174 "any_string" ,
175- alt ( ( quoted_string, unquoted_string_with_escapes) ) ,
175+ alt ( (
176+ double_quoted_string,
177+ single_quoted_string,
178+ unquoted_string_with_escapes,
179+ ) ) ,
176180 )
177181 . parse_next ( i)
178182}
179183
180- /// Quoted string value
181- fn quoted_string ( i : & mut & str ) -> ModalResult < CompactString > {
184+ /// Double quoted string value
185+ fn double_quoted_string ( i : & mut & str ) -> ModalResult < CompactString > {
182186 delimited (
183187 '"' ,
184188 escaped ( take_till ( 1 .., [ '"' , '\\' ] ) , '\\' , escapes) ,
@@ -188,6 +192,17 @@ fn quoted_string(i: &mut &str) -> ModalResult<CompactString> {
188192 . parse_next ( i)
189193}
190194
195+ /// Single string value
196+ fn single_quoted_string ( i : & mut & str ) -> ModalResult < CompactString > {
197+ delimited (
198+ '\'' ,
199+ escaped ( take_till ( 1 .., [ '\'' , '\\' ] ) , '\\' , escapes) ,
200+ '\'' ,
201+ )
202+ . map ( |s : CompactStringWrapper | s. 0 )
203+ . parse_next ( i)
204+ }
205+
191206/// Unquoted string value
192207fn unquoted_string_with_escapes ( i : & mut & str ) -> ModalResult < CompactString > {
193208 escaped ( take_till ( 1 .., [ ' ' , '\t' , '\n' , '\r' , '\\' ] ) , '\\' , escapes)
@@ -209,6 +224,7 @@ fn escapes<'input>(i: &mut &'input str) -> ModalResult<&'input str> {
209224 "t" . value ( "\t " ) ,
210225 " " . value ( " " ) ,
211226 "\" " . value ( "\" " ) ,
227+ "\' " . value ( "\' " ) ,
212228 "\\ " . value ( "\\ " ) ,
213229 ) )
214230 . parse_next ( i)
@@ -256,17 +272,36 @@ mod tests {
256272 let ( rem, out) = any_string. parse_peek ( "\" foo bar\" \n " ) . unwrap ( ) ;
257273 assert_eq ! ( rem, "\n " ) ;
258274 assert_eq ! ( out, "foo bar" . to_string( ) ) ;
275+
276+ let ( rem, out) = any_string. parse_peek ( "\' foo bar\' \n " ) . unwrap ( ) ;
277+ assert_eq ! ( rem, "\n " ) ;
278+ assert_eq ! ( out, "foo bar" . to_string( ) ) ;
259279 }
260280
261281 #[ test]
262- fn test_quoted_string ( ) {
263- let ( rem, out) = quoted_string . parse_peek ( "\" foo bar\" \n " ) . unwrap ( ) ;
282+ fn test_double_quoted_string ( ) {
283+ let ( rem, out) = double_quoted_string . parse_peek ( "\" foo bar\" \n " ) . unwrap ( ) ;
264284 assert_eq ! ( rem, "\n " ) ;
265285 assert_eq ! ( out, "foo bar" . to_string( ) ) ;
266286
267- let ( rem, out) = quoted_string. parse_peek ( "\" foo\\ \" bar\" \n " ) . unwrap ( ) ;
287+ let ( rem, out) = double_quoted_string
288+ . parse_peek ( "\" foo\\ \" bar'qux\" \n " )
289+ . unwrap ( ) ;
290+ assert_eq ! ( rem, "\n " ) ;
291+ assert_eq ! ( out, "foo\" bar'qux" . to_string( ) ) ;
292+ }
293+
294+ #[ test]
295+ fn test_single_quoted_string ( ) {
296+ let ( rem, out) = single_quoted_string. parse_peek ( "\' foo bar\' \n " ) . unwrap ( ) ;
297+ assert_eq ! ( rem, "\n " ) ;
298+ assert_eq ! ( out, "foo bar" . to_string( ) ) ;
299+
300+ let ( rem, out) = single_quoted_string
301+ . parse_peek ( "\' foo\\ \' bar\" qux\' \n " )
302+ . unwrap ( ) ;
268303 assert_eq ! ( rem, "\n " ) ;
269- assert_eq ! ( out, "foo\" bar" . to_string( ) ) ;
304+ assert_eq ! ( out, "foo\' bar\" qux " . to_string( ) ) ;
270305 }
271306
272307 #[ test]
0 commit comments