Add variable resolution; the error behavior is pretty bad here.
This commit is contained in:
47
src/bin.rs
47
src/bin.rs
@@ -3,10 +3,8 @@ use codespan_reporting::diagnostic::Diagnostic;
|
||||
use codespan_reporting::files::SimpleFiles;
|
||||
use codespan_reporting::term;
|
||||
use codespan_reporting::term::termcolor::{ColorChoice, StandardStream};
|
||||
use ngr::error::Error;
|
||||
use ngr::syntax::Program;
|
||||
use pretty::{Arena, Pretty};
|
||||
use std::fs;
|
||||
use ngr::passes::run_front_end;
|
||||
use pretty::Arena;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[clap(author, version, about, long_about = None)]
|
||||
@@ -19,36 +17,27 @@ struct CommandLineArguments {
|
||||
file: String,
|
||||
}
|
||||
|
||||
fn compile_file(
|
||||
file_database: &mut SimpleFiles<String, String>,
|
||||
initial_file_name: &str,
|
||||
) -> Result<Program, Error> {
|
||||
let initial_file_contents = fs::read_to_string(initial_file_name)?;
|
||||
let initial_file = file_database.add(initial_file_name.to_string(), initial_file_contents);
|
||||
let db_version = file_database.get(initial_file)?;
|
||||
let db_version_source = db_version.source();
|
||||
Ok(Program::parse(initial_file, db_version_source)?)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = CommandLineArguments::parse();
|
||||
let mut file_database = SimpleFiles::new();
|
||||
let initial_file_name = &args.file;
|
||||
let mut hil_conversion_result = run_front_end(&mut file_database, initial_file_name);
|
||||
|
||||
match compile_file(&mut file_database, initial_file_name) {
|
||||
Ok(p) => {
|
||||
let arena = Arena::new();
|
||||
p.pretty(&arena)
|
||||
.into_doc()
|
||||
.render_colored(72, StandardStream::stdout(ColorChoice::Auto))
|
||||
.unwrap()
|
||||
}
|
||||
Err(e) => {
|
||||
let diagnostic = Diagnostic::from(e);
|
||||
let writer = StandardStream::stderr(ColorChoice::Auto);
|
||||
let config = codespan_reporting::term::Config::default();
|
||||
let writer = StandardStream::stderr(ColorChoice::Auto);
|
||||
let config = codespan_reporting::term::Config::default();
|
||||
|
||||
term::emit(&mut writer.lock(), &config, &file_database, &diagnostic).unwrap();
|
||||
}
|
||||
for error in hil_conversion_result.errors.drain(..) {
|
||||
term::emit(&mut writer.lock(), &config, &file_database, &Diagnostic::from(error)).unwrap();
|
||||
}
|
||||
for warning in hil_conversion_result.warnings.drain(..) {
|
||||
term::emit(&mut writer.lock(), &config, &file_database, &Diagnostic::from(warning)).unwrap();
|
||||
}
|
||||
|
||||
if let Some((tree, variable_map)) = hil_conversion_result.result {
|
||||
let arena = Arena::new();
|
||||
tree.pretty(&variable_map, &arena)
|
||||
.into_doc()
|
||||
.render_colored(72, StandardStream::stdout(ColorChoice::Auto))
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user