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.
This commit is contained in:
ridiculousfish 2014-03-28 17:09:08 -07:00
parent 74b28f0a86
commit 7248b2213d
4 changed files with 12 additions and 4 deletions

View file

@ -1331,7 +1331,6 @@ const highlighter_t::color_array_t & highlighter_t::highlight()
case symbol_if_clause: case symbol_if_clause:
case symbol_else_clause: case symbol_else_clause:
case symbol_case_item: case symbol_case_item:
case symbol_switch_statement:
case symbol_boolean_statement: case symbol_boolean_statement:
case symbol_decorated_statement: case symbol_decorated_statement:
case symbol_if_statement: case symbol_if_statement:
@ -1340,6 +1339,15 @@ const highlighter_t::color_array_t & highlighter_t::highlight()
} }
break; 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: case symbol_for_header:
{ {
// Color the 'for' and 'in' as commands // Color the 'for' and 'in' as commands

View file

@ -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; parse_execution_result_t result = parse_execution_success;
/* Get the switch variable */ /* 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); const wcstring switch_value = get_source(switch_value_node);
/* Expand it. We need to offset any errors by the position of the string */ /* Expand it. We need to offset any errors by the position of the string */

View file

@ -237,7 +237,7 @@ RESOLVE(else_continuation)
PRODUCTIONS(switch_statement) = 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) RESOLVE_ONLY(switch_statement)

View file

@ -220,7 +220,7 @@ bool parse_tree_from_string(const wcstring &str, parse_tree_flags_t flags, parse
else_continuation = if_clause else_clause | else_continuation = if_clause else_clause |
<TOK_END> job_list <TOK_END> job_list
switch_statement = SWITCH <TOK_STRING> <TOK_END> case_item_list end_command arguments_or_redirections_list switch_statement = SWITCH argument <TOK_END> case_item_list end_command arguments_or_redirections_list
case_item_list = <empty> | case_item_list = <empty> |
case_item case_item_list | case_item case_item_list |
<TOK_END> case_item_list <TOK_END> case_item_list