grass/src/token.rs

37 lines
662 B
Rust
Raw Normal View History

2020-03-29 13:28:17 -04:00
use crate::common::Pos;
use crate::utils::IsWhitespace;
2020-03-19 19:32:11 -04:00
2020-03-29 13:28:17 -04:00
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
2020-03-19 19:32:11 -04:00
pub(crate) struct Token {
pub pos: Pos,
2020-03-29 13:28:17 -04:00
pub kind: char,
2020-03-19 19:32:11 -04:00
}
impl Token {
2020-03-29 13:28:17 -04:00
pub const fn new(pos: Pos, kind: char) -> Self {
Self { pos, kind }
2020-03-19 19:32:11 -04:00
}
pub const fn pos(&self) -> Pos {
self.pos
}
}
impl IsWhitespace for Token {
fn is_whitespace(&self) -> bool {
2020-03-29 13:28:17 -04:00
if self.kind.is_whitespace() {
2020-03-19 19:32:11 -04:00
return true;
}
false
}
}
impl IsWhitespace for &Token {
fn is_whitespace(&self) -> bool {
2020-03-29 13:28:17 -04:00
if self.kind.is_whitespace() {
2020-03-19 19:32:11 -04:00
return true;
}
false
}
}