just/src/token.rs

29 lines
580 B
Rust
Raw Normal View History

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