Skip to main content

IndenterSession

Struct IndenterSession 

pub struct IndenterSession { /* private fields */ }
Expand description

The live indenter state (Lark’s instance fields, indenter.py:29-34): paren_level, the indent_level stack, plus the resolved token ids and the last upstream token’s positions (the EOF flush’s borrow source, gated on that token’s value being non-empty). Fresh per session: paren_level 0, indent_level [0], no last token.

Implementations§

§

impl IndenterSession

pub fn new(config: &Indenter, names: &[String]) -> Result<Self, PostlexError>

Resolve the configured names against the id-indexed names table once (names[id] is the terminal’s name). An unknown nl/indent/dedent name is a PostlexError (those are emitted or consumed, so they must exist); unknown paren names are dropped — they are matched-only and inert when absent (Lark parity).

§

impl IndenterSession

The push surface. Not a trait: PostlexStream is the only contract, and these exist because a per-token state machine is the natural way to write an indenter — and because the conformance corpus and the postlex bench drive a session directly, in the Vec-returning shape.

pub fn feed(&mut self, token: Token) -> Result<Vec<Token>, PostlexError>

pub fn flush(&mut self) -> Result<Vec<Token>, PostlexError>

pub fn feed_into( &mut self, token: Token, out: &mut VecDeque<Token>, ) -> Result<(), PostlexError>

pub fn flush_into( &mut self, out: &mut VecDeque<Token>, ) -> Result<(), PostlexError>

Trait Implementations§

§

impl Clone for IndenterSession

§

fn clone(&self) -> IndenterSession

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
§

impl PostlexStream for IndenterSession

§

fn next_into( &mut self, src: &mut PostlexSource<'_, '_, '_>, out: &mut VecDeque<Token>, ) -> Result<bool, ParseError>

The deferred DedentError surfaces HERE, before any pull.

Lark’s yield from self.handle_NL(token) resumes into raise DedentError before the outer for token in stream asks the source for anything, so lark never pulls that next raw token. Checking at the top reproduces that: pull-then-feed would consume a raw token — and fire its lexer_callbacks hook — before the armed error could surface. pending_error is this session’s ONLY error source, which is what makes one check at the top sufficient.

§

fn clone_stream(&self) -> Option<Box<dyn PostlexStream>>

A fork for a copy() cursor — accepts() trial-feeds the parser state and never forks the lexer. None when the stream cannot be cloned (a Python generator); the fork then continues without postlex.

Auto Trait Implementations§

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 = !

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.