Coverage report: /development/source/library/org/datagraph/spocq-shard/src/core/ssl/utilities.lisp

KindCoveredAll%
expression0153 0.0
branch010 0.0
Key
Not instrumented
Conditionalized out
Executed
Not executed
 
Both branches taken
One branch taken
Neither branch taken
1
 ;;; -*- package: org.dataagraph.spocq.implementation -*- 
2
 ;;;
3
 ;;; define the internal operators which implement the SSL core api
4
 
5
 ;;; (load (compile-file "/opt/spocq/patches/ssl/ssl-api-internal.lisp"))
6
 
7
 ;;; see file:///Development/Downloads/VOWL/WebVOWL_Single_Ont/webvowl.html
8
 ;;; for the ontology diagram generator
9
 
10
 ;;; http : http://www.w3.org/TR/HTTP-in-RDF10
11
 ;;; http-headers : http://www.w3.org/2011/http-headers
12
 
13
 (in-package :spocq.i)
14
 
15
 (eval-when (:load-toplevel :compile-toplevel :execute)
16
 
17
 (defparameter *ssl-namespace-name* (package-name (find-package "ssl")))
18
  
19
 (defgeneric parse-blank-node-property-list (input &key parser version production default namespace-bindings)
20
   (:documentation 
21
   "Parse the INPUT as a blank node property list.
22
 
23
  INPUT : (or stream string vector) : the encoded form 
24
  :PARSER : symbol : the parser bnf identifier, eg. sparql-1-0-4:|GraphTerm|
25
  :DEFAULT : t : return value if the parse fails; if not supplied a failues signals and error
26
 
27
  VALUES : query : list
28
           tokens : vector
29
           token-index : integer
30
 
31
  NB. The behavior for a stream is to buffer through matching '[]' pairs, which is
32
  intended for invocation from a reader macro. It isnot suited to parse turtle in general, as
33
  that grammar production neither permits prefix definitions nor requires a terminating '.' .")
34
 
35
   (:method ((input vector) &key (version *query-parser*) (parser version) ((:base-iri *base-iri*) (base-iri))
36
             ((:namespace-bindings *namespace-bindings*) *namespace-bindings*)
37
             (production 'sparql-1-0-4::|BlankNodePropertyList|)
38
             default)
39
     (declare (ignore default))
40
     (let ((*task-indices* (make-task-indices))
41
           (*max-input-index* 0)
42
           (*namespace-bindings*
43
            (if (assoc "" *namespace-bindings* :test #'equal)
44
              *namespace-bindings*
45
              (acons "" *ssl-namespace-name* *namespace-bindings*)))
46
           (atnp:*atn-term* nil)
47
           (*variables* ()))
48
       (multiple-value-bind (result index success) (funcall parser input :start-name production)
49
         (values result
50
                 input
51
                 (if success index *max-input-index*)))))
52
 
53
   (:method ((source string) &rest options &key (default nil d-s) &allow-other-keys)
54
     (declare (dynamic-extent options))
55
     (if (equal source "\"\"")
56
       ""                                ; avoid triple-quote parse error
57
       (multiple-value-bind (input byte-offsets line-offsets) (tokenize-sparql source :start 0 :end (length source))
58
         (multiple-value-bind (sse-expression query-input index)
59
                              (apply #'parse-blank-node-property-list input options)
60
           (cond (sse-expression
61
                  (values sse-expression query-input index))
62
                 (d-s
63
                  (values default query-input index))
64
                 (t
65
                  (flet ((_aref (array index)
66
                           (when (and (integerp index(< index (length array))) (aref array index))))
67
                    (spocq.e::message-syntax-error :expression source
68
                                                   :token (_aref input index)
69
                                                   :byte-offset (_aref byte-offsets index)
70
                                                   :line-offset (_aref line-offsets index)))))))))
71
 
72
   (:method ((source stream) &rest options)
73
     (declare (dynamic-extent options))
74
     (apply #'parse-blank-node-property-list (read-blank-node-property-list-string source) options)))
75
 
76
 (defgeneric parse-collection (graph)
77
   (:method ((graph string))
78
     (parse-blank-node-property-list graph :production 'sparql-1-0-4::|Collection|)))
79
 
80
 
81
 (defun read-blank-node-property-list-string (stream)
82
   (let ((buffer (make-array 128 :element-type 'character :fill-pointer 0 :adjustable t)))
83
     (labels ((read-into-buffer ()
84
                (loop for char = (read-char stream)
85
                  do (vector-push-extend char buffer)
86
                  do (case char
87
                       (#\[ (read-into-buffer))
88
                       (#\] (return))
89
                       ((#\" #\') (read-string-into-buffer char)))))
90
              (read-string-into-buffer (delimiter)
91
                (loop for char = (read-char stream)
92
                  do (vector-push-extend char buffer)
93
                  do (case char
94
                       ;; leave the excape charater in the buffer for subsequent parsing
95
                       (#\\ (vector-push-extend (read-char stream) buffer))
96
                       ((#\" #\')
97
                        (when (eql char delimiter) (return)))))))
98
       (vector-push-extend (read-char stream) buffer)
99
       (read-into-buffer)
100
       (subseq buffer 0 (length buffer)))))
101
 ;;; (with-input-from-string (stream "[ a rdf:Class; [ a rdf:Class]]") (read-blank-node-property-list-string stream))
102
 ;;; (parse-blank-node-property-list "[ a _:Class; a 'name']")
103
 
104
 
105
 (defun blank-node-property-list-reader (stream char)
106
   (unread-char char stream)
107
   (parse-blank-node-property-list stream :namespace-bindings (acons "" "http://dydra.com/schema/spocq#"
108
                                                                     (acons "mime" "http://www.iana.org/assignments/media-types/"
109
                                                                            *namespace-bindings*))))
110
 
111
 (set-packaged-macro-character #\[ 'blank-node-property-list-reader)
112
 )