Coverage report: /development/source/library/org/datagraph/spocq-shard/src/core/encoding/ssf-sparql-1-0.lisp

KindCoveredAll%
expression302681 44.3
branch1658 27.6
Key
Not instrumented
Conditionalized out
Executed
Not executed
 
Both branches taken
One branch taken
Neither branch taken
1
 ;;; -*- Mode: lisp; Syntax: ansi-common-lisp; Base: 10; Package: org.datagraph.spocq.sparql-1-0; -*-
2
 
3
 (in-package :org.datagraph.spocq.sparql-1-0)
4
 
5
 
6
 ;;; reduction operators
7
 
8
 (defun |AdditiveExpression-Constructor| (|AddedMultiplicative*|
9
                                          |MultiplicativeExpression|)
10
   (if |AddedMultiplicative*|
11
     (let ((a-expression |MultiplicativeExpression|))
12
       (loop for (op . m-expression) in (reverse |AddedMultiplicative*|)
13
             do (setf a-expression `(,op ,a-expression ,m-expression)))
14
       a-expression)
15
     |MultiplicativeExpression|))
16
 
17
 (defun |AddedMultiplicative-Constructor| (AdditiveOperator |MultiplicativeExpression|)
18
   (cons AdditiveOperator |MultiplicativeExpression|))
19
 
20
 (defun |AdditiveOperator-Constructor| (item)
21
   (if (eq (symbol-package item) *syntax-package*)
22
     (or (find-builtin-operator item)
23
         (error "Invalid built-in operator: '~a'." item))
24
     item))
25
 
26
 (defun |ANON-Constructor| ()
27
   :anon)
28
 
29
 (defun |ArgList-Constructor| (Expression* nillist)
30
   (declare (ignore nillist))
31
   (when Expression*
32
     (reverse Expression*)))
33
 
34
 (defun |AskQuery-Constructor| (|DatasetClause| |WhereClause|)
35
   (update-dataset-graphs |DatasetClause| :query)
36
   `(spocq.a:|ask| ,|WhereClause|))
37
 
38
 (defun |BaseDecl-Constructor| (IRI_REF)
39
   (setf (base-iri) IRI_REF))
40
 
41
 (defun |BLANK_NODE_LABEL-Constructor| (PN_LOCAL)
42
   PN_LOCAL)
43
 
44
 (defun |BlankNode-Constructor| (ANON BLANK_NODE_LABEL)
45
   (cond (ANON
46
          (ecase *nondistinguished-marker-type*
47
            (:blank-node (cons-blank-node "b"))
48
            (:variable (cons-variable))))
49
         (BLANK_NODE_LABEL
50
          (intern-blank-node BLANK_NODE_LABEL))
51
         (t
52
          (error "One of (ANON BLANK_NODE_LABEL) is required."))))
53
 
54
 (defun |BlankNodePropertyList-Constructor| (PropertyListNotEmpty)
55
   (let ((subject (ecase *nondistinguished-marker-type*
56
                   (:blank-node (cons-blank-node "b"))
57
                   (:variable (cons-variable)))))
58
   (loop for (verb object) in PropertyListNotEmpty
59
     append (if (consp object)   ;  a blank node property list
60
                (if (spocq.i::triple-form-p  (first object))
61
                    (let* ((first-triple (first object))
62
                           (blank-node (second first-triple)))
63
                      (assert-argument-type |BlankNodePropertyList-Constructor|
64
                                            blank-node (or spocq:blank-node undistinguished-variable))
65
                      (list* `(spocq.a:|triple| ,subject ,verb ,blank-node)
66
                             object))
67
                    ;; otherwise build a collection
68
                    (loop for object in object
69
                      collect `(spocq.a:|triple| ,subject ,verb object)))
70
                `((spocq.a:|triple| ,subject ,verb ,object))))))
71
 
72
 
73
 (defun |BooleanLiteral-Constructor| (item)
74
   (case item
75
     (SPOCQ.S:|true| spocq.a:|true|)
76
     (SPOCQ.S:|false| spocq.a:|false|)
77
     (t (warn "anomalous boolean value: ~s." item)
78
        item)))
79
 
80
 (defun |BOUND-Constructor| (item)
81
   `(spocq.a:|bound| ,item))
82
 
83
 (defun |BrackettedExpression-Constructor| (|Expression|)
84
   |Expression|)
85
 
86
 (defun |BuiltinBinaryCall-Constructor| (|BuiltinBinaryOperator| |Expression*|)
87
   (cons |BuiltinBinaryOperator| (reverse |Expression*|)))
88
 
89
 (defun |BuiltinBinaryOperator-Constructor| (item)
90
   (if (eq (symbol-package item) *syntax-package*)
91
     (or (find-builtin-operator item)
92
         (error "Invalid built-in operator: '~a'." item))
93
     item))
94
 
95
 (defun |BuiltInCall-Constructor| (|BuiltinBinaryCall| |BuiltinUnaryCall| |RegexExpression|)
96
   (or |BuiltinBinaryCall| |BuiltinUnaryCall| |RegexExpression|))
97
 
98
 (defun |BuiltinUnaryCall-Constructor| (|BuiltinUnaryOperator| |Expression|)
99
   (list |BuiltinUnaryOperator| |Expression|))
100
 
101
 (defun |BuiltinUnaryOperator-Constructor| (item)
102
   (if (eq (symbol-package item) *syntax-package*)
103
     (or (find-builtin-operator item)
104
         (error "Invalid built-in operator: '~a'." item))
105
     item))
106
 
107
 (defun |Collection-Constructor| (DottedNode &rest rest) ; allow older bnf
108
   (let* ((GraphNode+ (if rest (first rest) DottedNode))
109
          (tail (if rest (or DottedNode '|rdf|:|nil|) '|rdf|:|nil|))
110
          (triples nil))
111
     (dolist (node GraphNode+)
112
       (let ((cell (ecase *nondistinguished-marker-type*
113
                     (:blank-node (cons-blank-node "b"))
114
                     (:variable (cons-variable)))))
115
         (when (consp node)
116
           (setf triples (append node triples))
117
           (setf node (second (first node))))
118
         (push (list 'spocq.a:|triple| cell '|rdf|:|rest| tail) triples)
119
         (push (list 'spocq.a:|triple| cell '|rdf|:|first| node) triples)
120
         (setf tail cell)))
121
     triples))
122
 ;;; (pprint (|Collection-Constructor| `( 3 2 ,(|Collection-Constructor| '(b a)))))
123
 
124
 (defun |ConditionalAndExpression-Constructor| (|ValueLogical*|)
125
   (destructuring-bind (value . rest-values) (reverse |ValueLogical*|)
126
     (if rest-values
127
       `(spocq.a:|&&| ,value ,(|ConditionalAndExpression-Constructor| rest-values))
128
       value)))
129
 
130
 (defun |ConditionalOrExpression-Constructor| (|ValueLogical*|)
131
   (destructuring-bind (value . rest-values) (reverse |ValueLogical*|)
132
     (if rest-values
133
       `(spocq.a:\|\| ,value ,(|ConditionalOrExpression-Constructor| rest-values))
134
       value)))
135
 
136
 (defun |Constraint-Constructor| (|BrackettedExpression| |BuiltInCall| |FunctionCall|)
137
   (or |BrackettedExpression| |BuiltInCall| |FunctionCall|))
138
 
139
 (defun |ConstructQuery-Constructor| (ConstructTemplate DatasetClause* |SolutionModifier| Var+ |WhereClause| Wild)
140
   (update-dataset-graphs DatasetClause* :query)
141
   (when |SolutionModifier|
142
     (destructuring-bind (&key limit offset order group-by) |SolutionModifier|
143
       (declare (ignore group-by))
144
       (when order
145
         (setf |WhereClause| `(spocq.a:|order| ,|WhereClause| ,order)))
146
       (when (or limit offset)
147
         (setf |WhereClause| `(spocq.a:|slice| ,|WhereClause|
148
                                               ,@(when offset `(:offset ,offset))
149
                                               ,@(when limit `(:count ,limit)))))))
150
   (cond (Wild                           ; build a construct pattern from all statements
151
          (setf ConstructTemplate (let ((statements ()))
152
                                    (flet ((collect-statements (expression)
153
                                             (if (bgp-form-p expression)
154
                                               (dolist (statement (rest expression) t)
155
                                                 (when (triple-form-p statement)
156
                                                   (pushnew statement statements :test #'equalp)))
157
                                               expression)))
158
                                      (declare (dynamic-extent #'collect-statements))
159
                                      (map-tree #'collect-statements |WhereClause|))
160
                                    (reverse statements))))
161
         (Var+                           ; build a construct pattern from all statements which intersect
162
          (setf ConstructTemplate (let ((statements ()))
163
                                    (flet ((collect-statements (expression)
164
                                             (if (bgp-form-p expression)
165
                                               (dolist (statement (rest expression) t)
166
                                                 (when (and (triple-form-p statement)
167
                                                            (intersection statement Var+))
168
                                                   (pushnew statement statements :test #'equalp)))
169
                                               expression)))
170
                                      (declare (dynamic-extent #'collect-statements))
171
                                      (map-tree #'collect-statements |WhereClause|))
172
                                    (reverse statements)))))
173
   `(spocq.a:|construct| ,|WhereClause| ,ConstructTemplate))
174
 
175
 (defun |ConstructTemplate-Constructor| (ConstructTriples)
176
   ConstructTriples)
177
 
178
 (defun |ConstructTriples-Constructor| (ConstructTriples TriplesSameSubject)
179
   (append TriplesSameSubject ConstructTriples))
180
 
181
 (defun |DatasetClause-Constructor| (DefaultGraphClause NamedGraphClause)
182
   (cond (DefaultGraphClause
183
           `(:default-graph ,DefaultGraphClause))
184
         (NamedGraphClause
185
          `(:named-graph ,NamedGraphClause))
186
         (t
187
          (error "one of DefaultGraphClause NamedGraphClause is required."))))
188
 
189
 (defun |DefaultGraphClause-Constructor| (item)
190
   item)
191
 
192
 (defun |DescribeQuery-Constructor| (|DatasetClause|* |SolutionModifier| |VarOrIRIref| |WhereClause|)
193
   (update-dataset-graphs |DatasetClause|* :query)
194
   (when |SolutionModifier|
195
     (unless |WhereClause|
196
       ;; if the where clause is empty, the modifier has no effect. retain the
197
       ;; the structure in any case by inserting a unit table
198
       (setf |WhereClause| '(spocq.a:|table| spocq.a:|unit|)))
199
     (destructuring-bind (&key limit offset order group-by) |SolutionModifier|
200
       (declare (ignore group-by))
201
       (when order
202
         (setf |WhereClause| `(spocq.a:|order| ,|WhereClause| ,order)))
203
       (when (or limit offset)
204
         (setf |WhereClause| `(spocq.a:|slice| ,|WhereClause|
205
                                               ,@(when offset `(:offset ,offset))
206
                                               ,@(when limit `(:count ,limit)))))))
207
   ;; null implies that a '*' was specified
208
   (unless |VarOrIRIref|
209
     (setf |VarOrIRIref| (expression-variables |WhereClause|)))
210
   `(spocq.a:|describe| ,|WhereClause| ,|VarOrIRIref|))
211
 
212
 (defun |Distinctness-Constructor| (item)
213
   "Returns distinctness as an operator. When it appears in a select form, it is applied as such.
214
  When is qualifies an aggregation form, it is interpreted as a boolean."
215
   (or (find-builtin-operator item)
216
       (error "Invalid built-in operator: '~a'." item)))
217
 
218
 (defun |Expression-Constructor| (Expression)
219
   Expression)
220
 
221
 (defun |Filter-Constructor| (Constraint)
222
   ;; return a tagged constraint for later combination
223
   `(:filter ,Constraint))
224
 
225
 (defun |FunctionCall-Constructor| (ArgList IRIref)
226
   (cond ((and (symbolp IRIref(fboundp IRIref) (spocq.i::symbol-term-id IRIRef))
227
          ;; compile static definions as simple function invocations
228
          ;; require that the iri is fbound _and_ a known term
229
          (cons IRIref ArgList))
230
         (t
231
          ;; this would be the place to otherwise expect a task-local binding
232
          ;; for a repository-specific library function
233
          (spocq.e:resource-not-found-error :identifier IRIref))))
234
 
235
 
236
 (defun |GraphGraphPattern-Constructor| (GroupGraphPattern VarOrIRIref)
237
   `(spocq.a:|graph| ,VarOrIRIref ,GroupGraphPattern))
238
 
239
 (defun |GraphNode-Constructor| (TriplesNode VarOrTerm)
240
   (or TriplesNode VarOrTerm))
241
 
242
 (defun |GraphPatternNotTriples-Constructor| (OptionalGraphPattern GroupOrUnionGraphPattern GraphGraphPattern)
243
   (or OptionalGraphPattern GroupOrUnionGraphPattern GraphGraphPattern))
244
 
245
 (defun |GraphTerm-Constructor| (|BlankNode| |BooleanLiteral| |IRIref| NILLIST |NumericLiteral| |RDFLiteral|)
246
   (or |BlankNode| |BooleanLiteral| |IRIref| NILLIST |NumericLiteral| |RDFLiteral|))
247
 
248
 (defun |GroupGraphPattern-Constructor| (GroupGraphPatternRest* TriplesBlock)
249
   ;; filter scope is the entire group, optional is left associated and
250
   ;; an optional treats a missing intial triple block as a unit table
251
   (let ((unit '(spocq.a:|table| spocq.a:|unit|)))
252
     (cond (GroupGraphPatternRest*
253
            (let ((group TriplesBlock)
254
                  (filters ()))
255
              (dolist (ggp-element (reverse GroupGraphPatternRest*))
256
                (destructuring-bind (gpnt-or-filter triples-block) ggp-element 
257
                  (case (first gpnt-or-filter)
258
                    (:filter
259
                     (push (second gpnt-or-filter) filters))
260
                    (:optional
261
                     ;; as per 6.1 the optional may have no predecessor
262
                     (let* ((optional-group (second gpnt-or-filter))
263
                            (optional-filter (when (eq (first optional-group) 'spocq.a:|filter|)
264
                                               (second optional-group))))
265
                       (when optional-filter
266
                         (setf optional-group (third optional-group)))
267
                       (setf group
268
                             `(spocq.a:|leftjoin| ,(or group unit) ,optional-group
269
                                                  ,@(when optional-filter (list :test optional-filter))))))
270
                    (t
271
                     (setf group
272
                           (if group
273
                             `(spocq.a:|join| ,group ,gpnt-or-filter)
274
                             gpnt-or-filter))))
275
                  (when triples-block
276
                    (setf group
277
                          (if group `(spocq.a:|join| ,group ,triples-block) triples-block)))))
278
              (if filters
279
                `(spocq.a:|filter| ,(or group unit)
280
                                   ,(if (rest filters)
281
                                      `(spocq.a:|exprlist| ,@(reverse filters))
282
                                      (first filters)))
283
                group)))
284
           (TriplesBlock)
285
           (t unit))))
286
 
287
 (defun |GroupGraphPatternRest-Constructor| (Filter GraphPatternNotTriples TriplesBlock)
288
   (list (or Filter GraphPatternNotTriples) TriplesBlock))
289
 
290
 (defun |GroupOrUnionGraphPattern-Constructor| (GroupGraphPattern*)
291
   (if (rest GroupGraphPattern*)
292
     (labels ((construct-union (rest)
293
                (destructuring-bind (first . rest) rest
294
                  `(spocq.a:|union| ,first
295
                                    ,(if (rest rest) (construct-union rest) (first rest))))))
296
       (construct-union (reverse GroupGraphPattern*)))
297
     (first GroupGraphPattern*)))
298
 
299
 (defun |INTEGER-Constructor| (item)
300
   item)
301
 
302
 (defun |IRI_NAMESTRING-Constructor| (item)
303
   "as per http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#relIRIs, _no_ iri normalization occurs,
304
  no even %-decoding."
305
   item)
306
 
307
 (defun |IRI_REF-Constructor| (item)
308
   "Return the designated iri given its namestring."
309
   (spocq.e:iri (or item "")))
310
 
311
 
312
 (defun |IRIref-Constructor| (IRI_REF |PrefixedName|)
313
   (or IRI_REF |PrefixedName|))
314
 
315
 #+(or)
316
 (defun |IRIrefOrFunction-Constructor| (|ArgList| |IRIref|)
317
   (if |ArgList|
318
     (cons |IRIref| (when (consp |ArgList|) |ArgList|))
319
     |IRIref|))
320
 
321
 (defun |IRIrefOrFunction-Constructor| (|FunctionCall| |IRIref|)
322
   (or |FunctionCall| |IRIref|))
323
 
324
 
325
 (defun |LANGTAG-Constructor| (item)
326
   (intern (string-upcase (subseq item 1)) :spocq.a))
327
 
328
 (defun |LimitClause-Constructor| (integer)
329
   `(:limit ,integer))
330
 
331
 (defun |LimitOffsetClauses-Constructor| (LimitClause OffsetClause)
332
   (append LimitClause OffsetClause))
333
 
334
 (defun |MultiplicativeExpression-Constructor| (|MultipliedUnary*| |UnaryExpression|)
335
   (if |MultipliedUnary*|
336
     (let ((m-expression |UnaryExpression|))
337
       (loop for (op . u-expression) in (reverse |MultipliedUnary*|)
338
             do (setf m-expression `(,op ,m-expression ,u-expression)))
339
       m-expression)
340
     |UnaryExpression|))
341
 
342
 (defun |MultipliedUnary-Constructor| (MultiplicativeOperator UnaryExpression)
343
   (cons MultiplicativeOperator UnaryExpression))
344
 
345
 (defun |MultiplicativeOperator-Constructor| (item)
346
   (if (eq (symbol-package item) *syntax-package*)
347
     (or (find-builtin-operator item)
348
         (error "Invalid built-in operator: '~a'." item))
349
     item))
350
 
351
 (defun |NamedGraphClause-Constructor| (SourceSelector)
352
   SourceSelector)
353
 
354
 (defun |NAMESPACE_REF-Constructor| (item)
355
   "Return the actual namespace namestring, not the designated iri.
356
  Iff there is a base-uri, delegate merging to the IRI_REF constructor, but coerce back to a string."
357
   (spocq.i:term-lexical-form (|IRI_REF-Constructor| item))
358
   #+(or)                                ; there is always a base iri
359
   (if *base-iri*
360
     (spocq.i:term-lexical-form (|IRI_REF-Constructor| item))
361
     (or item "")))
362
 
363
 (defun |NILLIST-Constructor| ()
364
   '|rdf|:|nil|)
365
 
366
 (defun |NumericExpression-Constructor| (AdditiveExpression)
367
   AdditiveExpression)
368
 
369
 (defun |NumericLiteral-Constructor| (item)
370
   item)
371
 
372
 (defun |NumericLiteralNegative-Constructor| (item)
373
   item)
374
 
375
 (defun |NumericLiteralPositive-Constructor| (item)
376
   item)
377
 
378
 (defun |Object-Constructor| (|GraphNode|)
379
   |GraphNode|)
380
 
381
 (defun |ObjectList-Constructor| (|Object*|)
382
   (reverse |Object*|))
383
 
384
 (defun |OrderDirection-Constructor| (item)
385
   (or (find-builtin-operator item)
386
       (error "Invalid order direction: '~a'." item)))
387
 
388
 (defun |OffsetClause-Constructor| (integer)
389
   `(:offset ,integer))
390
 
391
 (defun |OptionalGraphPattern-Constructor| (GroupGraphPattern)
392
   ;; return a tagged pattern for later combination
393
   `(:optional ,GroupGraphPattern))
394
 
395
 (defun |OrderClause-Constructor| (OrderCondition*)
396
   (list :order (reverse OrderCondition*)))
397
 
398
 (defun |OrderCondition-Constructor| (|BrackettedExpression| |Constraint| |OrderDirection| |Var|)
399
   (cond (|OrderDirection|
400
          `(,|OrderDirection| ,|BrackettedExpression|))
401
         (|Var| )
402
         (|Constraint| )))
403
 
404
 (defun |PN_LOCAL-Constructor| (item)
405
   ;; remove \ but leave %xx
406
   (when item (remove #\\ (string item))))
407
 
408
 (defun |PNAME_NS-Constructor| (item)
409
   (assert (eql (position #\: item) (1- (length item))) ()
410
           "Invalid pname_ls syntax: ~s." item)
411
   (if (equal item ":")
412
     ""
413
     (subseq item 0 (1- (length item)))))
414
 
415
 (defun |PNAME_LN-Constructor| (item)
416
   ;; remove \ but leave %xx
417
   (spocq.i:construct-prefixed-name (remove #\\ item)))
418
 
419
 (defun |PN_PREFIX-Constructor| (item)
420
   (when item (string item)))
421
 
422
 (defun |PrefixedName-Constructor| (item)
423
   (spocq.i:construct-prefixed-name item))
424
 
425
 (defun |PrefixDecl-Constructor| (NAMESPACE_REF PNAME_NS)
426
   (list PNAME_NS NAMESPACE_REF))
427
 
428
 (defun |PrimaryExpression-Constructor| (|BooleanLiteral| |BrackettedExpression| |BuiltInCall|
429
                                         |IRIrefOrFunction| |NumericLiteral| |RDFLiteral| |Var|)
430
   (or |BooleanLiteral| |BrackettedExpression| |BuiltInCall|
431
       |IRIrefOrFunction| |NumericLiteral| |RDFLiteral| |Var|))
432
 
433
 (defun |Prologue-Constructor| (BaseDecl? PrefixDecl*)
434
   (when BaseDecl?
435
     (setf (base-iri) BaseDecl?))
436
   (loop for (PNAME_NS IRI_REF) in PrefixDecl*
437
         do  (setf (prefix-namespace PNAME_NS) IRI_REF))
438
   (list BaseDecl? PrefixDecl*))
439
 
440
 (defun |PropertyList-Constructor| (PropertyListNotEmpty?)
441
   PropertyListNotEmpty?)
442
 
443
 (defun |PropertyListNotEmpty-Constructor| (VerbObjectList*)
444
   (reduce #'append (reverse VerbObjectList*) :from-end t))
445
 
446
 (defun |Query-Constructor| (AskQuery ConstructQuery DescribeQuery Prologue SelectQuery)
447
   (declare (ignore Prologue))
448
   (or AskQuery ConstructQuery DescribeQuery SelectQuery))
449
 
450
 (defun |RDFLiteral-Constructor| (IRIRef LANG_TAG String)
451
   ;; need to ensure that the string is unique as the parser may reparse token sequences
452
   (cond (IRIRef
453
          (intern-literal (copy-seq String) IRIRef))
454
         (LANG_TAG
455
          (intern-plain-literal (copy-seq String) LANG_TAG))
456
         (t
457
          String)))
458
 
459
 (defun |RegexExpression-Constructor| (Expression++?)
460
   `(spocq.a:|regex| ,@(reverse Expression++?)))
461
 
462
 (defun |RelatedNumeric-Constructor| (NumericExpression RelationalOperator)
463
   (list RelationalOperator NumericExpression))
464
 
465
 (defun |RelationalExpression-Constructor| (NumericExpression RelatedNumeric)
466
   (if RelatedNumeric
467
     `(,(first RelatedNumeric) ,NumericExpression ,(second RelatedNumeric))
468
      NumericExpression))
469
 
470
 (defun |RelationalOperator-Constructor| (item)
471
   (if (eq (symbol-package item) *syntax-package*)
472
     (or (find-builtin-operator item)
473
         (error "Invalid built-in operator: '~a'." item))
474
     item))
475
 
476
 (defun |SelectQuery-Constructor| (|DatasetClause| |Distinctness| |SolutionModifier| |Var*| |WhereClause|)
477
   (update-dataset-graphs |DatasetClause| :query)
478
   (destructuring-bind (&key limit offset order group-by) |SolutionModifier|
479
     (declare (ignore group-by))
480
     (when order
481
         (setf |WhereClause| `(spocq.a:|order| ,|WhereClause| ,order)))
482
     (when |Distinctness|
483
       (if (consp |Var*|)
484
         (setf |WhereClause| `(,|Distinctness| (spocq.a:|project| ,|WhereClause| ,|Var*|)))
485
         (setf |WhereClause| `(,|Distinctness| ,|WhereClause|))))
486
     (when (or limit offset)
487
       (setf |WhereClause| `(spocq.a:|slice| ,|WhereClause|
488
                                             ,@(when offset `(:offset ,offset))
489
                                             ,@(when limit `(:count ,limit))))))
490
   `(spocq.a:|select| ,|WhereClause|
491
                      ,(case |Var*|
492
                         ;; allow either a terminal, or a category value
493
                         ((nil spocq.s:*) (reverse *variables*))
494
                         (t |Var*|))))
495
 
496
 (defun |SolutionModifier-Constructor| (OrderClause? LimitOffsetClauses?)
497
   (append OrderClause? LimitOffsetClauses?))
498
 
499
 (defun |SourceSelector-Constructor| (|IRIref|)
500
   |IRIref|)
501
 
502
 (defun |STR-Constructor| (expression)
503
   `(spocq.a:|str| ,expression))
504
 
505
 (defun |String-Constructor| (item)
506
   item)
507
 
508
 (defun |TriplesBlock-Constructor| (TriplesBlock? TriplesSameSubject)
509
   (cons 'spocq.a:|bgp| (append TriplesSameSubject (rest TriplesBlock?))))
510
 
511
 (defun |TriplesNode-Constructor| (BlankNodePropertyList Collection)
512
   (or BlankNodePropertyList Collection))
513
 
514
 (defun |TriplesSameSubject-Constructor| (PropertyList PropertyListNotEmpty TriplesNode VarOrTerm)
515
   ;; PropertyList PropertyListNotEmpty are different non-terminals for the same form in different contexts
516
   (flet ((generate-triples (subject verb-object-list)
517
            (loop for (verb object) in verb-object-list
518
                  append (if (consp object)
519
                             (cons `(spocq.a:|triple| ,subject ,verb ,(second (first object)))
520
                                   object)
521
                             `((spocq.a:|triple| ,subject ,verb ,object))))))
522
     (cond (TriplesNode
523
            (if (eq TriplesNode '|rdf|:|nil|)
524
              (loop for (verb object) in PropertyList
525
                    collect `(spocq.a:|triple| ,TriplesNode ,verb ,object))
526
              (if PropertyList
527
                (append (generate-triples (second (first TriplesNode)) PropertyList)
528
                        TriplesNode)
529
                TriplesNode)))
530
           (VarOrTerm
531
            ;; expand the property lists. these will be either simple verb object, or verb with nested object
532
            (generate-triples VarOrTerm PropertyListNotEmpty))
533
           (t
534
            (error "One of |TriplesNode| |VarOrTerm| is required.")))))
535
 
536
 (defun |UnaryExpression-Constructor| (PrimaryExpression UnaryOperator)
537
   (if UnaryOperator
538
     (list UnaryOperator PrimaryExpression)
539
     PrimaryExpression))
540
 
541
 (defun |UnaryOperator-Constructor| (item)
542
   (if (eq (symbol-package item) *syntax-package*)
543
     (or (find-builtin-operator item)
544
         (error "Invalid built-in operator: '~a'." item))
545
     item))
546
 
547
 (defun |ValueLogical-Constructor| (RelationalExpression)
548
   RelationalExpression)
549
 
550
 (defun |Var-Constructor| (var)
551
   (pushnew var *variables*)
552
   var)
553
 
554
 (defun |VarOrIRIref-Constructor| (|IRIref| |Var|)
555
   (or |IRIref| |Var|))
556
 
557
 (defun |VarOrTerm-Constructor| (|GraphTerm| |Var|)
558
   (or |GraphTerm| |Var|))
559
 
560
 (defun |Verb-Constructor| (item)
561
   (or item |http://www.w3.org/1999/02/22-rdf-syntax-ns#|:|type|))
562
 
563
 (defun |VerbObjectList-Constructor| (ObjectList Verb)
564
   ;; (list Verb ObjectList)
565
   (loop for object in ObjectList
566
     collect (list Verb object)))
567
 ;;; (sparql-1-0-4::|VerbObjectList-Constructor|  '( 1 2) <http://test>)
568
 
569
 (defun |WhereClause-Constructor| (GroupGraphPattern)
570
   GroupGraphPattern)
571
 
572
 (defun |Wild-Constructor| (item)
573
   item)
574
 
575
 #|
576
 ;;; to compile the parser state machine manually
577
 (load (compile-file #p"LIBRARY:org;datagraph;spocq;src;parser;sparql.lisp"))
578
 
579
 ;;; to translate the bnf into lisp
580
 ;;; requires the de.setf.atn-parser system
581
 (let ((bnfp:*class.atn* bnfp:*class.atn*)
582
       (bnfp:*class.atn-node* bnfp:*class.atn-node*)
583
       (bnfp:*class.cat-atn-edge* bnfp:*class.cat-atn-edge*)
584
       (bnfp:*class.pop-atn-edge* bnfp:*class.pop-atn-edge*)
585
       (bnfp:*class.push-atn-edge* bnfp:*class.push-atn-edge*)
586
       (bnfp:*class.test-atn-edge* bnfp:*class.test-atn-edge*))
587
   (bnfp:compile-atn-system  #p"P-LIBRARY:org;datagraph;spocq;src;core;encoding;sparql-1-0.bnf"
588
                             :execute t :compile nil
589
                             :token-package (find-package :spocq.s)
590
                             :source-package (find-package :sparql-1-0)
591
                             :source-pathname "P-LIBRARY:org;datagraph;spocq;src;core;encoding;sparql-1-0.lisp"
592
                             :input-function 'input-reference
593
                             :input-eof-function 'input-eof?
594
                             :ambiguous t
595
                             :trace nil))
596
 
597
 ;;; generate the grammar's atn definition
598
 (let ((bnfp:*class.atn* bnfp:*class.atn*)
599
       (bnfp:*class.atn-node* bnfp:*class.atn-node*)
600
       (bnfp:*class.cat-atn-edge* bnfp:*class.cat-atn-edge*)
601
       (bnfp:*class.pop-atn-edge* bnfp:*class.pop-atn-edge*)
602
       (bnfp:*class.push-atn-edge* bnfp:*class.push-atn-edge*)
603
       (bnfp:*class.test-atn-edge* bnfp:*class.test-atn-edge*))
604
   (atnp::print-atn-system #p"LIBRARY:org;datagraph;spocq;src;core;encoding;sparql-1-0.bnf"
605
                           :source-package (find-package :sparql-1-0)))
606
 
607
 (let ((bnfp:*class.atn* bnfp:*class.atn*)
608
       (bnfp:*class.atn-node* bnfp:*class.atn-node*)
609
       (bnfp:*class.cat-atn-edge* bnfp:*class.cat-atn-edge*)
610
       (bnfp:*class.pop-atn-edge* bnfp:*class.pop-atn-edge*)
611
       (bnfp:*class.push-atn-edge* bnfp:*class.push-atn-edge*)
612
       (bnfp:*class.test-atn-edge* bnfp:*class.test-atn-edge*))
613
   (atnp::graph-atn-system #p"LIBRARY:org;datagraph;spocq;src;core;encoding;sparql-1-0.bnf"
614
                           :source-package (find-package :sparql-1-0)))
615
                           
616
 
617
 |#