aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-01-03 17:42:25 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-01-03 17:42:25 -0800
commitbf75731bbe479ced1a1afd3ec088c51fafbb4c12 (patch)
tree51bfe0c4c8f605b9b2e3caf68d41624bdd29c206
parentc8eec109b2621c71ea23bbdf8c3334aeec4aed88 (diff)
Fix for wrong syntax highlighting in the face of tokenizer errors, e.g.
"echo 'hi"
-rw-r--r--fish_tests.cpp9
-rw-r--r--parse_tree.cpp5
2 files changed, 12 insertions, 2 deletions
diff --git a/fish_tests.cpp b/fish_tests.cpp
index 6a52f120..0ce1092a 100644
--- a/fish_tests.cpp
+++ b/fish_tests.cpp
@@ -2638,8 +2638,15 @@ static void test_highlighting(void)
{NULL, -1}
};
+ const highlight_component_t components10[] =
+ {
+ {L"echo", HIGHLIGHT_COMMAND},
+ {L"'single_quote", HIGHLIGHT_ERROR},
+ {NULL, -1}
+ };
+
- const highlight_component_t *tests[] = {components1, components2, components3, components4, components5, components6, components7, components8, components9};
+ const highlight_component_t *tests[] = {components1, components2, components3, components4, components5, components6, components7, components8, components9, components10};
for (size_t which = 0; which < sizeof tests / sizeof *tests; which++)
{
const highlight_component_t *components = tests[which];
diff --git a/parse_tree.cpp b/parse_tree.cpp
index 75ecc0da..d3953ca2 100644
--- a/parse_tree.cpp
+++ b/parse_tree.cpp
@@ -1109,8 +1109,11 @@ bool parse_t::parse_internal(const wcstring &str, parse_tree_flags_t parse_flags
{
if (parse_flags & parse_flag_continue_after_error)
{
+ /* Hack hack hack. Typically the parse error is due to the first token. However, if it's a tokenizer error, then has_fatal_error was set due to the check above; in that case the second token is what matters. */
+ size_t error_token_idx = (queue[1].type == parse_special_type_tokenizer_error ? 1 : 0);
+
/* Mark a special error token, and then keep going */
- const parse_token_t token = {parse_special_type_parse_error, parse_keyword_none, false, queue[0].source_start, queue[0].source_length};
+ const parse_token_t token = {parse_special_type_parse_error, parse_keyword_none, false, queue[error_token_idx].source_start, queue[error_token_idx].source_length};
this->parser->accept_tokens(token, kInvalidToken);
this->parser->reset_symbols();
}