From c98ed6d07abeb7b4dc41d92f631a433e37d6f9ea Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Sat, 10 Mar 2018 13:16:07 -0600 Subject: [PATCH] Rename BRACKET to BRACE per #3802 --- src/common.cpp | 6 +-- src/expand.cpp | 93 +++++++++++++++++++++++----------------------- src/expand.h | 6 +-- src/highlight.cpp | 6 +-- src/parse_util.cpp | 6 +-- 5 files changed, 59 insertions(+), 58 deletions(-) diff --git a/src/common.cpp b/src/common.cpp index 84d2cdd8e..b3a96db18 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -1353,20 +1353,20 @@ static bool unescape_string_internal(const wchar_t *const input, const size_t in case L'{': { if (unescape_special) { bracket_count++; - to_append_or_none = BRACKET_BEGIN; + to_append_or_none = BRACE_BEGIN; } break; } case L'}': { if (unescape_special) { bracket_count--; - to_append_or_none = BRACKET_END; + to_append_or_none = BRACE_END; } break; } case L',': { if (unescape_special && bracket_count > 0) { - to_append_or_none = BRACKET_SEP; + to_append_or_none = BRACE_SEP; } break; } diff --git a/src/expand.cpp b/src/expand.cpp index 7605ed353..3ead4819a 100644 --- a/src/expand.cpp +++ b/src/expand.cpp @@ -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 &idx, std::vector &source_positions, size_t 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 (iswspace(in[pos]) || (in[pos] == INTERNAL_SEPARATOR)) pos++; @@ -846,39 +846,39 @@ static bool expand_variables(const wcstring &instr, std::vector *o return true; } -/// Perform bracket expansion. -static expand_error_t expand_brackets(const wcstring &instr, expand_flags_t flags, +/// Perform brace expansion. +static expand_error_t expand_braces(const wcstring &instr, expand_flags_t flags, std::vector *out, parse_error_list_t *errors) { 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 *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(); - // Locate the first non-nested bracket pair. + // Locate the first non-nested brace pair. for (const wchar_t *pos = in; (*pos) && !syntax_error; pos++) { switch (*pos) { - case BRACKET_BEGIN: { - if (bracket_count == 0) bracket_begin = pos; - bracket_count++; + case BRACE_BEGIN: { + if (brace_count == 0) brace_begin = pos; + brace_count++; break; } - case BRACKET_END: { - bracket_count--; - if (bracket_count < 0) { + case BRACE_END: { + brace_count--; + if (brace_count < 0) { syntax_error = true; - } else if (bracket_count == 0) { - bracket_end = pos; + } else if (brace_count == 0) { + brace_end = pos; } break; } - case BRACKET_SEP: { - if (bracket_count == 1) last_sep = pos; + case BRACE_SEP: { + if (brace_count == 1) last_sep = pos; break; } 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)) { syntax_error = true; } 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. wcstring mod; if (last_sep) { - mod.append(in, bracket_begin - in + 1); + mod.append(in, brace_begin - in + 1); mod.append(last_sep + 1); - mod.push_back(BRACKET_END); + mod.push_back(BRACE_END); } else { mod.append(in); - mod.push_back(BRACKET_END); + mod.push_back(BRACE_END); } // 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, // and this eases e.g. `find -exec {}`. See #1109. - if (bracket_begin + 1 == bracket_end) { + if (brace_begin + 1 == brace_end) { wcstring newstr = instr; - newstr.at(bracket_begin - in) = L'{'; - newstr.at(bracket_end - in) = L'}'; - return expand_brackets(newstr, flags, out, errors); + newstr.at(brace_begin - in) = L'{'; + newstr.at(brace_end - in) = L'}'; + return expand_braces(newstr, flags, out, errors); } 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; } - if (bracket_begin == NULL) { + if (brace_begin == NULL) { append_completion(out, instr); return EXPAND_OK; } - length_preceding_brackets = (bracket_begin - in); - length_following_brackets = wcslen(bracket_end) - 1; - tot_len = length_preceding_brackets + length_following_brackets; - item_begin = bracket_begin + 1; - for (const wchar_t *pos = (bracket_begin + 1); true; pos++) { - if (bracket_count == 0 && ((*pos == BRACKET_SEP) || (pos == bracket_end))) { + length_preceding_braces = (brace_begin - in); + length_following_braces = wcslen(brace_end) - 1; + tot_len = length_preceding_braces + length_following_braces; + item_begin = brace_begin + 1; + for (const wchar_t *pos = (brace_begin + 1); true; pos++) { + if (brace_count == 0 && ((*pos == BRACE_SEP) || (pos == brace_end))) { assert(pos >= item_begin); size_t item_len = pos - item_begin; wcstring whole_item; 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(bracket_end + 1); - expand_brackets(whole_item, flags, out, errors); + whole_item.append(brace_end + 1); + debug(0, L"Found brace item: %ls\n", whole_item.c_str()); + expand_braces(whole_item, flags, out, errors); item_begin = pos + 1; - if (pos == bracket_end) break; + if (pos == brace_end) break; } - if (*pos == BRACKET_BEGIN) { - bracket_count++; + if (*pos == BRACE_BEGIN) { + brace_count++; } - if (*pos == BRACKET_END) { - bracket_count--; + if (*pos == BRACE_END) { + brace_count--; } } return EXPAND_OK; @@ -1274,9 +1275,9 @@ static expand_error_t expand_stage_variables(const wcstring &input, std::vector< return EXPAND_OK; } -static expand_error_t expand_stage_brackets(const wcstring &input, std::vector *out, +static expand_error_t expand_stage_braces(const wcstring &input, std::vector *out, 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, @@ -1393,7 +1394,7 @@ expand_error_t expand_string(const wcstring &input, std::vector *o // Our expansion stages. 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}; // Load up our single initial completion. diff --git a/src/expand.h b/src/expand.h index 771d8773b..62bd6a482 100644 --- a/src/expand.h +++ b/src/expand.h @@ -65,11 +65,11 @@ enum { /// Character representing variable expansion into a single element. VARIABLE_EXPAND_SINGLE, /// Character representing the start of a bracket expansion. - BRACKET_BEGIN, + BRACE_BEGIN, /// Character representing the end of a bracket expansion. - BRACKET_END, + BRACE_END, /// Character representing separation between two bracket elements. - BRACKET_SEP, + BRACE_SEP, /// Separate subtokens in a token with this character. INTERNAL_SEPARATOR, /// Character representing an empty variable expansion. Only used transitively while expanding diff --git a/src/highlight.cpp b/src/highlight.cpp index c0366c7d5..1b94e87fa 100644 --- a/src/highlight.cpp +++ b/src/highlight.cpp @@ -122,9 +122,9 @@ bool is_potential_path(const wcstring &potential_path_fragment, const wcstring_l switch (c) { case VARIABLE_EXPAND: case VARIABLE_EXPAND_SINGLE: - case BRACKET_BEGIN: - case BRACKET_END: - case BRACKET_SEP: + case BRACE_BEGIN: + case BRACE_END: + case BRACE_SEP: case ANY_CHAR: case ANY_STRING: case ANY_STRING_RECURSIVE: { diff --git a/src/parse_util.cpp b/src/parse_util.cpp index 2927763ee..2fb17e94a 100644 --- a/src/parse_util.cpp +++ b/src/parse_util.cpp @@ -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); switch (char_after_dollar) { - case BRACKET_BEGIN: + case BRACE_BEGIN: 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, // report a bracket error. Otherwise just complain about the ${. bool looks_like_variable = false; 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; if (closing_bracket != wcstring::npos) { size_t var_start = dollar_pos + 2, var_end = closing_bracket;