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
1 parent
6d44cc5
commit 8658ee9
Showing
7 changed files
with
211 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use std::path::PathBuf; | ||
use std::borrow::Cow; | ||
|
||
use anyhow::anyhow; | ||
|
||
use rust_embed::RustEmbed; | ||
|
||
use crate::adlgen::sys::adlast2::ModuleName; | ||
|
||
#[derive(RustEmbed)] | ||
#[folder = "../../adl/stdlib/"] | ||
struct Asset; | ||
|
||
pub fn std_modules() -> Vec<ModuleName> { | ||
let mut mods = vec![]; | ||
for name in Asset::iter() { | ||
let mut path = PathBuf::from(name.to_string()); | ||
if let Some(e) = path.extension() { | ||
if e == "adl" { | ||
path.set_extension(""); | ||
mods.push(path.to_str().unwrap().replace("/", ".")); | ||
} | ||
} | ||
}; | ||
mods | ||
} | ||
|
||
pub fn get_stdlib(mn: &ModuleName, ext: &str) -> Option<Cow<'static, [u8]>> { | ||
let mut fname = mn.replace(".", "/"); | ||
fname.push_str(".adl"); | ||
if ext != "" { | ||
fname.push_str("-"); | ||
fname.push_str(ext); | ||
} | ||
if let Some(f) = Asset::get(fname.as_str()) { | ||
return Some(f.data); | ||
} | ||
None | ||
} | ||
|
||
pub(crate) fn dump(opts: &crate::cli::DumpStdlibOpts) -> Result<(), anyhow::Error> { | ||
std::fs::create_dir_all(&opts.outputdir).map_err(|_| anyhow!("can't create output dir '{:?}'", opts.outputdir))?; | ||
for name in Asset::iter() { | ||
let mut path = opts.outputdir.clone(); | ||
path.push(name.as_ref()); | ||
if let Some(data) = Asset::get(name.as_ref()) { | ||
std::fs::create_dir_all(path.parent().unwrap()).map_err(|_| anyhow!("can't create output dir for '{:?}'", &path))?; | ||
std::fs::write(&path, data.data.as_ref()).map_err(|s| anyhow!("can't write file '{:?}' error {}", &path, s))?; | ||
} else { | ||
return Err(anyhow!("could get the contents for {}", name)); | ||
} | ||
} | ||
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
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 |
---|---|---|
|
@@ -4,5 +4,6 @@ pub mod cli; | |
pub mod parser; | ||
pub mod processing; | ||
pub mod utils; | ||
pub mod adlstdlib; | ||
|
||
mod adlgen_dev; |
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