diff options
author | 2014-08-20 22:55:24 -0700 | |
---|---|---|
committer | 2014-08-20 22:55:24 -0700 | |
commit | 9a90e041f38e0b2497b999d1678377986d3d49f4 (patch) | |
tree | 2e322d71859158d5623107faba1133b7e14f8d24 /highlight.cpp | |
parent | b0be15d4f7eb47f9d7543ab1c8bb4a830f56aa4c (diff) |
Color `"$foo[1"` as an error
We can't color the whole argument as an error, since the tokenizer is
responsible for that and doesn't care abou this case, but we can color
the `$foo[` bit as an error.
Diffstat (limited to 'highlight.cpp')
-rw-r--r-- | highlight.cpp | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/highlight.cpp b/highlight.cpp index 9d43f8e0..5369f3a5 100644 --- a/highlight.cpp +++ b/highlight.cpp @@ -617,12 +617,26 @@ static size_t color_variable(const wchar_t *in, size_t in_len, std::vector<highl if (in[idx] == L'[') { wchar_t *slice_begin = NULL, *slice_end = NULL; - if (1 == parse_util_locate_slice(in, &slice_begin, &slice_end, false)) + switch (parse_util_locate_slice(in, &slice_begin, &slice_end, false)) { - size_t slice_begin_idx = slice_begin - in, slice_end_idx = slice_end - in; - assert(slice_end_idx > slice_begin_idx); - colors[slice_begin_idx] = highlight_spec_operator; - colors[slice_end_idx] = highlight_spec_operator; + case 1: + { + size_t slice_begin_idx = slice_begin - in, slice_end_idx = slice_end - in; + assert(slice_end_idx > slice_begin_idx); + colors[slice_begin_idx] = highlight_spec_operator; + colors[slice_end_idx] = highlight_spec_operator; + break; + } + case -1: + { + // syntax error + // Normally the entire token is colored red for us, but inside a double-quoted string + // that doesn't happen. As such, color the variable + the slice start red. Coloring any + // more than that looks bad, unless we're willing to try and detect where the double-quoted + // string ends, and I'd rather not do that. + std::fill(colors, colors + idx + 1, (highlight_spec_t)highlight_spec_error); + break; + } } } return idx; |