mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
Rename BRACKET to BRACE per #3802
This commit is contained in:
parent
18a9aa58cd
commit
c98ed6d07a
5 changed files with 59 additions and 58 deletions
|
@ -1353,20 +1353,20 @@ static bool unescape_string_internal(const wchar_t *const input, const size_t in
|
||||||
case L'{': {
|
case L'{': {
|
||||||
if (unescape_special) {
|
if (unescape_special) {
|
||||||
bracket_count++;
|
bracket_count++;
|
||||||
to_append_or_none = BRACKET_BEGIN;
|
to_append_or_none = BRACE_BEGIN;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case L'}': {
|
case L'}': {
|
||||||
if (unescape_special) {
|
if (unescape_special) {
|
||||||
bracket_count--;
|
bracket_count--;
|
||||||
to_append_or_none = BRACKET_END;
|
to_append_or_none = BRACE_END;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case L',': {
|
case L',': {
|
||||||
if (unescape_special && bracket_count > 0) {
|
if (unescape_special && bracket_count > 0) {
|
||||||
to_append_or_none = BRACKET_SEP;
|
to_append_or_none = BRACE_SEP;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -570,7 +570,7 @@ static void find_process(const wchar_t *proc, expand_flags_t flags,
|
||||||
static size_t parse_slice(const wchar_t *in, wchar_t **end_ptr, std::vector<long> &idx,
|
static size_t parse_slice(const wchar_t *in, wchar_t **end_ptr, std::vector<long> &idx,
|
||||||
std::vector<size_t> &source_positions, size_t array_size) {
|
std::vector<size_t> &source_positions, size_t array_size) {
|
||||||
const long size = (long)array_size;
|
const long size = (long)array_size;
|
||||||
size_t pos = 1; // skip past the opening square bracket
|
size_t pos = 1; // skip past the opening square brace
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
while (iswspace(in[pos]) || (in[pos] == INTERNAL_SEPARATOR)) pos++;
|
while (iswspace(in[pos]) || (in[pos] == INTERNAL_SEPARATOR)) pos++;
|
||||||
|
@ -846,39 +846,39 @@ static bool expand_variables(const wcstring &instr, std::vector<completion_t> *o
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Perform bracket expansion.
|
/// Perform brace expansion.
|
||||||
static expand_error_t expand_brackets(const wcstring &instr, expand_flags_t flags,
|
static expand_error_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 bracket_count = 0;
|
int brace_count = 0;
|
||||||
|
|
||||||
const wchar_t *bracket_begin = NULL, *bracket_end = NULL;
|
const wchar_t *brace_begin = NULL, *brace_end = NULL;
|
||||||
const wchar_t *last_sep = NULL;
|
const wchar_t *last_sep = NULL;
|
||||||
|
|
||||||
const wchar_t *item_begin;
|
const wchar_t *item_begin;
|
||||||
size_t length_preceding_brackets, length_following_brackets, tot_len;
|
size_t length_preceding_braces, length_following_braces, tot_len;
|
||||||
|
|
||||||
const wchar_t *const in = instr.c_str();
|
const wchar_t *const in = instr.c_str();
|
||||||
|
|
||||||
// Locate the first non-nested bracket pair.
|
// Locate the first non-nested brace pair.
|
||||||
for (const wchar_t *pos = in; (*pos) && !syntax_error; pos++) {
|
for (const wchar_t *pos = in; (*pos) && !syntax_error; pos++) {
|
||||||
switch (*pos) {
|
switch (*pos) {
|
||||||
case BRACKET_BEGIN: {
|
case BRACE_BEGIN: {
|
||||||
if (bracket_count == 0) bracket_begin = pos;
|
if (brace_count == 0) brace_begin = pos;
|
||||||
bracket_count++;
|
brace_count++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case BRACKET_END: {
|
case BRACE_END: {
|
||||||
bracket_count--;
|
brace_count--;
|
||||||
if (bracket_count < 0) {
|
if (brace_count < 0) {
|
||||||
syntax_error = true;
|
syntax_error = true;
|
||||||
} else if (bracket_count == 0) {
|
} else if (brace_count == 0) {
|
||||||
bracket_end = pos;
|
brace_end = pos;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case BRACKET_SEP: {
|
case BRACE_SEP: {
|
||||||
if (bracket_count == 1) last_sep = pos;
|
if (brace_count == 1) last_sep = pos;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
@ -887,72 +887,73 @@ static expand_error_t expand_brackets(const wcstring &instr, expand_flags_t flag
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bracket_count > 0) {
|
if (brace_count > 0) {
|
||||||
if (!(flags & EXPAND_FOR_COMPLETIONS)) {
|
if (!(flags & EXPAND_FOR_COMPLETIONS)) {
|
||||||
syntax_error = true;
|
syntax_error = true;
|
||||||
} else {
|
} else {
|
||||||
// The user hasn't typed an end bracket yet; make one up and append it, then expand
|
// The user hasn't typed an end brace yet; make one up and append it, then expand
|
||||||
// that.
|
// that.
|
||||||
wcstring mod;
|
wcstring mod;
|
||||||
if (last_sep) {
|
if (last_sep) {
|
||||||
mod.append(in, bracket_begin - in + 1);
|
mod.append(in, brace_begin - in + 1);
|
||||||
mod.append(last_sep + 1);
|
mod.append(last_sep + 1);
|
||||||
mod.push_back(BRACKET_END);
|
mod.push_back(BRACE_END);
|
||||||
} else {
|
} else {
|
||||||
mod.append(in);
|
mod.append(in);
|
||||||
mod.push_back(BRACKET_END);
|
mod.push_back(BRACE_END);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: this code looks very fishy, apparently it has never worked.
|
// Note: this code looks very fishy, apparently it has never worked.
|
||||||
return expand_brackets(mod, 1, out, errors);
|
return expand_braces(mod, 1, out, errors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expand a literal "{}" to itself because it is useless otherwise,
|
// Expand a literal "{}" to itself because it is useless otherwise,
|
||||||
// and this eases e.g. `find -exec {}`. See #1109.
|
// and this eases e.g. `find -exec {}`. See #1109.
|
||||||
if (bracket_begin + 1 == bracket_end) {
|
if (brace_begin + 1 == brace_end) {
|
||||||
wcstring newstr = instr;
|
wcstring newstr = instr;
|
||||||
newstr.at(bracket_begin - in) = L'{';
|
newstr.at(brace_begin - in) = L'{';
|
||||||
newstr.at(bracket_end - in) = L'}';
|
newstr.at(brace_end - in) = L'}';
|
||||||
return expand_brackets(newstr, flags, out, errors);
|
return expand_braces(newstr, flags, out, errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (syntax_error) {
|
if (syntax_error) {
|
||||||
append_syntax_error(errors, SOURCE_LOCATION_UNKNOWN, _(L"Mismatched brackets"));
|
append_syntax_error(errors, SOURCE_LOCATION_UNKNOWN, _(L"Mismatched braces"));
|
||||||
return EXPAND_ERROR;
|
return EXPAND_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bracket_begin == NULL) {
|
if (brace_begin == NULL) {
|
||||||
append_completion(out, instr);
|
append_completion(out, instr);
|
||||||
return EXPAND_OK;
|
return EXPAND_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
length_preceding_brackets = (bracket_begin - in);
|
length_preceding_braces = (brace_begin - in);
|
||||||
length_following_brackets = wcslen(bracket_end) - 1;
|
length_following_braces = wcslen(brace_end) - 1;
|
||||||
tot_len = length_preceding_brackets + length_following_brackets;
|
tot_len = length_preceding_braces + length_following_braces;
|
||||||
item_begin = bracket_begin + 1;
|
item_begin = brace_begin + 1;
|
||||||
for (const wchar_t *pos = (bracket_begin + 1); true; pos++) {
|
for (const wchar_t *pos = (brace_begin + 1); true; pos++) {
|
||||||
if (bracket_count == 0 && ((*pos == BRACKET_SEP) || (pos == bracket_end))) {
|
if (brace_count == 0 && ((*pos == BRACE_SEP) || (pos == brace_end))) {
|
||||||
assert(pos >= item_begin);
|
assert(pos >= item_begin);
|
||||||
size_t item_len = pos - item_begin;
|
size_t item_len = pos - item_begin;
|
||||||
|
|
||||||
wcstring whole_item;
|
wcstring whole_item;
|
||||||
whole_item.reserve(tot_len + item_len + 2);
|
whole_item.reserve(tot_len + item_len + 2);
|
||||||
whole_item.append(in, length_preceding_brackets);
|
whole_item.append(in, length_preceding_braces);
|
||||||
whole_item.append(item_begin, item_len);
|
whole_item.append(item_begin, item_len);
|
||||||
whole_item.append(bracket_end + 1);
|
whole_item.append(brace_end + 1);
|
||||||
expand_brackets(whole_item, flags, out, errors);
|
debug(0, L"Found brace item: %ls\n", whole_item.c_str());
|
||||||
|
expand_braces(whole_item, flags, out, errors);
|
||||||
|
|
||||||
item_begin = pos + 1;
|
item_begin = pos + 1;
|
||||||
if (pos == bracket_end) break;
|
if (pos == brace_end) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*pos == BRACKET_BEGIN) {
|
if (*pos == BRACE_BEGIN) {
|
||||||
bracket_count++;
|
brace_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*pos == BRACKET_END) {
|
if (*pos == BRACE_END) {
|
||||||
bracket_count--;
|
brace_count--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return EXPAND_OK;
|
return EXPAND_OK;
|
||||||
|
@ -1274,9 +1275,9 @@ static expand_error_t expand_stage_variables(const wcstring &input, std::vector<
|
||||||
return EXPAND_OK;
|
return EXPAND_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static expand_error_t expand_stage_brackets(const wcstring &input, std::vector<completion_t> *out,
|
static expand_error_t expand_stage_braces(const wcstring &input, std::vector<completion_t> *out,
|
||||||
expand_flags_t flags, parse_error_list_t *errors) {
|
expand_flags_t flags, parse_error_list_t *errors) {
|
||||||
return expand_brackets(input, flags, out, errors);
|
return expand_braces(input, flags, out, errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
static expand_error_t expand_stage_home(const wcstring &input,
|
static expand_error_t expand_stage_home(const wcstring &input,
|
||||||
|
@ -1393,7 +1394,7 @@ expand_error_t expand_string(const wcstring &input, std::vector<completion_t> *o
|
||||||
|
|
||||||
// Our expansion stages.
|
// Our expansion stages.
|
||||||
const expand_stage_t stages[] = {expand_stage_cmdsubst, expand_stage_variables,
|
const expand_stage_t stages[] = {expand_stage_cmdsubst, expand_stage_variables,
|
||||||
expand_stage_brackets, expand_stage_home,
|
expand_stage_braces, expand_stage_home,
|
||||||
expand_stage_wildcards};
|
expand_stage_wildcards};
|
||||||
|
|
||||||
// Load up our single initial completion.
|
// Load up our single initial completion.
|
||||||
|
|
|
@ -65,11 +65,11 @@ enum {
|
||||||
/// Character representing variable expansion into a single element.
|
/// Character representing variable expansion into a single element.
|
||||||
VARIABLE_EXPAND_SINGLE,
|
VARIABLE_EXPAND_SINGLE,
|
||||||
/// Character representing the start of a bracket expansion.
|
/// Character representing the start of a bracket expansion.
|
||||||
BRACKET_BEGIN,
|
BRACE_BEGIN,
|
||||||
/// Character representing the end of a bracket expansion.
|
/// Character representing the end of a bracket expansion.
|
||||||
BRACKET_END,
|
BRACE_END,
|
||||||
/// Character representing separation between two bracket elements.
|
/// Character representing separation between two bracket elements.
|
||||||
BRACKET_SEP,
|
BRACE_SEP,
|
||||||
/// Separate subtokens in a token with this character.
|
/// Separate subtokens in a token with this character.
|
||||||
INTERNAL_SEPARATOR,
|
INTERNAL_SEPARATOR,
|
||||||
/// Character representing an empty variable expansion. Only used transitively while expanding
|
/// Character representing an empty variable expansion. Only used transitively while expanding
|
||||||
|
|
|
@ -122,9 +122,9 @@ bool is_potential_path(const wcstring &potential_path_fragment, const wcstring_l
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case VARIABLE_EXPAND:
|
case VARIABLE_EXPAND:
|
||||||
case VARIABLE_EXPAND_SINGLE:
|
case VARIABLE_EXPAND_SINGLE:
|
||||||
case BRACKET_BEGIN:
|
case BRACE_BEGIN:
|
||||||
case BRACKET_END:
|
case BRACE_END:
|
||||||
case BRACKET_SEP:
|
case BRACE_SEP:
|
||||||
case ANY_CHAR:
|
case ANY_CHAR:
|
||||||
case ANY_STRING:
|
case ANY_STRING:
|
||||||
case ANY_STRING_RECURSIVE: {
|
case ANY_STRING_RECURSIVE: {
|
||||||
|
|
|
@ -834,14 +834,14 @@ void parse_util_expand_variable_error(const wcstring &token, size_t global_token
|
||||||
wchar_t char_after_dollar = dollar_pos + 1 >= token.size() ? 0 : token.at(dollar_pos + 1);
|
wchar_t char_after_dollar = dollar_pos + 1 >= token.size() ? 0 : token.at(dollar_pos + 1);
|
||||||
|
|
||||||
switch (char_after_dollar) {
|
switch (char_after_dollar) {
|
||||||
case BRACKET_BEGIN:
|
case BRACE_BEGIN:
|
||||||
case L'{': {
|
case L'{': {
|
||||||
// The BRACKET_BEGIN is for unquoted, the { is for quoted. Anyways we have (possible
|
// The BRACE_BEGIN is for unquoted, the { is for quoted. Anyways we have (possible
|
||||||
// quoted) ${. See if we have a }, and the stuff in between is variable material. If so,
|
// quoted) ${. See if we have a }, and the stuff in between is variable material. If so,
|
||||||
// report a bracket error. Otherwise just complain about the ${.
|
// report a bracket error. Otherwise just complain about the ${.
|
||||||
bool looks_like_variable = false;
|
bool looks_like_variable = false;
|
||||||
size_t closing_bracket =
|
size_t closing_bracket =
|
||||||
token.find(char_after_dollar == L'{' ? L'}' : wchar_t(BRACKET_END), dollar_pos + 2);
|
token.find(char_after_dollar == L'{' ? L'}' : wchar_t(BRACE_END), dollar_pos + 2);
|
||||||
wcstring var_name;
|
wcstring var_name;
|
||||||
if (closing_bracket != wcstring::npos) {
|
if (closing_bracket != wcstring::npos) {
|
||||||
size_t var_start = dollar_pos + 2, var_end = closing_bracket;
|
size_t var_start = dollar_pos + 2, var_end = closing_bracket;
|
||||||
|
|
Loading…
Reference in a new issue