#[non_exhaustive]pub enum ParseError {
Lex(LexError),
Expected {
expected: String,
loc: DiagLoc,
},
Redefinition {
kind: SymbolKind,
id: SymbolId,
loc: DiagLoc,
},
UndefinedSymbol {
kind: SymbolKind,
id: SymbolId,
loc: DiagLoc,
},
InvalidSlotId {
source: AddError,
loc: DiagLoc,
},
IntegerWidthOutOfRange {
width: u64,
max: u32,
loc: DiagLoc,
},
Io(String),
}Expand description
Top-level parser error.
Variants are added phase-by-phase as new parser arms come online.
Wording matches LLParser.cpp for the cases shipped today; structured
fields let callers match without inspecting the rendered string.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Lex(LexError)
The lexer rejected the next token.
Expected
LLParser::error site for “expected X” / “expected Y” diagnostics.
expected carries the human-readable description LLParser would
pass to tokError.
Redefinition
redefinition of <symbol> — mirrors LLParser::checkValueID and
the "redefinition of " diagnostic site in LLParser.cpp.
UndefinedSymbol
use of undefined ... — mirrors the "use of undefined "
diagnostics that LLParser emits when a module-level forward
reference is never satisfied. Carries the reference’s first-seen
location so renderers can point at the use site.
InvalidSlotId
slot mapping rejected slot id — wraps a SlotAddError from
crate::numbered_values::NumberedValues::add. Mirrors the
assert(ID >= NextUnusedID) site that LLParser triggers when a
.ll file uses a non-monotonic slot id.
IntegerWidthOutOfRange
bitwidth for integer type out of range — mirrors the upstream
LLParser::parseType arm that rejects iN for N outside
[1, MAX_INT_BITS].
Io(String)
I/O failure pulling source bytes. The lexer itself does not perform
I/O; this is for callers using
crate::read_to_owned-style helpers. The wrapped string is the
Display form of the underlying std::io::Error; we don’t keep
the std::io::Error itself because it lacks Clone/Eq/Hash,
which the rest of ParseError derives.
Implementations§
Source§impl ParseError
impl ParseError
Sourcepub fn loc(&self) -> Option<DiagLoc>
pub fn loc(&self) -> Option<DiagLoc>
The diagnostic location to highlight, when the variant carries one.
Examples found in repository?
69fn report_error(path: &Path, src: &[u8], err: &ParseError) {
70 let sm = SourceMap::new(src);
71 let span = err.loc().map(|l| l.span).unwrap_or(Span::new(0, 0));
72 let (line, col) = sm.line_col(span.start);
73 eprintln!("{path}:{line}:{col}: {err}", path = path.display());
74 if let Some(line_bytes) = sm.line_text(line) {
75 eprintln!(" | {}", String::from_utf8_lossy(line_bytes));
76 let underline_len = (span.end.saturating_sub(span.start) as usize).max(1);
77 eprintln!(
78 " | {pad}{caret}",
79 pad = " ".repeat((col - 1) as usize),
80 caret = "^".repeat(underline_len)
81 );
82 }
83}Trait Implementations§
Source§impl Clone for ParseError
impl Clone for ParseError
Source§fn clone(&self) -> ParseError
fn clone(&self) -> ParseError
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ParseError
impl Debug for ParseError
Source§impl Display for ParseError
impl Display for ParseError
impl Eq for ParseError
Source§impl Error for ParseError
impl Error for ParseError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()