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
impl IndenterSession
pub fn new(config: &Indenter, names: &[String]) -> Result<Self, PostlexError>
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.
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
impl Clone for IndenterSession
§fn clone(&self) -> IndenterSession
fn clone(&self) -> IndenterSession
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl PostlexStream for IndenterSession
impl PostlexStream for IndenterSession
§fn next_into(
&mut self,
src: &mut PostlexSource<'_, '_, '_>,
out: &mut VecDeque<Token>,
) -> Result<bool, ParseError>
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>>
fn clone_stream(&self) -> Option<Box<dyn PostlexStream>>
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.