Struct ImmutableInteractiveParser
pub struct ImmutableInteractiveParser<'p> { /* private fields */ }Expand description
Lark’s ImmutableInteractiveParser: the
copy-on-feed wrapper. Some methods are overridden in Lark (feed_token,
exhaust_lexer, as_mutable) so they return a new immutable and never mutate
self; others are inherited unmodified (resume_parse, feed_eof, pretty,
accepts, choices, copy) and keep their base semantics — including the
quirk that resume_parse runs the base parse_from_state over the shared
state and mutates it in place. This surface mirrors Lark faithfully,
documenting each quirk with its citation rather than idealizing it away.
NOTE: unlike the mutable parser, these driving methods do NOT thread the
embedded-transformer hook — they feed hookless. Unreachable today (the only
constructor is pub(crate), OwnedInteractiveParser has no as_immutable,
and the public parse_interactive entry carries no transformer), so this
is an API-consistency gap rather than a live bug: wire the hook through
before exposing any path that reaches here with a transformer configured.
Implementations§
§impl<'p> ImmutableInteractiveParser<'p>
impl<'p> ImmutableInteractiveParser<'p>
pub fn feed_token(
&self,
token: Token,
) -> Result<ImmutableInteractiveParser<'p>, ParseError>
pub fn feed_token( &self, token: Token, ) -> Result<ImmutableInteractiveParser<'p>, ParseError>
feed_token copies, feeds the copy, records result on it, and returns the
new immutable parser. A rejected feed
propagates the error (raw expected — direct path) and discards the copy,
leaving the original untouched.
pub fn accepts(&self) -> Vec<String>
pub fn choices(&self) -> BTreeMap<String, ChoiceAction>
pub fn result(&self) -> Option<&NodeValue>
pub fn peeked(&self) -> Option<&Token>
pub fn peeked(&self) -> Option<&Token>
The token queued for the next feed, if any; see
InteractiveParser::peeked. This side has no peek_next, so a token the
copy inherited is otherwise invisible — and unlike the mutable side, a
rejected feed here discards the COPY, leaving self still holding it, so a
retry with a different argument is possible.
pub fn pretty(&self) -> String
pub fn pretty(&self) -> String
pretty() (inherited unmodified): the
choices dump over the shared state — read-only, so it delegates.
pub fn copy(&self) -> ImmutableInteractiveParser<'p>
pub fn copy(&self) -> ImmutableInteractiveParser<'p>
A separate immutable copy (Lark’s inherited copy/__copy__ returns
type(self)(...), so an immutable copies to an immutable).
Feeding a copy never touches this one.
pub fn exhaust_lexer(
&self,
) -> Result<ImmutableInteractiveParser<'p>, ParseError>
pub fn exhaust_lexer( &self, ) -> Result<ImmutableInteractiveParser<'p>, ParseError>
exhaust_lexer (overridden): copies to a
mutable cursor, exhausts that, and returns a new immutable — self is
left untouched. Lark discards the consumed-token list here (unlike the
mutable exhaust_lexer, which returns it).
pub fn resume_parse(&mut self) -> Result<ParsedTree, ParseError>
pub fn resume_parse(&mut self) -> Result<ParsedTree, ParseError>
resume_parse (inherited unmodified):
Lark runs parse_from_state over the shared parser_state, mutating it in
place and returning the finished tree — so on an immutable it does mutate
(a faithful quirk, not idealized). We take &mut self to mirror that; the
arenas move into the tree, leaving this parser finished.
pub fn feed_eof(&self) -> Result<ImmutableInteractiveParser<'p>, ParseError>
pub fn feed_eof(&self) -> Result<ImmutableInteractiveParser<'p>, ParseError>
feed_eof (inherited): its body is
self.feed_token(eof), and on an immutable self.feed_token is the
copy-on-feed override — so feed_eof returns a new immutable whose
result holds the accepted tree value (NOT a bare tree). The bare $END
takes the (0,1,1) else-branch; a reject reports the raw expected set.
pub fn as_mutable(self) -> InteractiveParser<'p>
pub fn as_mutable(self) -> InteractiveParser<'p>
Convert back to a mutable parser (Lark as_mutable).