7
7
use std:: fmt:: { self , Write } ;
8
8
9
9
use crate :: {
10
- common:: { identifier:: Identifier , token, Span } ,
10
+ common:: { identifier:: Identifier , token, Span , Spanned } ,
11
11
util:: write_joined,
12
12
value:: { IntegerLiteral , Literal , StringLiteral } ,
13
13
} ;
@@ -27,6 +27,24 @@ pub enum Annotation {
27
27
Values ( Values ) ,
28
28
}
29
29
30
+ impl Spanned for Annotation {
31
+ fn span ( & self ) -> Option < Span > {
32
+ match self {
33
+ Annotation :: Abstract ( annotation) => annotation. span ( ) ,
34
+ Annotation :: Cardinality ( annotation) => annotation. span ( ) ,
35
+ Annotation :: Cascade ( annotation) => annotation. span ( ) ,
36
+ Annotation :: Distinct ( annotation) => annotation. span ( ) ,
37
+ Annotation :: Independent ( annotation) => annotation. span ( ) ,
38
+ Annotation :: Key ( annotation) => annotation. span ( ) ,
39
+ Annotation :: Range ( annotation) => annotation. span ( ) ,
40
+ Annotation :: Regex ( annotation) => annotation. span ( ) ,
41
+ Annotation :: Subkey ( annotation) => annotation. span ( ) ,
42
+ Annotation :: Unique ( annotation) => annotation. span ( ) ,
43
+ Annotation :: Values ( annotation) => annotation. span ( ) ,
44
+ }
45
+ }
46
+ }
47
+
30
48
impl fmt:: Display for Annotation {
31
49
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
32
50
match self {
@@ -47,7 +65,7 @@ impl fmt::Display for Annotation {
47
65
48
66
#[ derive( Debug , Clone , Eq , PartialEq ) ]
49
67
pub struct Abstract {
50
- span : Option < Span > ,
68
+ pub span : Option < Span > ,
51
69
}
52
70
53
71
impl Abstract {
@@ -56,6 +74,12 @@ impl Abstract {
56
74
}
57
75
}
58
76
77
+ impl Spanned for Abstract {
78
+ fn span ( & self ) -> Option < Span > {
79
+ self . span
80
+ }
81
+ }
82
+
59
83
impl fmt:: Display for Abstract {
60
84
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
61
85
write ! ( f, "@{}" , token:: Annotation :: Abstract )
@@ -64,7 +88,7 @@ impl fmt::Display for Abstract {
64
88
65
89
#[ derive( Debug , Clone , Eq , PartialEq ) ]
66
90
pub struct Cardinality {
67
- span : Option < Span > ,
91
+ pub span : Option < Span > ,
68
92
pub range : CardinalityRange ,
69
93
}
70
94
@@ -74,6 +98,12 @@ impl Cardinality {
74
98
}
75
99
}
76
100
101
+ impl Spanned for Cardinality {
102
+ fn span ( & self ) -> Option < Span > {
103
+ self . span
104
+ }
105
+ }
106
+
77
107
impl fmt:: Display for Cardinality {
78
108
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
79
109
write ! ( f, "@{}({})" , token:: Annotation :: Cardinality , self . range)
@@ -98,7 +128,7 @@ impl fmt::Display for CardinalityRange {
98
128
99
129
#[ derive( Debug , Clone , Eq , PartialEq ) ]
100
130
pub struct Cascade {
101
- span : Option < Span > ,
131
+ pub span : Option < Span > ,
102
132
}
103
133
104
134
impl Cascade {
@@ -107,6 +137,12 @@ impl Cascade {
107
137
}
108
138
}
109
139
140
+ impl Spanned for Cascade {
141
+ fn span ( & self ) -> Option < Span > {
142
+ self . span
143
+ }
144
+ }
145
+
110
146
impl fmt:: Display for Cascade {
111
147
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
112
148
write ! ( f, "@{}" , token:: Annotation :: Cascade )
@@ -115,7 +151,7 @@ impl fmt::Display for Cascade {
115
151
116
152
#[ derive( Debug , Clone , Eq , PartialEq ) ]
117
153
pub struct Distinct {
118
- span : Option < Span > ,
154
+ pub span : Option < Span > ,
119
155
}
120
156
121
157
impl Distinct {
@@ -124,6 +160,12 @@ impl Distinct {
124
160
}
125
161
}
126
162
163
+ impl Spanned for Distinct {
164
+ fn span ( & self ) -> Option < Span > {
165
+ self . span
166
+ }
167
+ }
168
+
127
169
impl fmt:: Display for Distinct {
128
170
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
129
171
write ! ( f, "@{}" , token:: Annotation :: Distinct )
@@ -132,7 +174,7 @@ impl fmt::Display for Distinct {
132
174
133
175
#[ derive( Debug , Clone , Eq , PartialEq ) ]
134
176
pub struct Independent {
135
- span : Option < Span > ,
177
+ pub span : Option < Span > ,
136
178
}
137
179
138
180
impl Independent {
@@ -141,6 +183,12 @@ impl Independent {
141
183
}
142
184
}
143
185
186
+ impl Spanned for Independent {
187
+ fn span ( & self ) -> Option < Span > {
188
+ self . span
189
+ }
190
+ }
191
+
144
192
impl fmt:: Display for Independent {
145
193
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
146
194
write ! ( f, "@{}" , token:: Annotation :: Independent )
@@ -149,7 +197,7 @@ impl fmt::Display for Independent {
149
197
150
198
#[ derive( Debug , Clone , Eq , PartialEq ) ]
151
199
pub struct Key {
152
- span : Option < Span > ,
200
+ pub span : Option < Span > ,
153
201
}
154
202
155
203
impl Key {
@@ -158,6 +206,12 @@ impl Key {
158
206
}
159
207
}
160
208
209
+ impl Spanned for Key {
210
+ fn span ( & self ) -> Option < Span > {
211
+ self . span
212
+ }
213
+ }
214
+
161
215
impl fmt:: Display for Key {
162
216
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
163
217
write ! ( f, "@{}" , token:: Annotation :: Key )
@@ -166,7 +220,7 @@ impl fmt::Display for Key {
166
220
167
221
#[ derive( Debug , Clone , Eq , PartialEq ) ]
168
222
pub struct Range {
169
- span : Option < Span > ,
223
+ pub span : Option < Span > ,
170
224
pub min : Option < Literal > ,
171
225
pub max : Option < Literal > ,
172
226
}
@@ -177,6 +231,12 @@ impl Range {
177
231
}
178
232
}
179
233
234
+ impl Spanned for Range {
235
+ fn span ( & self ) -> Option < Span > {
236
+ self . span
237
+ }
238
+ }
239
+
180
240
impl fmt:: Display for Range {
181
241
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
182
242
write ! ( f, "@{}(" , token:: Annotation :: Range ) ?;
@@ -194,7 +254,7 @@ impl fmt::Display for Range {
194
254
195
255
#[ derive( Debug , Clone , Eq , PartialEq ) ]
196
256
pub struct Regex {
197
- span : Option < Span > ,
257
+ pub span : Option < Span > ,
198
258
pub regex : StringLiteral ,
199
259
}
200
260
@@ -204,6 +264,12 @@ impl Regex {
204
264
}
205
265
}
206
266
267
+ impl Spanned for Regex {
268
+ fn span ( & self ) -> Option < Span > {
269
+ self . span
270
+ }
271
+ }
272
+
207
273
impl fmt:: Display for Regex {
208
274
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
209
275
write ! ( f, "@{}({})" , token:: Annotation :: Regex , self . regex. value)
@@ -212,7 +278,7 @@ impl fmt::Display for Regex {
212
278
213
279
#[ derive( Debug , Clone , Eq , PartialEq ) ]
214
280
pub struct Subkey {
215
- span : Option < Span > ,
281
+ pub span : Option < Span > ,
216
282
pub ident : Identifier ,
217
283
}
218
284
@@ -222,6 +288,12 @@ impl Subkey {
222
288
}
223
289
}
224
290
291
+ impl Spanned for Subkey {
292
+ fn span ( & self ) -> Option < Span > {
293
+ self . span
294
+ }
295
+ }
296
+
225
297
impl fmt:: Display for Subkey {
226
298
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
227
299
write ! ( f, "@{}({})" , token:: Annotation :: Subkey , self . ident)
@@ -230,7 +302,7 @@ impl fmt::Display for Subkey {
230
302
231
303
#[ derive( Debug , Clone , Eq , PartialEq ) ]
232
304
pub struct Unique {
233
- span : Option < Span > ,
305
+ pub span : Option < Span > ,
234
306
}
235
307
236
308
impl Unique {
@@ -239,6 +311,12 @@ impl Unique {
239
311
}
240
312
}
241
313
314
+ impl Spanned for Unique {
315
+ fn span ( & self ) -> Option < Span > {
316
+ self . span
317
+ }
318
+ }
319
+
242
320
impl fmt:: Display for Unique {
243
321
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
244
322
write ! ( f, "@{}" , token:: Annotation :: Unique )
@@ -247,7 +325,7 @@ impl fmt::Display for Unique {
247
325
248
326
#[ derive( Debug , Clone , Eq , PartialEq ) ]
249
327
pub struct Values {
250
- span : Option < Span > ,
328
+ pub span : Option < Span > ,
251
329
pub values : Vec < Literal > ,
252
330
}
253
331
@@ -257,6 +335,12 @@ impl Values {
257
335
}
258
336
}
259
337
338
+ impl Spanned for Values {
339
+ fn span ( & self ) -> Option < Span > {
340
+ self . span
341
+ }
342
+ }
343
+
260
344
impl fmt:: Display for Values {
261
345
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
262
346
write ! ( f, "@{}(" , token:: Annotation :: Values ) ?;
0 commit comments