forked from adl-lang/adl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
87 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use super::AstOpts; | ||
|
||
use anyhow::anyhow; | ||
|
||
use crate::processing::loader::loader_from_search_paths; | ||
use crate::processing::resolver::{Module1, Resolver}; | ||
|
||
pub fn ast(opts: &AstOpts) -> anyhow::Result<()> { | ||
let loader = loader_from_search_paths(&opts.searchdir); | ||
let mut resolver = Resolver::new(loader); | ||
for m in &opts.modules { | ||
let r = resolver.add_module(m); | ||
match r { | ||
Ok(()) => (), | ||
Err(e) => return Err(anyhow!("Failed to load module {}: {:?}", m, e)), | ||
} | ||
} | ||
let modules: Vec<&Module1> = resolver | ||
.get_module_names() | ||
.into_iter() | ||
.map(|mn| resolver.get_module(&mn).unwrap()) | ||
.collect(); | ||
println!("{}", serde_json::to_string_pretty(&modules).unwrap()); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,18 @@ | ||
use std::path::PathBuf; | ||
|
||
use super::VerifyOpts; | ||
|
||
use crate::processing::{ | ||
loader::{AdlLoader, DirTreeLoader, MultiLoader}, | ||
resolver::Resolver, | ||
}; | ||
use anyhow::anyhow; | ||
|
||
use crate::processing::{loader::loader_from_search_paths, resolver::Resolver}; | ||
|
||
pub fn verify(opts: &VerifyOpts) { | ||
pub fn verify(opts: &VerifyOpts) -> anyhow::Result<()> { | ||
let loader = loader_from_search_paths(&opts.searchdir); | ||
let mut resolver = Resolver::new(loader); | ||
for m in &opts.modules { | ||
let r = resolver.add_module(m); | ||
match r { | ||
Ok(()) => println!("Verified module {}", m), | ||
Err(e) => println!("Failed to verify module {}: {:?}", m, e), | ||
Err(e) => return Err(anyhow!("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())) | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,6 @@ | ||
use compiler::cli::{CliOptions, Command}; | ||
use gumdrop::Options; | ||
|
||
use compiler::cli::verify::verify; | ||
use compiler::cli::run_cli; | ||
|
||
fn main() { | ||
let opts = CliOptions::parse_args_default_or_exit(); | ||
|
||
match opts.command { | ||
None => println!("{}", CliOptions::self_usage(&opts)), | ||
Some(Command::Verify(opts)) => verify(&opts), | ||
} | ||
let exit_code = run_cli(); | ||
std::process::exit(exit_code); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#[derive(serde::Serialize)] | ||
pub enum PrimitiveType { | ||
Void, | ||
Bool, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters