shorten file

This commit is contained in:
Erin 2023-01-04 15:30:03 +01:00 committed by ondra05
parent acd7cad29e
commit 1d91e68b05

View file

@ -1,137 +1,60 @@
use logos::{Lexer, Logos}; use logos::{Lexer, Logos};
#[derive(Logos, Debug, PartialEq, Eq, Clone)] #[derive(Logos, Debug, PartialEq, Eq, Clone)]
#[rustfmt::skip]
pub enum Token { pub enum Token {
// Symbols // Symbols
#[token("(")] #[token("(")] LeftParen,
LeftParen, #[token(")")] RightParen,
#[token("[")] LeftBracket,
#[token(")")] #[token("]")] RightBracket,
RightParen, #[token("{")] LeftCurly,
#[token("}")] RightCurly,
#[token("[")] #[token(";")] Semicolon,
LeftBracket, #[token(",")] Comma,
#[token("]")]
RightBracket,
#[token("{")]
LeftCurly,
#[token("}")]
RightCurly,
#[token(";")]
Semicolon,
#[token(",")]
Comma,
// Operators // Operators
#[token("+")] #[token("+")] Plus,
Plus, #[token("-")] Minus,
#[token("*")] Star,
#[token("-")] #[token("/")] FwdSlash,
Minus, #[token("=:")] Assign,
#[token("<=")] Arrow,
#[token("*")]
Star,
#[token("/")]
FwdSlash,
#[token("=:")]
Assign,
#[token("<=")]
Arrow,
// Logical operators // Logical operators
#[token("<")] #[token("<")] LessThan,
LessThan, #[token(">")] GreaterThan,
#[token("=")] Equals,
#[token(">")] #[token("ain't")] Aint,
GreaterThan,
#[token("=")]
Equals,
#[token("ain't")]
Aint,
// Keywords // Keywords
#[token("functio")] #[token("functio")] Functio,
Functio, #[token("bff")] Bff,
#[token("dim")] Dim,
/// Brain fuck FFI #[token("print")] Print,
#[token("bff")] #[token("read")] Read,
Bff, #[token("melo")] Melo,
#[token("T-Dark")] TDark,
/// Variable bro
#[token("dim")]
Dim,
/// Prints the preceding things
#[token("print")]
Print,
/// Read input into preceding variable
#[token("read")]
Read,
/// Ban the following variable from ever being used again
#[token("melo")]
Melo,
#[token("T-Dark")]
TDark,
// Control flow keywords // Control flow keywords
#[token("unless")] #[token("unless")] Unless,
Unless, #[token("loop")] Loop,
#[token("enough")] Enough,
#[token("and again")] AndAgain,
#[token("finally")] Finally,
#[token("rlyeh")] Rlyeh,
#[token("loop")] #[token("rickroll")] Rickroll,
Loop,
/// Break out of the loop
#[token("enough")]
Enough,
/// Jump at the start of the loop
#[token("and again")]
AndAgain,
/// Run at the end of the program
#[token("finally")]
Finally,
/// Crash with random error (see discussion #17)
#[token("rlyeh")]
Rlyeh,
#[token("rickroll")]
Rickroll,
// Literals // Literals
/// String #[token("/*", get_string)] String(String),
#[token("/*", get_string)] #[regex(r"-?[0-9]+", get_value)] Integer(isize),
String(String), #[regex(r"\p{XID_Start}", get_value)] Char(char),
/// Integer
#[regex(r"-?[0-9]+", get_value)]
Integer(isize),
// A character (to be base-55 converted)
#[regex(r"\p{XID_Start}", get_value)]
Char(char),
/// An identifier
#[regex(r"\p{XID_Start}[\p{XID_Continue}]+", get_ident)] #[regex(r"\p{XID_Start}[\p{XID_Continue}]+", get_ident)]
#[token("and ", |_| "and".to_owned())] #[token("and ", |_| "and".to_owned())]
Identifier(String), Identifier(String),
#[regex(r"owo .*")] #[regex(r"owo .*")] Comment,
Comment,
#[regex(r"[ \t\n\f]+", logos::skip)] #[regex(r"[ \t\n\f]+", logos::skip)]
#[error] #[error]