Changed name of TokenType to Token.

This commit is contained in:
Goren Barak 2023-11-24 18:40:54 -05:00
parent cfdb31ed7a
commit 94e7c083cd
2 changed files with 13 additions and 13 deletions

View file

@ -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, // ;
@ -83,8 +83,8 @@ pub enum TokenType {
// LITERALS
#[regex(r#"("[^"]*")|('[^']*')"#)]
String, // A string literal.
#[regex("[0-9]+")]
Number, // An integer.
#[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.
#[token("true")]
@ -95,10 +95,10 @@ pub enum TokenType {
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()));
}

View file

@ -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 { () => {} }"))
}