Skip to main content

Module subscript_escape

Module subscript_escape 

Source
Expand description

subscript_escape submodule (Rust-only; see the module docs). Rust-only utility (NOT a port — lives outside src/ported/ by design).

C resolves the quoting inside a [...] subscript by RE-LEXING the subscript text: getindex (Src/params.c:2022) calls parse_subscript(s, scanflags & SCANPM_DQUOTED, ']') at c:2029, which untokenizes the text and pushes it back through the lexer (dquote_parse, Src/lex.c:1751-1769). zshrs has no equivalent step on that path — its lex::parse_subscript port throws away the tokenized text C copies back at c:Src/lex.c:1772, and re-entering the real lexer from inside paramsubst (and from the compiler, which resolves literal assignment keys at compile time) would mean re-entrant lexer state on the hottest expansion path.

So the three C stages that decide what a backslash inside a subscript MEANS — dquote_parse’s backslash arm, getarg’s marker disposition, and the remnulargs / parsestr + singsub round that follows — are expressed here as the one string transform they add up to. Each rule cites the C line it comes from; see [subscript_unescape].

Both callers are the “what key is this?” sites:

  • ported::subst::paramsubst${A[\[k\]]} (read)
  • extensions::compile_zsh::compile_assignA[\[k\]]=v (store)

Enums§

SubscriptBound
!!! WARNING: RUST-ONLY HELPER !!! Classification of ONE subscript operand — a range bound (${a[lo,hi]}) or a chained subscript (${a[lo,hi][SUB]}) — whose text may open with a (...) flag group.

Functions§

subscript_arg_split
!!! WARNING: RUST-ONLY HELPER !!! C has no separate function here: this is the scan loop that OPENS getarg (c:Src/params.c:1533-1541), lifted out because the Rust paramsubst expands the whole subscript in one place and then needs to know where C would have cut it.
subscript_bound_classify
!!! WARNING: RUST-ONLY HELPER !!! Classify one subscript operand against arr — see SubscriptBound.
subscript_escape_markers
Same C stages as subscript_unescape, stopped one step earlier and re-encoded for a caller that still has to run C’s parsestr + singsub round (c:Src/params.c:1585-1592) through the word compiler.
subscript_range_bounds
!!! WARNING: RUST-ONLY HELPER !!! Resolve “is this subscript a range, and what are its bounds?” using the parse-time decision recorded by subscript_arg_split when one is available (c:Src/params.c:1533-1536 — C splits BEFORE expanding), and falling back to a depth-0 comma scan of the already-expanded text for the reference paths that do not record one.
subscript_requote_for_assign
!!! WARNING: RUST-ONLY HELPER !!! Inverse of subscript_unescape’s marked set, for the one place the port has to hand an ALREADY-EXPANDED key back through a text subscript.
subscript_unescape
Backslash disposition inside a [...] subscript — the net effect of the re-lex C runs on a subscript’s SOURCE text.