Function parse_with
pub fn parse_with(
job: ParseJob<'_, '_>,
transform: Option<&mut dyn ReduceCallback>,
) -> Result<ParsedTree, ParseError>Expand description
Parse with an explicit lexer source (04: the single shared shift/reduce loop).
Flow: lex → feed_token shift/reduce loop → synthetic $END feed (a reject
raises UnexpectedToken('$END')) → finish_parse
(re-wraps a root Splice). propagate_positions fills each reduce’s
crate::model::Meta (see lalr::materialize); off-mode leaves the arena
empty. Both arms feed only non-%ignore tokens (the lexer drops them).
- Basic: iterate the basic lexer over the whole input, context-free.
- Custom: pull the caller’s
crate::custom::TokenSourceone token at a time, keyed on the live parser state like the contextual arm (Lark hands the custom lexer the liveparser_state). Token positions are the source’s verbatim ($ENDborrows them unchanged); an unknown type name is Lark’s KeyError analogue —ParseError::UnexpectedTokenwith the current-state accepts; a source failure keeps its class (crate::custom::CustomLexError). Postlex composes on top, same as the other arms (Lark’sPostLexConnectorwraps a custom lexer too). - Contextual: drive [
ContextualLexer::next_token] one token at a time, keyed on the current parser state (state.position(); Lark’sparser_state.position), threading oneLexerStateacross the whole parse. ALexError::WrongContextToken(the char is a real terminal but not in this state) maps toParseError::UnexpectedTokenwith the root-lexed token and the precise accepts set at the current state (parse_from_state’sinteractive_parserattach; the carried per-stateallowedis intentionally dropped — see [ParserState::context_unexpected_token]).
A $END reject is returned as-is (no UnexpectedEOF rewrite);
an ordinary lexer failure surfaces as ParseError::UnexpectedCharacters
(basic path: the basic-lexer allowed; contextual path: the parser-context
per-state allowed after the root re-raise).
transform: when Some, the reduce-time transform
seam replaces the tree builder — the boxed crate::model::ReduceCallback
fires once per reduction (named / _-splice / __-synthetic alike) and its
return becomes the reduced node’s value (Lark’s embedded transformer=,
LALR-only). The returned ParsedTree’s root is then the start rule’s
transformed value (a Tree, or a binding Foreign); the arenas carry any
trees the hooks built via crate::model::ReduceCx::build_tree. None is
the ordinary tree-building parse. The facade wave boxes its
binding transformer and passes it here.