mirror of
https://forge.katzen.cafe/katzen-cafe/iowo.git
synced 2025-10-30 09:07:57 +01:00
start with bare basics
This commit is contained in:
commit
b71b7f309b
10 changed files with 712 additions and 0 deletions
58
src/lexer.rs
Normal file
58
src/lexer.rs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
use logos::Logos;
|
||||
|
||||
#[derive(Logos, Debug, PartialEq)]
|
||||
#[logos(skip r"[\s]+")]
|
||||
pub enum Token<'a> {
|
||||
#[regex("[\\w]+", |lex| lex.slice())]
|
||||
Word(&'a str),
|
||||
#[regex("[\\d]+", priority = 2, callback = |lex| lex.slice().parse::<i64>().unwrap())]
|
||||
IntLiteral(i64),
|
||||
#[regex("[\\d]+.[\\d]+", |lex| lex.slice().parse::<f64>().unwrap())]
|
||||
FloatLiteral(f64),
|
||||
#[regex(r#""([^"\\]|\\["\\bnfrt]|u[a-fA-F0-9]{4})*""#, |lex| lex.slice().to_owned())]
|
||||
StringLiteral(String),
|
||||
#[token("def")]
|
||||
Define,
|
||||
#[token("type")]
|
||||
Type,
|
||||
#[token("->")]
|
||||
RightArrow,
|
||||
#[token("|")]
|
||||
Pipe,
|
||||
#[token("[")]
|
||||
BracketOpening,
|
||||
#[token("]")]
|
||||
BracketClosing,
|
||||
#[token("(")]
|
||||
ParensOpening,
|
||||
#[token(")")]
|
||||
ParensClosing,
|
||||
#[token("{")]
|
||||
BraceOpening,
|
||||
#[token("}")]
|
||||
BraceClosing,
|
||||
#[token("+")]
|
||||
Plus,
|
||||
#[token("-")]
|
||||
Minus,
|
||||
#[token("*")]
|
||||
Multiply,
|
||||
#[token("/")]
|
||||
Divide,
|
||||
#[token("%")]
|
||||
Percent,
|
||||
#[token("&")]
|
||||
Ampersand,
|
||||
#[token(":")]
|
||||
Colon,
|
||||
#[token(";")]
|
||||
Semicolon,
|
||||
#[token(".")]
|
||||
Dot,
|
||||
#[token(",")]
|
||||
Comma,
|
||||
#[token("!")]
|
||||
ExclaimationMark,
|
||||
#[token("?")]
|
||||
QuestionMark,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue