Skip to main content

resolve_lexer

Function resolve_lexer 

pub fn resolve_lexer(
    spec: LexerSpec,
    parser: ParserKind,
    has_postlex: bool,
) -> Result<ResolvedLexer, FrontendError>
Expand description

Resolve lexer='auto' and validate the parser×lexer pairing, in Lark’s evaluation order:

  1. auto resolves by parser: LALR→contextual; Earley →basic when a postlex is present, else →dynamic. An explicit spec passes through unchanged. Differs from Lark: Lark logs an info note for that Earley-with-postlex fallback; hyperlark has no logging facility, so it resolves silently.
  2. postlex×dynamic: an explicit dynamic/dynamic_complete with a postlex is a ConfigurationError (“Can’t use postlex with a dynamic lexer. Use basic or contextual instead”). Fires before the matrix, for any parser (so lalr+dynamic+postlex yields this, not the matrix message). Unreachable via auto (Earley+postlex already resolved to basic).
  3. matrix: LALR accepts ('basic', 'contextual'); Earley accepts ('basic', 'dynamic', 'dynamic_complete'). A miss is a ConfigurationError with Lark’s "Parser %r does not support lexer %r, expected one of %s".

The dynamic×lexer_callbacks GrammarError is a separate, later check — validate_dynamic_lexer_callbacks — because Lark raises it at Earley-parser construction, after this resolution.