just/src/token.rs

29 lines
643 B
Rust
Raw Normal View History

use crate::common::*;
2017-11-16 23:30:08 -08:00
#[derive(Debug, PartialEq, Clone)]
pub(crate) struct Token<'a> {
pub(crate) offset: usize,
pub(crate) length: usize,
pub(crate) line: usize,
pub(crate) column: usize,
pub(crate) text: &'a str,
pub(crate) kind: TokenKind,
2017-11-16 23:30:08 -08:00
}
impl<'a> Token<'a> {
pub(crate) fn lexeme(&self) -> &'a str {
&self.text[self.offset..self.offset + self.length]
}
pub(crate) fn error(&self, kind: CompilationErrorKind<'a>) -> CompilationError<'a> {
2017-11-16 23:30:08 -08:00
CompilationError {
column: self.column,
offset: self.offset,
line: self.line,
text: self.text,
width: self.length,
2018-03-05 13:21:35 -08:00
kind,
2017-11-16 23:30:08 -08:00
}
}
}