JustBash.Parser.WordParts.Bracket (JustBash v0.4.0)
View SourceBracket matching utilities for word parts parsing.
Provides functions to find matching brackets, braces, parentheses, and other paired delimiters while respecting nesting and escape sequences.
Summary
Functions
Find the closing backtick for a backtick-style command substitution.
Find the end of a double-parenthesis arithmetic expression )).
Find the end of a glob bracket pattern [...].
Find the matching closing brace } for an opening brace {.
Find the matching closing bracket ] for an opening bracket [.
Find the matching closing parenthesis ) for an opening parenthesis (.
Functions
@spec find_backtick_end(String.t(), non_neg_integer()) :: non_neg_integer()
Find the closing backtick for a backtick-style command substitution.
Parameters
value- The string to search instart- Position after the opening backtick
Returns
Position of the closing backtick.
Examples
iex> find_backtick_end("`echo hi`", 1)
8
@spec find_double_paren_end(String.t(), non_neg_integer()) :: non_neg_integer()
Find the end of a double-parenthesis arithmetic expression )).
Handles nested (( )) arithmetic expressions and single parentheses
for grouping within the expression.
Parameters
value- The string to search instart- Position of the first character inside$((
Returns
Position of the first ) in the closing )).
Examples
iex> find_double_paren_end("$((1+2))", 3)
5
iex> find_double_paren_end("$((1+((2+3))))", 3)
11
@spec find_glob_bracket_end(String.t(), non_neg_integer()) :: {:ok, non_neg_integer()} | :error
Find the end of a glob bracket pattern [...].
Parameters
value- The string to search instart- Position of the opening bracket
Returns
{:ok, position} of the closing bracket, or :error if not found.
Examples
iex> find_glob_bracket_end("[abc]", 0)
{:ok, 4}
iex> find_glob_bracket_end("[a-z]", 0)
{:ok, 4}
@spec find_matching_brace(String.t(), non_neg_integer()) :: non_neg_integer()
Find the matching closing brace } for an opening brace {.
Parameters
value- The string to search instart- Position of the opening brace
Returns
Position of the matching closing brace.
Examples
iex> find_matching_brace("${foo}", 1)
5
iex> find_matching_brace("${a:-${b}}", 1)
9
@spec find_matching_bracket(String.t(), non_neg_integer()) :: non_neg_integer()
Find the matching closing bracket ] for an opening bracket [.
Parameters
value- The string to search instart- Position of the opening bracket
Returns
Position of the matching closing bracket.
Examples
iex> find_matching_bracket("arr[0]", 3)
5
iex> find_matching_bracket("arr[i+1]", 3)
7
@spec find_matching_paren(String.t(), non_neg_integer()) :: non_neg_integer()
Find the matching closing parenthesis ) for an opening parenthesis (.
Parameters
value- The string to search instart- Position of the opening parenthesis
Returns
Position of the matching closing parenthesis.
Examples
iex> find_matching_paren("$(echo hi)", 1)
9
iex> find_matching_paren("$(echo $(pwd))", 1)
13