mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 05:28:49 +00:00
Expand the variable name as an ordinary parameter in for loops. Added
test for it too.
This commit is contained in:
parent
a57077aba3
commit
bc43409624
5 changed files with 23 additions and 14 deletions
|
@ -1333,19 +1333,9 @@ const highlighter_t::color_array_t & highlighter_t::highlight()
|
|||
this->color_node(*literal_for_node, highlight_spec_command);
|
||||
this->color_node(*literal_in_node, highlight_spec_command);
|
||||
|
||||
// Color the variable name appropriately
|
||||
// We don't expand this during execution, so just look for invalid chars
|
||||
// Color the variable name as a parameter
|
||||
const parse_node_t *var_name_node = this->parse_tree.get_child(node, 1, parse_token_type_string);
|
||||
if (var_name_node->has_source())
|
||||
{
|
||||
size_t source_end = var_name_node->source_start + var_name_node->source_length;
|
||||
for (size_t i = var_name_node->source_start; i < source_end; i++)
|
||||
{
|
||||
wchar_t wc = buff.at(i);
|
||||
highlight_spec_t color = wcsvarchr(wc) ? highlight_spec_param : highlight_spec_error;
|
||||
color_array.at(i) = color;
|
||||
}
|
||||
}
|
||||
this->color_argument(*var_name_node);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -157,6 +157,9 @@ typedef unsigned int parser_test_error_bits_t;
|
|||
/** Error message when encountering an illegal command name */
|
||||
#define ILLEGAL_CMD_ERR_MSG _( L"Illegal command name '%ls'")
|
||||
|
||||
/** Error message when encountering a failed expansion, e.g. for the variable name in for loops */
|
||||
#define FAILED_EXPANSION_VARIABLE_NAME_ERR_MSG _( L"Unable to expand variable name '%ls'")
|
||||
|
||||
/** Error message when encountering an illegal file descriptor */
|
||||
#define ILLEGAL_FD_ERR_MSG _( L"Illegal file descriptor in redirection '%ls'")
|
||||
|
||||
|
|
|
@ -436,9 +436,14 @@ parse_execution_result_t parse_execution_context_t::run_for_statement(const pars
|
|||
assert(header.type == symbol_for_header);
|
||||
assert(block_contents.type == symbol_job_list);
|
||||
|
||||
/* Get the variable name: `for var_name in ...` */
|
||||
/* Get the variable name: `for var_name in ...`. We expand the variable name. It better result in just one. */
|
||||
const parse_node_t &var_name_node = *get_child(header, 1, parse_token_type_string);
|
||||
const wcstring for_var_name = get_source(var_name_node);
|
||||
wcstring for_var_name = get_source(var_name_node);
|
||||
if (! expand_one(for_var_name, 0))
|
||||
{
|
||||
report_error(var_name_node, FAILED_EXPANSION_VARIABLE_NAME_ERR_MSG, for_var_name.c_str());
|
||||
return parse_execution_errored;
|
||||
}
|
||||
|
||||
/* Get the contents to iterate over. */
|
||||
const parse_node_t *unmatched_wildcard = NULL;
|
||||
|
|
|
@ -70,4 +70,13 @@ end
|
|||
# Test implicit cd. This should do nothing.
|
||||
./
|
||||
|
||||
# Test special for loop expansion
|
||||
# Here we the name of the variable is derived from another variable
|
||||
echo "Testing for loop"
|
||||
set var1 var2
|
||||
for $var1 in 1 2 3
|
||||
echo -n $var2
|
||||
end
|
||||
echo
|
||||
|
||||
false
|
||||
|
|
|
@ -8,3 +8,5 @@ Foop
|
|||
Foop
|
||||
Foop
|
||||
Doop
|
||||
Testing for loop
|
||||
123
|
||||
|
|
Loading…
Reference in a new issue