parser in rust
This commit is contained in:
parent
4844e43447
commit
ae959f7768
5 changed files with 337 additions and 5 deletions
|
@ -7,10 +7,12 @@ use std::{
|
|||
path::Path,
|
||||
};
|
||||
|
||||
use tracing::error;
|
||||
use tracing::{error, info};
|
||||
|
||||
pub mod cli;
|
||||
pub mod expression;
|
||||
pub mod keywords;
|
||||
pub mod parser;
|
||||
pub mod scanner;
|
||||
pub mod token;
|
||||
pub mod tokenizer {
|
||||
|
@ -28,7 +30,11 @@ pub mod tokenizer {
|
|||
/// Read the source code in a file and scan it to tokens.
|
||||
pub fn compile(source: &Path) -> Result<(), io::Error> {
|
||||
let input = fs::read_to_string(source)?;
|
||||
let _tokens = scanner::tokenize(&input);
|
||||
let tokens = scanner::tokenize(&input);
|
||||
match parser::generate_ast(tokens) {
|
||||
Ok(ast) => info!("{ast:?}"),
|
||||
Err(e) => error!("{e}"),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -45,6 +51,10 @@ pub fn repl() {
|
|||
Err(e) => error!("{}", e),
|
||||
}
|
||||
let input = input.trim().to_string();
|
||||
let _tokens = scanner::tokenize(&input);
|
||||
let tokens = scanner::tokenize(&input);
|
||||
match parser::generate_ast(tokens) {
|
||||
Ok(ast) => info!("{ast:?}"),
|
||||
Err(e) => error!("{e}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue