crftng-intrprtrs/src/lexer/token.rs

58 lines
646 B
Rust

use crate::error::Location;
#[derive(Debug)]
pub struct Token<'a> {
pub token_type: TokenType,
pub location: Location<'a>,
}
impl<'a> Token<'a> {
pub fn as_tuple<'b>(&'b self) -> (&'b TokenType, Location<'a>) {
(&self.token_type, self.location)
}
}
#[derive(Debug)]
pub enum TokenType {
LeftParen,
RightParen,
LeftBrace,
RightBrace,
Comma,
Dot,
Minus,
Plus,
Semicolon,
Slash,
Star,
Bang,
BangEqual,
Equal,
EqualEqual,
Greater,
GreaterEqual,
Less,
LessEqual,
Identifier(String),
String(String),
Int(i32),
Float(f32),
And,
Else,
False,
Fun,
For,
If,
Nil,
Or,
Print,
Return,
True,
Let,
While,
Eof,
}