| 1 |
;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: CL-PPCRE; Base: 10 -*- |
|---|
| 2 |
;;; $Header: /usr/local/cvsrep/cl-ppcre/specials.lisp,v 1.41 2008/07/23 22:25:15 edi Exp $ |
|---|
| 3 |
|
|---|
| 4 |
;;; globally declared special variables |
|---|
| 5 |
|
|---|
| 6 |
;;; Copyright (c) 2002-2008, Dr. Edmund Weitz. All rights reserved. |
|---|
| 7 |
|
|---|
| 8 |
;;; Redistribution and use in source and binary forms, with or without |
|---|
| 9 |
;;; modification, are permitted provided that the following conditions |
|---|
| 10 |
;;; are met: |
|---|
| 11 |
|
|---|
| 12 |
;;; * Redistributions of source code must retain the above copyright |
|---|
| 13 |
;;; notice, this list of conditions and the following disclaimer. |
|---|
| 14 |
|
|---|
| 15 |
;;; * Redistributions in binary form must reproduce the above |
|---|
| 16 |
;;; copyright notice, this list of conditions and the following |
|---|
| 17 |
;;; disclaimer in the documentation and/or other materials |
|---|
| 18 |
;;; provided with the distribution. |
|---|
| 19 |
|
|---|
| 20 |
;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED |
|---|
| 21 |
;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|---|
| 22 |
;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|---|
| 23 |
;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
|---|
| 24 |
;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|---|
| 25 |
;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
|---|
| 26 |
;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|---|
| 27 |
;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|---|
| 28 |
;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|---|
| 29 |
;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|---|
| 30 |
;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 31 |
|
|---|
| 32 |
(in-package :cl-ppcre) |
|---|
| 33 |
|
|---|
| 34 |
;;; special variables used to effect declarations |
|---|
| 35 |
|
|---|
| 36 |
(defvar *standard-optimize-settings* |
|---|
| 37 |
'(optimize |
|---|
| 38 |
speed |
|---|
| 39 |
(safety 0) |
|---|
| 40 |
(space 0) |
|---|
| 41 |
(debug 1) |
|---|
| 42 |
(compilation-speed 0) |
|---|
| 43 |
#+:lispworks (hcl:fixnum-safety 0)) |
|---|
| 44 |
"The standard optimize settings used by most declaration expressions.") |
|---|
| 45 |
|
|---|
| 46 |
(defvar *special-optimize-settings* |
|---|
| 47 |
'(optimize speed space) |
|---|
| 48 |
"Special optimize settings used only by a few declaration expressions.") |
|---|
| 49 |
|
|---|
| 50 |
;;; special variables used by the lexer/parser combo |
|---|
| 51 |
|
|---|
| 52 |
(defvar *extended-mode-p* nil |
|---|
| 53 |
"Whether the parser will start in extended mode.") |
|---|
| 54 |
(declaim (boolean *extended-mode-p*)) |
|---|
| 55 |
|
|---|
| 56 |
;;; special variables used by the SCAN function and the matchers |
|---|
| 57 |
|
|---|
| 58 |
(defvar *regex-char-code-limit* char-code-limit |
|---|
| 59 |
"The upper exclusive bound on the char-codes of characters which can |
|---|
| 60 |
occur in character classes. Change this value BEFORE creating |
|---|
| 61 |
scanners if you don't need the \(full) Unicode support of |
|---|
| 62 |
implementations like AllegroCL, CLISP, LispWorks, or SBCL.") |
|---|
| 63 |
(declaim (fixnum *regex-char-code-limit*)) |
|---|
| 64 |
|
|---|
| 65 |
(defvar *string* "" |
|---|
| 66 |
"The string which is currently scanned by SCAN. |
|---|
| 67 |
Will always be coerced to a SIMPLE-STRING.") |
|---|
| 68 |
(declaim (simple-string *string*)) |
|---|
| 69 |
|
|---|
| 70 |
(defvar *start-pos* 0 |
|---|
| 71 |
"Where to start scanning within *STRING*.") |
|---|
| 72 |
(declaim (fixnum *start-pos*)) |
|---|
| 73 |
|
|---|
| 74 |
(defvar *real-start-pos* nil |
|---|
| 75 |
"The real start of *STRING*. This is for repeated scans and is only used internally.") |
|---|
| 76 |
(declaim (type (or null fixnum) *real-start-pos*)) |
|---|
| 77 |
|
|---|
| 78 |
(defvar *end-pos* 0 |
|---|
| 79 |
"Where to stop scanning within *STRING*.") |
|---|
| 80 |
(declaim (fixnum *end-pos*)) |
|---|
| 81 |
|
|---|
| 82 |
(defvar *reg-starts* (make-array 0) |
|---|
| 83 |
"An array which holds the start positions |
|---|
| 84 |
of the current register candidates.") |
|---|
| 85 |
(declaim (simple-vector *reg-starts*)) |
|---|
| 86 |
|
|---|
| 87 |
(defvar *regs-maybe-start* (make-array 0) |
|---|
| 88 |
"An array which holds the next start positions |
|---|
| 89 |
of the current register candidates.") |
|---|
| 90 |
(declaim (simple-vector *regs-maybe-start*)) |
|---|
| 91 |
|
|---|
| 92 |
(defvar *reg-ends* (make-array 0) |
|---|
| 93 |
"An array which holds the end positions |
|---|
| 94 |
of the current register candidates.") |
|---|
| 95 |
(declaim (simple-vector *reg-ends*)) |
|---|
| 96 |
|
|---|
| 97 |
(defvar *end-string-pos* nil |
|---|
| 98 |
"Start of the next possible end-string candidate.") |
|---|
| 99 |
|
|---|
| 100 |
(defvar *rep-num* 0 |
|---|
| 101 |
"Counts the number of \"complicated\" repetitions while the matchers |
|---|
| 102 |
are built.") |
|---|
| 103 |
(declaim (fixnum *rep-num*)) |
|---|
| 104 |
|
|---|
| 105 |
(defvar *zero-length-num* 0 |
|---|
| 106 |
"Counts the number of repetitions the inner regexes of which may |
|---|
| 107 |
have zero-length while the matchers are built.") |
|---|
| 108 |
(declaim (fixnum *zero-length-num*)) |
|---|
| 109 |
|
|---|
| 110 |
(defvar *repeat-counters* (make-array 0 |
|---|
| 111 |
:initial-element 0 |
|---|
| 112 |
:element-type 'fixnum) |
|---|
| 113 |
"An array to keep track of how often |
|---|
| 114 |
repetitive patterns have been tested already.") |
|---|
| 115 |
(declaim (type (array fixnum (*)) *repeat-counters*)) |
|---|
| 116 |
|
|---|
| 117 |
(defvar *last-pos-stores* (make-array 0) |
|---|
| 118 |
"An array to keep track of the last positions |
|---|
| 119 |
where we saw repetitive patterns. |
|---|
| 120 |
Only used for patterns which might have zero length.") |
|---|
| 121 |
(declaim (simple-vector *last-pos-stores*)) |
|---|
| 122 |
|
|---|
| 123 |
(defvar *use-bmh-matchers* nil |
|---|
| 124 |
"Whether the scanners created by CREATE-SCANNER should use the \(fast |
|---|
| 125 |
but large) Boyer-Moore-Horspool matchers.") |
|---|
| 126 |
|
|---|
| 127 |
(defvar *optimize-char-classes* nil |
|---|
| 128 |
"Whether character classes should be compiled into look-ups into |
|---|
| 129 |
O\(1) data structures. This is usually fast but will be costly in |
|---|
| 130 |
terms of scanner creation time and might be costly in terms of size if |
|---|
| 131 |
*REGEX-CHAR-CODE-LIMIT* is high. This value will be used as the :KIND |
|---|
| 132 |
keyword argument to CREATE-OPTIMIZED-TEST-FUNCTION - see there for the |
|---|
| 133 |
possible non-NIL values.") |
|---|
| 134 |
|
|---|
| 135 |
(defvar *property-resolver* nil |
|---|
| 136 |
"Should be NIL or a designator for a function which accepts strings |
|---|
| 137 |
and returns unary character test functions or NIL. This 'resolver' is |
|---|
| 138 |
intended to handle `character properties' like \\p{IsAlpha}. If |
|---|
| 139 |
*PROPERTY-RESOLVER* is NIL, then the parser will simply treat \\p and |
|---|
| 140 |
\\P as #\\p and #\\P as in older versions of CL-PPCRE.") |
|---|
| 141 |
|
|---|
| 142 |
(defvar *allow-quoting* nil |
|---|
| 143 |
"Whether the parser should support Perl's \\Q and \\E.") |
|---|
| 144 |
|
|---|
| 145 |
(defvar *allow-named-registers* nil |
|---|
| 146 |
"Whether the parser should support AllegroCL's named registers |
|---|
| 147 |
\(?<name>\"<regex>\") and back-reference \\k<name> syntax.") |
|---|
| 148 |
|
|---|
| 149 |
(pushnew :cl-ppcre *features*) |
|---|
| 150 |
|
|---|
| 151 |
;; stuff for Nikodemus Siivola's HYPERDOC |
|---|
| 152 |
;; see <http://common-lisp.net/project/hyperdoc/> |
|---|
| 153 |
;; and <http://www.cliki.net/hyperdoc> |
|---|
| 154 |
;; also used by LW-ADD-ONS |
|---|
| 155 |
|
|---|
| 156 |
(defvar *hyperdoc-base-uri* "http://weitz.de/cl-ppcre/") |
|---|
| 157 |
|
|---|
| 158 |
(let ((exported-symbols-alist |
|---|
| 159 |
(loop for symbol being the external-symbols of :cl-ppcre |
|---|
| 160 |
collect (cons symbol |
|---|
| 161 |
(concatenate 'string |
|---|
| 162 |
"#" |
|---|
| 163 |
(string-downcase symbol)))))) |
|---|
| 164 |
(defun hyperdoc-lookup (symbol type) |
|---|
| 165 |
(declare (ignore type)) |
|---|
| 166 |
(cdr (assoc symbol |
|---|
| 167 |
exported-symbols-alist |
|---|
| 168 |
:test #'eq)))) |
|---|
| 169 |
|
|---|