pub enum LexError {
UnterminatedBlockComment {
span: Span,
},
UnterminatedString {
span: Span,
},
UnterminatedQuotedName {
kind: QuotedNameKind,
span: Span,
},
NulInName {
span: Span,
},
IdOverflow {
span: Span,
},
IntegerOverflow64 {
span: Span,
},
IntegerOverflow128 {
span: Span,
},
IntegerWidthOutOfRange {
width: u64,
max: u32,
span: Span,
},
HexFpTooLarge {
target: HexFpKind,
span: Span,
},
UnknownToken {
span: Span,
},
StraySlash {
span: Span,
},
}Expand description
All lexer-level failures.
Variants§
UnterminatedBlockComment
UnterminatedString
UnterminatedQuotedName
NulInName
IdOverflow
IntegerOverflow64
IntegerOverflow128
IntegerWidthOutOfRange
HexFpTooLarge
UnknownToken
StraySlash
Implementations§
Source§impl LexError
impl LexError
Sourcepub fn span(&self) -> Span
pub fn span(&self) -> Span
The span the diagnostic should highlight. Useful for callers that want
to render (line, column) without case-matching every variant.
Examples found in repository?
examples/lex_file.rs (line 68)
67fn report_error(path: &std::path::Path, sm: &SourceMap<'_>, err: &LexError) {
68 let span = err.span();
69 let (l, c) = sm.line_col(span.start);
70 eprintln!("{path}:{l}:{c}: {err}", path = path.display());
71 if let Some(line) = sm.line_text(l) {
72 eprintln!(" | {}", String::from_utf8_lossy(line));
73 let underline_len = (span.end.saturating_sub(span.start) as usize).max(1);
74 eprintln!(
75 " | {pad}{caret}",
76 pad = " ".repeat((c - 1) as usize),
77 caret = "^".repeat(underline_len)
78 );
79 }
80}Trait Implementations§
impl Eq for LexError
Source§impl Error for LexError
impl Error for LexError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Source§impl From<LexError> for ParseError
impl From<LexError> for ParseError
impl StructuralPartialEq for LexError
Auto Trait Implementations§
impl Freeze for LexError
impl RefUnwindSafe for LexError
impl Send for LexError
impl Sync for LexError
impl Unpin for LexError
impl UnsafeUnpin for LexError
impl UnwindSafe for LexError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more