46 lines
671 B
Rust
46 lines
671 B
Rust
|
// Rhea
|
||
|
|
||
|
use logos::Logos;
|
||
|
|
||
|
#[derive(Logos, Debug, PartialEq)]
|
||
|
#[logos(skip r"[ \t\n\f]+")] // Ignore this regex pattern between tokens
|
||
|
enum Token {
|
||
|
#[token(".")]
|
||
|
Period,
|
||
|
|
||
|
#[token("(")]
|
||
|
LeftParen,
|
||
|
|
||
|
#[token("{")]
|
||
|
LeftBrace,
|
||
|
|
||
|
#[token(")")]
|
||
|
RightParen,
|
||
|
|
||
|
#[token("}")]
|
||
|
RightBrace,
|
||
|
|
||
|
#[token("include")]
|
||
|
Include,
|
||
|
|
||
|
#[token("=")]
|
||
|
Equals,
|
||
|
|
||
|
#[token(";")]
|
||
|
Semicolon,
|
||
|
|
||
|
#[token("\"")]
|
||
|
Quote,
|
||
|
|
||
|
// Or regular expressions.
|
||
|
#[regex("[a-zA-Z]+")]
|
||
|
Text,
|
||
|
}
|
||
|
|
||
|
fn main() {
|
||
|
let mut lex = Token::lexer(include_str!("../assets/examples/library.rhea"));
|
||
|
for x in lex {
|
||
|
println!("{:?}", x);
|
||
|
}
|
||
|
}
|