Changeset trunk,31 for trunk/parsing.lisp
- Timestamp:
- 02/09/2008 09:13:22 PM (18 years ago)
- revision id:
- svn-v3-trunk0:2948df59-2b31-0410-8e06-c40c0b09d5b6:trunk:34
- File:
-
- 1 edited
-
trunk/parsing.lisp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/parsing.lisp
r27 r31 2 2 3 3 #| 4 Copyright (C) 2007 David Owen <dsowen@fugue88.ws>4 Copyright (C) 2007, 2008 David Owen <dsowen@fugue88.ws> 5 5 6 This library is free software; you can redistribute it and/or7 modify it under the terms of the GNU Lesser General Public 8 License as published by the Free Software Foundation; either9 version 2.1 of the License, or(at your option) any later version.6 This program is free software: you can redistribute it and/or modify 7 it under the terms of the GNU Lesser Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 10 11 This libraryis distributed in the hope that it will be useful,11 This program is distributed in the hope that it will be useful, 12 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU14 Lesser GeneralPublic License for more details.13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU Lesser Public License for more details. 15 15 16 You should have received a copy of the GNU Lesser General Public 17 License along with this library; if not, write to the Free Software 18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 16 You should have received a copy of the GNU Lesser Public License 17 along with this program. If not, see <http://www.gnu.org/licenses/>. 19 18 |# 20 19 … … 23 22 24 23 25 (defmacro defparser (name rule & optionalfilter)24 (defmacro defparser (name rule &key cclass filter) 26 25 "Defines a function named NAME that parses its input according to 27 26 RULE (see IF-MATCHES). On success, returns the values T, the 28 unconsumed input, and the tree (labeled with NAME ). On failure ,29 returns NIL.27 unconsumed input, and the tree (labeled with NAME, unless CCLASS is 28 true). On failure, returns NIL. 30 29 31 30 The tree may optionally be filtered by FILTER before being labeled." 32 `(defun ,name (input) 33 (if-matches input ,rule (next match) 34 (values t next (cons ',name ,(if filter `(,filter match) 'match)))))) 31 (let ((filtered (if filter `(,filter match) `match))) 32 `(defun ,name (input) 33 (if-matches input ,rule (next match) 34 (values t next ,(if cclass `,filtered `(cons ',name ,filtered))))))) 35 35 36 36 (defmacro defgrammar (() &body definitions) … … 38 38 39 39 (DEFGRAMMAR (options*) definitions*) 40 definitions: (name rule filter?)" 41 (flet ((x (definition) 42 (destructuring-bind (name rule &optional filter) definition 43 `(defparser ,name ,rule ,filter)))) 40 definitions: (name rule &key filter cclass)" 41 (flet ((x (definition) `(defparser ,@definition))) 44 42 `(progv () ,@(mapcar #'x definitions))))
Note: See TracChangeset
for help on using the changeset viewer.
