Skip to main content

parse_subscript

Function parse_subscript 

Source
pub fn parse_subscript(s: &str, endchar: char) -> Option<usize>
Expand description

Parse a subscript in string s. Return the position after the closing bracket, or None on error.

Direct port of zsh/Src/lex.c:1742-1788 parse_subscript. The C source uses dupstring_wlen + inpush + dquote_parse to lex the subscript through the main lexer; zshrs implements a focused bracket-balancing walker that handles the same nesting rules ([...], (...), {...}) without re-entering the lexer.

zshrs port note: zsh’s parse_subscript also handles a sub flag that controls whether $ and quotes are tokenized — that flag isn’t exposed here. Most callers don’t need it; the few that do (parameter expansion’s ${var[expr]}) handle the quote-aware lex separately at the expansion layer.