Skip to main content

Parser

Struct Parser 

Source
pub struct Parser<'a> { /* private fields */ }
Expand description

Parser for bash scripts.

Implementations§

Source§

impl<'a> Parser<'a>

Source

pub fn parse(self) -> ParseResult

Parse the input and return the AST, recovery diagnostics, and syntax facts.

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.

Source

pub fn with_profile(input: &'a str, shell_profile: ShellProfile) -> Self

Create a new parser for the given input and full shell profile.

Source

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

Create a new parser with a custom maximum AST depth.

Source

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

Create a new parser with a custom fuel limit.

Source

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

Create a new parser with custom depth and fuel limits.

max_depth is clamped to HARD_MAX_AST_DEPTH (500) to prevent stack overflow from misconfiguration. Even if the caller passes max_depth = 1_000_000, the parser will cap it at 500.

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.

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.

Source

pub fn dialect(&self) -> ShellDialect

Return the dialect associated with this parser.

Source

pub fn shell_profile(&self) -> &ShellProfile

Borrow the full shell profile associated with this parser.

Source

pub fn current_span(&self) -> Span

Get the current token’s span.

Source

pub fn parse_word_string(input: &str) -> Word

Parse a string as a word (handling $var, $((expr)), ${…}, etc.). Used by the interpreter to expand operands in parameter expansions lazily.

Source

pub fn parse_assignment_word( source: &str, word: Word, explicit_array_kind: Option<ArrayKind>, subscript_interpretation: SubscriptInterpretation, ) -> Option<Assignment>

Classify an already-parsed word as a shell assignment and split its value.

This is the parser-owned entrypoint for downstream analysis that needs assignment target/value structure from a Word that was parsed as a normal command argument.

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.

Source

pub fn parse_word_string_with_limits( input: &str, max_depth: usize, max_fuel: usize, ) -> Word

Parse a word string with caller-configured limits. Prevents bypass of parser limits in parameter expansion contexts.

Source

pub fn parse_word_string_with_limits_and_dialect( input: &str, max_depth: usize, max_fuel: usize, dialect: ShellDialect, ) -> Word

Parse a word string with caller-configured limits and shell dialect.

Source

pub fn parse_word_fragment(source: &str, text: &str, span: Span) -> Word

Parse a fragment against the original source span so part offsets stay aligned with the surrounding script.

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 · 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.