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