pub enum ScanError {
InvalidEscape {
byte_offset: usize,
seq: String,
},
UnterminatedCapture {
byte_offset: usize,
},
EmptyCapture {
byte_offset: usize,
},
InvalidCaptureName {
byte_offset: usize,
name: String,
},
UnknownCaptureKind {
byte_offset: usize,
name: String,
},
UnknownConstructor {
byte_offset: usize,
name: String,
},
MalformedCaptureBody {
byte_offset: usize,
message: String,
},
CallShape(ValidationError),
NestingTooDeep {
byte_offset: usize,
what: &'static str,
},
}Expand description
An error encountered while scanning a template interior or a capture body.
Variants§
InvalidEscape
An invalid escape sequence (e.g. \q). seq is the text the source
actually wrote, sliced from it, not a re-format! of a guessed byte.
UnterminatedCapture
An unterminated capture {... (no closing }).
EmptyCapture
An empty capture {}.
InvalidCaptureName
A capture whose name is not an identifier (§4.1).
UnknownCaptureKind
A capture body naming a parser that does not exist.
UnknownConstructor
A capture body calling a constructor that does not exist (§7.5).
MalformedCaptureBody
A capture body that is not a parser expression at all.
CallShape(ValidationError)
A constructor call in a capture body whose arguments do not have §7.5’s
shape. Carries the ValidationError check_call produced, so the
code and the message are the same ones a top-level call would report.
NestingTooDeep
Nesting past MAX_NESTING.
what is which nesting hit the bound — templates, {, or (. A
diagnostic that states the wrong thing is worse than a vague one: a
csv( thirty-three deep is a parenthesis bound, and calling it template
nesting misnames the limit in text that holds one template.
Implementations§
Source§impl ScanError
impl ScanError
Sourcepub fn byte_offset(&self) -> usize
pub fn byte_offset(&self) -> usize
The byte offset in the scanned text this error is anchored at.
Sourcepub fn shifted(self, delta: usize) -> ScanError
pub fn shifted(self, delta: usize) -> ScanError
The same error, anchored delta bytes later.
A nested template’s interior is scanned in its own offsets: the scanner is handed the text between the backticks and knows nothing about where that text sits in the template that contains it. The caller does know, and this is how the two are joined. Without it every caret under a nested template lands short by the nested interior’s own offset.
Sourcepub fn code(&self) -> DiagCode
pub fn code(&self) -> DiagCode
The diagnostic this error is reported under.
Exhaustive on purpose. A wildcard would flatten every variant it
caught into DiagCode::TemplateScan (I030) and leave the codes ADR-051
allocates for these cases — InvalidCaptureName I011,
UnknownCaptureKind I012, UnknownConstructor I013 — constructed
nowhere in the tree. A match with no wildcard is what stops the next
variant from silently inheriting I030.
Sourcepub fn unknown_parser_name(&self) -> Option<&str>
pub fn unknown_parser_name(&self) -> Option<&str>
The parser name this error could not resolve, when that is what went wrong — the word a “did you mean” would replace (ADR-132).
Exhaustive, so a variant added later has to answer: a name that reaches a caller by accident is a fix offered for the wrong span, and a name that does not reach it is a fix silently not offered.
Trait Implementations§
impl Eq for ScanError
Source§impl Error for ScanError
impl Error for ScanError
1.30.0 · 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()