2022-10-21 13:52:34 +11:00
|
|
|
use std::path::Path;
|
2022-10-21 14:05:56 +11:00
|
|
|
|
2022-10-20 13:47:43 +11:00
|
|
|
use nom_locate::LocatedSpan;
|
|
|
|
use std::str;
|
|
|
|
|
2022-10-21 14:05:56 +11:00
|
|
|
mod preset;
|
2022-10-20 13:47:43 +11:00
|
|
|
mod token;
|
|
|
|
mod value;
|
2022-10-21 13:52:34 +11:00
|
|
|
|
|
|
|
pub(crate) type Span<'a> = LocatedSpan<&'a str>;
|
|
|
|
pub(crate) use token::Token;
|
2022-10-20 13:47:43 +11:00
|
|
|
|
|
|
|
use crate::error::ParsePresetError;
|
2022-10-21 13:52:34 +11:00
|
|
|
use crate::parse::preset::resolve_values;
|
|
|
|
use crate::parse::value::parse_preset;
|
|
|
|
use crate::Preset;
|
|
|
|
|
|
|
|
pub(crate) fn remove_if<T>(values: &mut Vec<T>, f: impl FnMut(&T) -> bool) -> Option<T> {
|
2022-10-21 14:05:56 +11:00
|
|
|
values.iter().position(f).map(|idx| values.remove(idx))
|
2022-10-21 13:52:34 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Preset {
|
|
|
|
pub fn try_parse(path: impl AsRef<Path>) -> Result<Preset, ParsePresetError> {
|
|
|
|
let values = parse_preset(path)?;
|
|
|
|
Ok(resolve_values(values))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use crate::Preset;
|
2022-10-21 14:05:56 +11:00
|
|
|
use std::path::PathBuf;
|
2022-10-21 13:52:34 +11:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
pub fn parse_preset() {
|
|
|
|
let root =
|
2022-10-21 14:23:20 +11:00
|
|
|
PathBuf::from("test/slang-shaders/ntsc/ntsc-256px-svideo.slangp");
|
2022-10-21 13:52:34 +11:00
|
|
|
let basic = Preset::try_parse(root);
|
|
|
|
eprintln!("{:#?}", basic);
|
|
|
|
assert!(basic.is_ok());
|
|
|
|
}
|
2022-10-21 14:05:56 +11:00
|
|
|
}
|