From 7248b2213d53b34747b89594f563e1c32dd9a835 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Fri, 28 Mar 2014 17:09:08 -0700 Subject: [PATCH] Fix switch statement syntax highlighting so that the arguemnt to switch is colored as a parameter, not a command. Promote this from a tok_string to a symbol_argument in the grammar too. --- highlight.cpp | 10 +++++++++- parse_execution.cpp | 2 +- parse_productions.cpp | 2 +- parse_tree.h | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/highlight.cpp b/highlight.cpp index d03a60873..eeda753ea 100644 --- a/highlight.cpp +++ b/highlight.cpp @@ -1331,7 +1331,6 @@ const highlighter_t::color_array_t & highlighter_t::highlight() case symbol_if_clause: case symbol_else_clause: case symbol_case_item: - case symbol_switch_statement: case symbol_boolean_statement: case symbol_decorated_statement: case symbol_if_statement: @@ -1340,6 +1339,15 @@ const highlighter_t::color_array_t & highlighter_t::highlight() } break; + case symbol_switch_statement: + { + const parse_node_t *literal_switch = this->parse_tree.get_child(node, 0, parse_token_type_string); + const parse_node_t *switch_arg = this->parse_tree.get_child(node, 1, symbol_argument); + this->color_node(*literal_switch, highlight_spec_command); + this->color_node(*switch_arg, highlight_spec_param); + } + break; + case symbol_for_header: { // Color the 'for' and 'in' as commands diff --git a/parse_execution.cpp b/parse_execution.cpp index 46df733ce..1da9858fe 100644 --- a/parse_execution.cpp +++ b/parse_execution.cpp @@ -509,7 +509,7 @@ parse_execution_result_t parse_execution_context_t::run_switch_statement(const p parse_execution_result_t result = parse_execution_success; /* Get the switch variable */ - const parse_node_t &switch_value_node = *get_child(statement, 1, parse_token_type_string); + const parse_node_t &switch_value_node = *get_child(statement, 1, symbol_argument); const wcstring switch_value = get_source(switch_value_node); /* Expand it. We need to offset any errors by the position of the string */ diff --git a/parse_productions.cpp b/parse_productions.cpp index 0fd754354..221316b38 100644 --- a/parse_productions.cpp +++ b/parse_productions.cpp @@ -237,7 +237,7 @@ RESOLVE(else_continuation) PRODUCTIONS(switch_statement) = { - { KEYWORD(parse_keyword_switch), parse_token_type_string, parse_token_type_end, symbol_case_item_list, symbol_end_command, symbol_arguments_or_redirections_list} + { KEYWORD(parse_keyword_switch), symbol_argument, parse_token_type_end, symbol_case_item_list, symbol_end_command, symbol_arguments_or_redirections_list} }; RESOLVE_ONLY(switch_statement) diff --git a/parse_tree.h b/parse_tree.h index c0e24a5ca..0e1a0b2fa 100644 --- a/parse_tree.h +++ b/parse_tree.h @@ -220,7 +220,7 @@ bool parse_tree_from_string(const wcstring &str, parse_tree_flags_t flags, parse else_continuation = if_clause else_clause | job_list - switch_statement = SWITCH case_item_list end_command arguments_or_redirections_list + switch_statement = SWITCH argument case_item_list end_command arguments_or_redirections_list case_item_list = | case_item case_item_list | case_item_list