Changed name of TokenType to Token.
This commit is contained in:
parent
cfdb31ed7a
commit
94e7c083cd
|
@ -3,11 +3,11 @@ use logos::Logos;
|
||||||
use logos::Lexer;
|
use logos::Lexer;
|
||||||
use core::iter::Peekable;
|
use core::iter::Peekable;
|
||||||
|
|
||||||
pub use TokenType::*;
|
pub use Token::*;
|
||||||
|
|
||||||
#[derive(Debug, Logos, PartialEq, Eq)]
|
#[derive(Debug, Logos, PartialEq, Eq)]
|
||||||
#[logos(skip r"[ \t\n\f]+")]
|
#[logos(skip r"[ \t\n\f]+")]
|
||||||
pub enum TokenType {
|
pub enum Token {
|
||||||
// SINGLE CHARACTER TOKENS
|
// SINGLE CHARACTER TOKENS
|
||||||
#[token(";")]
|
#[token(";")]
|
||||||
Semicolon, // ;
|
Semicolon, // ;
|
||||||
|
@ -83,8 +83,8 @@ pub enum TokenType {
|
||||||
// LITERALS
|
// LITERALS
|
||||||
#[regex(r#"("[^"]*")|('[^']*')"#)]
|
#[regex(r#"("[^"]*")|('[^']*')"#)]
|
||||||
String, // A string literal.
|
String, // A string literal.
|
||||||
#[regex("[0-9]+")]
|
#[regex("[0-9]+", |lex| lex.slice().parse().ok())]
|
||||||
Number, // An integer.
|
Number(u64), // An integer.
|
||||||
#[regex(r#"[^[0-9]^"^-^[ \t\n\f]^\.^=^(^)^{^}.^,^;]+[^"^-^=^\..^[ \t\n\f]^(^)^{^}^,^;]*"#)]
|
#[regex(r#"[^[0-9]^"^-^[ \t\n\f]^\.^=^(^)^{^}.^,^;]+[^"^-^=^\..^[ \t\n\f]^(^)^{^}^,^;]*"#)]
|
||||||
Identifier, // An identifier.
|
Identifier, // An identifier.
|
||||||
#[token("true")]
|
#[token("true")]
|
||||||
|
@ -95,10 +95,10 @@ pub enum TokenType {
|
||||||
Null, // none
|
Null, // none
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lex_str(this: &str) -> Vec<(TokenType, &str)> {
|
pub fn lex_str(this: &str) -> Vec<(Token, &str)> {
|
||||||
println!("\"{}\"", this);
|
println!("\"{}\"", this);
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
let mut lexer = TokenType::lexer(this);
|
let mut lexer = Token::lexer(this);
|
||||||
while let Some(Ok(token)) = lexer.next() {
|
while let Some(Ok(token)) = lexer.next() {
|
||||||
buf.push((token, lexer.slice()));
|
buf.push((token, lexer.slice()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
#![allow(warnings)]
|
#![allow(warnings)]
|
||||||
|
|
||||||
pub mod lex;
|
pub mod lex;
|
||||||
use crate::lex::tok::*;
|
|
||||||
pub mod codegen;
|
pub mod codegen;
|
||||||
use crate::codegen::fasm::*;
|
use crate::codegen::fasm::*;
|
||||||
|
use crate::lex::tok::*;
|
||||||
use crate::parse::ast::*;
|
use crate::parse::ast::*;
|
||||||
|
|
||||||
pub mod parse;
|
pub mod parse;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -42,5 +43,4 @@ fn main() {
|
||||||
|
|
||||||
|
|
||||||
// println!("{}", fc);
|
// println!("{}", fc);
|
||||||
println!("{:#?}", lex_str("macro_rules! println { () => {} }"))
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue