From 21aa3df3bdc1dc63b93d8d43852870b0c7a7b1a9 Mon Sep 17 00:00:00 2001 From: dlichteblau Date: Sun, 4 Mar 2007 18:30:40 +0000 Subject: [PATCH]
  • Fixed attributes to carry an lname even without when occurring without a namespace.
  • Klacks improvements: Incompatibly changed klacks:find-element and find-event to consider the current event as a result. Added klacks-error, klacks:expect, klacks:skip, klacks:expecting-element.
  • --- doc/GNUmakefile | 3 ++- doc/index.xml | 9 ++++++++ doc/installation.xml | 6 +----- doc/klacks.xml | 26 +++++++++++++++++++++++ klacks/klacks.lisp | 49 ++++++++++++++++++++++++++++++++++++++++---- klacks/package.lisp | 7 ++++++- xml/xml-parse.lisp | 23 ++++++++++----------- 7 files changed, 100 insertions(+), 23 deletions(-) diff --git a/doc/GNUmakefile b/doc/GNUmakefile index 3c7d1f7..bbabd6d 100644 --- a/doc/GNUmakefile +++ b/doc/GNUmakefile @@ -1,4 +1,5 @@ all: dom.html index.html installation.html klacks.html quickstart.html sax.html xmls-compat.html %.html: %.xml html.xsl - xsltproc html.xsl $< >$@ + xsltproc html.xsl $< >$@.tmp + mv $@.tmp $@ diff --git a/doc/index.xml b/doc/index.xml index e0bf719..d0d2269 100644 --- a/doc/index.xml +++ b/doc/index.xml @@ -50,6 +50,15 @@

    Recent Changes

    +

    rel-2007-xx-yy

    +

    rel-2007-02-18

    diff --git a/doc/klacks.xml b/doc/klacks.xml index dcdacda..6c32e7a 100644 --- a/doc/klacks.xml +++ b/doc/klacks.xml @@ -231,6 +231,32 @@ namespace matches. Return values like peek or NIL if no such event was found.

    +

    +

    Condition KLACKS:KLACKS-ERROR (xml-parse-error)
    + The condition class signalled by expect. +

    +

    +

    Function KLACKS:EXPECT (source key &optional + value1 value2 value3)
    + Assert that the current event is equal to (key value1 value2 + value3). (Ignore value arguments that are NIL.) If so, + return it as multiple values. Otherwise signal a + klacks-error. +

    +

    +

    Function KLACKS:SKIP (source key &optional + value1 value2 value3)
    + expect the specific event, then consume it. +

    +

    +

    Macro KLACKS:EXPECTING-ELEMENT ((fn source + &optional lname uri) &body body
    + Assert that the current event matches (:start-element uri lname). + (Ignore value arguments that are NIL) Otherwise signal a + klacks-error. + Evaluate body as an implicit progn. Finally assert that + the remaining event matches (:end-element uri lname). +

    Bridging Klacks and SAX

    diff --git a/klacks/klacks.lisp b/klacks/klacks.lisp index 9ff4944..2f54859 100644 --- a/klacks/klacks.lisp +++ b/klacks/klacks.lisp @@ -148,7 +148,7 @@ (defun klacks:find-element (source &optional lname uri) (loop (multiple-value-bind (key current-uri current-lname current-qname) - (klacks:peek-next source) + (klacks:peek source) (case key ((nil) (return nil)) @@ -159,14 +159,55 @@ (or (null uri) (equal uri (klacks:current-uri source)))) (return - (values key current-uri current-lname current-qname)))))))) + (values key current-uri current-lname current-qname))))) + (klacks:consume source)))) (defun klacks:find-event (source key) (loop (multiple-value-bind (this a b c) - (klacks:peek-next source) + (klacks:peek source) (cond ((null this) (return nil)) ((eq this key) - (return (values this a b c))))))) + (return (values this a b c)))) + (klacks:consume source)))) + +(define-condition klacks-error (xml-parse-error) ()) + +(defun klacks-error (fmt &rest args) + (%error 'klacks-error + nil + (format nil "Klacks assertion failed: ~?" fmt args))) + +(defun klacks:expect (source key &optional u v w) + (multiple-value-bind (this a b c) + (klacks:peek source) + (unless (eq this key) (klacks-error "expected ~A but got ~A" key this)) + (when (and u (not (equal a u))) + (klacks-error "expected ~A but got ~A" u a)) + (when (and v (not (equal b v))) + (klacks-error "expected ~A but got ~A" v b)) + (when (and w (not (equal c w))) + (klacks-error "expected ~A but got ~A" w c)) + (values this a b c))) + +(defun klacks:skip (source key &optional a b c) + (klacks:expect source key a b c) + (klacks:consume source)) + +(defun invoke-expecting-element (fn source &optional lname uri) + (multiple-value-bind (key a b) + (klacks:peek source) + (unless (eq key :start-element) + (klacks-error "expected ~A but got ~A" (or lname "element") key)) + (when (and uri (not (equal a uri))) + (klacks-error "expected ~A but got ~A" uri a)) + (when (and lname (not (equal b lname))) + (klacks-error "expected ~A but got ~A" lname b)) + (multiple-value-prog1 + (funcall fn) + (klacks:skip source :end-element a b)))) + +(defmacro klacks:expecting-element ((source &optional lname uri) &body body) + `(invoke-expecting-element (lambda () ,@body) ,source ,lname ,uri)) diff --git a/klacks/package.lisp b/klacks/package.lisp index 276ef13..9abc922 100644 --- a/klacks/package.lisp +++ b/klacks/package.lisp @@ -27,8 +27,11 @@ #:peek-next #:consume + #:expect + #:skip #:find-element #:find-event + #:expecting-element #:map-attributes #:list-attributes @@ -40,4 +43,6 @@ #:serialize-event #:serialize-element - #:serialize-source)) + #:serialize-source + + #:klacks-error)) diff --git a/xml/xml-parse.lisp b/xml/xml-parse.lisp index dc87174..244d9ab 100644 --- a/xml/xml-parse.lisp +++ b/xml/xml-parse.lisp @@ -948,12 +948,9 @@ (wf-error nil "Entity '~A' is not defined." (rod-string name))) def)) -(defun xstream-open-extid (extid) - (let* ((sysid (extid-system extid)) - (stream - (or (funcall (or (entity-resolver *ctx*) (constantly nil)) - (extid-public extid) - (extid-system extid)) +(defun xstream-open-extid* (entity-resolver pubid sysid) + (let* ((stream + (or (funcall (or entity-resolver (constantly nil)) pubid sysid) (open (uri-to-pathname sysid) :element-type '(unsigned-byte 8) :direction :input)))) @@ -961,6 +958,11 @@ :name (make-stream-name :uri sysid) :initial-speed 1))) +(defun xstream-open-extid (extid) + (xstream-open-extid* (entity-resolver *ctx*) + (extid-public extid) + (extid-system extid))) + (defun call-with-entity-expansion-as-stream (zstream cont name kind internalp) ;; `zstream' is for error messages (let ((in (entity->xstream zstream name kind internalp))) @@ -3568,15 +3570,12 @@ (setf (sax:attribute-namespace-uri attribute) #"http://www.w3.org/2000/xmlns/") (multiple-value-bind (prefix local-name) (split-qname qname) - (declare (ignorable local-name)) (when (and prefix ;; default namespace doesn't apply to attributes (or (not (rod= #"xmlns" prefix)) sax:*use-xmlns-namespace*)) - (multiple-value-bind (uri prefix local-name) - (decode-qname qname) - (declare (ignore prefix)) - (setf (sax:attribute-namespace-uri attribute) uri) - (setf (sax:attribute-local-name attribute) local-name))))))) + (setf (sax:attribute-namespace-uri attribute) + (decode-qname qname))) + (setf (sax:attribute-local-name attribute) local-name))))) ;;;;;;;;;;;;;;;;;