Add codegen for new rust yunq parser.
This commit is contained in:
parent
8f35d38e93
commit
2cbf871d09
8 changed files with 261 additions and 96 deletions
|
|
@ -3,7 +3,7 @@ mod lexer;
|
|||
mod parser;
|
||||
|
||||
use std::error::Error;
|
||||
use std::fs::read_to_string;
|
||||
use std::fs;
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
|
|
@ -13,22 +13,24 @@ struct Args {
|
|||
// The .yunq file to parse
|
||||
#[arg(short, long)]
|
||||
input_path: String,
|
||||
|
||||
// The .rs file to generate
|
||||
#[arg(short, long)]
|
||||
output_path: String,
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let args = Args::parse();
|
||||
let input = read_to_string(args.input_path)?;
|
||||
let input = fs::read_to_string(args.input_path)?;
|
||||
let tokens = lexer::lex_input(&input)?;
|
||||
|
||||
let mut ast_parser = parser::Parser::new(&tokens);
|
||||
ast_parser.parse_ast()?;
|
||||
ast_parser.type_check()?;
|
||||
|
||||
for decl in ast_parser.ast() {
|
||||
println!("{:?}", decl);
|
||||
}
|
||||
let code = codegen::generate_code(ast_parser.ast());
|
||||
|
||||
println!("{}", codegen::generate_code(ast_parser.ast())?);
|
||||
fs::write(args.output_path, code)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue