Add support for +=, -=, *=, and /= operators. This is basically just
syntactic sugar, but it's still nice to have
a += 1
compiles to the equivalent of
a = a + 1
with all the same implications of scoping rules.
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
76 lines
954 B
Rust
76 lines
954 B
Rust
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
|
pub enum TokenKind {
|
|
// Keywords
|
|
Return,
|
|
If,
|
|
Else,
|
|
True,
|
|
False,
|
|
Nil,
|
|
Import,
|
|
From,
|
|
|
|
// Expressions
|
|
Name,
|
|
Number,
|
|
String,
|
|
|
|
// Binary operators
|
|
Plus,
|
|
Minus,
|
|
Star,
|
|
Slash,
|
|
|
|
// Augmented assignment operators
|
|
PlusEq,
|
|
MinusEq,
|
|
StarEq,
|
|
SlashEq,
|
|
|
|
// Unary operators (not already covered)
|
|
Bang,
|
|
|
|
// Boolean operators
|
|
And,
|
|
Or,
|
|
|
|
// Comparison
|
|
BangEq,
|
|
EqEq,
|
|
Greater,
|
|
GreaterEq,
|
|
Less,
|
|
LessEq,
|
|
|
|
// Braces, parens, etc
|
|
LParen,
|
|
RParen,
|
|
LBrace,
|
|
RBrace,
|
|
LBracket,
|
|
RBracket,
|
|
|
|
// Assignment
|
|
Eq,
|
|
|
|
// Dot, comma
|
|
Dot,
|
|
Comma,
|
|
Arrow,
|
|
Colon,
|
|
|
|
// Line end
|
|
Eol,
|
|
|
|
// File end
|
|
Eof,
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct Token {
|
|
pub line: usize,
|
|
//pub index: usize,
|
|
pub text: String,
|
|
pub kind: TokenKind,
|
|
}
|