iowo/crates/lang/src/tokens.rs

55 lines
1.2 KiB
Rust
Raw Normal View History

2024-03-08 12:34:09 +01:00
use logos::Logos;
2024-04-03 00:08:00 +02:00
#[derive(Logos, Debug, PartialEq, Eq, Clone)]
2024-03-08 12:34:09 +01:00
#[logos(skip r"[ \t\n\f]+")]
pub enum Token<'a> {
2024-04-03 00:08:00 +02:00
// hack!
// this isn't actually supposed to be in the language.
// i just can't figure out how to automatically choose between a top level declaration
// or a top level expression
// so a declaration needs the keyword def until i can figure this out
#[token("def")]
Def,
2024-03-08 12:34:09 +01:00
#[regex("[a-zA-Z0-9_\\-]+", |lex| lex.slice())]
Word(&'a str),
#[regex("\\$[a-zA-Z0-9_\\-]+", |lex| &lex.slice()[1..])]
VarIdent(&'a str),
#[token("@..")]
InputSpread,
#[regex("\\@[a-zA-Z0-9_\\-]+", |lex| &lex.slice()[1..])]
InputIdent(&'a str),
#[token(",")]
Comma,
#[token("|")]
Pipe,
#[token("@|")]
MappingPipe,
#[token("!|")]
NullPipe,
#[token("@")]
At,
#[token(">")]
GreaterThan,
#[token("=")]
Equals,
#[token(":")]
Colon,
2024-04-03 00:08:00 +02:00
#[token(";")]
SemiColon,
2024-03-08 12:34:09 +01:00
#[token("[")]
BracketOpen,
#[token("]")]
BracketClose,
#[token("(")]
ParenOpen,
#[token(")")]
ParenClose,
#[token("{")]
BraceOpen,
#[token("}")]
BraceClose,
}
#[cfg(test)]
mod tests;