From dlichteblau at common-lisp.net Sun Feb 11 12:09:33 2007
From: dlichteblau at common-lisp.net (dlichteblau)
Date: Sun, 11 Feb 2007 07:09:33 -0500 (EST)
Subject: [cxml-cvs] CVS cxml/pull
Message-ID: <20070211120933.C4CD253069@common-lisp.net>
Update of /project/cxml/cvsroot/cxml/pull
In directory clnet:/tmp/cvs-serv5263/pull
Log Message:
Directory /project/cxml/cvsroot/cxml/pull added to the repository
From dlichteblau at common-lisp.net Sun Feb 11 12:54:28 2007
From: dlichteblau at common-lisp.net (dlichteblau)
Date: Sun, 11 Feb 2007 07:54:28 -0500 (EST)
Subject: [cxml-cvs] CVS cxml/klacks
Message-ID: <20070211125428.3C4B32B11D@common-lisp.net>
Update of /project/cxml/cvsroot/cxml/klacks
In directory clnet:/tmp/cvs-serv10428/klacks
Log Message:
Directory /project/cxml/cvsroot/cxml/klacks added to the repository
From dlichteblau at common-lisp.net Sun Feb 11 18:21:20 2007
From: dlichteblau at common-lisp.net (dlichteblau)
Date: Sun, 11 Feb 2007 13:21:20 -0500 (EST)
Subject: [cxml-cvs] CVS cxml
Message-ID: <20070211182120.A34C475093@common-lisp.net>
Update of /project/cxml/cvsroot/cxml
In directory clnet:/tmp/cvs-serv26091
Modified Files:
cxml.asd
Log Message:
klacks parser
--- /project/cxml/cvsroot/cxml/cxml.asd 2006/09/13 15:58:36 1.13
+++ /project/cxml/cvsroot/cxml/cxml.asd 2007/02/11 18:21:20 1.14
@@ -109,6 +109,18 @@
(:file "dom-sax" :depends-on ("package")))
:depends-on (:cxml-xml))
+(asdf:defsystem :cxml-klacks
+ :default-component-class closure-source-file
+ :pathname (merge-pathnames
+ "klacks/"
+ (make-pathname :name nil :type nil :defaults *load-truename*))
+ :serial t
+ :components
+ ((:file "package")
+ (:file "klacks")
+ (:file "klacks-impl"))
+ :depends-on (:cxml-xml))
+
(asdf:defsystem :cxml-test
:default-component-class closure-source-file
:pathname (merge-pathnames
@@ -117,4 +129,6 @@
:components ((:file "domtest") (:file "xmlconf"))
:depends-on (:cxml-xml :cxml-dom))
-(asdf:defsystem :cxml :components () :depends-on (:cxml-dom :cxml-test))
+(asdf:defsystem :cxml
+ :components ()
+ :depends-on (:cxml-dom :cxml-klacks :cxml-test))
From dlichteblau at common-lisp.net Sun Feb 11 18:21:20 2007
From: dlichteblau at common-lisp.net (dlichteblau)
Date: Sun, 11 Feb 2007 13:21:20 -0500 (EST)
Subject: [cxml-cvs] CVS cxml/dom
Message-ID: <20070211182120.E104C100B@common-lisp.net>
Update of /project/cxml/cvsroot/cxml/dom
In directory clnet:/tmp/cvs-serv26091/dom
Modified Files:
dom-builder.lisp
Log Message:
klacks parser
--- /project/cxml/cvsroot/cxml/dom/dom-builder.lisp 2005/12/27 01:35:14 1.10
+++ /project/cxml/cvsroot/cxml/dom/dom-builder.lisp 2007/02/11 18:21:20 1.11
@@ -38,7 +38,9 @@
(push document (element-stack handler))))
(defmethod sax:end-document ((handler dom-builder))
- (setf (slot-value (document handler) 'dtd) (cxml::dtd cxml::*ctx*))
+ (setf (slot-value (document handler) 'dtd)
+ ;; FIXME!
+ (and cxml::*ctx* (cxml::dtd cxml::*ctx*)))
(let ((doctype (dom:doctype (document handler))))
(when doctype
(setf (slot-value (dom:entities doctype) 'read-only-p) t)
From dlichteblau at common-lisp.net Sun Feb 11 18:21:21 2007
From: dlichteblau at common-lisp.net (dlichteblau)
Date: Sun, 11 Feb 2007 13:21:21 -0500 (EST)
Subject: [cxml-cvs] CVS cxml/klacks
Message-ID: <20070211182121.B1000120A0@common-lisp.net>
Update of /project/cxml/cvsroot/cxml/klacks
In directory clnet:/tmp/cvs-serv26091/klacks
Added Files:
klacks-impl.lisp klacks.lisp package.lisp
Log Message:
klacks parser
--- /project/cxml/cvsroot/cxml/klacks/klacks-impl.lisp 2007/02/11 18:21:21 NONE
+++ /project/cxml/cvsroot/cxml/klacks/klacks-impl.lisp 2007/02/11 18:21:21 1.1
;;; -*- Mode: Lisp; readtable: runes; -*-
;;; (c) copyright 2007 David Lichteblau
;;; This library is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU Library General Public
;;; License as published by the Free Software Foundation; either
;;; version 2 of the License, or (at your option) any later version.
;;;
;;; This library is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;;; Library General Public License for more details.
;;;
;;; You should have received a copy of the GNU Library General Public
;;; License along with this library; if not, write to the
;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;;; Boston, MA 02111-1307 USA.
(in-package :cxml)
(defclass cxml-source (klacks:source)
(;; args to make-source
(context :initarg :context)
(validate :initarg :validate)
(root :initarg :root)
(dtd :initarg :dtd)
(error-culprit :initarg :error-culprit)
;; current state
(continuation)
(current-key :initform nil)
(current-values)
(current-attributes)
(cdata-section-p :reader klacks:current-cdata-section-p)
;; extra with-source magic
(data-behaviour :initform :DTD)
(namespace-stack :initform (list *initial-namespace-bindings*))
(temporary-streams :initform nil)
(scratch-pad :initarg :scratch-pad)
(scratch-pad-2 :initarg :scratch-pad-2)
(scratch-pad-3 :initarg :scratch-pad-3)
(scratch-pad-4 :initarg :scratch-pad-4)))
(defmethod klacks:close-source ((source cxml-source))
(dolist (xstream (slot-value source 'temporary-streams))
;; fixme: error handling?
(close-xstream xstream)))
(defmacro with-source ((source &rest slots) &body body)
(let ((s (gensym)))
`(let* ((,s ,source)
(*ctx* (slot-value ,s 'context))
(*validate* (slot-value ,s 'validate))
(*data-behaviour* (slot-value source 'data-behaviour))
(*namespace-bindings* (car (slot-value source 'namespace-stack)))
(*scratch-pad* (slot-value source 'scratch-pad))
(*scratch-pad-2* (slot-value source 'scratch-pad-2))
(*scratch-pad-3* (slot-value source 'scratch-pad-3))
(*scratch-pad-4* (slot-value source 'scratch-pad-4)))
(handler-case
(with-slots (, at slots) ,s
, at body)
(runes-encoding:encoding-error (c)
(wf-error (slot-value ,s 'error-culprit) "~A" c))))))
(defun fill-source (source)
(with-slots (current-key current-values continuation) source
(unless current-key
(setf current-key :bogus)
(setf continuation (funcall continuation))
(assert (not (eq current-key :bogus))))))
(defmethod klacks:peek ((source cxml-source))
(with-source (source current-key current-values)
(fill-source source)
(apply #'values current-key current-values)))
(defmethod klacks:peek-value ((source cxml-source))
(with-source (source current-key current-values)
(fill-source source)
(apply #'values current-values)))
(defmethod klacks:consume ((source cxml-source))
(with-source (source current-key current-values)
(fill-source source)
(multiple-value-prog1
(apply #'values current-key current-values)
(setf current-key nil))))
(defmethod klacks:map-attributes (fn (source cxml-source))
(dolist (a (slot-value source 'current-attributes))
(funcall fn
(sax:attribute-namespace-uri a)
(sax:attribute-local-name a)
(sax:attribute-qname a)
(sax:attribute-value a)
(sax:attribute-specified-p a))))
(defmethod klacks:list-attributes ((source cxml-source))
(slot-value source 'current-attributes))
(defun make-source
(input &rest args
&key validate dtd root entity-resolver disallow-internal-subset
pathname)
(declare (ignore validate dtd root entity-resolver disallow-internal-subset))
(etypecase input
(xstream
(let ((*ctx* nil))
(let ((zstream (make-zstream :input-stack (list input))))
(peek-rune input)
(with-scratch-pads ()
(apply #'%make-source
zstream
(loop
for (name value) on args by #'cddr
unless (eq name :pathname)
append (list name value)))))))
(stream
(let ((xstream (make-xstream input)))
(setf (xstream-name xstream)
(make-stream-name
:entity-name "main document"
:entity-kind :main
:uri (pathname-to-uri
(merge-pathnames (or pathname (pathname input))))))
(apply #'make-source xstream args)))
(pathname
(let* ((xstream
(make-xstream (open input :element-type '(unsigned-byte 8))))
(source (apply #'make-source
xstream
:pathname input
args)))
(push xstream (slot-value source 'temporary-streams))
source))
(rod
(let ((xstream (string->xstream input)))
(setf (xstream-name xstream)
(make-stream-name
:entity-name "main document"
:entity-kind :main
:uri nil))
(apply #'make-source xstream args)))))
(defun %make-source
(input &key validate dtd root entity-resolver disallow-internal-subset
error-culprit)
;; check types of user-supplied arguments for better error messages:
(check-type validate boolean)
(check-type dtd (or null extid))
(check-type root (or null rod))
(check-type entity-resolver (or null function symbol))
(check-type disallow-internal-subset boolean)
(let* ((context
(make-context :handler nil
:main-zstream input
:entity-resolver entity-resolver
:disallow-internal-subset disallow-internal-subset))
(source
(make-instance 'cxml-source
:context context
:validate validate
:dtd dtd
:root root
:error-culprit error-culprit
:scratch-pad *scratch-pad*
:scratch-pad-2 *scratch-pad-2*
:scratch-pad-3 *scratch-pad-3*
:scratch-pad-4 *scratch-pad-4*)))
(setf (slot-value source 'continuation)
(lambda () (klacks/xmldecl source input)))
source))
(defun klacks/xmldecl (source input)
(with-source (source current-key current-values)
(let ((hd (p/xmldecl input)))
(setf current-key :start-document)
(setf current-values
(when hd
(list (xml-header-version hd)
(xml-header-encoding hd)
(xml-header-standalone-p hd))))
(lambda ()
(klacks/misc*-2 source input
(lambda ()
(klacks/doctype source input)))))))
(defun klacks/misc*-2 (source input successor)
(with-source (source current-key current-values)
(multiple-value-bind (cat sem) (peek-token input)
(case cat
(:COMMENT
(setf current-key :comment)
(setf current-values (list sem))
(consume-token input)
(lambda () (klacks/misc*-2 source input successor)))
(:PI
(setf current-key :processing-instruction)
(setf current-values (list (car sem) (cdr sem)))
(consume-token input)
(lambda () (klacks/misc*-2 source input successor)))
(:S
(consume-token input)
(klacks/misc*-2 source input successor))
(t
(funcall successor))))))
(defun klacks/doctype (source input)
(with-source (source current-key current-values validate dtd)
(let ((cont (lambda () (klacks/finish-doctype source input)))
ignoreme name extid)
(prog1
(cond
((eq (peek-token input) :xstream zstream name :general nil)))
(push new-xstream temporary-streams)
(push :stop (zstream-input-stack zstream))
(zstream-push new-xstream zstream)
(let ((next
(lambda ()
(klacks/entity-reference-2 source zstream new-xstream cont))))
(etypecase (checked-get-entdef name :general)
(internal-entdef
(klacks/content source zstream next))
(external-entdef
(klacks/ext-parsed-ent source zstream next)))))))
(defun klacks/entity-reference-2 (source zstream new-xstream cont)
(with-source (source temporary-streams)
(unless (eq (peek-token zstream) :eof)
(wf-error zstream "Trailing garbage. - ~S" (peek-token zstream)))
(assert (eq (peek-token zstream) :eof))
(assert (eq (pop (zstream-input-stack zstream)) new-xstream))
(assert (eq (pop (zstream-input-stack zstream)) :stop))
(setf (zstream-token-category zstream) nil)
(setf temporary-streams (remove new-xstream temporary-streams))
(close-xstream new-xstream)
(funcall cont)))
(defun klacks/ext-parsed-ent (source input cont)
(with-source (source)
(when (eq (peek-token input) :xml-decl)
(let ((hd (parse-text-decl (cdr (nth-value 1 (peek-token input))))))
(setup-encoding input hd))
(consume-token input))
(set-full-speed input)
(klacks/content source input cont)))
#+(or)
(trace CXML::KLACKS/DOCTYPE
CXML::KLACKS/EXT-PARSED-ENT
CXML::KLACKS/MISC*-2
CXML::KLACKS/ENTITY-REFERENCE
CXML::KLACKS/ENTITY-REFERENCE-2
CXML::KLACKS/ELEMENT
CXML::KLACKS/ZTAG
CXML::KLACKS/XMLDECL
CXML::KLACKS/FINISH-DOCTYPE
CXML::KLACKS/ELEMENT-3
CXML::KLACKS/EOF
CXML::KLACKS/ELEMENT-2
CXML::KLACKS/CONTENT )
--- /project/cxml/cvsroot/cxml/klacks/klacks.lisp 2007/02/11 18:21:21 NONE
+++ /project/cxml/cvsroot/cxml/klacks/klacks.lisp 2007/02/11 18:21:21 1.1
;;; -*- Mode: Lisp; readtable: runes; -*-
;;; (c) copyright 2007 David Lichteblau
;;; This library is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU Library General Public
;;; License as published by the Free Software Foundation; either
;;; version 2 of the License, or (at your option) any later version.
;;;
;;; This library is distributed in the hope that it will be useful,
[86 lines skipped]
--- /project/cxml/cvsroot/cxml/klacks/package.lisp 2007/02/11 18:21:21 NONE
+++ /project/cxml/cvsroot/cxml/klacks/package.lisp 2007/02/11 18:21:21 1.1
[124 lines skipped]
From dlichteblau at common-lisp.net Sun Feb 11 18:21:22 2007
From: dlichteblau at common-lisp.net (dlichteblau)
Date: Sun, 11 Feb 2007 13:21:22 -0500 (EST)
Subject: [cxml-cvs] CVS cxml/xml
Message-ID: <20070211182122.CCE3E1A007@common-lisp.net>
Update of /project/cxml/cvsroot/cxml/xml
In directory clnet:/tmp/cvs-serv26091/xml
Modified Files:
package.lisp xml-parse.lisp
Log Message:
klacks parser
--- /project/cxml/cvsroot/cxml/xml/package.lisp 2006/12/02 13:21:37 1.13
+++ /project/cxml/cvsroot/cxml/xml/package.lisp 2007/02/11 18:21:21 1.14
@@ -83,4 +83,6 @@
#:make-namespace-normalizer
#:make-whitespace-normalizer
#:rod-to-utf8-string
- #:utf8-string-to-rod))
+ #:utf8-string-to-rod
+
+ #:make-source))
--- /project/cxml/cvsroot/cxml/xml/xml-parse.lisp 2006/09/16 07:52:59 1.64
+++ /project/cxml/cvsroot/cxml/xml/xml-parse.lisp 2007/02/11 18:21:22 1.65
@@ -68,11 +68,11 @@
;; :stag (
CXML implements a namespace-aware,
- validating SAX-like XML 1.0
parser as well as the DOM Level 2 Core
- interfaces.
+ interfaces. Two parser interfaces are offered, one SAX-like, the
+ other similar to StAX.
rel-2006-xx-yy rel-2007-xx-yyRecent Changes
-
+
* (cxml:parse-file "example.xml" (cxml-xmls:make-xmls-builder)) ("test" (("a" "b")) ("child" NIL))+ +
Use klacks to read events from the parser incrementally. The + following example looks only for :start-element and :end-element + events and prints them (read more):
+* (klacks:with-open-source + (s (cxml:make-source #p"example.xml")) + (loop + for key = (klacks:peek s) + while key + do + (case key + (:start-element + (format t "~A {" (klacks:current-qname s))) + (:end-element + (format t "}"))) + (klacks:consume s))) +test {child {}}