mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-14 05:53:59 +00:00
Rename expand_error_t to expand_result_t and make it class enum
Also lowercase it all.
This commit is contained in:
parent
b54c44f2f6
commit
dcaac58f45
8 changed files with 95 additions and 92 deletions
|
@ -665,11 +665,11 @@ void completer_t::complete_cmd(const wcstring &str_cmd, bool use_function, bool
|
||||||
|
|
||||||
if (use_command) {
|
if (use_command) {
|
||||||
// Append all possible executables
|
// Append all possible executables
|
||||||
expand_error_t result = expand_string(str_cmd, &this->completions,
|
expand_result_t result = expand_string(str_cmd, &this->completions,
|
||||||
EXPAND_SPECIAL_FOR_COMMAND | EXPAND_FOR_COMPLETIONS |
|
EXPAND_SPECIAL_FOR_COMMAND | EXPAND_FOR_COMPLETIONS |
|
||||||
EXECUTABLES_ONLY | this->expand_flags(),
|
EXECUTABLES_ONLY | this->expand_flags(),
|
||||||
vars, NULL);
|
vars, NULL);
|
||||||
if (result != EXPAND_ERROR && this->wants_descriptions()) {
|
if (result != expand_result_t::error && this->wants_descriptions()) {
|
||||||
this->complete_cmd_desc(str_cmd);
|
this->complete_cmd_desc(str_cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -677,7 +677,7 @@ void completer_t::complete_cmd(const wcstring &str_cmd, bool use_function, bool
|
||||||
if (use_implicit_cd) {
|
if (use_implicit_cd) {
|
||||||
// We don't really care if this succeeds or fails. If it succeeds this->completions will be
|
// We don't really care if this succeeds or fails. If it succeeds this->completions will be
|
||||||
// updated with choices for the user.
|
// updated with choices for the user.
|
||||||
expand_error_t ignore =
|
expand_result_t ignore =
|
||||||
// Append all matching directories
|
// Append all matching directories
|
||||||
expand_string(str_cmd, &this->completions,
|
expand_string(str_cmd, &this->completions,
|
||||||
EXPAND_FOR_COMPLETIONS | DIRECTORIES_ONLY | this->expand_flags(), vars,
|
EXPAND_FOR_COMPLETIONS | DIRECTORIES_ONLY | this->expand_flags(), vars,
|
||||||
|
@ -1092,7 +1092,8 @@ void completer_t::complete_param_expand(const wcstring &str, bool do_file,
|
||||||
// See #4954.
|
// See #4954.
|
||||||
const wcstring sep_string = wcstring(str, sep_index + 1);
|
const wcstring sep_string = wcstring(str, sep_index + 1);
|
||||||
std::vector<completion_t> local_completions;
|
std::vector<completion_t> local_completions;
|
||||||
if (expand_string(sep_string, &local_completions, flags, vars, NULL) == EXPAND_ERROR) {
|
if (expand_string(sep_string, &local_completions, flags, vars, NULL) ==
|
||||||
|
expand_result_t::error) {
|
||||||
debug(3, L"Error while expanding string '%ls'", sep_string.c_str());
|
debug(3, L"Error while expanding string '%ls'", sep_string.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1111,7 +1112,7 @@ void completer_t::complete_param_expand(const wcstring &str, bool do_file,
|
||||||
// consider relaxing this if there was a preceding double-dash argument.
|
// consider relaxing this if there was a preceding double-dash argument.
|
||||||
if (string_prefixes_string(L"-", str)) flags &= ~EXPAND_FUZZY_MATCH;
|
if (string_prefixes_string(L"-", str)) flags &= ~EXPAND_FUZZY_MATCH;
|
||||||
|
|
||||||
if (expand_string(str, &this->completions, flags, vars, NULL) == EXPAND_ERROR) {
|
if (expand_string(str, &this->completions, flags, vars, NULL) == expand_result_t::error) {
|
||||||
debug(3, L"Error while expanding string '%ls'", str.c_str());
|
debug(3, L"Error while expanding string '%ls'", str.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
104
src/expand.cpp
104
src/expand.cpp
|
@ -470,8 +470,8 @@ static bool expand_variables(wcstring instr, std::vector<completion_t> *out, siz
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Perform brace expansion.
|
/// Perform brace expansion.
|
||||||
static expand_error_t expand_braces(const wcstring &instr, expand_flags_t flags,
|
static expand_result_t expand_braces(const wcstring &instr, expand_flags_t flags,
|
||||||
std::vector<completion_t> *out, parse_error_list_t *errors) {
|
std::vector<completion_t> *out, parse_error_list_t *errors) {
|
||||||
bool syntax_error = false;
|
bool syntax_error = false;
|
||||||
int brace_count = 0;
|
int brace_count = 0;
|
||||||
|
|
||||||
|
@ -542,12 +542,12 @@ static expand_error_t expand_braces(const wcstring &instr, expand_flags_t flags,
|
||||||
|
|
||||||
if (syntax_error) {
|
if (syntax_error) {
|
||||||
append_syntax_error(errors, SOURCE_LOCATION_UNKNOWN, _(L"Mismatched braces"));
|
append_syntax_error(errors, SOURCE_LOCATION_UNKNOWN, _(L"Mismatched braces"));
|
||||||
return EXPAND_ERROR;
|
return expand_result_t::error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (brace_begin == NULL) {
|
if (brace_begin == NULL) {
|
||||||
append_completion(out, instr);
|
append_completion(out, instr);
|
||||||
return EXPAND_OK;
|
return expand_result_t::ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
length_preceding_braces = (brace_begin - in);
|
length_preceding_braces = (brace_begin - in);
|
||||||
|
@ -585,7 +585,7 @@ static expand_error_t expand_braces(const wcstring &instr, expand_flags_t flags,
|
||||||
brace_count--;
|
brace_count--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return EXPAND_OK;
|
return expand_result_t::ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Perform cmdsubst expansion.
|
/// Perform cmdsubst expansion.
|
||||||
|
@ -880,24 +880,24 @@ class expander_t {
|
||||||
/// An expansion stage is a member function pointer.
|
/// An expansion stage is a member function pointer.
|
||||||
/// It accepts the input string (transferring ownership) and returns the list of output
|
/// It accepts the input string (transferring ownership) and returns the list of output
|
||||||
/// completions by reference. It may return an error, which halts expansion.
|
/// completions by reference. It may return an error, which halts expansion.
|
||||||
using stage_t = expand_error_t (expander_t::*)(wcstring, std::vector<completion_t> *);
|
using stage_t = expand_result_t (expander_t::*)(wcstring, std::vector<completion_t> *);
|
||||||
|
|
||||||
expand_error_t stage_cmdsubst(wcstring input, std::vector<completion_t> *out);
|
expand_result_t stage_cmdsubst(wcstring input, std::vector<completion_t> *out);
|
||||||
expand_error_t stage_variables(wcstring input, std::vector<completion_t> *out);
|
expand_result_t stage_variables(wcstring input, std::vector<completion_t> *out);
|
||||||
expand_error_t stage_braces(wcstring input, std::vector<completion_t> *out);
|
expand_result_t stage_braces(wcstring input, std::vector<completion_t> *out);
|
||||||
expand_error_t stage_home_and_self(wcstring input, std::vector<completion_t> *out);
|
expand_result_t stage_home_and_self(wcstring input, std::vector<completion_t> *out);
|
||||||
expand_error_t stage_wildcards(wcstring path_to_expand, std::vector<completion_t> *out);
|
expand_result_t stage_wildcards(wcstring path_to_expand, std::vector<completion_t> *out);
|
||||||
|
|
||||||
expander_t(const environment_t &vars, expand_flags_t flags, parse_error_list_t *errors)
|
expander_t(const environment_t &vars, expand_flags_t flags, parse_error_list_t *errors)
|
||||||
: vars(vars), flags(flags), errors(errors) {}
|
: vars(vars), flags(flags), errors(errors) {}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static expand_error_t expand_string(wcstring input, std::vector<completion_t> *out_completions,
|
static expand_result_t expand_string(wcstring input, std::vector<completion_t> *out_completions,
|
||||||
expand_flags_t flags, const environment_t &vars,
|
expand_flags_t flags, const environment_t &vars,
|
||||||
parse_error_list_t *errors);
|
parse_error_list_t *errors);
|
||||||
};
|
};
|
||||||
|
|
||||||
expand_error_t expander_t::stage_cmdsubst(wcstring input, std::vector<completion_t> *out) {
|
expand_result_t expander_t::stage_cmdsubst(wcstring input, std::vector<completion_t> *out) {
|
||||||
if (EXPAND_SKIP_CMDSUBST & flags) {
|
if (EXPAND_SKIP_CMDSUBST & flags) {
|
||||||
size_t cur = 0, start = 0, end;
|
size_t cur = 0, start = 0, end;
|
||||||
switch (parse_util_locate_cmdsubst_range(input, &cur, nullptr, &start, &end, true)) {
|
switch (parse_util_locate_cmdsubst_range(input, &cur, nullptr, &start, &end, true)) {
|
||||||
|
@ -908,17 +908,17 @@ expand_error_t expander_t::stage_cmdsubst(wcstring input, std::vector<completion
|
||||||
append_cmdsub_error(errors, start, L"Command substitutions not allowed");
|
append_cmdsub_error(errors, start, L"Command substitutions not allowed");
|
||||||
case -1:
|
case -1:
|
||||||
default:
|
default:
|
||||||
return EXPAND_ERROR;
|
return expand_result_t::error;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bool cmdsubst_ok = expand_cmdsubst(std::move(input), out, errors);
|
bool cmdsubst_ok = expand_cmdsubst(std::move(input), out, errors);
|
||||||
if (!cmdsubst_ok) return EXPAND_ERROR;
|
if (!cmdsubst_ok) return expand_result_t::error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXPAND_OK;
|
return expand_result_t::ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
expand_error_t expander_t::stage_variables(wcstring input, std::vector<completion_t> *out) {
|
expand_result_t expander_t::stage_variables(wcstring input, std::vector<completion_t> *out) {
|
||||||
// We accept incomplete strings here, since complete uses expand_string to expand incomplete
|
// We accept incomplete strings here, since complete uses expand_string to expand incomplete
|
||||||
// strings from the commandline.
|
// strings from the commandline.
|
||||||
wcstring next;
|
wcstring next;
|
||||||
|
@ -934,29 +934,29 @@ expand_error_t expander_t::stage_variables(wcstring input, std::vector<completio
|
||||||
} else {
|
} else {
|
||||||
size_t size = next.size();
|
size_t size = next.size();
|
||||||
if (!expand_variables(std::move(next), out, size, vars, errors)) {
|
if (!expand_variables(std::move(next), out, size, vars, errors)) {
|
||||||
return EXPAND_ERROR;
|
return expand_result_t::error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return EXPAND_OK;
|
return expand_result_t::ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
expand_error_t expander_t::stage_braces(wcstring input, std::vector<completion_t> *out) {
|
expand_result_t expander_t::stage_braces(wcstring input, std::vector<completion_t> *out) {
|
||||||
UNUSED(vars);
|
UNUSED(vars);
|
||||||
return expand_braces(input, flags, out, errors);
|
return expand_braces(input, flags, out, errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
expand_error_t expander_t::stage_home_and_self(wcstring input, std::vector<completion_t> *out) {
|
expand_result_t expander_t::stage_home_and_self(wcstring input, std::vector<completion_t> *out) {
|
||||||
if (!(EXPAND_SKIP_HOME_DIRECTORIES & flags)) {
|
if (!(EXPAND_SKIP_HOME_DIRECTORIES & flags)) {
|
||||||
expand_home_directory(input, vars);
|
expand_home_directory(input, vars);
|
||||||
}
|
}
|
||||||
expand_percent_self(input);
|
expand_percent_self(input);
|
||||||
append_completion(out, std::move(input));
|
append_completion(out, std::move(input));
|
||||||
return EXPAND_OK;
|
return expand_result_t::ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
expand_error_t expander_t::stage_wildcards(wcstring path_to_expand,
|
expand_result_t expander_t::stage_wildcards(wcstring path_to_expand,
|
||||||
std::vector<completion_t> *out) {
|
std::vector<completion_t> *out) {
|
||||||
expand_error_t result = EXPAND_OK;
|
expand_result_t result = expand_result_t::ok;
|
||||||
|
|
||||||
remove_internal_separator(&path_to_expand, flags & EXPAND_SKIP_WILDCARDS);
|
remove_internal_separator(&path_to_expand, flags & EXPAND_SKIP_WILDCARDS);
|
||||||
const bool has_wildcard = wildcard_has(path_to_expand, true /* internal, i.e. ANY_STRING */);
|
const bool has_wildcard = wildcard_has(path_to_expand, true /* internal, i.e. ANY_STRING */);
|
||||||
|
@ -1017,17 +1017,17 @@ expand_error_t expander_t::stage_wildcards(wcstring path_to_expand,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result = EXPAND_WILDCARD_NO_MATCH;
|
result = expand_result_t::wildcard_no_match;
|
||||||
std::vector<completion_t> expanded;
|
std::vector<completion_t> expanded;
|
||||||
for (size_t wd_idx = 0; wd_idx < effective_working_dirs.size(); wd_idx++) {
|
for (size_t wd_idx = 0; wd_idx < effective_working_dirs.size(); wd_idx++) {
|
||||||
int local_wc_res = wildcard_expand_string(
|
int local_wc_res = wildcard_expand_string(
|
||||||
path_to_expand, effective_working_dirs.at(wd_idx), flags, &expanded);
|
path_to_expand, effective_working_dirs.at(wd_idx), flags, &expanded);
|
||||||
if (local_wc_res > 0) {
|
if (local_wc_res > 0) {
|
||||||
// Something matched,so overall we matched.
|
// Something matched,so overall we matched.
|
||||||
result = EXPAND_WILDCARD_MATCH;
|
result = expand_result_t::wildcard_match;
|
||||||
} else if (local_wc_res < 0) {
|
} else if (local_wc_res < 0) {
|
||||||
// Cancellation
|
// Cancellation
|
||||||
result = EXPAND_ERROR;
|
result = expand_result_t::error;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1045,13 +1045,14 @@ expand_error_t expander_t::stage_wildcards(wcstring path_to_expand,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
expand_error_t expander_t::expand_string(wcstring input, std::vector<completion_t> *out_completions,
|
expand_result_t expander_t::expand_string(wcstring input,
|
||||||
expand_flags_t flags, const environment_t &vars,
|
std::vector<completion_t> *out_completions,
|
||||||
parse_error_list_t *errors) {
|
expand_flags_t flags, const environment_t &vars,
|
||||||
|
parse_error_list_t *errors) {
|
||||||
// Early out. If we're not completing, and there's no magic in the input, we're done.
|
// Early out. If we're not completing, and there's no magic in the input, we're done.
|
||||||
if (!(flags & EXPAND_FOR_COMPLETIONS) && expand_is_clean(input)) {
|
if (!(flags & EXPAND_FOR_COMPLETIONS) && expand_is_clean(input)) {
|
||||||
append_completion(out_completions, std::move(input));
|
append_completion(out_completions, std::move(input));
|
||||||
return EXPAND_OK;
|
return expand_result_t::ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
expander_t expand(vars, flags, errors);
|
expander_t expand(vars, flags, errors);
|
||||||
|
@ -1065,18 +1066,18 @@ expand_error_t expander_t::expand_string(wcstring input, std::vector<completion_
|
||||||
std::vector<completion_t> completions, output_storage;
|
std::vector<completion_t> completions, output_storage;
|
||||||
append_completion(&completions, input);
|
append_completion(&completions, input);
|
||||||
|
|
||||||
expand_error_t total_result = EXPAND_OK;
|
expand_result_t total_result = expand_result_t::ok;
|
||||||
for (stage_t stage : stages) {
|
for (stage_t stage : stages) {
|
||||||
for (completion_t &comp : completions) {
|
for (completion_t &comp : completions) {
|
||||||
expand_error_t this_result =
|
expand_result_t this_result =
|
||||||
(expand.*stage)(std::move(comp.completion), &output_storage);
|
(expand.*stage)(std::move(comp.completion), &output_storage);
|
||||||
// If this_result was no match, but total_result is that we have a match, then don't
|
// If this_result was no match, but total_result is that we have a match, then don't
|
||||||
// change it.
|
// change it.
|
||||||
if (!(this_result == EXPAND_WILDCARD_NO_MATCH &&
|
if (!(this_result == expand_result_t::wildcard_no_match &&
|
||||||
total_result == EXPAND_WILDCARD_MATCH)) {
|
total_result == expand_result_t::wildcard_match)) {
|
||||||
total_result = this_result;
|
total_result = this_result;
|
||||||
}
|
}
|
||||||
if (total_result == EXPAND_ERROR) {
|
if (total_result == expand_result_t::error) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1084,12 +1085,12 @@ expand_error_t expander_t::expand_string(wcstring input, std::vector<completion_
|
||||||
// Output becomes our next stage's input.
|
// Output becomes our next stage's input.
|
||||||
completions.swap(output_storage);
|
completions.swap(output_storage);
|
||||||
output_storage.clear();
|
output_storage.clear();
|
||||||
if (total_result == EXPAND_ERROR) {
|
if (total_result == expand_result_t::error) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (total_result != EXPAND_ERROR) {
|
if (total_result != expand_result_t::error) {
|
||||||
// Hack to un-expand tildes (see #647).
|
// Hack to un-expand tildes (see #647).
|
||||||
if (!(flags & EXPAND_SKIP_HOME_DIRECTORIES)) {
|
if (!(flags & EXPAND_SKIP_HOME_DIRECTORIES)) {
|
||||||
unexpand_tildes(input, vars, &completions);
|
unexpand_tildes(input, vars, &completions);
|
||||||
|
@ -1102,9 +1103,9 @@ expand_error_t expander_t::expand_string(wcstring input, std::vector<completion_
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
expand_error_t expand_string(wcstring input, std::vector<completion_t> *out_completions,
|
expand_result_t expand_string(wcstring input, std::vector<completion_t> *out_completions,
|
||||||
expand_flags_t flags, const environment_t &vars,
|
expand_flags_t flags, const environment_t &vars,
|
||||||
parse_error_list_t *errors) {
|
parse_error_list_t *errors) {
|
||||||
return expander_t::expand_string(std::move(input), out_completions, flags, vars, errors);
|
return expander_t::expand_string(std::move(input), out_completions, flags, vars, errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1116,7 +1117,8 @@ bool expand_one(wcstring &string, expand_flags_t flags, const environment_t &var
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expand_string(string, &completions, flags | EXPAND_NO_DESCRIPTIONS, vars, errors) &&
|
if (expand_string(string, &completions, flags | EXPAND_NO_DESCRIPTIONS, vars, errors) !=
|
||||||
|
expand_result_t::error &&
|
||||||
completions.size() == 1) {
|
completions.size() == 1) {
|
||||||
string = std::move(completions.at(0).completion);
|
string = std::move(completions.at(0).completion);
|
||||||
return true;
|
return true;
|
||||||
|
@ -1124,21 +1126,21 @@ bool expand_one(wcstring &string, expand_flags_t flags, const environment_t &var
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
expand_error_t expand_to_command_and_args(const wcstring &instr, const environment_t &vars,
|
expand_result_t expand_to_command_and_args(const wcstring &instr, const environment_t &vars,
|
||||||
wcstring *out_cmd, wcstring_list_t *out_args,
|
wcstring *out_cmd, wcstring_list_t *out_args,
|
||||||
parse_error_list_t *errors) {
|
parse_error_list_t *errors) {
|
||||||
// Fast path.
|
// Fast path.
|
||||||
if (expand_is_clean(instr)) {
|
if (expand_is_clean(instr)) {
|
||||||
|
|
||||||
*out_cmd = instr;
|
*out_cmd = instr;
|
||||||
return EXPAND_OK;
|
return expand_result_t::ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<completion_t> completions;
|
std::vector<completion_t> completions;
|
||||||
expand_error_t expand_err = expand_string(
|
expand_result_t expand_err = expand_string(
|
||||||
instr, &completions, EXPAND_SKIP_CMDSUBST | EXPAND_NO_DESCRIPTIONS | EXPAND_SKIP_JOBS, vars,
|
instr, &completions, EXPAND_SKIP_CMDSUBST | EXPAND_NO_DESCRIPTIONS | EXPAND_SKIP_JOBS, vars,
|
||||||
errors);
|
errors);
|
||||||
if (expand_err == EXPAND_OK || expand_err == EXPAND_WILDCARD_MATCH) {
|
if (expand_err == expand_result_t::ok || expand_err == expand_result_t::wildcard_match) {
|
||||||
// The first completion is the command, any remaning are arguments.
|
// The first completion is the command, any remaning are arguments.
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto &comp : completions) {
|
for (auto &comp : completions) {
|
||||||
|
|
26
src/expand.h
26
src/expand.h
|
@ -89,15 +89,15 @@ enum {
|
||||||
};
|
};
|
||||||
|
|
||||||
/// These are the possible return values for expand_string. Note how zero value is the only error.
|
/// These are the possible return values for expand_string. Note how zero value is the only error.
|
||||||
enum expand_error_t {
|
enum class expand_result_t {
|
||||||
/// Error
|
/// Error
|
||||||
EXPAND_ERROR,
|
error,
|
||||||
/// Ok
|
/// Ok
|
||||||
EXPAND_OK,
|
ok,
|
||||||
/// Ok, a wildcard in the string matched no files.
|
/// Ok, a wildcard in the string matched no files.
|
||||||
EXPAND_WILDCARD_NO_MATCH,
|
wildcard_no_match,
|
||||||
/// Ok, a wildcard in the string matched a file.
|
/// Ok, a wildcard in the string matched a file.
|
||||||
EXPAND_WILDCARD_MATCH
|
wildcard_match,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The string represented by PROCESS_EXPAND_SELF
|
/// The string represented by PROCESS_EXPAND_SELF
|
||||||
|
@ -118,12 +118,12 @@ enum expand_error_t {
|
||||||
/// \param vars variables used during expansion.
|
/// \param vars variables used during expansion.
|
||||||
/// \param errors Resulting errors, or NULL to ignore
|
/// \param errors Resulting errors, or NULL to ignore
|
||||||
///
|
///
|
||||||
/// \return One of EXPAND_OK, EXPAND_ERROR, EXPAND_WILDCARD_MATCH and EXPAND_WILDCARD_NO_MATCH.
|
/// \return An expand_result_t.
|
||||||
/// EXPAND_WILDCARD_NO_MATCH and EXPAND_WILDCARD_MATCH are normal exit conditions used only on
|
/// wildcard_no_match and wildcard_match are normal exit conditions used only on
|
||||||
/// strings containing wildcards to tell if the wildcard produced any matches.
|
/// strings containing wildcards to tell if the wildcard produced any matches.
|
||||||
__warn_unused expand_error_t expand_string(wcstring input, std::vector<completion_t> *output,
|
__warn_unused expand_result_t expand_string(wcstring input, std::vector<completion_t> *output,
|
||||||
expand_flags_t flags, const environment_t &vars,
|
expand_flags_t flags, const environment_t &vars,
|
||||||
parse_error_list_t *errors);
|
parse_error_list_t *errors);
|
||||||
|
|
||||||
/// expand_one is identical to expand_string, except it will fail if in expands to more than one
|
/// expand_one is identical to expand_string, except it will fail if in expands to more than one
|
||||||
/// string. This is used for expanding command names.
|
/// string. This is used for expanding command names.
|
||||||
|
@ -143,9 +143,9 @@ bool expand_one(wcstring &inout_str, expand_flags_t flags, const environment_t &
|
||||||
/// that API does not distinguish between expansion resulting in an empty command (''), and
|
/// that API does not distinguish between expansion resulting in an empty command (''), and
|
||||||
/// expansion resulting in no command (e.g. unset variable).
|
/// expansion resulting in no command (e.g. unset variable).
|
||||||
// \return an expand error.
|
// \return an expand error.
|
||||||
expand_error_t expand_to_command_and_args(const wcstring &instr, const environment_t &vars,
|
expand_result_t expand_to_command_and_args(const wcstring &instr, const environment_t &vars,
|
||||||
wcstring *out_cmd, wcstring_list_t *out_args,
|
wcstring *out_cmd, wcstring_list_t *out_args,
|
||||||
parse_error_list_t *errors = NULL);
|
parse_error_list_t *errors = NULL);
|
||||||
|
|
||||||
/// Convert the variable value to a human readable form, i.e. escape things, handle arrays, etc.
|
/// Convert the variable value to a human readable form, i.e. escape things, handle arrays, etc.
|
||||||
/// Suitable for pretty-printing.
|
/// Suitable for pretty-printing.
|
||||||
|
|
|
@ -1592,7 +1592,7 @@ static bool expand_test(const wchar_t *in, expand_flags_t flags, ...) {
|
||||||
wchar_t *arg;
|
wchar_t *arg;
|
||||||
parse_error_list_t errors;
|
parse_error_list_t errors;
|
||||||
|
|
||||||
if (expand_string(in, &output, flags, pwd_environment_t{}, &errors) == EXPAND_ERROR) {
|
if (expand_string(in, &output, flags, pwd_environment_t{}, &errors) == expand_result_t::error) {
|
||||||
if (errors.empty()) {
|
if (errors.empty()) {
|
||||||
err(L"Bug: Parse error reported but no error text found.");
|
err(L"Bug: Parse error reported but no error text found.");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -344,8 +344,8 @@ static bool plain_statement_get_expanded_command(const wcstring &src,
|
||||||
// Get the command. Try expanding it. If we cannot, it's an error.
|
// Get the command. Try expanding it. If we cannot, it's an error.
|
||||||
maybe_t<wcstring> cmd = command_for_plain_statement(stmt, src);
|
maybe_t<wcstring> cmd = command_for_plain_statement(stmt, src);
|
||||||
if (!cmd) return false;
|
if (!cmd) return false;
|
||||||
expand_error_t err = expand_to_command_and_args(*cmd, vars, out_cmd, nullptr);
|
expand_result_t err = expand_to_command_and_args(*cmd, vars, out_cmd, nullptr);
|
||||||
return err == EXPAND_OK || err == EXPAND_WILDCARD_MATCH;
|
return err == expand_result_t::ok || err == expand_result_t::wildcard_match;
|
||||||
}
|
}
|
||||||
|
|
||||||
rgb_color_t highlight_get_color(const highlight_spec_t &highlight, bool is_background) {
|
rgb_color_t highlight_get_color(const highlight_spec_t &highlight, bool is_background) {
|
||||||
|
|
|
@ -449,21 +449,21 @@ parse_execution_result_t parse_execution_context_t::run_switch_statement(
|
||||||
// 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.
|
||||||
std::vector<completion_t> switch_values_expanded;
|
std::vector<completion_t> switch_values_expanded;
|
||||||
parse_error_list_t errors;
|
parse_error_list_t errors;
|
||||||
int expand_ret = expand_string(switch_value, &switch_values_expanded, EXPAND_NO_DESCRIPTIONS,
|
auto expand_ret = expand_string(switch_value, &switch_values_expanded, EXPAND_NO_DESCRIPTIONS,
|
||||||
parser->vars(), &errors);
|
parser->vars(), &errors);
|
||||||
parse_error_offset_source_start(&errors, switch_value_n.source_range()->start);
|
parse_error_offset_source_start(&errors, switch_value_n.source_range()->start);
|
||||||
|
|
||||||
switch (expand_ret) {
|
switch (expand_ret) {
|
||||||
case EXPAND_ERROR: {
|
case expand_result_t::error: {
|
||||||
result = report_errors(errors);
|
result = report_errors(errors);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case EXPAND_WILDCARD_NO_MATCH: {
|
case expand_result_t::wildcard_no_match: {
|
||||||
result = report_unmatched_wildcard_error(switch_value_n);
|
result = report_unmatched_wildcard_error(switch_value_n);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case EXPAND_WILDCARD_MATCH:
|
case expand_result_t::wildcard_match:
|
||||||
case EXPAND_OK: {
|
case expand_result_t::ok: {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
@ -746,15 +746,15 @@ parse_execution_result_t parse_execution_context_t::expand_command(
|
||||||
wcstring unexp_cmd = *command_for_plain_statement(statement, pstree->src);
|
wcstring unexp_cmd = *command_for_plain_statement(statement, pstree->src);
|
||||||
|
|
||||||
// Expand the string to produce completions, and report errors.
|
// Expand the string to produce completions, and report errors.
|
||||||
expand_error_t expand_err =
|
expand_result_t expand_err =
|
||||||
expand_to_command_and_args(unexp_cmd, parser->vars(), out_cmd, out_args, &errors);
|
expand_to_command_and_args(unexp_cmd, parser->vars(), out_cmd, out_args, &errors);
|
||||||
if (expand_err == EXPAND_ERROR) {
|
if (expand_err == expand_result_t::error) {
|
||||||
proc_set_last_statuses(statuses_t::just(STATUS_ILLEGAL_CMD));
|
proc_set_last_statuses(statuses_t::just(STATUS_ILLEGAL_CMD));
|
||||||
return report_errors(errors);
|
return report_errors(errors);
|
||||||
} else if (expand_err == EXPAND_WILDCARD_NO_MATCH) {
|
} else if (expand_err == expand_result_t::wildcard_no_match) {
|
||||||
return report_unmatched_wildcard_error(statement);
|
return report_unmatched_wildcard_error(statement);
|
||||||
}
|
}
|
||||||
assert(expand_err == EXPAND_OK || expand_err == EXPAND_WILDCARD_MATCH);
|
assert(expand_err == expand_result_t::ok || expand_err == expand_result_t::wildcard_match);
|
||||||
|
|
||||||
// Complain if the resulting expansion was empty, or expanded to an empty string.
|
// Complain if the resulting expansion was empty, or expanded to an empty string.
|
||||||
if (out_cmd->empty()) {
|
if (out_cmd->empty()) {
|
||||||
|
@ -906,15 +906,15 @@ parse_execution_result_t parse_execution_context_t::expand_arguments_from_nodes(
|
||||||
// Expand this string.
|
// Expand this string.
|
||||||
parse_error_list_t errors;
|
parse_error_list_t errors;
|
||||||
arg_expanded.clear();
|
arg_expanded.clear();
|
||||||
int expand_ret =
|
auto expand_ret =
|
||||||
expand_string(arg_str, &arg_expanded, EXPAND_NO_DESCRIPTIONS, parser->vars(), &errors);
|
expand_string(arg_str, &arg_expanded, EXPAND_NO_DESCRIPTIONS, parser->vars(), &errors);
|
||||||
parse_error_offset_source_start(&errors, arg_node.source_range()->start);
|
parse_error_offset_source_start(&errors, arg_node.source_range()->start);
|
||||||
switch (expand_ret) {
|
switch (expand_ret) {
|
||||||
case EXPAND_ERROR: {
|
case expand_result_t::error: {
|
||||||
this->report_errors(errors);
|
this->report_errors(errors);
|
||||||
return parse_execution_errored;
|
return parse_execution_errored;
|
||||||
}
|
}
|
||||||
case EXPAND_WILDCARD_NO_MATCH: {
|
case expand_result_t::wildcard_no_match: {
|
||||||
if (glob_behavior == failglob) {
|
if (glob_behavior == failglob) {
|
||||||
// Report the unmatched wildcard error and stop processing.
|
// Report the unmatched wildcard error and stop processing.
|
||||||
report_unmatched_wildcard_error(arg_node);
|
report_unmatched_wildcard_error(arg_node);
|
||||||
|
@ -922,8 +922,8 @@ parse_execution_result_t parse_execution_context_t::expand_arguments_from_nodes(
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case EXPAND_WILDCARD_MATCH:
|
case expand_result_t::wildcard_match:
|
||||||
case EXPAND_OK: {
|
case expand_result_t::ok: {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
|
|
@ -1134,7 +1134,7 @@ static bool detect_errors_in_plain_statement(const wcstring &buff_src,
|
||||||
wcstring command;
|
wcstring command;
|
||||||
// Check that we can expand the command.
|
// Check that we can expand the command.
|
||||||
if (expand_to_command_and_args(*unexp_command, null_environment_t{}, &command, nullptr,
|
if (expand_to_command_and_args(*unexp_command, null_environment_t{}, &command, nullptr,
|
||||||
parse_errors) == EXPAND_ERROR) {
|
parse_errors) == expand_result_t::error) {
|
||||||
errored = true;
|
errored = true;
|
||||||
parse_error_offset_source_start(parse_errors, source_start);
|
parse_error_offset_source_start(parse_errors, source_start);
|
||||||
}
|
}
|
||||||
|
|
|
@ -332,7 +332,7 @@ void parser_t::expand_argument_list(const wcstring &arg_list_src, expand_flags_t
|
||||||
while (auto arg = arg_list.next_in_list<grammar::argument>()) {
|
while (auto arg = arg_list.next_in_list<grammar::argument>()) {
|
||||||
const wcstring arg_src = arg.get_source(arg_list_src);
|
const wcstring arg_src = arg.get_source(arg_list_src);
|
||||||
if (expand_string(arg_src, output_arg_list, eflags, vars, NULL /* errors */) ==
|
if (expand_string(arg_src, output_arg_list, eflags, vars, NULL /* errors */) ==
|
||||||
EXPAND_ERROR) {
|
expand_result_t::error) {
|
||||||
break; // failed to expand a string
|
break; // failed to expand a string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue