1;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: CL-INTERPOL; Base: 10 -*- 2;;; $Header: /usr/local/cvsrep/cl-interpol/specials.lisp,v 1.12 2008/07/23 13:58:40 edi Exp $ 3 4;;; Copyright (c) 2003-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-interpol) 31 32(defvar *list-delimiter* #\Space 33 "What is inserted between the elements of a list which is 34interpolated by #\@.") 35 36(defvar *inner-delimiters* '((#\( . #\)) 37 (#\{ . #\}) 38 (#\< . #\>) 39 (#\[ . #\])) 40 "Legal delimiters for interpolation with #\$ and #\@.") 41 42(defvar *outer-delimiters* '((#\( . #\)) 43 (#\{ . #\}) 44 (#\< . #\>) 45 (#\[ . #\]) 46 #\/ #\| #\" #\' #\#) 47 "Legal outer delimiters for CL-INTERPOL strings.") 48 49(defvar *regex-delimiters* '(#\/) 50 "Outer delimiters which automatically enable regex mode.") 51 52(defvar *unicode-aliases* 53 (make-hash-table :test #'equalp) 54 "A hash table which maps Unicode aliases to their real names.") 55 56(defvar *optional-delimiters-p* nil 57 "Whether text following $ or @ should interpolate even without a 58following delimiter. Lexical variables are handled correctly, 59but the rules are somewhat complex -- see the docs for details.") 60 61(defvar *interpolate-format-directives* nil 62 "Whether to allow ~X(...) as format control directives in interpolated strings.") 63 64(defmacro defvar-unbound (variable-name documentation) 65 "Like DEFVAR, but the variable will be unbound rather than getting 66an initial value. This is useful for variables which should have no 67global value but might have a dynamically bound value." 68 ;; stolen from comp.lang.lisp article <k7727i3s.fsf@comcast.net> by 69 ;; "prunesquallor@comcast.net" 70 `(eval-when (:load-toplevel :compile-toplevel :execute) 71 (defvar ,variable-name) 72 (setf (documentation ',variable-name 'variable) 73 ,documentation))) 74 75(defvar-unbound *saw-backslash* 76 "Whether we have to re-process an \L or \U because it closes several 77scopes.") 78 79(defvar-unbound *pair-level* 80 "") 81 82(defvar-unbound *stream* 83 "Bound to the stream which is read from while parsing a string.") 84 85(defvar-unbound *start-char* 86 "Bound to the opening outer delimiter while parsing a string.") 87 88(defvar-unbound *term-char* 89 "Bound to the closing outer delimiter while parsing a string.") 90 91(defvar *previous-readtables* nil 92 "A stack which holds the previous readtables that have been pushed 93here by ENABLE-INTERPOL-SYNTAX.") 94 95(defvar-unbound *readtable-copy* 96 "Bound to the current readtable if it has to be temporarily 97modified.") 98 99;; stuff for Nikodemus Siivola's HYPERDOC 100;; see <http://common-lisp.net/project/hyperdoc/> 101;; and <http://www.cliki.net/hyperdoc> 102 103(defvar *hyperdoc-base-uri* "http://weitz.de/cl-interpol/") 104 105(let ((exported-symbols-alist 106 (loop for symbol being the external-symbols of :cl-interpol 107 collect (cons symbol 108 (concatenate 'string 109 "#" 110 (string-downcase symbol)))))) 111 (defun hyperdoc-lookup (symbol type) 112 (declare (ignore type)) 113 (cdr (assoc symbol 114 exported-symbols-alist 115 :test #'eq)))) 116