srdf/lib.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
//! This crate contains a _Simple_ RDF wrapper which can be useful to work with RDF data
//!
//! It contains several traits that handle RDF data:
//! - [`SRDFBasic`]: Basic comparisons on RDF nodes
//! - [`SRDF`]: Definitions on RDF graphs
//! - [`FocusRDF`]: RDF graphs with a focus node
//! - [`RDFNodeParse`]: RDF graphs that can be parsed
pub mod async_srdf;
pub mod bnode;
pub mod lang;
pub mod literal;
pub mod neighs;
pub mod numeric_literal;
pub mod object;
pub mod query_srdf;
pub mod rdf;
pub mod rdf_data_config;
pub mod rdf_format;
pub mod shacl_path;
pub mod srdf;
pub mod srdf_basic;
pub mod srdf_builder;
pub mod srdf_graph;
pub mod srdf_parser;
pub mod srdf_sparql;
pub mod subject;
pub mod triple;
pub mod vocab;
pub use crate::async_srdf::*;
pub use crate::neighs::*;
pub use crate::query_srdf::*;
pub use crate::rdf_data_config::*;
pub use crate::srdf::*;
pub use crate::srdf_basic::*;
pub use bnode::*;
pub use object::*;
pub use rdf::*;
pub use rdf_format::*;
pub use shacl_path::*;
pub use srdf_builder::*;
pub use srdf_graph::*;
pub use srdf_parser::*;
pub use srdf_sparql::*;
pub use subject::*;
pub use triple::*;
pub use vocab::*;
/// Creates an integer literal
///
#[macro_export]
macro_rules! int {
(
$n: tt
) => {
$crate::literal::Literal::integer($n)
};
}
/// Declares a named RDF parser which can be reused.
///
/// The expression which creates the parser should have no side effects as it may be called
/// multiple times even during a single parse attempt.
///
/// This macro is useful when declaring mutually recursive parsers
///
/// ```
///
/// #[macro_use]
/// use iri_s::IriS;
/// use srdf::{rdf_parser, RDFParser, RDF, RDFFormat, FocusRDF, satisfy, ReaderMode, RDFNodeParse, SRDF, SRDFBasic, property_value, rdf_list, set_focus, parse_property_value_as_list};
/// use srdf::srdf_graph::SRDFGraph;
///
/// rdf_parser!{
/// fn is_term['a, RDF](term: &'a RDF::Term)(RDF) -> ()
/// where [
/// ] {
/// let name = format!("is_{term}");
/// satisfy(|t| { t == *term }, name.as_str())
/// }
/// }
///
/// let s = r#"prefix : <http://example.org/>
/// :x :p 1.
/// "#;
/// let mut graph = SRDFGraph::from_str(s, &RDFFormat::Turtle, None, &ReaderMode::default()).unwrap();
/// let x = IriS::new_unchecked("http://example.org/x");
/// let term = <SRDFGraph as SRDFBasic>::iri_s2term(&x);
/// assert_eq!(is_term(&term).parse(&x, graph).unwrap(), ())
/// ````
#[macro_export]
macro_rules! rdf_parser {
(
$(#[$attr:meta])*
$fn_vis: vis fn $name: ident [$($type_params: tt)*]( $($arg: ident : $arg_type: ty),*)
($input_type: ty) -> $output_type: ty
where [$($where_clause: tt)*]
$parser: block
) => {
$crate::combine_rdf_parser_impl!{
#[allow(non_camel_case_types)]
#[doc(hidden)]
$fn_vis struct $name;
$(#[$attr])*
$fn_vis fn $name [$($type_params)*]($($arg : $arg_type),*)($input_type) -> $output_type
where [$($where_clause)*]
$parser
}
};
}
/// Auxiliary macro that is invoked from `rdf_parser` which supports different templates
#[macro_export]
macro_rules! combine_rdf_parser_impl {
(
$(#[$derive:meta])*
$struct_vis: vis struct $type_name: ident;
$(#[$attr:meta])*
$fn_vis: vis fn $name: ident [$($type_params: tt)*]( $($arg: ident : $arg_type: ty),*)
($input_type: ty) -> $output_type: ty
where [$($where_clause: tt)*]
$parser: block
) => {
$(#[$derive])*
$struct_vis struct $type_name<$($type_params)*>
where
$input_type : $crate::FocusRDF,
$($where_clause)*
{
$(pub $arg : $arg_type,)*
__marker: ::std::marker::PhantomData<$input_type>,
}
impl <$($type_params)*> $crate::RDFNodeParse<$input_type> for $type_name<$($type_params)*>
where
$input_type : $crate::FocusRDF,
$($where_clause)*
{
type Output = $output_type;
#[inline]
fn parse_impl(
&mut self,
input: &mut $input_type,
) -> $crate::srdf_parser::PResult<$output_type>
{
let $type_name { $( $arg: ref mut $arg,)* .. } = *self;
let r = $parser.parse_impl(input)?;
Ok(r)
}
}
$(#[$attr])*
#[inline]
$fn_vis fn $name< $($type_params)* >(
$($arg : $arg_type),*
) -> $type_name<$($type_params)*>
where
$input_type: $crate::FocusRDF,
$($where_clause)*
{
$type_name {
$($arg,)*
__marker: ::std::marker::PhantomData,
}
}
}
}
#[macro_export]
macro_rules! combine_parsers {
($first : expr) => {
$first
};
($first : expr, $($rest : expr),+) => {
combine_vec($first, combine_parsers!($($rest),+))
}
}