Before attempt to convert buffer to dyn

This commit is contained in:
2024-11-21 19:21:15 -07:00
parent 028051a178
commit abaf58374f
3 changed files with 36 additions and 7 deletions

View File

@@ -1,21 +1,28 @@
mod parser;
mod tokenizer;
use std::io::{Read, Seek};
use clap::Parser;
use parser::Parser as ASTParser;
use tokenizer::{Tokenizer, TokenizerError};
#[derive(Debug, thiserror::Error)]
enum StationlangError {
#[error("{0}")]
#[error(transparent)]
TokenizerError(#[from] TokenizerError),
#[error(transparent)]
ParserError(#[from] parser::ParseError),
#[error(transparent)]
IoError(#[from] std::io::Error),
}
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
/// What file should be compiled
/// What file should be compiled. If not set, input will be read from stdin
#[arg(short, long)]
input_file: String,
input_file: Option<String>,
/// The default stack size for the program
#[arg(short, long, default_value_t = 512)]
stack_size: usize,
@@ -28,10 +35,28 @@ fn run_logic() -> Result<(), StationlangError> {
let args = Args::parse();
let input_file = args.input_file;
let mut tokenizer = Tokenizer::from_path(&input_file)?;
let tokenizer: Tokenizer<_> = match input_file {
Some(input_file) => Tokenizer::from_path(&input_file)?,
None => {
let mut buf = String::new();
let stdin = std::io::stdin();
while let Some(token) = tokenizer.next_token()? {
println!("{:?}", token);
let read_result = stdin.lock().read_to_string(&mut buf)?;
if read_result == 0 {
return Ok(());
}
Tokenizer::from(buf)
}
};
let mut parser = ASTParser::new(tokenizer);
let ast = parser.parse()?;
if let Some(ast) = ast {
println!("{}", ast);
}
Ok(())