Expand description
§rdf-winnow
Streaming RDF lexical primitives built on winnow.
The crate parses small RDF grammar productions from partial byte slices so
format-specific parsers can handle input one chunk at a time without losing
the distinction between incomplete input and invalid syntax.
§Scope
rdf-winnow provides the reusable lexical layer used by text RDF parsers:
- IRI references and absolute IRI references;
- blank-node labels;
- language tags, including RDF directional language tags;
- numeric and boolean literals;
- quoted string forms and escapes;
- prefixed-name components;
- RDF-star/triple-term delimiters;
- UTF-8 characters, whitespace, and comments.
It does not parse a complete RDF document, build a graph, perform IRI
resolution, or assign application semantics to a datatype. A caller composes
these primitives into Turtle, TriG, N-Triples, N-Quads, or another RDF
syntax.
§Partial input
Every parser consumes a winnow::Partial<&[u8]>. A parser returns
ErrMode::Incomplete when the current buffer ends in the middle of a valid
production. It returns a contextual syntax error when the input cannot be
valid. This distinction lets an asynchronous feeder read another chunk only
when more bytes are actually needed.
use rdf_winnow::{iri_ref, string_literal_quote, Input, RdfResult};
use winnow::Partial;
fn parse_pair<'a>(input: &mut Input<'a>) -> RdfResult<(&'a [u8], &'a [u8])> {
let iri = iri_ref(input)?;
let literal = string_literal_quote(input)?;
Ok((iri, literal))
}
let mut input = Partial::new(&b"<https://example.org/name>\"Alice\""[..]);
let (iri, literal) = parse_pair(&mut input)?;
assert_eq!(iri, b"https://example.org/name");
assert_eq!(literal, b"Alice");The returned byte slices borrow from the caller’s input. That keeps the lexical layer allocation-free for callers that can process each token before the next buffer is read.
§Typed literals and custom datatypes
RDF permits a literal to use any valid datatype IRI. This crate provides the IRI and string primitives needed to parse that syntax but does not maintain a datatype registry or restrict callers to XML Schema datatypes. A higher-level parser can therefore preserve application-specific datatypes, including media-oriented datatypes, without changing this crate.
§API overview
| Item | Purpose |
|---|---|
Input<'a> | Partial byte-slice input shared by the parsers. |
RdfResult<T> | Winnow result type used by the public primitives. |
iri_ref | Parses an RDF IRI reference body. |
absolute_iri_ref | Parses an IRI reference and requires a scheme. |
string_literal_* | Parses the four RDF quoted-string forms. |
lang_tag | Parses a language tag and optional text direction. |
numeric_literal | Parses RDF numeric lexical forms. |
pn_* | Parses prefixed-name components. |
§License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.
Re-exports§
pub use blank::blank_node_label;pub use boolean::boolean_literal;pub use iri::absolute_iri_ref;pub use iri::iri_ref;pub use iri::is_absolute_iri;pub use lang::LangDirection;pub use lang::LangTag;pub use lang::lang_tag;pub use numeric::NumericKind;pub use numeric::NumericLiteral;pub use numeric::numeric_literal;pub use pn::pn_chars;pub use pn::pn_chars_base;pub use pn::pn_chars_u;pub use pn::pn_local;pub use pn::pn_prefix;pub use string::string_literal_long_quote;pub use string::string_literal_long_single_quote;pub use string::string_literal_quote;pub use string::string_literal_single_quote;pub use triple_term::triple_term_close;pub use triple_term::triple_term_open;pub use whitespace::comment;pub use whitespace::whitespace;pub use whitespace::whitespace_or_comment;
Modules§
- blank
- Blank-node label primitive.
- boolean
- Boolean literal primitive.
- iri
- IRI reference primitive:
IRIREF ::= '<' (...)* '>'. - lang
- Language-tag primitive.
- numeric
- Numeric-literal primitive.
- pn
- Prefixed-name (PN) primitives shared between Turtle/TriG and blank-node labels.
- string
- String-literal primitives.
- triple_
term - RDF 1.2 triple-term delimiter primitives.
- utf8
- Byte-level UTF-8 code-point helper.
- whitespace
- Whitespace and comment primitives shared across RDF text parsers.
Type Aliases§
- Input
- Partial byte-slice input type used by every primitive in this
crate.
Partialmakestake_while/take_till/ literal matchers returnErrMode::Incompleterather thanErrwhen the buffer ends mid-production, so an asynchronous feeder can resume cleanly on the next chunk. - RdfResult
- Shorthand for the
ModalResulttype used across the crate.