| 1 |
;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: CL-PPCRE; Base: 10 -*- |
|---|
| 2 |
;;; $Header: /usr/local/cvsrep/cl-ppcre/errors.lisp,v 1.21 2008/07/06 18:12:04 edi Exp $ |
|---|
| 3 |
|
|---|
| 4 |
;;; Copyright (c) 2002-2008, 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 |
|
|---|
| 30 |
(in-package :cl-ppcre) |
|---|
| 31 |
|
|---|
| 32 |
(defvar *syntax-error-string* nil |
|---|
| 33 |
"The string which caused the syntax error.") |
|---|
| 34 |
|
|---|
| 35 |
(define-condition ppcre-error (simple-error) |
|---|
| 36 |
() |
|---|
| 37 |
(:documentation "All errors signaled by CL-PPCRE are of |
|---|
| 38 |
this type.")) |
|---|
| 39 |
|
|---|
| 40 |
(define-condition ppcre-syntax-error (ppcre-error) |
|---|
| 41 |
((string :initarg :string |
|---|
| 42 |
:reader ppcre-syntax-error-string) |
|---|
| 43 |
(pos :initarg :pos |
|---|
| 44 |
:reader ppcre-syntax-error-pos)) |
|---|
| 45 |
(:default-initargs |
|---|
| 46 |
:pos nil |
|---|
| 47 |
:string *syntax-error-string*) |
|---|
| 48 |
(:report (lambda (condition stream) |
|---|
| 49 |
(format stream "~?~@[ at position ~A~]~@[ in string ~S~]" |
|---|
| 50 |
(simple-condition-format-control condition) |
|---|
| 51 |
(simple-condition-format-arguments condition) |
|---|
| 52 |
(ppcre-syntax-error-pos condition) |
|---|
| 53 |
(ppcre-syntax-error-string condition)))) |
|---|
| 54 |
(:documentation "Signaled if CL-PPCRE's parser encounters an error |
|---|
| 55 |
when trying to parse a regex string or to convert a parse tree into |
|---|
| 56 |
its internal representation.")) |
|---|
| 57 |
|
|---|
| 58 |
(setf (documentation 'ppcre-syntax-error-string 'function) |
|---|
| 59 |
"Returns the string the parser was parsing when the error was |
|---|
| 60 |
encountered \(or NIL if the error happened while trying to convert a |
|---|
| 61 |
parse tree).") |
|---|
| 62 |
|
|---|
| 63 |
(setf (documentation 'ppcre-syntax-error-pos 'function) |
|---|
| 64 |
"Returns the position within the string where the error occurred |
|---|
| 65 |
\(or NIL if the error happened while trying to convert a parse tree") |
|---|
| 66 |
|
|---|
| 67 |
(define-condition ppcre-invocation-error (ppcre-error) |
|---|
| 68 |
() |
|---|
| 69 |
(:documentation "Signaled when CL-PPCRE functions are |
|---|
| 70 |
invoked with wrong arguments.")) |
|---|
| 71 |
|
|---|
| 72 |
(defmacro signal-syntax-error* (pos format-control &rest format-arguments) |
|---|
| 73 |
`(error 'ppcre-syntax-error |
|---|
| 74 |
:pos ,pos |
|---|
| 75 |
:format-control ,format-control |
|---|
| 76 |
:format-arguments (list ,@format-arguments))) |
|---|
| 77 |
|
|---|
| 78 |
(defmacro signal-syntax-error (format-control &rest format-arguments) |
|---|
| 79 |
`(signal-syntax-error* nil ,format-control ,@format-arguments)) |
|---|
| 80 |
|
|---|
| 81 |
(defmacro signal-invocation-error (format-control &rest format-arguments) |
|---|
| 82 |
`(error 'ppcre-invocation-error |
|---|
| 83 |
:format-control ,format-control |
|---|
| 84 |
:format-arguments (list ,@format-arguments))) |
|---|