51 lines
851 B
Rust
51 lines
851 B
Rust
use logos::Logos;
|
|
|
|
#[derive(Logos, Debug, PartialEq)]
|
|
pub enum Token {
|
|
#[token(".")]
|
|
Period,
|
|
|
|
// Or regular expressions.
|
|
#[token("i32")]
|
|
Int32,
|
|
|
|
#[token("(")]
|
|
RightParen,
|
|
|
|
#[token(")")]
|
|
LeftParen,
|
|
|
|
#[token("add")]
|
|
AddOp,
|
|
|
|
#[token("func")]
|
|
FuncIden,
|
|
#[token("export")]
|
|
Export,
|
|
#[token("module")]
|
|
Module,
|
|
|
|
#[token("param")]
|
|
Param,
|
|
|
|
#[token("result")]
|
|
Result,
|
|
|
|
#[regex("get_local")]
|
|
GetLocal,
|
|
|
|
#[regex(r"\$[a-zA-Z]+")]
|
|
FunctionName,
|
|
|
|
#[regex(r##""[a-zA-Z]+""##)]
|
|
WasmString,
|
|
|
|
// Logos requires one token variant to handle errors,
|
|
// it can be named anything you wish.
|
|
#[error]
|
|
// We can also use this variant to define whitespace,
|
|
// or any other matches we wish to skip.
|
|
#[regex(r"[ \t\n\f]+", logos::skip)]
|
|
Error,
|
|
}
|