{"record":{"id":"0926672e569941bc","repo":"BoundaryML/baml","slug":"encountered-impossible-identifier-during-parsing","errorCode":null,"errorMessage":"Encountered impossible identifier during parsing.","messagePattern":"Encountered impossible identifier during parsing\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-lib/ast/src/parser/parse_identifier.rs","lineNumber":23,"sourceCode":"    ast::{Identifier, RefIdentifier, WithName},\n    parser::Rule,\n};\n\npub fn parse_identifier(pair: Pair<'_>, diagnostics: &mut Diagnostics) -> Identifier {\n    assert_correct_parser(&pair, &[Rule::identifier], diagnostics);\n\n    if let Some(inner) = pair.into_inner().next() {\n        return match inner.as_rule() {\n            Rule::path_identifier => parse_path_identifier(inner, diagnostics),\n            Rule::namespaced_identifier => parse_namespaced_identifier(inner, diagnostics),\n            Rule::single_word => parse_single_word(inner, diagnostics),\n            _ => {\n                unreachable_rule(&inner, \"identifier\", diagnostics);\n                Identifier::Local(String::new(), diagnostics.span(inner.as_span()))\n            }\n        };\n    }\n    unreachable!(\"Encountered impossible identifier during parsing.\")\n}\n\nfn parse_single_word(pair: Pair<'_>, diagnostics: &mut Diagnostics) -> Identifier {\n    assert_correct_parser(&pair, &[Rule::single_word], diagnostics);\n    let span = diagnostics.span(pair.as_span());\n\n    Identifier::from((pair.as_str(), span))\n}\n\npub fn parse_path_identifier(pair: Pair<'_>, diagnostics: &mut Diagnostics) -> Identifier {\n    assert_correct_parser(&pair, &[Rule::path_identifier], diagnostics);\n\n    let span = diagnostics.span(pair.as_span());\n    let raw_str = pair.as_str();\n    let mut vec = vec![];\n    for inner in pair.into_inner() {\n        match inner.as_rule() {\n            Rule::single_word => vec.push(inner.as_str()),","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/ast/src/parser/parse_identifier.rs#L5-L41","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Ensure the identifier in your .bml file uses valid syntax (letters, dots for path identifiers) at the reported span","File a bug with the input — the match arms no longer cover all grammar alternatives","Update parse_identifier's match to cover the new/renamed identifier sub-rules","Regenerate/verify the pest grammar so identifier variants match the parser"],"exampleFix":"// before\nfn f(1bad) {}\n// after\nfn f(good_name) {}","handlingStrategy":"validation","validationCode":"fn valid_identifier(name: &str) -> bool {\n    !name.is_empty()\n        && name.chars().next().unwrap().is_alphabetic()\n        && name.chars().all(|c| c.is_alphanumeric() || c == '_' || c == '.')\n}\n// run over all declared names in the .bml source before parsing","typeGuard":"fn is_parsable_identifier(tok: &str) -> bool {\n    let t = tok.trim().trim_matches('\"');\n    !t.is_empty() && t.chars().all(|c| c.is_alphanumeric() || c == '_' || c == '.')\n}","tryCatchPattern":"std::panic::catch_unwind(|| parse_identifier(pair, &mut diagnostics))\n    .map_err(|_| diagnostics.push(\"identifier rule not covered by parser\"));","preventionTips":["Use standard identifier characters in .bml names; avoid digits-first names","Update parse_identifier whenever identifier sub-rules change in the grammar","Keep an exhaustive match with a diagnostic fallback instead of unreachable! in custom forks","Test parsing on a corpus of real .bml files after upgrades"],"tags":["parser","rust","panic","identifier","internal-bug"],"backgroundTag":"internal-invariant-violation","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}