2021-06-28 14:35:45 +00:00
|
|
|
pub mod compiler;
|
2021-06-29 20:32:35 +00:00
|
|
|
pub mod gen;
|
2023-07-21 16:15:30 +00:00
|
|
|
pub mod support;
|
|
|
|
pub mod syntax;
|
2021-06-28 14:35:45 +00:00
|
|
|
|
2021-09-15 12:03:33 +00:00
|
|
|
pub use support::Codec;
|
|
|
|
pub use support::Deserialize;
|
|
|
|
pub use support::ParseError;
|
|
|
|
|
2021-06-28 14:35:45 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
#[test]
|
|
|
|
fn can_access_preserves_core() {
|
|
|
|
use preserves::value::*;
|
|
|
|
assert_eq!(format!("{:?}", UnwrappedIOValue::from(3 + 4)), "7");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn simple_rendering() {
|
|
|
|
use crate::syntax::block::*;
|
2023-07-21 16:15:30 +00:00
|
|
|
use crate::*;
|
2021-06-28 14:35:45 +00:00
|
|
|
|
|
|
|
let code = semiblock![
|
|
|
|
seq!["f", parens!["a", "b", "c"]],
|
|
|
|
seq!["f", parens!["a", "b", "c"]],
|
|
|
|
seq!["f", parens!["a", "b", "c"]],
|
|
|
|
seq!["f", parens!["a", "b", "c"]],
|
|
|
|
seq!["f", parens!["a", "b", "c"]],
|
|
|
|
seq!["f", parens!["a", "b", "c"]],
|
|
|
|
seq!["g", parens![]],
|
|
|
|
parens![]
|
|
|
|
];
|
|
|
|
println!("{}", Formatter::to_string(&code));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn metaschema_parsing() -> Result<(), std::io::Error> {
|
2023-07-21 16:15:30 +00:00
|
|
|
use crate::gen::schema::*;
|
2021-09-15 13:07:46 +00:00
|
|
|
use crate::support::Parse;
|
|
|
|
use crate::support::Unparse;
|
2023-07-21 16:15:30 +00:00
|
|
|
use preserves::value::{BinarySource, IOBinarySource, Reader};
|
2021-06-28 14:35:45 +00:00
|
|
|
|
|
|
|
let mut f = std::fs::File::open("../../../schema/schema.bin")?;
|
2021-07-04 15:16:13 +00:00
|
|
|
let mut src = IOBinarySource::new(&mut f);
|
|
|
|
let mut reader = src.packed_iovalues();
|
2021-06-30 13:18:20 +00:00
|
|
|
let schema = reader.demand_next(false)?;
|
2021-09-15 13:14:36 +00:00
|
|
|
let language = crate::gen::Language::default();
|
|
|
|
let parsed = Schema::parse(&language, &schema).expect("successful parse");
|
|
|
|
assert_eq!(schema, parsed.unparse(&language));
|
2021-06-28 14:35:45 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
2021-09-19 14:43:46 +00:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! define_language {
|
|
|
|
($fname:ident () : $lang:ident < $default_value:ty > { $($field:ident : $($type:ident)::+ ,)* }) => {
|
|
|
|
pub struct $lang<N: $crate::support::preserves::value::NestedValue> {
|
|
|
|
$(pub $field: std::sync::Arc<$($type)::*<N>>),*
|
|
|
|
}
|
|
|
|
|
|
|
|
$(impl<'a, N: $crate::support::preserves::value::NestedValue> From<&'a $lang<N>> for &'a $($type)::*<N> {
|
|
|
|
fn from(v: &'a $lang<N>) -> Self {
|
|
|
|
&v.$field
|
|
|
|
}
|
|
|
|
})*
|
|
|
|
|
2021-09-20 13:38:21 +00:00
|
|
|
impl<N: $crate::support::preserves::value::NestedValue> $crate::support::NestedValueCodec
|
|
|
|
for $lang<N> {}
|
|
|
|
|
2021-09-19 14:43:46 +00:00
|
|
|
mod $fname {
|
|
|
|
use super::*;
|
|
|
|
lazy_static::lazy_static! {
|
2023-01-28 21:38:14 +00:00
|
|
|
pub static ref GLOBAL_LANG: std::sync::Arc<$lang<$default_value>> =
|
|
|
|
std::sync::Arc::new($lang {
|
|
|
|
$($field: std::sync::Arc::new($($type)::*::default())),*
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl $lang<$default_value> {
|
|
|
|
pub fn arc() -> &'static std::sync::Arc<$lang<$default_value>> {
|
|
|
|
&*$fname::GLOBAL_LANG
|
2021-09-19 14:43:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn $fname() -> &'static $lang<$default_value> {
|
|
|
|
&*$fname::GLOBAL_LANG
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|