MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / sh_array_word

Function sh_array_word

src/pipeline/pass_shell.c:973–993  ·  view source on GitHub ↗

"${name[@]}" / ${name[*]} as a whole word: the array, NULL when not. */

Source from the content-addressed store, hash-verified

971
972/* "${name[@]}" / ${name[*]} as a whole word: the array, NULL when not. */
973static const sh_val_t *sh_array_word(sh_t *s, TSNode w) {
974 if (sh_type(w, "string") && ts_node_named_child_count(w) == SKIP_ONE) {
975 w = ts_node_named_child(w, 0);
976 }
977 if (!sh_type(w, "expansion") || ts_node_named_child_count(w) != SKIP_ONE) {
978 return NULL;
979 }
980 TSNode sub = ts_node_named_child(w, 0);
981 if (!sh_type(sub, "subscript")) {
982 return NULL;
983 }
984 TSNode base = ts_node_child_by_field_name(sub, TS_FIELD("name"));
985 TSNode idx = ts_node_child_by_field_name(sub, TS_FIELD("index"));
986 const char *it = ts_node_is_null(idx) ? NULL : sh_text(s, idx);
987 if (ts_node_is_null(base) || !it || (strcmp(it, "@") != 0 && strcmp(it, "*") != 0)) {
988 return NULL;
989 }
990 bool found = false;
991 const sh_val_t *v = sh_lookup(s, sh_text(s, base), &found);
992 return v;
993}
994
995/* An unquoted expansion may split into several words. */
996static bool sh_may_split(TSNode w) {

Callers 1

sh_argv_wordFunction · 0.85

Calls 3

sh_typeFunction · 0.85
sh_textFunction · 0.85
sh_lookupFunction · 0.85

Tested by

no test coverage detected