This repository has been archived on 2024-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
huia/huiac/src/main.rs
2018-09-06 19:41:43 +12:00

34 lines
939 B
Rust

extern crate clap;
extern crate huia_parser;
use clap::{App, Arg};
use std::fs;
use std::process;
const VERSION: &'static str = env!("CARGO_PKG_VERSION");
fn main() {
let matches = App::new("huiac")
.version(VERSION)
.author("James Harton <james@automat.nz>")
.about("The compiler for the Huia programming language.")
.arg(
Arg::with_name("INPUT")
.help("The source file to compile")
.required(true)
.index(1),
)
.get_matches();
let source_path = matches.value_of("INPUT").unwrap();
let source_file = fs::read_to_string(source_path).expect("Unable to read input file");
let result = huia_parser::parse_file(&source_file);
if result.is_ok() {
println!("{:#?}", result.unwrap());
process::exit(0);
} else {
println!("{}", result.err().unwrap());
process::exit(1);
}
}