2019-04-11 15:23:14 -07:00
|
|
|
use crate::common::*;
|
2017-11-16 23:30:08 -08:00
|
|
|
|
|
|
|
#[derive(Debug, PartialEq, Clone)]
|
2019-09-21 15:35:03 -07:00
|
|
|
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> {
|
2019-09-21 15:35:03 -07:00
|
|
|
pub(crate) fn lexeme(&self) -> &'a str {
|
2019-04-15 22:40:02 -07:00
|
|
|
&self.text[self.offset..self.offset + self.length]
|
|
|
|
}
|
|
|
|
|
2019-09-21 15:35:03 -07:00
|
|
|
pub(crate) fn error(&self, kind: CompilationErrorKind<'a>) -> CompilationError<'a> {
|
2017-11-16 23:30:08 -08:00
|
|
|
CompilationError {
|
2019-04-15 22:40:02 -07:00
|
|
|
column: self.column,
|
|
|
|
offset: self.offset,
|
2018-12-08 14:29:41 -08:00
|
|
|
line: self.line,
|
|
|
|
text: self.text,
|
2019-04-15 22:40:02 -07:00
|
|
|
width: self.length,
|
2018-03-05 13:21:35 -08:00
|
|
|
kind,
|
2017-11-16 23:30:08 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|