(module sxpath-lolevel ( ;; sxpathlib nodeset? as-nodeset sxml:element? ntype-names?? ntype?? ntype-namespace-id?? sxml:complement node-eq? node-equal? node-pos sxml:filter take-until take-after map-union node-reverse node-trace select-kids node-self node-join node-reduce node-or node-closure sxml:node? sxml:attr-list sxml:attribute sxml:child sxml:parent node-parent sxml:child-nodes sxml:child-elements ;; sxml-tools sxml:empty-element? sxml:shallow-normalized? sxml:normalized? sxml:shallow-minimized? sxml:minimized? sxml:name sxml:element-name sxml:node-name sxml:ncname sxml:name->ns-id sxml:content sxml:text sxml:content-raw sxml:attr-list-u sxml:aux-list sxml:aux-list-u sxml:aux-node sxml:aux-nodes sxml:attr sxml:attr-from-list sxml:num-attr sxml:attr-u sxml:ns-list sxml:ns-id->nodes sxml:ns-id->uri sxml:ns-uri->nodes sxml:ns-uri->id sxml:ns-id sxml:ns-uri sxml:ns-prefix sxml:change-content! sxml:change-content sxml:change-attrlist sxml:change-attrlist! sxml:change-name! sxml:change-name sxml:add-attr sxml:add-attr! sxml:change-attr sxml:change-attr! sxml:set-attr sxml:set-attr! sxml:add-aux sxml:add-aux! sxml:squeeze! sxml:squeeze sxml:clean select-first-kid sxml:node-parent sxml:add-parents sxml:lookup sxml:attr->xml sxml:string->xml sxml:sxml->xml sxml:attr->html sxml:string->html sxml:non-terminated-html-tag? sxml:sxml->html ;; sxml-errors (actually, defined here) sxml:error ;; sxpath-ext sxml:string sxml:boolean sxml:number sxml:string-value sxml:id sxml:list-head sxml:merge-sort sxml:equality-cmp sxml:equal? sxml:not-equal? sxml:relational-cmp sxml:ancestor sxml:ancestor-or-self sxml:descendant sxml:descendant-or-self sxml:following sxml:following-sibling sxml:namespace sxml:preceding sxml:preceding-sibling ) (import (except chicken define-macro) scheme (only extras pp) (only ports call-with-input-string)) ;; There's no real danger of hygiene breakage because the macros here ;; are only used locally (define-syntax define-macro (syntax-rules () ((define-macro (macro-name . args) body ...) (define-syntax (macro-name exp rename compare) (apply (lambda args body ...) (cdr exp)))))) ;; A bit big to include this here, but we don't want a dependency on ;; sxml-transforms just for this one. (define (make-char-quotator char-encoding) (let ((bad-chars (map car char-encoding))) ; Check to see if str contains one of the characters in charset, ; from the position i onward. If so, return that character's index. ; otherwise, return #f (define (index-cset str i charset) (let loop ((i i)) (and (< i (string-length str)) (if (memv (string-ref str i) charset) i (loop (inc i)))))) ; The body of the function (lambda (str) (let ((bad-pos (index-cset str 0 bad-chars))) (if (not bad-pos) str ; str had all good chars (let loop ((from 0) (to bad-pos)) (cond ((>= from (string-length str)) '()) ((not to) (cons (substring str from (string-length str)) '())) (else (let ((quoted-char (cdr (assv (string-ref str to) char-encoding))) (new-to (index-cset str (inc to) bad-chars))) (if (< from to) (cons (substring str from to) (cons quoted-char (loop (inc to) new-to))) (cons quoted-char (loop (inc to) new-to)))))))))))) (include "chicken/common.scm") (include "sxml-tools/sxml-tools.scm") ;; We need the sxpathlib because sxml-tools makes use of a few of its ;; procedures, like sxml:filter and select-kids, but sxpathlib itself ;; also uses sxml-tools, so they are tied together. (include "sxml-tools/sxpathlib.scm") ;; Because we include sxpathlib, we should also include sxpath-ext ;; because together they form the "low-level" interface to sxpath. (include "sxml-tools/sxpath-ext.scm") ;; Overwrite the meaning of sxml:error so it does something sane (set! sxml:error error) )