diff options
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 26 |
1 files changed, 10 insertions, 16 deletions
@@ -220,29 +220,23 @@ int match_bracket(TxtLoc l, TxtLoc *out, u32 c) { u32 o = bracket_opp(c); if (txt_chr(l) != c) return 0; int dir = bracket_dir(c); + if (!dir) return 0; int in_str = 0, in_chr = 0; while (depth > 0) { if (dir < 0 && at_start(l)) break; if (dir > 0 && at_end(l)) break; l = dir < 0 ? cprev(l) : cnext(l); u32 x = txt_chr(l); - if (dir > 0 && x == '\\') { - l = cnext(l); - continue; - } else if (dir < 0 && txt_chr(cprev(l)) == '\\') { - l = cprev(l); - continue; + int bs = (txt_chr(cprev(l)) == '\\') && (txt_chr(cprev(cprev(l))) != '\\'); + if (in_chr) { + if (!bs && x == '\'') in_chr = 0; + } else if (in_str) { + if (!bs && x == '"') in_str = 0; } else { - if (in_chr) { - if (x == '\'') in_chr = 0; - } else if (in_str) { - if (x == '"') in_str = 0; - } else { - if (x == '\'') in_chr = 1; - else if (x == '"') in_str = 1; - else if (x == c) depth++; - else if (x == o) depth--; - } + if (x == '\'') in_chr = 1; + else if (x == '"') in_str = 1; + else if (x == c) depth++; + else if (x == o) depth--; } } if (depth == 0) { |
