| 1 |
;;; |
| 2 |
;;; sxml-ssax - XML parser |
| 3 |
;;; |
| 4 |
;;; This file is mechanically translated for Gauche from |
| 5 |
;;; Oleg Kiselyov's SSAX XML parser, SSAX.scm, v4.9. |
| 6 |
;;; Public domain. |
| 7 |
;;; |
| 8 |
|
| 9 |
;; NB: we need to extend several modules since sxml:make-parser inserts |
| 10 |
;; calls to procedures defined in them. Eventually we need to update |
| 11 |
;; ssax source for R5RS macro version and 'extend' should go away. |
| 12 |
|
| 13 |
(define-module sxml.ssax |
| 14 |
(use scheme.list) |
| 15 |
(use srfi.13) |
| 16 |
(extend sxml.adaptor text.parse) |
| 17 |
(export-all) |
| 18 |
) |
| 19 |
(select-module sxml.ssax) |
| 20 |
|
| 21 |
(define ssax:warn-handler (make-parameter #f)) |
| 22 |
|
| 23 |
(define (ssax:warn port msg . args) |
| 24 |
(when (procedure? (ssax:warn-handler)) |
| 25 |
(let ((err (open-output-string))) |
| 26 |
(display (port-position-prefix port) err) |
| 27 |
(display "Warning: " err) |
| 28 |
(if (and (string? msg) (string-prefix? "\n" msg)) |
| 29 |
(display (string-drop msg 1) err) |
| 30 |
(display msg err)) |
| 31 |
(for-each (lambda (m) |
| 32 |
(cond ((equal? m "\n")) ;ignore |
| 33 |
((string? m) (display m err)) |
| 34 |
(else (write m err)))) |
| 35 |
args) |
| 36 |
(newline err) |
| 37 |
((ssax:warn-handler) (get-output-string err))))) |
| 38 |
|
| 39 |
;; We make this constant so that various parsing routines can be optimized. |
| 40 |
(define-constant ssax:S-chars (map ascii->char '(32 10 9 13))) |
| 41 |
|
| 42 |
;#include-body "src/SSAX.scm" |
| 43 |
|
| 44 |
;; Local variables: |
| 45 |
;; mode: scheme |
| 46 |
;; end: |