osa1 / lexgen

A fully-featured lexer generator, implemented as a proc macro
MIT License
63 stars 7 forks source link

Annotate custom errors with location info #34

Closed osa1 closed 2 years ago

osa1 commented 2 years ago

This commit changes LexerError type from:

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum LexerError<E> {
    InvalidToken {
        location: Loc,
    },

    /// Custom error, raised by a semantic action
    Custom(E),
}

to:

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct LexerError<E> {
    pub location: Loc,
    pub kind: LexerErrorKind<E>,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum LexerErrorKind<E> {
    /// Lexer error, raised by lexgen-generated code
    InvalidToken,

    /// Custom error, raised by a semantic action
    Custom(E),
}

So we annotate all errors with location info now.