Commit | Line | Data |
---|---|---|
400a5dcb LC |
1 | ;;; -*- mode: scheme; coding: utf-8; -*- |
2 | ;;; | |
3 | ;;; Copyright (C) 2010 Free Software Foundation, Inc. | |
4 | ;;; | |
5 | ;;; This library is free software; you can redistribute it and/or modify it | |
6 | ;;; under the terms of the GNU Lesser General Public License as published by | |
7 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
8 | ;;; your option) any later version. | |
9 | ;;; | |
10 | ;;; This library is distributed in the hope that it will be useful, but | |
11 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser | |
13 | ;;; General Public License for more details. | |
14 | ;;; | |
15 | ;;; You should have received a copy of the GNU Lesser General Public License | |
16 | ;;; along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
18 | (define-module (sxml match) | |
19 | #:export (sxml-match | |
20 | sxml-match-let | |
21 | sxml-match-let*) | |
22 | #:use-module (srfi srfi-1) | |
23 | #:use-module (srfi srfi-11)) | |
24 | ||
25 | \f | |
26 | ;;; Commentary: | |
27 | ;;; | |
28 | ;;; This module provides an SXML pattern matcher, written by Jim Bender. This | |
29 | ;;; allows application code to match on SXML nodes and attributes without having | |
30 | ;;; to deal with the details of s-expression matching, without worrying about | |
31 | ;;; the order of attributes, etc. | |
32 | ;;; | |
33 | ;;; It is fully documented in the Guile Reference Manual. | |
34 | ;;; | |
35 | ;;; Code: | |
36 | ||
37 | ||
38 | \f | |
39 | ;;; | |
40 | ;;; PLT compatibility layer. | |
41 | ;;; | |
42 | ||
43 | (define-syntax syntax-object->datum | |
44 | (syntax-rules () | |
45 | ((_ stx) | |
46 | (syntax->datum stx)))) | |
47 | ||
48 | (define-syntax void | |
49 | (syntax-rules () | |
50 | ((_) *unspecified*))) | |
51 | ||
52 | (define-syntax call/ec | |
53 | ;; aka. `call-with-escape-continuation' | |
54 | (syntax-rules () | |
55 | ((_ proc) | |
56 | (let ((prompt (make-prompt-tag))) | |
57 | (call-with-prompt prompt | |
58 | (lambda () | |
59 | (proc (lambda args | |
60 | (apply abort-to-prompt | |
61 | prompt args)))) | |
62 | (lambda (_ . args) | |
63 | (apply values args))))))) | |
64 | ||
65 | (define-syntax let/ec | |
66 | (syntax-rules () | |
67 | ((_ cont body ...) | |
68 | (call/ec (lambda (cont) body ...))))) | |
69 | ||
70 | (define (raise-syntax-error x msg obj sub) | |
71 | (throw 'sxml-match-error x msg obj sub)) | |
72 | ||
73 | (define-syntax module | |
74 | (syntax-rules (provide require) | |
75 | ((_ name lang (provide p_ ...) (require r_ ...) | |
76 | body ...) | |
77 | (begin body ...)))) | |
78 | ||
79 | \f | |
80 | ;;; | |
81 | ;;; Include upstream source file. | |
82 | ;;; | |
83 | ||
01fded8c | 84 | ;; This file was taken from |
400a5dcb LC |
85 | ;; <http://planet.plt-scheme.org/package-source/jim/sxml-match.plt/1/1/> on |
86 | ;; 2010-05-24. It was written by Jim Bender <benderjg2@aol.com> and released | |
87 | ;; under the MIT/X11 license | |
88 | ;; <http://www.gnu.org/licenses/license-list.html#X11License>. | |
01fded8c LC |
89 | ;; |
90 | ;; Modified the `sxml-match1' macro to allow multiple-value returns (upstream | |
91 | ;; was notified.) | |
400a5dcb LC |
92 | |
93 | (include-from-path "sxml/sxml-match.ss") | |
94 | ||
95 | ;;; match.scm ends here |