Rename eval(_token)? to expand(_token)? and use a const Context

This commit is contained in:
Maxime Coste 2015-04-30 09:33:08 +01:00
parent 4e89cbfe83
commit d3607bc773

View File

@ -262,13 +262,13 @@ TokenList parse(StringView line)
return result; return result;
} }
String eval_token(const Token& token, Context& context, String expand_token(const Token& token, const Context& context,
ConstArrayView<String> shell_params, ConstArrayView<String> shell_params,
const EnvVarMap& env_vars); const EnvVarMap& env_vars);
String eval(StringView str, Context& context, String expand(StringView str, const Context& context,
ConstArrayView<String> shell_params, ConstArrayView<String> shell_params,
const EnvVarMap& env_vars) const EnvVarMap& env_vars)
{ {
String res; String res;
auto pos = 0_byte; auto pos = 0_byte;
@ -286,7 +286,7 @@ String eval(StringView str, Context& context,
else if (str[pos] == '%') else if (str[pos] == '%')
{ {
Token token = parse_percent_token<true>(str, pos); Token token = parse_percent_token<true>(str, pos);
res += eval_token(token, context, shell_params, env_vars); res += expand_token(token, context, shell_params, env_vars);
++pos; ++pos;
} }
else else
@ -295,9 +295,9 @@ String eval(StringView str, Context& context,
return res; return res;
} }
String eval_token(const Token& token, Context& context, String expand_token(const Token& token, const Context& context,
ConstArrayView<String> shell_params, ConstArrayView<String> shell_params,
const EnvVarMap& env_vars) const EnvVarMap& env_vars)
{ {
auto& content = token.content(); auto& content = token.content();
switch (token.type()) switch (token.type())
@ -317,7 +317,7 @@ String eval_token(const Token& token, Context& context,
return ShellManager::instance().get_val(content, context); return ShellManager::instance().get_val(content, context);
} }
case Token::Type::RawEval: case Token::Type::RawEval:
return eval(content, context, shell_params, env_vars); return expand(content, context, shell_params, env_vars);
case Token::Type::Raw: case Token::Type::Raw:
return content; return content;
default: kak_assert(false); default: kak_assert(false);
@ -410,9 +410,9 @@ 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>(eval_token(*it, context, auto shell_tokens = parse<true>(expand_token(*it, context,
shell_params, shell_params,
env_vars)); env_vars));
it = tokens.erase(it); it = tokens.erase(it);
for (auto& token : shell_tokens) for (auto& token : shell_tokens)
it = ++tokens.insert(it, std::move(token)); it = ++tokens.insert(it, std::move(token));
@ -423,8 +423,8 @@ void CommandManager::execute(StringView command_line,
it -= shell_tokens.size() + 1; it -= shell_tokens.size() + 1;
} }
else else
params.push_back(eval_token(*it, context, shell_params, params.push_back(expand_token(*it, context, shell_params,
env_vars)); env_vars));
} }
execute_single_command(params, context, command_coord); execute_single_command(params, context, command_coord);
} }