summaryrefslogtreecommitdiff
path: root/errors.lisp
blob: efff1d51828566d524138d74d6b429031a3b4006 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
(in-package :kurt)

(defun report-line (line-num line col? &optional (stream t))
  (format stream "~5a:~a~%" line-num line)
  (iter (for i from 0 below (+ 6 (if (consp col?)
                                     (getf (cdr col?) :col) ;; if token get col
                                     col?)))
        (write-char #\Space stream))
  (format stream "^~%"))

(defun char-num-pair (ch?)
  (if (characterp ch?)
      (list ch? (char-code ch?))
      ch?))

(define-condition char-error ()
  ((line :initarg :line :reader line)
   (col :initarg :col :reader col)
   (line-num :initarg :line-num :reader line-num)
   (ch :initarg :ch :reader ch :initform 'yok)))

(define-condition char-not-closed (char-error) ()
  (:report (lambda (condition stream)
             (format stream "Karakterin kapanış sembolü ' (tek tırnak) eksik.~%Okunan karakter: ~s~%" (char-num-pair (ch condition)))
             (report-line (line-num condition) (line condition) (col condition) stream))))

(define-condition empty-char (char-error) ()
  (:report (lambda (condition stream)
             (format stream "Boş karakter oluşturulamaz.~%")
             (report-line (line-num condition) (line condition) (col condition) stream))))

(defun cond-char-not-closed (line-num line token-or-col ch)
  (make-condition 'char-not-closed :line-num line-num :line line :col token-or-col :ch ch))

(defun cond-empty-char (line-num line token-or-col)
  (make-condition 'empty-char :line-num line-num :line line :col token-or-col))



(define-condition string-error ()
  ((line :initarg :line :reader line)
   (col :initarg :col :reader col)
   (line-num :initarg :line-num :reader line-num)
   (content :initarg :content :reader content :initform 'yok)))

(define-condition string-not-closed (string-error) ()
  (:report (lambda (condition stream)
             (format stream "Metnin kapanış sembolü \" (çift tırnak) eksik.~%Okunan metin: ~s~%"
                     (list (content condition) (length (content condition))))
             (report-line (line-num condition) (line condition) (col condition) stream))))

(defun cond-string-not-closed (line-num line token-or-col &optional (content 'yok))
  (make-condition 'string-not-closed :line-num line-num :line line
                                     :col token-or-col :content content))

(define-condition empty-string (string-error) ()
  (:report (lambda (condition stream)
             (format stream "Boş metin oluşturulamaz.~%")
             (report-line (line-num condition) (line condition) (col condition) stream))))

(defun cond-empty-string (line-num line token-or-col)
  (make-condition 'empty-string :line-num line-num :line line :col token-or-col))



;; (define-condition op-not-implemented (style-warning)
;;   ((undef-ops :initarg :ops :reader undef-ops))
;;   (:report (lambda (condition stream)
;;              (format stream "These ops are not defined in op-case: ~s"
;;                      (undef-ops condition)))))