diff --git a/config/syntax.toml b/config/syntax.toml index dcd77273f..fbf8548bc 100644 --- a/config/syntax.toml +++ b/config/syntax.toml @@ -12,7 +12,7 @@ atom_patterns = [ ] string_patterns = [ # Double-quoted strings - '"((\\")|[^"])*"', + '"((\\.)|[^"])*"', # Single quoted strings "'((\\\\')|[^'])*'", # Backtick strings @@ -57,7 +57,7 @@ atom_patterns = [ ] string_patterns = [ # Double-quoted strings - '"((\\")|[^"])*"', + '"((\\.)|[^"])*"', # Single quoted strings "'((\\\\')|[^'])*'", ] @@ -80,7 +80,7 @@ atom_patterns = [ ] string_patterns = [ # Double-quoted strings - '"((\\")|[^"])*"', + '"((\\.)|[^"])*"', ] comment_patterns = [ ';.*', @@ -123,7 +123,7 @@ atom_patterns = [ ] string_patterns = [ # Double-quoted strings - '"((\\")|[^"])*"', + '"((\\.)|[^"])*"', ] comment_patterns = [ # Mult-line comments @@ -146,7 +146,7 @@ atom_patterns = [ ] string_patterns = [ # Double-quoted strings - '"((\\")|[^"])*"', + '"((\\.)|[^"])*"', ] comment_patterns = [ ';.*', @@ -176,7 +176,7 @@ atom_patterns = [ ] string_patterns = [ # Double-quoted strings - '"((\\")|[^"])*"', + '"((\\.)|[^"])*"', ] comment_patterns = [ # Single line comments diff --git a/src/parse.rs b/src/parse.rs index 81453cb31..23cd1eb4c 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -470,6 +470,71 @@ mod tests { ); } + #[test] + fn test_parse_string_escaped_doublequote() { + let arena = Arena::new(); + + assert_syntaxes( + // "\"" + &parse(&arena, "\"\\\"\"", &lang()), + &[Syntax::new_atom( + &arena, + vec![SingleLineSpan { + line: 0.into(), + start_col: 0, + end_col: 4, + }], + "\"\\\"\"", + )], + ); + } + + #[test] + fn test_parse_string_escaped_backlash() { + let arena = Arena::new(); + + assert_syntaxes( + // "\\" + &parse(&arena, "\"\\\\\"", &lang()), + &[Syntax::new_atom( + &arena, + vec![SingleLineSpan { + line: 0.into(), + start_col: 0, + end_col: 4, + }], + "\"\\\\\"", + )], + ); + } + + #[test] + fn test_parse_string_escaped_backlash_and_second_string() { + let arena = Arena::new(); + + assert_syntaxes( + // "\\" "a" + &parse(&arena, "\"\\\\\" \"a\"", &lang()), + &[Syntax::new_atom( + &arena, + vec![SingleLineSpan { + line: 0.into(), + start_col: 0, + end_col: 4, + }], + "\"\\\\\"", + ), Syntax::new_atom( + &arena, + vec![SingleLineSpan { + line: 0.into(), + start_col: 5, + end_col: 8, + }], + "\"a\"", + )], + ); + } + #[test] fn test_parse_multiple() { let arena = Arena::new();