nquads_syntax/
lib.rs

1//! N-Quads is a line-based, plain text format for encoding an RDF dataset.
2//! This library provides a [W3C Recommendation](https://www.w3.org/TR/n-quads/)
3//! compliant parser that keeps track of the position of each syntax node in the
4//! source file using the [locspan](https://crates.io/crates/locspan) library.
5use iref::IriBuf;
6
7pub mod lexing;
8pub mod parsing;
9
10pub use lexing::Lexer;
11use locspan::{Meta, Span};
12pub use parsing::Parse;
13pub use rdf_types::{BlankIdBuf, GraphLabel, Subject};
14use rdf_types::{Id, Object, Term};
15
16pub type Quad =
17	rdf_types::Quad<Meta<Id, Span>, Meta<IriBuf, Span>, Meta<Object, Span>, Meta<GraphLabel, Span>>;
18
19pub type GrdfQuad = rdf_types::Quad<Meta<Term, Span>>;
20
21/// N-Quads document.
22pub type Document = Vec<Meta<Quad, Span>>;
23
24/// gRDF N-Quads document.
25pub type GrdfDocument = Vec<Meta<GrdfQuad, Span>>;
26
27/// Strips all the metadata from the given quad.
28#[allow(clippy::type_complexity)]
29pub fn strip_quad<S, P, O, G, M>(
30	quad: rdf_types::Quad<Meta<S, M>, Meta<P, M>, Meta<O, M>, Meta<G, M>>,
31) -> rdf_types::Quad<S, P, O, G> {
32	quad.map_all(Meta::into_value, Meta::into_value, Meta::into_value, |g| {
33		g.map(Meta::into_value)
34	})
35}