2021-04-12 13:20:45 -05:00
|
|
|
use logos::Logos;
|
|
|
|
|
|
|
|
#[derive(Logos, Debug, PartialEq)]
|
|
|
|
pub enum Token {
|
2021-04-18 15:33:55 -05:00
|
|
|
// Literals
|
|
|
|
/// True, False
|
|
|
|
#[regex("true|false")]
|
|
|
|
Boolean,
|
|
|
|
|
|
|
|
/// Always, Sometimes, Never
|
|
|
|
#[regex("always|sometimes|never")]
|
|
|
|
Aboolean,
|
|
|
|
|
|
|
|
/// String
|
|
|
|
#[regex("\"(\\.|[^\"])*\"")]
|
|
|
|
String,
|
|
|
|
|
|
|
|
/// Integer
|
|
|
|
#[regex(r"[0-9]+")]
|
|
|
|
Integer,
|
|
|
|
|
2021-04-12 13:20:45 -05:00
|
|
|
/// A C-complaint identifier
|
|
|
|
#[regex(r"[a-zA-Z_][a-zA-Z_0-9]*")]
|
|
|
|
Identifier,
|
|
|
|
|
|
|
|
#[token("(")]
|
|
|
|
LeftParenthesis,
|
|
|
|
|
|
|
|
#[token(")")]
|
|
|
|
RightParenthesis,
|
|
|
|
|
|
|
|
#[token("[")]
|
|
|
|
LeftBracket,
|
|
|
|
|
|
|
|
#[token("]")]
|
|
|
|
RightBracket,
|
|
|
|
|
|
|
|
#[token("{")]
|
|
|
|
LeftBrace,
|
|
|
|
|
|
|
|
#[token("}")]
|
|
|
|
RightBrace,
|
|
|
|
|
|
|
|
#[token(";")]
|
|
|
|
Semicolon,
|
|
|
|
|
2021-04-26 03:44:42 -05:00
|
|
|
#[token(".")]
|
|
|
|
FullStop,
|
|
|
|
|
|
|
|
#[token(",")]
|
|
|
|
Comma,
|
|
|
|
|
2021-04-12 13:20:45 -05:00
|
|
|
#[regex(r"#.*")]
|
|
|
|
Comment,
|
|
|
|
|
2021-04-18 09:39:43 -05:00
|
|
|
// Operators
|
2021-04-12 13:20:45 -05:00
|
|
|
#[token("-")]
|
|
|
|
Subtract,
|
|
|
|
|
|
|
|
#[token("+")]
|
|
|
|
Addition,
|
|
|
|
|
|
|
|
#[token("*")]
|
|
|
|
Multiply,
|
|
|
|
|
|
|
|
#[token("/")]
|
|
|
|
Divide,
|
|
|
|
|
|
|
|
#[token("=")]
|
|
|
|
Assignment,
|
|
|
|
|
2021-04-26 03:44:42 -05:00
|
|
|
// Logical operators
|
|
|
|
#[token("<")]
|
|
|
|
OpLt,
|
|
|
|
|
|
|
|
#[token(">")]
|
|
|
|
OpGt,
|
|
|
|
|
|
|
|
#[token("==")]
|
|
|
|
OpEq,
|
|
|
|
|
|
|
|
#[token("!=")]
|
|
|
|
OpNeq,
|
|
|
|
|
2021-04-12 13:20:45 -05:00
|
|
|
/// Base52 based character ('a')
|
|
|
|
#[token("'.*'")]
|
|
|
|
Char,
|
|
|
|
|
|
|
|
#[token("functio")]
|
|
|
|
Function,
|
|
|
|
|
|
|
|
/// Brain fuck FFI
|
|
|
|
#[token("bff")]
|
|
|
|
BfFunction,
|
|
|
|
|
|
|
|
/// Variable bro
|
|
|
|
#[token("var")]
|
|
|
|
Variable,
|
|
|
|
|
|
|
|
/// Prints the preceding things
|
|
|
|
#[token("print")]
|
|
|
|
Print,
|
|
|
|
|
|
|
|
/// Ban the following variable from ever being used again
|
|
|
|
#[token("melo")]
|
|
|
|
Melo,
|
|
|
|
|
|
|
|
#[token("T-Dark")]
|
|
|
|
TDark,
|
|
|
|
|
2021-04-18 09:39:43 -05:00
|
|
|
// Expressions
|
|
|
|
#[token("if")]
|
|
|
|
If,
|
|
|
|
|
|
|
|
#[token("else")]
|
|
|
|
Else,
|
|
|
|
|
|
|
|
#[token("loop")]
|
|
|
|
Loop,
|
|
|
|
|
2021-04-12 13:20:45 -05:00
|
|
|
#[regex(r"[ \t\n\f]+", logos::skip)]
|
|
|
|
#[error]
|
|
|
|
Error,
|
2021-04-11 17:22:06 -05:00
|
|
|
}
|