pub struct SyntaxError {
pub offset: usize,
pub line: usize,
pub column: usize,
pub expected: Vec<String>,
pub found: Option<char>,
pub line_text: String,
}Expand description
A syntax error, with the position in the document it was found at.
The position is the furthest one the parser reached, which is the character the document stops making sense at rather than the point the last alternative gave up on.
§Examples
use links_notation::{parse_lino, ParseError};
let error = parse_lino("ci_gate x\nstage: rust: nextest\n").unwrap_err();
let ParseError::SyntaxError(error) = error else { panic!("expected a syntax error") };
assert_eq!((error.line, error.column), (2, 12));
assert_eq!(error.found, Some(':'));Fields§
§offset: usizeByte offset of the offending position from the start of the document.
line: usizeLine the offending position is on, counted from 1.
column: usizeColumn the offending position is at, in characters, counted from 1.
expected: Vec<String>What could have continued the document at this position. Empty when the parser stopped somewhere it names no expectation for.
found: Option<char>The character found instead, or None at the end of the document.
line_text: StringThe offending line, as written, without its line ending.
Implementations§
Source§impl SyntaxError
impl SyntaxError
Sourcepub fn summary(&self) -> String
pub fn summary(&self) -> String
The one-line summary: where the parser stopped, what could have stood there and what does.
§Examples
use links_notation::{parse_lino, ParseError};
let ParseError::SyntaxError(error) = parse_lino("a: b: c").unwrap_err() else {
panic!("expected a syntax error")
};
assert_eq!(
error.summary(),
r#"line 1, column 5: expected "(", a reference or end of line, found ":""#
);Sourcepub fn snippet(&self) -> String
pub fn snippet(&self) -> String
The offending line with a caret under the offending column, quoted the
way rustc quotes source.
A long line is shown as a window around the caret, so the message stays the same size whether the document has ten lines or fifteen hundred.
§Examples
use links_notation::{parse_lino, ParseError};
let ParseError::SyntaxError(error) = parse_lino("a: b: c").unwrap_err() else {
panic!("expected a syntax error")
};
assert_eq!(error.snippet(), "1 | a: b: c\n | ^");Trait Implementations§
Source§impl Clone for SyntaxError
impl Clone for SyntaxError
Source§fn clone(&self) -> SyntaxError
fn clone(&self) -> SyntaxError
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 SyntaxError
impl Debug for SyntaxError
Source§impl Display for SyntaxError
impl Display for SyntaxError
impl Eq for SyntaxError
Source§impl Error for SyntaxError
impl Error for SyntaxError
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()