Coverage report: /development/source/library/org/datagraph/spocq-shard/src/core/ssl/utilities.lisp
| Kind | Covered | All | % |
| expression | 0 | 153 | 0.0 |
| branch | 0 | 10 | 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 -*-
3
;;; define the internal operators which implement the SSL core api
5
;;; (load (compile-file "/opt/spocq/patches/ssl/ssl-api-internal.lisp"))
7
;;; see file:///Development/Downloads/VOWL/WebVOWL_Single_Ont/webvowl.html
8
;;; for the ontology diagram generator
10
;;; http : http://www.w3.org/TR/HTTP-in-RDF10
11
;;; http-headers : http://www.w3.org/2011/http-headers
15
(eval-when (:load-toplevel :compile-toplevel :execute)
17
(defparameter *ssl-namespace-name* (package-name (find-package "ssl")))
19
(defgeneric parse-blank-node-property-list (input &key parser version production default namespace-bindings)
21
"Parse the INPUT as a blank node property list.
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
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 '.' .")
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|)
39
(declare (ignore default))
40
(let ((*task-indices* (make-task-indices))
43
(if (assoc "" *namespace-bindings* :test #'equal)
45
(acons "" *ssl-namespace-name* *namespace-bindings*)))
48
(multiple-value-bind (result index success) (funcall parser input :start-name production)
51
(if success index *max-input-index*)))))
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)
61
(values sse-expression query-input index))
63
(values default query-input index))
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)))))))))
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)))
76
(defgeneric parse-collection (graph)
77
(:method ((graph string))
78
(parse-blank-node-property-list graph :production 'sparql-1-0-4::|Collection|)))
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)
87
(#\[ (read-into-buffer))
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)
94
;; leave the excape charater in the buffer for subsequent parsing
95
(#\\ (vector-push-extend (read-char stream) buffer))
97
(when (eql char delimiter) (return)))))))
98
(vector-push-extend (read-char stream) 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']")
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*))))
111
(set-packaged-macro-character #\[ 'blank-node-property-list-reader)