Small command parsing refactoring

This commit is contained in:
Maxime Coste 2016-12-07 13:26:11 +00:00
parent d9679db9b6
commit 2f704eab16

View File

@ -431,7 +431,7 @@ void CommandManager::execute(StringView command_line,
DisplayCoord command_coord; DisplayCoord command_coord;
Vector<String> params; Vector<String> params;
for (auto it = tokens.begin(); it != tokens.end(); ++it) for (auto it = tokens.begin(); it != tokens.end(); )
{ {
if (params.empty()) if (params.empty())
command_coord = it->coord(); command_coord = it->coord();
@ -444,22 +444,20 @@ void CommandManager::execute(StringView command_line,
// Shell expand are retokenized // Shell expand are retokenized
else if (it->type() == Token::Type::ShellExpand) else if (it->type() == Token::Type::ShellExpand)
{ {
auto shell_tokens = parse<true>(expand_token(*it, context, auto new_tokens = parse<true>(expand_token(*it, context,
shell_context)); shell_context));
it = tokens.erase(it); it = tokens.insert(tokens.erase(it),
for (Token& token : shell_tokens) std::make_move_iterator(new_tokens.begin()),
it = ++tokens.emplace(it, std::move(token)); std::make_move_iterator(new_tokens.end()));
continue; // skip incrementing, we already point to next token
if (tokens.empty())
break;
it -= shell_tokens.size() + 1;
} }
else if (it->type() == Token::Type::ArgExpand and it->content() == '@') else if (it->type() == Token::Type::ArgExpand and it->content() == '@')
std::copy(shell_context.params.begin(), shell_context.params.end(), params.insert(params.end(), shell_context.params.begin(),
std::back_inserter(params)); shell_context.params.end());
else else
params.push_back(expand_token(*it, context, shell_context)); params.push_back(expand_token(*it, context, shell_context));
++it;
} }
execute_single_command(params, context, shell_context, command_coord); execute_single_command(params, context, shell_context, command_coord);
} }