pub trait RDFNodeParse<RDF: FocusRDF> {
    type Output;

Show 13 methods // Required method fn parse_impl(&mut self, rdf: &mut RDF) -> PResult<Self::Output>; // Provided methods fn parse( &mut self, node: &IriS, rdf: &mut RDF ) -> Result<Self::Output, RDFParseError> { ... } fn flat_map<F, O>(self, f: F) -> FlatMap<Self, F> where Self: Sized, F: FnMut(Self::Output) -> PResult<O> { ... } fn and_then<F, O, E>(self, f: F) -> AndThen<Self, F> where Self: Sized, F: FnMut(Self::Output) -> Result<O, E>, E: Into<RDFParseError> { ... } fn map<F, B>(self, f: F) -> Map<Self, F> where Self: Sized, F: FnMut(Self::Output) -> B { ... } fn and<P2>(self, parser: P2) -> (Self, P2) where Self: Sized, P2: RDFNodeParse<RDF> { ... } fn then<N, F>(self, f: F) -> Then<Self, F> where Self: Sized, F: FnMut(Self::Output) -> N, N: RDFNodeParse<RDF> { ... } fn then_ref<N, F>(self, f: F) -> ThenRef<Self, F> where Self: Sized, F: FnMut(&Self::Output) -> N, N: RDFNodeParse<RDF> { ... } fn then_mut<N, F>(self, f: F) -> ThenMut<Self, F> where Self: Sized, F: FnMut(&mut Self::Output) -> N, N: RDFNodeParse<RDF> { ... } fn then_state<'a, N, F, S>( self, state: &'a mut S, f: F ) -> ThenState<'a, Self, F, S> where Self: Sized, F: FnMut(&'a mut S, Self::Output) -> N, N: RDFNodeParse<RDF> { ... } fn or<P2>(self, parser: P2) -> Or<Self, P2> where Self: Sized, P2: RDFNodeParse<RDF, Output = Self::Output> { ... } fn focus(self, node: &RDF::Term) -> SetFocus<RDF> where Self: Sized { ... } fn with<P, A>(self, parser: P) -> With<Self, P> where Self: Sized, P: RDFNodeParse<RDF, Output = A> { ... }
}
Expand description

By implementing the RDFNodeParse trait a type says that it can be used to parse RDF data which have a focus node. RDF data with a focus node have to implement the FocusRDF trait.

Required Associated Types§

source

type Output

The type which is returned if the parser is successful.

Required Methods§

source

fn parse_impl(&mut self, rdf: &mut RDF) -> PResult<Self::Output>

Parses the current focus node without modifying the state

Provided Methods§

source

fn parse( &mut self, node: &IriS, rdf: &mut RDF ) -> Result<Self::Output, RDFParseError>

Entry point to the parser. It moves the focus node of rdf to node and runs the parser.

Returns the parsed result if the parser succeeds, or an error otherwise.

source

fn flat_map<F, O>(self, f: F) -> FlatMap<Self, F>
where Self: Sized, F: FnMut(Self::Output) -> PResult<O>,

Uses f to map over the output of self. If f returns an error the parser fails.

use srdf::{RDFNodeParse, RDFFormat, RDFParseError, property_string, PResult};
    let s = r#"prefix : <http://example.org/>
    :x :p "1" .
  "#;
  let mut graph = SRDFGraph::from_str(s, &RDFFormat::Turtle, None).unwrap();
  let x = iri!("http://example.org/x");
  let p = iri!("http://example.org/p");
  fn cnv_int(s: String) -> PResult<isize> {
     s.parse().map_err(|_| RDFParseError::Custom{ msg: format!("Error converting {s}")})
  }
  let mut parser = property_string(&p).flat_map(cnv_int);
  assert_eq!(parser.parse(&x, &mut graph).unwrap(), 1)
source

fn and_then<F, O, E>(self, f: F) -> AndThen<Self, F>
where Self: Sized, F: FnMut(Self::Output) -> Result<O, E>, E: Into<RDFParseError>,

Parses with self and applies f on the result if self parses successfully. f may optionally fail with an error which is automatically converted to a RDFParseError.

use srdf::{RDFNodeParse, RDFFormat, RDFParseError, property_string};
let s = r#"prefix : <http://example.org/>
       :x :p "1" .
  "#;
let mut graph = SRDFGraph::from_str(s, &RDFFormat::Turtle, None).unwrap();
let x = iri!("http://example.org/x");
let p = iri!("http://example.org/p");
 
 
struct IntConversionError(String);
 
fn cnv_int(s: String) -> Result<isize, IntConversionError> {
   s.parse().map_err(|_| IntConversionError(s))
}
 
impl Into<RDFParseError> for IntConversionError {
    fn into(self) -> RDFParseError {
        RDFParseError::Custom { msg: format!("Int conversion error: {}", self.0)}
    }
}
 
let mut parser = property_string(&p).and_then(cnv_int);
assert_eq!(parser.parse(&x, &mut graph).unwrap(), 1)
source

fn map<F, B>(self, f: F) -> Map<Self, F>
where Self: Sized, F: FnMut(Self::Output) -> B,

Uses f to map over the parsed value.

use srdf::{RDFNodeParse, RDFFormat, property_integer};
let s = r#"prefix : <http://example.org/>
         :x :p 1 . 
 "#;
let mut graph = SRDFGraph::from_str(s, &RDFFormat::Turtle, None).unwrap();
let p = iri!("http://example.org/p");
let mut parser = property_integer(&p).map(|n| n + 1);
assert_eq!(parser.parse(&iri!("http://example.org/x"), &mut graph).unwrap(), 2)
source

fn and<P2>(self, parser: P2) -> (Self, P2)
where Self: Sized, P2: RDFNodeParse<RDF>,

Parses self followed by p. Succeeds if both parsers succeed, otherwise fails. Returns a tuple with both values on success.

let s = r#"prefix : <http://example.org/>
      :x :p true ;
         :q 1    .
    "#;
let mut graph = SRDFGraph::from_str(s, &RDFFormat::Turtle, None).unwrap();
let x = IriS::new_unchecked("http://example.org/x");
let p = IriS::new_unchecked("http://example.org/p");
let q = IriS::new_unchecked("http://example.org/q");
let mut parser = property_bool(&p).and(property_integer(&q));
assert_eq!(parser.parse(&x, &mut graph).unwrap(), (true, 1))
source

fn then<N, F>(self, f: F) -> Then<Self, F>
where Self: Sized, F: FnMut(Self::Output) -> N, N: RDFNodeParse<RDF>,

Parses using self and then passes the value to f which returns a parser used to parse the rest of the input.

source

fn then_ref<N, F>(self, f: F) -> ThenRef<Self, F>
where Self: Sized, F: FnMut(&Self::Output) -> N, N: RDFNodeParse<RDF>,

Parses using self and then passes a reference to the value to f which returns a parser used to parse the rest of the input.

source

fn then_mut<N, F>(self, f: F) -> ThenMut<Self, F>
where Self: Sized, F: FnMut(&mut Self::Output) -> N, N: RDFNodeParse<RDF>,

Parses using self and then passes a reference to the mutable value to f which returns a parser used to parse the rest of the input.

use srdf::{RDFNodeParse, RDFFormat, ok, property_integers};
      let s = r#"prefix : <http://example.org/>
      :x :p 1, 2, 3 .
    "#;
    let mut graph = SRDFGraph::from_str(s, &RDFFormat::Turtle, None).unwrap();
    let x = IriS::new_unchecked("http://example.org/x");
    let p = IriS::new_unchecked("http://example.org/p");
    let mut parser = property_integers(&p).then_mut(move |ns| {
        ns.extend(vec![4, 5]);
        ok(ns)
     });
    assert_eq!(parser.parse(&x, &mut graph).unwrap(), HashSet::from([1, 2, 3, 4, 5]))
source

fn then_state<'a, N, F, S>( self, state: &'a mut S, f: F ) -> ThenState<'a, Self, F, S>
where Self: Sized, F: FnMut(&'a mut S, Self::Output) -> N, N: RDFNodeParse<RDF>,

source

fn or<P2>(self, parser: P2) -> Or<Self, P2>
where Self: Sized, P2: RDFNodeParse<RDF, Output = Self::Output>,

Returns a parser which attempts to parse using self. If self fails then it attempts parser.

 let s = r#"prefix : <http://example.org/>
      :x :p 1, 2 ;
         :q true .
    "#;
 let mut graph = SRDFGraph::from_str(s, &RDFFormat::Turtle, None).unwrap();
 let x = IriS::new_unchecked("http://example.org/x");
 let p = IriS::new_unchecked("http://example.org/p");
 let q = IriS::new_unchecked("http://example.org/q");
 let mut parser = property_bool(&p).or(property_bool(&q));
 assert_eq!(parser.parse(&x, &mut graph).unwrap(), true)
source

fn focus(self, node: &RDF::Term) -> SetFocus<RDF>
where Self: Sized,

Sets the focus node and returns ()

source

fn with<P, A>(self, parser: P) -> With<Self, P>
where Self: Sized, P: RDFNodeParse<RDF, Output = A>,

Discards the value of the current parser and returns the value of parser

let s = r#"prefix : <http://example.org/>
           :x :p :y .
"#;
let mut graph = SRDFGraph::from_str(s, &RDFFormat::Turtle, None).unwrap();
let p = IriS::new_unchecked("http://example.org/p");
let x = IriS::new_unchecked("http://example.org/x");
assert_eq!(
  property_value(&p).with(ok(&1))
  .parse(&x, &mut graph).unwrap(),
  1
)

Implementations on Foreign Types§

source§

impl<RDF, P1, P2, A, B> RDFNodeParse<RDF> for (P1, P2)
where RDF: FocusRDF, P1: RDFNodeParse<RDF, Output = A>, P2: RDFNodeParse<RDF, Output = B>,

§

type Output = (A, B)

source§

fn parse_impl(&mut self, rdf: &mut RDF) -> PResult<Self::Output>

Implementors§

source§

impl<'a, RDF, P, F, N, S> RDFNodeParse<RDF> for ThenState<'a, P, F, S>
where RDF: FocusRDF, P: RDFNodeParse<RDF>, F: FnMut(&mut S, P::Output) -> N, N: RDFNodeParse<RDF>,

§

type Output = <N as RDFNodeParse<RDF>>::Output

source§

impl<RDF> RDFNodeParse<RDF> for GetFocus<RDF>
where RDF: FocusRDF,

§

type Output = <RDF as SRDFBasic>::Term

source§

impl<RDF> RDFNodeParse<RDF> for Neighs<RDF>
where RDF: FocusRDF,

§

type Output = HashMap<<RDF as SRDFBasic>::IRI, HashSet<<RDF as SRDFBasic>::Term>>

source§

impl<RDF> RDFNodeParse<RDF> for PropertyValue<RDF>
where RDF: FocusRDF,

§

type Output = <RDF as SRDFBasic>::Term

source§

impl<RDF> RDFNodeParse<RDF> for PropertyValueDebug<RDF>
where RDF: FocusRDF + Debug,

§

type Output = <RDF as SRDFBasic>::Term

source§

impl<RDF> RDFNodeParse<RDF> for PropertyValues<RDF>
where RDF: FocusRDF,

§

type Output = HashSet<<RDF as SRDFBasic>::Term>

source§

impl<RDF> RDFNodeParse<RDF> for RDFList<RDF>
where RDF: FocusRDF,

§

type Output = Vec<<RDF as SRDFBasic>::Term>

source§

impl<RDF> RDFNodeParse<RDF> for SetFocus<RDF>
where RDF: FocusRDF,

§

type Output = ()

source§

impl<RDF> RDFNodeParse<RDF> for SubjectsPropertyValue<RDF>
where RDF: FocusRDF,

§

type Output = Vec<<RDF as SRDFBasic>::Subject>

source§

impl<RDF> RDFNodeParse<RDF> for Term<RDF>
where RDF: FocusRDF,

§

type Output = <RDF as SRDFBasic>::Term

source§

impl<RDF, A, B, P1, P2> RDFNodeParse<RDF> for With<P1, P2>
where RDF: FocusRDF, P1: RDFNodeParse<RDF, Output = A>, P2: RDFNodeParse<RDF, Output = B>,

§

type Output = B

source§

impl<RDF, A, B, P, F> RDFNodeParse<RDF> for Map<P, F>
where RDF: FocusRDF, P: RDFNodeParse<RDF, Output = A>, F: FnMut(A) -> B,

§

type Output = B

source§

impl<RDF, A, P> RDFNodeParse<RDF> for ParserNodes<RDF, P>
where RDF: FocusRDF, P: RDFNodeParse<RDF, Output = A>,

§

type Output = Vec<A>

source§

impl<RDF, P1, P2, A> RDFNodeParse<RDF> for CombineVec<P1, P2>
where RDF: FocusRDF, P1: RDFNodeParse<RDF, Output = Vec<A>>, P2: RDFNodeParse<RDF, Output = Vec<A>>,

§

type Output = Vec<A>

source§

impl<RDF, P1, P2, O> RDFNodeParse<RDF> for Or<P1, P2>
where RDF: FocusRDF, P1: RDFNodeParse<RDF, Output = O>, P2: RDFNodeParse<RDF, Output = O>,

§

type Output = O

source§

impl<RDF, P> RDFNodeParse<RDF> for Optional<P>
where RDF: FocusRDF, P: RDFNodeParse<RDF>,

§

type Output = Option<<P as RDFNodeParse<RDF>>::Output>

source§

impl<RDF, P> RDFNodeParse<RDF> for Satisfy<RDF, P>
where RDF: FocusRDF, P: FnMut(&RDF::Term) -> bool,

§

type Output = ()

source§

impl<RDF, P, A> RDFNodeParse<RDF> for ParseByType<IriS, P>
where RDF: FocusRDF, P: RDFNodeParse<RDF, Output = A>,

§

type Output = A

source§

impl<RDF, P, A> RDFNodeParse<RDF> for ParseRDFList<P>
where RDF: FocusRDF, P: RDFNodeParse<RDF, Output = A>,

§

type Output = Vec<A>

source§

impl<RDF, P, F, N> RDFNodeParse<RDF> for Then<P, F>
where RDF: FocusRDF, P: RDFNodeParse<RDF>, F: FnMut(P::Output) -> N, N: RDFNodeParse<RDF>,

§

type Output = <N as RDFNodeParse<RDF>>::Output

source§

impl<RDF, P, F, N> RDFNodeParse<RDF> for ThenMut<P, F>
where RDF: FocusRDF, P: RDFNodeParse<RDF>, F: FnMut(&mut P::Output) -> N, N: RDFNodeParse<RDF>,

§

type Output = <N as RDFNodeParse<RDF>>::Output

source§

impl<RDF, P, F, N> RDFNodeParse<RDF> for ThenRef<P, F>
where RDF: FocusRDF, P: RDFNodeParse<RDF>, F: FnMut(&P::Output) -> N, N: RDFNodeParse<RDF>,

§

type Output = <N as RDFNodeParse<RDF>>::Output

source§

impl<RDF, P, F, O> RDFNodeParse<RDF> for FlatMap<P, F>
where RDF: FocusRDF, P: RDFNodeParse<RDF>, F: FnMut(P::Output) -> PResult<O>,

§

type Output = O

source§

impl<RDF, P, F, O, E> RDFNodeParse<RDF> for AndThen<P, F>
where RDF: FocusRDF, P: RDFNodeParse<RDF>, F: FnMut(P::Output) -> Result<O, E>, E: Into<RDFParseError>,

§

type Output = O