Expand description
N-Quads parsing.
N-Quads is a line-based, plain text format for encoding an RDF dataset.
This library provides a W3C Recommendation
compliant parser built on rdfx terms. Parsing also returns a
CodeMap recording the source span of every quad and of each of its
components, so a downstream validation error can be reported against the
exact byte range that caused it.
Both the standard grammar and the generalized (gRDF) grammar are supported. gRDF lifts the restrictions on which term kinds may appear where: any term may be a subject, predicate, object or graph label.
§RDF version
The grammar implemented here is the RDF 1.1 one. rdfx models RDF 1.2,
so its term types can represent triple terms and directional language
strings, but this parser never produces them — the three RDF 1.2 syntax
additions are rejected:
| Syntax | Example | Status |
|---|---|---|
| Triple terms | <<( :a :b :c )>> | rejected |
| Directional language strings | "x"@en--ltr | rejected |
| Reifiers | :s :p "x" ~ :r | rejected |
§Usage
let source = r#"<http://example.com/#a> <http://example.com/#b> "value"@en ."#;
let (document, code_map) = n_quads::document_from_str(source)?;
assert_eq!(document.len(), 1);
// Span of the whole quad, then of its subject, predicate and object.
let (quad_span, components) = code_map[0];
assert_eq!(&source[quad_span.range()], source);
assert_eq!(&source[components.0.range()], "<http://example.com/#a>");
assert_eq!(&source[components.2.range()], r#""value"@en"#);For the generalized grammar, use grdf_document_from_str. For input that
is not already a &str — a fallible byte stream, UTF-16, a custom decoder
— use the Parse trait directly.
Re-exports§
pub use lexing::LexingError;
Modules§
- lexing
- N-Quads lexing.
Structs§
- Blank
IdBuf - Owned blank node identifier.
- Parser
- N-Quads parser.
Enums§
- Error
- Parse error.
Traits§
- Parse
- N-Quads parsing methods.
Functions§
- document_
from_ str - Parses an N-Quads document from a string.
- grdf_
document_ from_ str - Parses a generalized (gRDF) N-Quads document from a string.
Type Aliases§
- CodeMap
- Source spans of every quad in a document, in source order.
- Document
- N-Quads document.
- Grdf
Document - gRDF N-Quads document.
- Quad
Spans - Source spans of a single quad.