1cb90f4e65
Eventually, there will probably be a `crate` visibility specifier that does the same thing as `pub(crate)`. This commit replaces `pub` with `pub(crate)`, so when `crate` is available we can easily switch to it.
29 lines
643 B
Rust
29 lines
643 B
Rust
use crate::common::*;
|
|
|
|
#[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,
|
|
}
|
|
|
|
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> {
|
|
CompilationError {
|
|
column: self.column,
|
|
offset: self.offset,
|
|
line: self.line,
|
|
text: self.text,
|
|
width: self.length,
|
|
kind,
|
|
}
|
|
}
|
|
}
|