Skip to content

Commit

Permalink
fleshing out verification command
Browse files Browse the repository at this point in the history
  • Loading branch information
timbod7 committed Dec 7, 2022
1 parent a360977 commit 0805b16
Showing 4 changed files with 48 additions and 13 deletions.
2 changes: 2 additions & 0 deletions rust/compiler/src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -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 {
27 changes: 27 additions & 0 deletions rust/compiler/src/cli/verify.rs
Original file line number Diff line number Diff line change
@@ -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<PathBuf>) -> Box<dyn AdlLoader> {
let loaders = paths.iter().map(loader_from_dir_tree).collect();
Box::new(MultiLoader::new(loaders))
}

pub fn loader_from_dir_tree(path: &PathBuf) -> Box<dyn AdlLoader> {
Box::new(DirTreeLoader::new(path.clone()))
}
8 changes: 5 additions & 3 deletions rust/compiler/src/main.rs
Original file line number Diff line number Diff line change
@@ -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),
}
}
24 changes: 14 additions & 10 deletions rust/compiler/src/parser/mod.rs
Original file line number Diff line number Diff line change
@@ -363,6 +363,11 @@ fn oversion_(i: Input) -> Res<Input, u64> {
}

pub fn field(i: Input) -> Res<Input, adlast::Field<TypeExpr0>> {
context("field", field0)(i)
}


pub fn field0(i: Input) -> Res<Input, adlast::Field<TypeExpr0>> {
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<Input, Vec<adlast::Ident>> {
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<VerboseError<Input>>) -> 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<Input>) -> 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<Input>) -> 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)
}

0 comments on commit 0805b16

Please sign in to comment.