Skip to main content

LexError

Type Alias LexError 

Source
pub type LexError = SyntaxError;
Expand description

Lexical errors share the syntax error type: the engine reports both as SyntaxError.

Aliased Type§

pub struct LexError {
    pub message: String,
    pub span: Span,
    pub positionless: bool,
}

Fields§

§message: String

Human readable message (no position prefix).

§span: Span

Where the error happened.

§positionless: bool

Whether the reference reports this error without a position.

Almost every syntax error is printed as SyntaxError: <message> followed by at <file>:<line>:<column>. A handful are not, and the difference is not cosmetic: the reference raises them from js_resolve_module, after parsing has succeeded, so there is no position to give — export {a} with no a prints a bare SyntaxError: exported variable 'a' does not exist. Our parser makes that check itself (it has the declared names in hand), so it has to say “report me like a link error” explicitly.

Implementations§

Source§

impl LexError

Source

pub fn new(message: impl Into<String>, span: Span) -> LexError

Build an error at span.

Source

pub fn positionless(self) -> LexError

Mark this error as one the reference reports without a position.

See SyntaxError::positionless.

Source

pub fn line(&self) -> u32

1-based line of the error.

Source

pub fn column(&self) -> u32

1-based column of the error.