Skip to main content

Parser

Struct Parser 

Source
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>

Source

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>

Source

pub fn new(input: &'a str) -> Self

Create a new parser for the given input.

Source

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.

Source

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.

Source

pub fn with_max_depth(input: &'a str, max_depth: usize) -> Self

Create a new bash parser with a custom maximum AST depth.

The requested depth is clamped to the parser’s hard safety cap. Hitting the limit produces a non-clean ParseResult rather than panicking.

Source

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.

Source

pub fn with_limits(input: &'a str, max_depth: usize, max_fuel: usize) -> Self

Create a new bash parser with custom depth and fuel limits.

max_depth is clamped to the parser’s hard safety cap to prevent stack overflow from misconfiguration. max_fuel bounds parser operations. Either limit can produce a non-clean ParseResult.

Source

pub fn with_limits_and_dialect( input: &'a str, max_depth: usize, max_fuel: usize, dialect: ShellDialect, ) -> Self

Create a new parser with custom depth, fuel, and dialect settings.

This uses ShellProfile::native for dialect; use Parser::with_limits_and_profile when explicit zsh option state is available.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<'a> Clone for Parser<'a>

Source§

fn clone(&self) -> Parser<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Parser<'a>

§

impl<'a> RefUnwindSafe for Parser<'a>

§

impl<'a> Send for Parser<'a>

§

impl<'a> Sync for Parser<'a>

§

impl<'a> Unpin for Parser<'a>

§

impl<'a> UnsafeUnpin for Parser<'a>

§

impl<'a> UnwindSafe for Parser<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.