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
) => { ... };
}
Expand description
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(), ())