BoundaryML/baml · error

Encountered impossible identifier during parsing.

Error message

Encountered impossible identifier during parsing.

What it means

A terminal unreachable!("Encountered impossible identifier during parsing.") in parse_identifier. The function's control flow is expected to return through one of the inner-rule match arms; if it falls through — no recognized identifier child rule was found — this panic fires. It marks a grammar/parser desynchronization, not a validated user error.

Source

Thrown at engine/baml-lib/ast/src/parser/parse_identifier.rs:23

    ast::{Identifier, RefIdentifier, WithName},
    parser::Rule,
};

pub fn parse_identifier(pair: Pair<'_>, diagnostics: &mut Diagnostics) -> Identifier {
    assert_correct_parser(&pair, &[Rule::identifier], diagnostics);

    if let Some(inner) = pair.into_inner().next() {
        return match inner.as_rule() {
            Rule::path_identifier => parse_path_identifier(inner, diagnostics),
            Rule::namespaced_identifier => parse_namespaced_identifier(inner, diagnostics),
            Rule::single_word => parse_single_word(inner, diagnostics),
            _ => {
                unreachable_rule(&inner, "identifier", diagnostics);
                Identifier::Local(String::new(), diagnostics.span(inner.as_span()))
            }
        };
    }
    unreachable!("Encountered impossible identifier during parsing.")
}

fn parse_single_word(pair: Pair<'_>, diagnostics: &mut Diagnostics) -> Identifier {
    assert_correct_parser(&pair, &[Rule::single_word], diagnostics);
    let span = diagnostics.span(pair.as_span());

    Identifier::from((pair.as_str(), span))
}

pub fn parse_path_identifier(pair: Pair<'_>, diagnostics: &mut Diagnostics) -> Identifier {
    assert_correct_parser(&pair, &[Rule::path_identifier], diagnostics);

    let span = diagnostics.span(pair.as_span());
    let raw_str = pair.as_str();
    let mut vec = vec![];
    for inner in pair.into_inner() {
        match inner.as_rule() {
            Rule::single_word => vec.push(inner.as_str()),

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Ensure the identifier in your .bml file uses valid syntax (letters, dots for path identifiers) at the reported span
  2. File a bug with the input — the match arms no longer cover all grammar alternatives
  3. Update parse_identifier's match to cover the new/renamed identifier sub-rules
  4. Regenerate/verify the pest grammar so identifier variants match the parser

Example fix

// before
fn f(1bad) {}
// after
fn f(good_name) {}
Defensive patterns

Strategy: validation

Validate before calling

fn valid_identifier(name: &str) -> bool {
    !name.is_empty()
        && name.chars().next().unwrap().is_alphabetic()
        && name.chars().all(|c| c.is_alphanumeric() || c == '_' || c == '.')
}
// run over all declared names in the .bml source before parsing

Type guard

fn is_parsable_identifier(tok: &str) -> bool {
    let t = tok.trim().trim_matches('"');
    !t.is_empty() && t.chars().all(|c| c.is_alphanumeric() || c == '_' || c == '.')
}

Try / catch

std::panic::catch_unwind(|| parse_identifier(pair, &mut diagnostics))
    .map_err(|_| diagnostics.push("identifier rule not covered by parser"));

Prevention

When it happens

Trigger: parse_identifier called with a pair whose inner rules match none of the expected alternatives (e.g. Rule::single_word, path, or quoted variants removed/renamed in the grammar).

Common situations: Encountered while developing the BAML grammar (renaming identifier sub-rules without updating parse_identifier), or with a parse tree crafted by an out-of-sync pest-generated parser.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/0926672e569941bc. Report an issue: GitHub.