]> dreyeck.freedombox.rocks Git - topic-maps.git/blob - src/ctm/conditions.lisp
Register final Variant Reification original for Slice 22B
[topic-maps.git] / src / ctm / conditions.lisp
1 (in-package #:topic-maps.ctm)
2
3 (define-condition ctm-error (error)
4 ((code :initarg :code :reader error-code)
5 (message :initarg :message :reader error-message)
6 (position :initarg :position :reader error-position)
7 (line :initarg :line :reader error-line)
8 (column :initarg :column :reader error-column)
9 (source :initarg :source :reader error-source)
10 (position-unit :initarg :position-unit :initform :character :reader error-position-unit)
11 (context :initarg :context :initform nil :reader error-context)
12 (cause :initarg :cause :initform nil :reader error-cause))
13 (:report (lambda (condition stream)
14 (format stream "~A~@[ in ~A~] at ~A ~D~@[ (line ~D~]~@[, column ~D)~]: ~A"
15 (error-code condition) (error-source condition)
16 (error-position-unit condition) (error-position condition)
17 (error-line condition) (error-column condition)
18 (error-message condition))
19 (dolist (frame (reverse (error-context condition)))
20 (when (member (getf frame :purpose) '(:mergemap :include))
21 (format stream "~% via %~(~A~) in ~A at character ~D -> ~A~@[ (source ~A)~]"
22 (getf frame :purpose)
23 (or (getf frame :source) (getf frame :document-iri)) (getf frame :position)
24 (getf frame :resource-iri) (getf frame :resource-source)))))))
25 (define-condition ctm-rejection (ctm-error) ())
26 (define-condition undefined-prefix (ctm-rejection) ())
27 (define-condition prefix-collision (ctm-rejection) ())
28 (define-condition ctm-unsupported (ctm-error) ())
29 ;; Retrieval/configuration failures are not evidence of malformed CTM.
30 (define-condition ctm-resource-error (ctm-error) ())
31 (defvar *resource-context* nil)
32
33 (define-condition template-error (ctm-rejection) ())
34 (define-condition duplicate-template (template-error) ())
35 (define-condition undefined-template (template-error) ())
36 (define-condition template-arity-error (template-error) ())
37 (define-condition unbound-template-variable (template-error) ())
38 (define-condition invalid-template-argument (template-error) ())
39 (define-condition invalid-template-body (template-error) ())
40 (defvar *template-context* nil)
41 (defvar *source-name* nil)
42 (defvar *source-text* "")
43
44 (defun problem (type code position message &optional (unit :character) cause)
45 (let ((line (when (eq unit :character) 1)) (column (when (eq unit :character) 1))
46 (previous-cr nil))
47 (when line
48 (loop for c across (subseq *source-text* 0 (min position (length *source-text*))) do
49 (cond ((char= c #\Return) (incf line) (setf column 1 previous-cr t))
50 ((char= c #\Newline) (unless previous-cr (incf line))
51 (setf column 1 previous-cr nil))
52 (t (incf column) (setf previous-cr nil)))))
53 (error type :code code :message message :position position :line line
54 :column column :source *source-name* :position-unit unit :cause cause :context (copy-tree (append *template-context* *resource-context*)))))