match.scm 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. ;;; -*- mode: scheme; coding: utf-8; -*-
  2. ;;;
  3. ;;; Copyright (C) 2010, 2011 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. (define-module (sxml match)
  18. #:export (sxml-match
  19. sxml-match-let
  20. sxml-match-let*)
  21. #:use-module (srfi srfi-1)
  22. #:use-module (srfi srfi-11))
  23. ;;; Commentary:
  24. ;;;
  25. ;;; This module provides an SXML pattern matcher, written by Jim Bender. This
  26. ;;; allows application code to match on SXML nodes and attributes without having
  27. ;;; to deal with the details of s-expression matching, without worrying about
  28. ;;; the order of attributes, etc.
  29. ;;;
  30. ;;; It is fully documented in the Guile Reference Manual.
  31. ;;;
  32. ;;; Code:
  33. ;;;
  34. ;;; PLT compatibility layer.
  35. ;;;
  36. (define-syntax-rule (syntax-object->datum stx)
  37. (syntax->datum stx))
  38. (define-syntax-rule (void)
  39. *unspecified*)
  40. (define %call/ec-prompt
  41. (make-prompt-tag))
  42. (define-syntax-rule (call/ec proc)
  43. ;; aka. `call-with-escape-continuation'
  44. (call-with-prompt %call/ec-prompt
  45. (lambda ()
  46. (proc (lambda args
  47. (apply abort-to-prompt
  48. %call/ec-prompt args))))
  49. (lambda (_ . args)
  50. (apply values args))))
  51. (define-syntax-rule (let/ec cont body ...)
  52. (call/ec (lambda (cont) body ...)))
  53. (define (raise-syntax-error x msg obj sub)
  54. (throw 'sxml-match-error x msg obj sub))
  55. (define-syntax module
  56. (syntax-rules (provide require)
  57. ((_ name lang (provide p_ ...) (require r_ ...)
  58. body ...)
  59. (begin body ...))))
  60. ;;;
  61. ;;; Include upstream source file.
  62. ;;;
  63. ;; This file was taken from
  64. ;; <http://planet.plt-scheme.org/package-source/jim/sxml-match.plt/1/1/> on
  65. ;; 2010-05-24. It was written by Jim Bender <benderjg2@aol.com> and released
  66. ;; under the MIT/X11 license
  67. ;; <http://www.gnu.org/licenses/license-list.html#X11License>.
  68. ;;
  69. ;; Modified the `sxml-match1' macro to allow multiple-value returns (upstream
  70. ;; was notified.)
  71. (include-from-path "sxml/sxml-match.ss")
  72. ;;; match.scm ends here