diff --git a/src/lex/tok.rs b/src/lex/tok.rs index 0484910..2b45e73 100644 --- a/src/lex/tok.rs +++ b/src/lex/tok.rs @@ -3,11 +3,11 @@ use logos::Logos; use logos::Lexer; use core::iter::Peekable; -pub use TokenType::*; +pub use Token::*; #[derive(Debug, Logos, PartialEq, Eq)] #[logos(skip r"[ \t\n\f]+")] -pub enum TokenType { +pub enum Token { // SINGLE CHARACTER TOKENS #[token(";")] Semicolon, // ; @@ -82,23 +82,23 @@ pub enum TokenType { // LITERALS #[regex(r#"("[^"]*")|('[^']*')"#)] - String, // A string literal. - #[regex("[0-9]+")] - Number, // An integer. + String, // A string literal. + #[regex("[0-9]+", |lex| lex.slice().parse().ok())] + Number(u64), // An integer. #[regex(r#"[^[0-9]^"^-^[ \t\n\f]^\.^=^(^)^{^}.^,^;]+[^"^-^=^\..^[ \t\n\f]^(^)^{^}^,^;]*"#)] - Identifier, // An identifier. + Identifier, // An identifier. #[token("true")] - True, // true + True, // true #[token("false")] - False, // false + False, // false #[token("none")] - Null, // none + Null, // none } -pub fn lex_str(this: &str) -> Vec<(TokenType, &str)> { +pub fn lex_str(this: &str) -> Vec<(Token, &str)> { println!("\"{}\"", this); let mut buf = Vec::new(); - let mut lexer = TokenType::lexer(this); + let mut lexer = Token::lexer(this); while let Some(Ok(token)) = lexer.next() { buf.push((token, lexer.slice())); } diff --git a/src/main.rs b/src/main.rs index 178a755..ba8c58d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,11 @@ #![allow(warnings)] pub mod lex; -use crate::lex::tok::*; pub mod codegen; use crate::codegen::fasm::*; +use crate::lex::tok::*; use crate::parse::ast::*; + pub mod parse; fn main() { @@ -42,5 +43,4 @@ fn main() { // println!("{}", fc); - println!("{:#?}", lex_str("macro_rules! println { () => {} }")) }