Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 106 lines (89 sloc) 4.714 kb
8f57024a »
2012-08-30 Rename system and packages from html-template to x-html-template
1 ;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: X-HTML-TEMPLATE; Base: 10 -*-
3cb70ddc »
2012-08-30 Initial commit. Fork HTML-Template
2 ;;; $Header: /usr/local/cvsrep/html-template/errors.lisp,v 1.8 2007/01/01 23:49:16 edi Exp $
3
4 ;;; Copyright (c) 2003-2007, Dr. Edmund Weitz. All rights reserved.
5
6 ;;; Redistribution and use in source and binary forms, with or without
7 ;;; modification, are permitted provided that the following conditions
8 ;;; are met:
9
10 ;;; * Redistributions of source code must retain the above copyright
11 ;;; notice, this list of conditions and the following disclaimer.
12
13 ;;; * Redistributions in binary form must reproduce the above
14 ;;; copyright notice, this list of conditions and the following
15 ;;; disclaimer in the documentation and/or other materials
16 ;;; provided with the distribution.
17
18 ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED
19 ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
8f57024a »
2012-08-30 Rename system and packages from html-template to x-html-template
30 (in-package #:x-html-template)
3cb70ddc »
2012-08-30 Initial commit. Fork HTML-Template
31
32 (defstruct syntax-error-location
33 "Structure to store parser locations consisting of a stream, a line
34 number, and a column number."
35 line col stream)
36
37 (defvar *syntax-error-location* (make-syntax-error-location)
38 "Used internally to remember the last position which made sense to
39 the parser.")
40
41 (define-condition template-error (simple-error)
42 ()
8f57024a »
2012-08-30 Rename system and packages from html-template to x-html-template
43 (:documentation "All errors signaled by X-HTML-TEMPLATE are of
3cb70ddc »
2012-08-30 Initial commit. Fork HTML-Template
44 this type."))
45
46 (define-condition template-invocation-error (template-error)
47 ()
8f57024a »
2012-08-30 Rename system and packages from html-template to x-html-template
48 (:documentation "Signaled when X-HTML-TEMPLATE functions are
3cb70ddc »
2012-08-30 Initial commit. Fork HTML-Template
49 invoked with wrong arguments."))
50
51 (define-condition template-missing-value-error (template-error)
52 ()
53 (:documentation "Signaled when a TMPL_VAR printer is provided
54 with a NIL value and *CONVERT-NIL-TO-EMPTY-STRING* is false."))
55
56 (define-condition template-not-a-string-error (template-error)
57 ((value :initarg :value
58 :reader template-not-a-string-error-value))
59 (:documentation "Signaled when a TMPL_VAR printer is provided
60 with a non-string value."))
61
62 (define-condition template-syntax-error (template-error)
63 ((line :initarg :line
64 :reader template-syntax-error-line)
65 (col :initarg :col
66 :reader template-syntax-error-col)
67 (stream :initarg :stream
68 :reader template-syntax-error-stream))
69 (:default-initargs
70 :line (syntax-error-location-line *syntax-error-location*)
71 :col (syntax-error-location-col *syntax-error-location*)
72 :stream (syntax-error-location-stream *syntax-error-location*))
73 (:report (lambda (condition stream)
74 (format stream "~?~%[Line ~A, column ~A, stream ~A]"
75 (simple-condition-format-control condition)
76 (simple-condition-format-arguments condition)
77 (template-syntax-error-line condition)
78 (template-syntax-error-col condition)
79 (template-syntax-error-stream condition))))
80 (:documentation "Signaled when a syntax error occurs while
81 parsing a template."))
82
83 (defmacro signal-template-invocation-error (format-control &rest format-arguments)
84 `(error 'template-invocation-error
85 :format-control ,format-control
86 :format-arguments (list ,@format-arguments)))
87
88 (defmacro signal-template-missing-value-error (format-control &rest format-arguments)
89 `(error 'template-missing-value-error
90 :format-control ,format-control
91 :format-arguments (list ,@format-arguments)))
92
93 (defmacro signal-template-syntax-error (format-control &rest format-arguments)
94 `(error 'template-syntax-error
95 :format-control ,format-control
96 :format-arguments (list ,@format-arguments)))
97
98 (defmacro with-syntax-error-location ((&rest rest) &body body)
99 "This is wrapped around forms in order to remember a meaningful
100 position within the stream in case an error has to be signaled."
101 (declare (ignore rest))
102 `(let ((*syntax-error-location* (make-syntax-error-location
103 :line *current-line*
104 :col *current-column*
105 :stream *standard-input*)))
106 ,@body))
Something went wrong with that request. Please try again.