pub struct Parser<'a> { /* private fields */ }Expand description
Stateful parser for shell scripts.
Construct a parser with one of the Parser::with_* constructors and then
call parse to obtain a super::ParseResult. The parser is single-use:
parse consumes the value so internal recovery state cannot leak between
parses.
Implementations§
Source§impl<'a> Parser<'a>
impl<'a> Parser<'a>
Sourcepub fn parse(self) -> ParseResult
pub fn parse(self) -> ParseResult
Parse the configured input.
The returned ParseResult contains the best AST the parser could
produce, plus recovery diagnostics and syntax facts. Use
ParseResult::is_ok when a caller needs to reject recovered parses.
Source§impl<'a> Parser<'a>
impl<'a> Parser<'a>
Sourcepub fn with_dialect(input: &'a str, dialect: ShellDialect) -> Self
pub fn with_dialect(input: &'a str, dialect: ShellDialect) -> Self
Create a new parser for the given input and shell dialect.
This uses ShellProfile::native for the selected dialect. Use
Parser::with_profile when zsh option state is known.
Sourcepub fn with_profile(input: &'a str, shell_profile: ShellProfile) -> Self
pub fn with_profile(input: &'a str, shell_profile: ShellProfile) -> Self
Create a new parser for the given input and full shell profile.
Profiles allow callers to provide parser-visible zsh option state in addition to the broad shell dialect.
Sourcepub fn with_fuel(input: &'a str, max_fuel: usize) -> Self
pub fn with_fuel(input: &'a str, max_fuel: usize) -> Self
Create a new bash parser with a custom fuel limit.
Fuel bounds the number of parser operations. Exhaustion produces a
terminal parse error in the returned ParseResult.
Sourcepub fn with_limits_and_profile(
input: &'a str,
max_depth: usize,
max_fuel: usize,
shell_profile: ShellProfile,
) -> Self
pub fn with_limits_and_profile( input: &'a str, max_depth: usize, max_fuel: usize, shell_profile: ShellProfile, ) -> Self
Create a new parser with custom depth, fuel, and shell-profile settings.
This is the most explicit constructor for embedders that need both resource limits and parser-visible shell option state.
Sourcepub fn parse_word_string(input: &str) -> Word
pub fn parse_word_string(input: &str) -> Word
Parse a standalone shell word string.
This handles shell word constructs such as parameter expansion, command
substitution, arithmetic expansion, and quoting. The returned word is
positioned as if input started at the beginning of a file.
Sourcepub fn parse_assignment_word_group(
source: &str,
words: &[&Word],
explicit_array_kind: Option<ArrayKind>,
subscript_interpretation: SubscriptInterpretation,
) -> Option<Assignment>
pub fn parse_assignment_word_group( source: &str, words: &[&Word], explicit_array_kind: Option<ArrayKind>, subscript_interpretation: SubscriptInterpretation, ) -> Option<Assignment>
Classify a contiguous group of already-parsed words as a shell assignment.
Some shell syntax, such as process substitution inside an array subscript, can produce multiple AST words while still occupying one contiguous assignment operand in the source.