initial commit
This commit is contained in:
commit
43df8c4b0a
9 changed files with 596 additions and 0 deletions
62
src/main.rs
Normal file
62
src/main.rs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
mod ast;
|
||||
mod parsing;
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
use std::fs;
|
||||
|
||||
/// Experimental compiler for krone
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(author = "Romain P. <rpqt@rpqt.fr>")]
|
||||
#[command(version, about, long_about = None)]
|
||||
struct Cli {
|
||||
#[command(subcommand)]
|
||||
command: Commands,
|
||||
}
|
||||
|
||||
#[derive(Subcommand, Debug)]
|
||||
enum Commands {
|
||||
Parse {
|
||||
/// Path to the source file
|
||||
file: String,
|
||||
|
||||
/// Dump the AST to stdout
|
||||
#[arg(long)]
|
||||
dump_ast: bool,
|
||||
|
||||
/// Add missing return types in the AST
|
||||
#[arg(long)]
|
||||
complete_ast: bool,
|
||||
},
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let cli = Cli::parse();
|
||||
|
||||
match &cli.command {
|
||||
Commands::Parse {
|
||||
file,
|
||||
dump_ast,
|
||||
complete_ast,
|
||||
} => {
|
||||
let source = fs::read_to_string(&file).expect("could not read the source file");
|
||||
let mut ast = match parsing::parse(&source) {
|
||||
Ok(ast) => ast,
|
||||
Err(e) => panic!("Parsing error: {:#?}", e),
|
||||
};
|
||||
|
||||
if *complete_ast {
|
||||
if let Err(e) = ast.check_return_types() {
|
||||
eprintln!("{:#?}", e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if *dump_ast {
|
||||
println!("{:#?}", &ast);
|
||||
return;
|
||||
}
|
||||
|
||||
println!("Parsing OK");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue