1use std::fmt;
3
4use iref::IriRefBuf;
5pub use rdf_types::{BlankId, BlankIdBuf, LiteralType};
6pub use xsd_types::lexical::{DecimalBuf, DoubleBuf, IntegerBuf};
7
8#[derive(Clone, Debug)]
10pub enum Iri<M> {
11 IriRef(IriRefBuf),
12 PrefixedName((String, M), (String, M)),
13}
14
15#[derive(Clone, Debug)]
17pub struct Document<M> {
18 pub statements: Vec<(Statement<M>, M)>,
19}
20
21impl<M> Default for Document<M> {
22 fn default() -> Self {
23 Self {
24 statements: Vec::new(),
25 }
26 }
27}
28
29impl<M> Document<M> {
30 pub fn new() -> Document<M> {
31 Self::default()
32 }
33
34 pub fn insert(&mut self, statement: (Statement<M>, M)) {
35 self.statements.push(statement)
36 }
37}
38
39#[derive(Clone, Debug)]
41pub enum Statement<M> {
42 Directive(Directive<M>),
44
45 Triples(Triples<M>),
47}
48
49#[derive(Clone, Debug)]
50pub struct Triples<M> {
51 pub subject: (Subject<M>, M),
52 pub predicate_objects_list: (PredicateObjectsList<M>, M),
53}
54
55pub type PredicateObjectsList<M> = Vec<(PredicateObjects<M>, M)>;
56
57#[derive(Clone, Debug)]
59pub enum Directive<M> {
60 Prefix((String, M), (IriRefBuf, M)),
62
63 Base((IriRefBuf, M)),
65
66 SparqlPrefix((String, M), (IriRefBuf, M)),
68
69 SparqlBase((IriRefBuf, M)),
71}
72
73#[derive(Clone, Debug)]
75pub enum Verb<M> {
76 A,
78
79 Predicate(Iri<M>),
81}
82
83#[derive(Clone, Debug)]
85pub enum Subject<M> {
86 Iri(Iri<M>),
88
89 BlankNode(BlankNode<M>),
91
92 Collection(Collection<M>),
94}
95
96#[derive(Clone, Debug)]
98pub struct Collection<M>(pub Vec<(Object<M>, M)>);
99
100#[derive(Clone, Debug)]
101pub enum BlankNode<M> {
102 Label(BlankIdBuf),
103 Anonymous((BlankNodePropertyList<M>, M)),
104}
105
106pub type BlankNodePropertyList<M> = PredicateObjectsList<M>;
107
108#[derive(Clone, Debug)]
110pub enum Object<M> {
111 Iri(Iri<M>),
113
114 BlankNode(BlankNode<M>),
116
117 Collection(Collection<M>),
119
120 Literal(Literal<M>),
122}
123
124#[derive(Clone, Debug)]
125pub struct PredicateObjects<M> {
126 pub verb: (Verb<M>, M),
127 pub objects: (Objects<M>, M),
128}
129
130#[derive(Clone, Debug)]
132pub struct Objects<M>(pub Vec<(Object<M>, M)>);
133
134#[derive(Clone, Debug)]
136pub enum Literal<M> {
137 Rdf(RdfLiteral<M>),
139
140 Numeric(NumericLiteral),
142
143 Boolean(bool),
145}
146
147#[derive(Clone, Debug)]
149pub struct RdfLiteral<M, T = Iri<M>> {
150 pub value: (String, M),
151
152 pub type_: (LiteralType<T>, M),
153}
154
155impl<M, T> RdfLiteral<M, T> {
156 pub fn new(value: (String, M), type_: (LiteralType<T>, M)) -> Self {
157 Self { value, type_ }
158 }
159}
160
161impl<M, T> From<RdfLiteral<M, T>> for rdf_types::Literal<T> {
162 fn from(value: RdfLiteral<M, T>) -> Self {
163 rdf_types::Literal {
164 value: value.value.0,
165 type_: value.type_.0,
166 }
167 }
168}
169
170#[derive(Clone, Debug)]
172pub enum NumericLiteral {
173 Integer(IntegerBuf),
174 Decimal(DecimalBuf),
175 Double(DoubleBuf),
176}
177
178impl fmt::Display for NumericLiteral {
179 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
180 match self {
181 Self::Integer(i) => i.fmt(f),
182 Self::Decimal(d) => d.fmt(f),
183 Self::Double(d) => d.fmt(f),
184 }
185 }
186}