Changeset 3377
- Timestamp:
- 06/29/08 16:25:31 (6 months ago)
- Files:
-
- trunk/thirdparty/xuriella/.git/index (modified) (previous)
- trunk/thirdparty/xuriella/.git/logs/HEAD (modified) (1 diff)
- trunk/thirdparty/xuriella/.git/logs/refs/heads/master (modified) (1 diff)
- trunk/thirdparty/xuriella/.git/logs/refs/remotes/origin/master (modified) (1 diff)
- trunk/thirdparty/xuriella/.git/refs/heads/master (modified) (1 diff)
- trunk/thirdparty/xuriella/.git/refs/remotes/origin/master (modified) (1 diff)
- trunk/thirdparty/xuriella/package.lisp (modified) (2 diffs)
- trunk/thirdparty/xuriella/parser.lisp (modified) (1 diff)
- trunk/thirdparty/xuriella/unparse.lisp (modified) (10 diffs)
- trunk/thirdparty/xuriella/xslt.lisp (modified) (10 diffs)
- trunk/thirdparty/xuriella/xuriella.asd (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/thirdparty/xuriella/.git/logs/HEAD
r3108 r3377 1 1 0000000000000000000000000000000000000000 597e3261a39717ea6937c225486e2263a438ab87 Hans Huebner <hans@netzhansa.com> 1210314314 +0000 2 597e3261a39717ea6937c225486e2263a438ab87 5932fdcf8c40e0d81b5f344dc9d98ee064f0ce06 Hans Huebner <hans@voltaren.huebner.org> 1214749586 +0000 pull : Fast forward trunk/thirdparty/xuriella/.git/logs/refs/heads/master
r3108 r3377 1 1 0000000000000000000000000000000000000000 597e3261a39717ea6937c225486e2263a438ab87 Hans Huebner <hans@netzhansa.com> 1210314314 +0000 2 597e3261a39717ea6937c225486e2263a438ab87 5932fdcf8c40e0d81b5f344dc9d98ee064f0ce06 Hans Huebner <hans@voltaren.huebner.org> 1214749586 +0000 pull : Fast forward trunk/thirdparty/xuriella/.git/logs/refs/remotes/origin/master
r3108 r3377 1 1 0000000000000000000000000000000000000000 597e3261a39717ea6937c225486e2263a438ab87 Hans Huebner <hans@netzhansa.com> 1210314314 +0000 clone: from git://repo.or.cz/xuriella.git 2 597e3261a39717ea6937c225486e2263a438ab87 5932fdcf8c40e0d81b5f344dc9d98ee064f0ce06 Hans Huebner <hans@voltaren.huebner.org> 1214749530 +0000 pull : fast forward trunk/thirdparty/xuriella/.git/refs/heads/master
r3108 r3377 1 59 7e3261a39717ea6937c225486e2263a438ab871 5932fdcf8c40e0d81b5f344dc9d98ee064f0ce06 trunk/thirdparty/xuriella/.git/refs/remotes/origin/master
r3108 r3377 1 59 7e3261a39717ea6937c225486e2263a438ab871 5932fdcf8c40e0d81b5f344dc9d98ee064f0ce06 trunk/thirdparty/xuriella/package.lisp
r3108 r3377 54 54 #:define-extension-compiler 55 55 #:parse-body 56 #:compile-instruction) 56 #:compile-instruction 57 58 #:enable-profiling 59 #:disable-profiling 60 #:report) 57 61 (:import-from :xpath-protocol #:define-default-method) 58 62 (:documentation … … 78 82 @aboutfun{parse-stylesheet} 79 83 @aboutclass{stylesheet} 84 @end{section} 85 @begin[Profiling support]{section} 86 The profiling facility records the run time of XSLT templates. 87 88 @aboutfun{enable-profiling} 89 @aboutfun{disable-profiling} 90 @aboutfun{report} 80 91 @end{section} 81 92 @begin[Defining extension elements]{section} trunk/thirdparty/xuriella/parser.lisp
r3108 r3377 210 210 `(xsl:terminate 211 211 (xsl:text 212 "no fallback children in unknown element using forwards compatible processing"))))) 212 ,(format nil "no fallback children in unknown element ~A/~A using forwards compatible processing" 213 (stp:local-name node) 214 (stp:namespace-uri node))))))) 213 215 214 216 (defmacro define-instruction-parser (name (node-var) &body body) trunk/thirdparty/xuriella/unparse.lisp
r3148 r3377 57 57 (funcall fn *sink*)) 58 58 59 (defmacro defun/unparse (name (&rest args) &body body) 60 `(defun ,name ,args 61 (with-profile-counter (*unparse-xml-counter*) 62 (let ((*unparse-xml-counter* nil)) 63 ,@body)))) 64 59 65 (defmacro with-element 60 66 ((local-name uri &key suggested-prefix extra-namespaces process-aliases) … … 67 73 :process-aliases ,process-aliases)) 68 74 69 (defun doctype (name public-id system-id &optional internal-subset)75 (defun/unparse doctype (name public-id system-id &optional internal-subset) 70 76 (sax:start-dtd *sink* name public-id system-id) 71 77 (when internal-subset 72 78 (sax:unparsed-internal-subset *sink* internal-subset)) 73 79 (sax:end-dtd *sink*)) 74 75 (defstruct sink-element76 local-name77 uri78 suggested-prefix79 all-namespaces80 new-namespaces81 used-prefixes82 attributes83 actual-qname)84 85 (defstruct sink-attribute86 local-name87 uri88 suggested-prefix89 value)90 80 91 81 (defun maybe-emit-start-tag () … … 187 177 :value uri)) 188 178 179 (defstruct sink-element 180 local-name 181 uri 182 suggested-prefix 183 all-namespaces 184 new-namespaces 185 used-prefixes 186 attributes 187 actual-qname) 188 189 (defstruct sink-attribute 190 local-name 191 uri 192 suggested-prefix 193 value) 194 189 195 (defparameter *initial-unparse-namespaces* 190 196 '(("" . "") … … 199 205 (defun invoke-with-element 200 206 (fn local-name uri &key suggested-prefix extra-namespaces process-aliases) 201 (check-type local-name string) 202 (check-type uri string) 203 (check-type suggested-prefix (or null string)) 204 (maybe-emit-start-tag) 205 (when process-aliases 206 (setf uri (unalias-uri uri))) 207 ;; fixme: don't litter this function with calls to with-profile-counter 208 (with-profile-counter (*unparse-xml-counter*) 209 (check-type local-name string) 210 (check-type uri string) 211 (check-type suggested-prefix (or null string)) 212 (maybe-emit-start-tag) 213 (when process-aliases 214 (setf uri (unalias-uri uri)))) 207 215 (let* ((parent *current-element*) 208 216 (elt (make-sink-element … … 217 225 (*current-element* elt) 218 226 (*start-tag-written-p* nil)) 219 ;; always establish explicitly copied namespaces first 220 ;; (not including declarations of the default namespace) 221 (process-extra-namespaces elt extra-namespaces process-aliases) 222 ;; establish the element's prefix (which might have to be the default 223 ;; namespace if it's the empty URI) 224 (ensure-prefix-for-uri elt uri suggested-prefix) 227 (with-profile-counter (*unparse-xml-counter*) 228 ;; always establish explicitly copied namespaces first 229 ;; (not including declarations of the default namespace) 230 (process-extra-namespaces elt extra-namespaces process-aliases) 231 ;; establish the element's prefix (which might have to be the default 232 ;; namespace if it's the empty URI) 233 (ensure-prefix-for-uri elt uri suggested-prefix)) 225 234 ;; we'll do attributes incrementally 226 235 (multiple-value-prog1 227 236 (funcall fn) 228 (maybe-emit-start-tag) 229 (sax:end-element *sink* uri local-name (sink-element-actual-qname elt)) 230 (loop 231 for (prefix . uri) in (sink-element-new-namespaces elt) do 232 (sax:end-prefix-mapping *sink* prefix))))) 237 (with-profile-counter (*unparse-xml-counter*) 238 (maybe-emit-start-tag) 239 (sax:end-element *sink* uri local-name (sink-element-actual-qname elt)) 240 (loop 241 for (prefix . uri) in (sink-element-new-namespaces elt) do 242 (sax:end-prefix-mapping *sink* prefix)))))) 233 243 234 244 (defun process-extra-namespace (elt prefix uri process-aliases) … … 270 280 (push cons (sink-element-new-namespaces elt)))))) 271 281 272 (defun write-attribute282 (defun/unparse write-attribute 273 283 (local-name uri value &key suggested-prefix process-aliases) 274 284 (check-type local-name string) … … 297 307 (sink-element-attributes *current-element*))))))) 298 308 299 (defun write-extra-namespace (prefix uri process-aliases)309 (defun/unparse write-extra-namespace (prefix uri process-aliases) 300 310 (check-type prefix string) 301 311 (check-type uri string) … … 310 320 (process-extra-namespace *current-element* prefix uri process-aliases)))) 311 321 312 (defun write-text (data)322 (defun/unparse write-text (data) 313 323 (maybe-emit-start-tag) 314 324 (sax:characters *sink* data) 315 325 data) 316 326 317 (defun write-comment (data)327 (defun/unparse write-comment (data) 318 328 (maybe-emit-start-tag) 319 329 ;; kludge: rewrite this in a nicer way … … 330 340 (cxml::nc-name-p str))) 331 341 332 (defun write-processing-instruction (target data)342 (defun/unparse write-processing-instruction (target data) 333 343 (maybe-emit-start-tag) 334 344 (setf data (cl-ppcre:regex-replace-all "[?]>" data "? >")) … … 340 350 data) 341 351 342 (defun write-unescaped (str)352 (defun/unparse write-unescaped (str) 343 353 (maybe-emit-start-tag) 344 354 (sax:unescaped *sink* str)) trunk/thirdparty/xuriella/xslt.lisp
r3148 r3377 151 151 ;;; (funcall fn))) 152 152 153 (defstruct profile-counter calls run real) 154 155 (defvar *apply-stylesheet-counter* (make-profile-counter)) 156 (defvar *parse-stylesheet-counter* (make-profile-counter)) 157 (defvar *parse-xml-counter* (make-profile-counter)) 158 (defvar *unparse-xml-counter* (make-profile-counter)) 159 160 (defmacro with-profile-counter ((var) &body body) 161 `((lambda (fn) 162 (if (and *profiling-enabled-p* ,var) 163 (invoke-with-profile-counter fn ,var) 164 (funcall fn))) 165 (lambda () ,@body))) 166 153 167 154 168 ;;;; Helper functions and macros … … 525 539 (stp:append-child new-document-element new-template) 526 540 (stp:append-child new-template literal-result-element) 541 (setf (stp:base-uri new-template) (stp:base-uri literal-result-element)) 527 542 new-document-element)) 528 543 … … 716 731 717 732 (defvar *stylesheet*) 718 719 (defstruct template720 match-expression721 compiled-pattern722 name723 import-priority724 apply-imports-limit725 priority726 position727 mode728 mode-qname729 params730 body731 n-variables)732 733 733 734 (defun parse-stylesheet (designator &key uri-resolver) … … 1231 1232 (with-import-magic (<template> env) 1232 1233 (dolist (template (compile-template <template> env i)) 1234 (setf (template-stylesheet template) stylesheet) 1235 (setf (template-base-uri template) (stp:base-uri <template>)) 1233 1236 (let ((name (template-name template))) 1234 1237 (if name … … 1390 1393 (let ((instruction-base-uri *instruction-base-uri*)) 1391 1394 (lambda (ctx) 1392 (let* ((object (funcall object ctx)) 1393 (node-set (and node-set (funcall node-set ctx))) 1394 (base-uri 1395 (if node-set 1396 (document-base-uri (xpath::textually-first-node node-set)) 1397 instruction-base-uri))) 1398 (xpath-sys:make-node-set 1399 (if (xpath:node-set-p object) 1400 (xpath:map-node-set->list 1401 (lambda (node) 1402 (%document (xpath:string-value node) 1403 (if node-set 1404 base-uri 1405 (document-base-uri node)))) 1406 object) 1407 (list (%document (xpath:string-value object) base-uri)))))))) 1395 (with-profile-counter (*parse-xml-counter*) 1396 (let* ((object (funcall object ctx)) 1397 (node-set (and node-set (funcall node-set ctx))) 1398 (base-uri 1399 (if node-set 1400 (document-base-uri (xpath::textually-first-node node-set)) 1401 instruction-base-uri))) 1402 (xpath-sys:make-node-set 1403 (if (xpath:node-set-p object) 1404 (xpath:map-node-set->list 1405 (lambda (node) 1406 (%document (xpath:string-value node) 1407 (if node-set 1408 base-uri 1409 (document-base-uri node)))) 1410 object) 1411 (list (%document (xpath:string-value object) base-uri))))))))) 1408 1412 1409 1413 … … 1603 1607 1604 1608 @see{parse-stylesheet}" 1605 (when (typep stylesheet 'xml-designator) 1606 (setf stylesheet 1607 (handler-bind 1608 ((cxml:xml-parse-error 1609 (lambda (c) 1610 (xslt-error "cannot parse stylesheet: ~A" c)))) 1611 (parse-stylesheet stylesheet :uri-resolver uri-resolver)))) 1612 (with-resignalled-errors () 1613 (invoke-with-output-sink 1614 (lambda () 1615 (let* ((*uri-to-document* (make-hash-table :test 'equal)) 1616 (*root-to-document* 1617 ;; fixme? should be xpath-protocol:node-equal 1618 (make-hash-table :test 'equal)) 1619 (xpath:*navigator* (or navigator :default-navigator)) 1620 (puri:*strict-parse* nil) 1621 (*stylesheet* stylesheet) 1622 (*empty-mode* (make-mode)) 1623 (*default-mode* (find-mode stylesheet nil)) 1624 (global-variable-chains 1625 (stylesheet-global-variables stylesheet)) 1626 (*global-variable-values* 1627 (make-variable-value-array (length global-variable-chains))) 1628 (*uri-resolver* uri-resolver) 1629 (source-document 1630 (if (typep source-designator 'xml-designator) 1631 (cxml:parse source-designator (stp:make-builder)) 1632 source-designator)) 1633 (xpath-root-node 1634 (make-whitespace-stripper 1635 source-document 1636 (stylesheet-strip-thunk stylesheet))) 1637 (ctx (xpath:make-context xpath-root-node)) 1638 (document (make-source-document 1639 :id 0 1640 :root-node xpath-root-node))) 1641 (when (pathnamep source-designator) ;fixme: else use base uri? 1642 (setf (gethash source-designator *uri-to-document*) document)) 1643 (setf (gethash xpath-root-node *root-to-document*) document) 1644 (map nil 1645 (lambda (chain) 1646 (let ((head (car (variable-chain-definitions chain)))) 1647 (when (variable-param-p head) 1648 (let ((value 1649 (find-parameter-value 1650 (variable-chain-local-name chain) 1651 (variable-chain-uri chain) 1652 parameters))) 1653 (when value 1654 (setf (global-variable-value 1655 (variable-chain-index chain)) 1656 value)))))) 1657 global-variable-chains) 1658 (map nil 1659 (lambda (chain) 1660 (funcall (variable-chain-thunk chain) ctx)) 1661 global-variable-chains) 1662 ;; zzz we wouldn't have to mask float traps here if we used the 1663 ;; XPath API properly. Unfortunately I've been using FUNCALL 1664 ;; everywhere instead of EVALUATE, so let's paper over that 1665 ;; at a central place to be sure: 1666 (xpath::with-float-traps-masked () 1667 (apply-templates ctx :mode *default-mode*)))) 1668 (stylesheet-output-specification stylesheet) 1669 output))) 1609 (with-profile-counter (*apply-stylesheet-counter*) 1610 (when (typep stylesheet 'xml-designator) 1611 (with-profile-counter (*parse-stylesheet-counter*) 1612 (setf stylesheet 1613 (handler-bind 1614 ((cxml:xml-parse-error 1615 (lambda (c) 1616 (xslt-error "cannot parse stylesheet: ~A" c)))) 1617 (parse-stylesheet stylesheet :uri-resolver uri-resolver))))) 1618 (with-resignalled-errors () 1619 (invoke-with-output-sink 1620 (lambda () 1621 (let* ((*uri-to-document* (make-hash-table :test 'equal)) 1622 (*root-to-document* 1623 ;; fixme? should be xpath-protocol:node-equal 1624 (make-hash-table :test 'equal)) 1625 (xpath:*navigator* (or navigator :default-navigator)) 1626 (puri:*strict-parse* nil) 1627 (*stylesheet* stylesheet) 1628 (*empty-mode* (make-mode)) 1629 (*default-mode* (find-mode stylesheet nil)) 1630 (global-variable-chains 1631 (stylesheet-global-variables stylesheet)) 1632 (*global-variable-values* 1633 (make-variable-value-array (length global-variable-chains))) 1634 (*uri-resolver* uri-resolver) 1635 (source-document 1636 (if (typep source-designator 'xml-designator) 1637 (with-profile-counter (*parse-xml-counter*) 1638 (cxml:parse source-designator (stp:make-builder))) 1639 source-designator)) 1640 (xpath-root-node 1641 (make-whitespace-stripper 1642 source-document 1643 (stylesheet-strip-thunk stylesheet))) 1644 (ctx (xpath:make-context xpath-root-node)) 1645 (document (make-source-document 1646 :id 0 1647 :root-node xpath-root-node))) 1648 (when (pathnamep source-designator) ;fixme: else use base uri? 1649 (setf (gethash source-designator *uri-to-document*) document)) 1650 (setf (gethash xpath-root-node *root-to-document*) document) 1651 (map nil 1652 (lambda (chain) 1653 (let ((head (car (variable-chain-definitions chain)))) 1654 (when (variable-param-p head) 1655 (let ((value 1656 (find-parameter-value 1657 (variable-chain-local-name chain) 1658 (variable-chain-uri chain) 1659 parameters))) 1660 (when value 1661 (setf (global-variable-value 1662 (variable-chain-index chain)) 1663 value)))))) 1664 global-variable-chains) 1665 (map nil 1666 (lambda (chain) 1667 (funcall (variable-chain-thunk chain) ctx)) 1668 global-variable-chains) 1669 ;; zzz we wouldn't have to mask float traps here if we used the 1670 ;; XPath API properly. Unfortunately I've been using FUNCALL 1671 ;; everywhere instead of EVALUATE, so let's paper over that 1672 ;; at a central place to be sure: 1673 (xpath::with-float-traps-masked () 1674 (apply-templates ctx :mode *default-mode*)))) 1675 (stylesheet-output-specification stylesheet) 1676 output)))) 1670 1677 1671 1678 (defun find-attribute-set (local-name uri &optional (stylesheet *stylesheet*)) … … 1727 1734 1728 1735 (defvar *apply-imports*) 1736 (defvar *profiling-enabled-p* nil) 1729 1737 1730 1738 (defun apply-applicable-templates (ctx templates param-bindings finally) … … 1739 1747 (<= low (template-import-priority x) high)) 1740 1748 templates)) 1741 (invoke-template ctx this actual-param-bindings)) 1749 (if *profiling-enabled-p* 1750 (invoke-template/profile ctx this actual-param-bindings) 1751 (invoke-template ctx this actual-param-bindings))) 1742 1752 (funcall finally)))) 1743 1753 (let ((*apply-imports* #'apply-imports)) … … 1866 1876 (make-auto-detect-sink (make-combi-sink) method-key))))))) 1867 1877 1878 (defstruct template 1879 match-expression 1880 compiled-pattern 1881 name 1882 import-priority 1883 apply-imports-limit 1884 priority 1885 position 1886 mode 1887 mode-qname 1888 params 1889 body 1890 n-variables 1891 ;; for profiling output only: 1892 unparsed-qname 1893 stylesheet 1894 base-uri) 1895 1868 1896 (defun expression-priority (form) 1869 1897 (let ((step (second form))) … … 1970 1998 :params param-bindings 1971 1999 :body outer-body-thunk 1972 :n-variables n-variables)))) 2000 :n-variables n-variables 2001 ;; record unparsed `name' for profiler output: 2002 :unparsed-qname name)))) 1973 2003 (when match 1974 2004 (mapcar (lambda (expression) trunk/thirdparty/xuriella/xuriella.asd
r3108 r3377 29 29 (:file "stpx") 30 30 (:file "extensions") 31 (:file "profile") 31 32 (:file "test")) 32 33 :depends-on (:cxml :cxml-stp :closure-html :xpath :split-sequence))
