diff --git a/rust/compiler/src/cli/mod.rs b/rust/compiler/src/cli/mod.rs index 2ab26c3f..6d1e0ebe 100644 --- a/rust/compiler/src/cli/mod.rs +++ b/rust/compiler/src/cli/mod.rs @@ -1,6 +1,8 @@ use gumdrop::Options; use std::path::PathBuf; +pub mod verify; + // Define options for the program. #[derive(Debug, Options)] pub struct CliOptions { diff --git a/rust/compiler/src/cli/verify.rs b/rust/compiler/src/cli/verify.rs new file mode 100644 index 00000000..9464842f --- /dev/null +++ b/rust/compiler/src/cli/verify.rs @@ -0,0 +1,27 @@ +use std::path::PathBuf; + +use super::VerifyOpts; + +use crate::processing::loader::{MultiLoader, DirTreeLoader, AdlLoader}; + +pub fn verify(opts: &VerifyOpts) { + let mut loader = loader_from_search_paths(&opts.searchdir); + for m in &opts.modules { + let lm = loader.load(m); + match lm { + Ok(Some(_)) => println!("Verified module {}", m), + Ok(None) => println!("Failed to find module {}", m), + Err(e) => println!("Failed to verify module {}: {}", m, e), + + } + } +} + +pub fn loader_from_search_paths(paths: &Vec) -> Box { + let loaders = paths.iter().map(loader_from_dir_tree).collect(); + Box::new(MultiLoader::new(loaders)) +} + +pub fn loader_from_dir_tree(path: &PathBuf) -> Box { +Box::new(DirTreeLoader::new(path.clone())) +} \ No newline at end of file diff --git a/rust/compiler/src/main.rs b/rust/compiler/src/main.rs index a68847ea..e7fd3b65 100644 --- a/rust/compiler/src/main.rs +++ b/rust/compiler/src/main.rs @@ -1,11 +1,13 @@ -use compiler::cli::CliOptions; +use compiler::cli::{CliOptions, Command}; use gumdrop::Options; +use compiler::cli::verify::verify; + fn main() { let opts = CliOptions::parse_args_default_or_exit(); match opts.command { - None => println!("{}", CliOptions::usage()), - Some(cmd) => println!("{:#?}", cmd), + None => println!("{}", CliOptions::self_usage(&opts)), + Some(Command::Verify(opts)) => verify(&opts), } } diff --git a/rust/compiler/src/parser/mod.rs b/rust/compiler/src/parser/mod.rs index c015cc3d..00bf6ac8 100644 --- a/rust/compiler/src/parser/mod.rs +++ b/rust/compiler/src/parser/mod.rs @@ -363,6 +363,11 @@ fn oversion_(i: Input) -> Res { } pub fn field(i: Input) -> Res> { + context("field", field0)(i) +} + + +pub fn field0(i: Input) -> Res> { let (i, annotations) = many0(prefix_annotation)(i)?; let (i, texpr) = ws(type_expr)(i)?; let (i, name_) = ws(spanned(ident0))(i)?; @@ -437,7 +442,7 @@ pub fn type_params(i: Input) -> Res> { map( opt(delimited( wtag("<"), - separated_list0(ws(tag(",")), map(ident0, |i| i.to_string())), + separated_list0(ws(tag(",")), map(ws(ident0), |i| i.to_string())), wtag(">"), )), |idents| idents.unwrap_or_else(|| Vec::new()), @@ -574,17 +579,16 @@ where pub fn process_parse_error(e: Err>) -> anyhow::Error { match e { Err::Incomplete(_) => return anyhow!("incomplete input"), - Err::Error(e) => process_parse_error1(e), + Err::Error(e) => process_parse_error1( e), Err::Failure(e) => process_parse_error1(e), } } -fn process_parse_error1(_e: VerboseError) -> anyhow::Error { - // let errors = e - // .errors - // .into_iter() - // .map(|(input, error)| (*input.fragment(), error)) - // .collect(); - // let x = convert_error( - anyhow!("error") +fn process_parse_error1(e: VerboseError) -> anyhow::Error { + let messages: Vec<_> = e + .errors + .into_iter() + .map(|(input, error)| format!("line: {}, column: {}, error: {:?}",input.location_line(), input.get_column(), error)) + .collect(); + anyhow!("parse error: {:#?}", messages) }