From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: mah@everybody.org (Mark A. Hershberger) Newsgroups: gmane.emacs.devel,gmane.emacs.pretest.bugs Subject: Re: Refactoring xml.el namespace handling Date: Wed, 03 Mar 2004 00:35:42 -0600 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <878yiimo8x.fsf@weblog.localhost> References: <87u117ew6g.fsf@weblog.localhost> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1078384686 14081 80.91.224.253 (4 Mar 2004 07:18:06 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 4 Mar 2004 07:18:06 +0000 (UTC) Cc: emacs-pretest-bug@gnu.org, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Thu Mar 04 08:17:55 2004 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1Ayn7D-00019g-00 for ; Thu, 04 Mar 2004 08:17:55 +0100 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1Ayn7C-0000rb-00 for ; Thu, 04 Mar 2004 08:17:54 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.30) id 1Ayn1r-0004aP-9x for emacs-devel@quimby.gnus.org; Thu, 04 Mar 2004 02:12:23 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.30) id 1AyQ8y-0003Ck-0k for emacs-devel@gnu.org; Wed, 03 Mar 2004 01:46:12 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.30) id 1AyQ7D-0002d3-Om for emacs-devel@gnu.org; Wed, 03 Mar 2004 01:44:56 -0500 Original-Received: from [204.251.8.130] (helo=superman.everybody.org) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.30) id 1AyQ5R-00026E-RX; Wed, 03 Mar 2004 01:42:34 -0500 Original-Received: from [65.70.26.191] (helo=weblog.localhost.everybody.org) by superman.everybody.org with asmtp (Exim 3.35 #1 (Debian)) id 1AyQ6v-0000mC-00; Wed, 03 Mar 2004 00:44:05 -0600 Original-To: Stefan Monnier X-URL: http://mah.everybody.org/weblog/ In-Reply-To: (Stefan Monnier's message of "02 Mar 2004 16:52:19 -0500") User-Agent: Gnus/5.110002 (No Gnus v0.2) Emacs/22.0.0 (gnu/linux) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:20238 gmane.emacs.pretest.bugs:2317 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:20238 Stefan Monnier writes: > Could you send a patch relative to the CVS head version? > Your patch does not apply cleanly to the current code. Argh. My CVS skillz are lacking. Now that I've gotten a good HEAD, here is a fresh diff. 2004-03-03 Mark A. Hershberger * xml.el (xml-maybe-do-ns): new function to handle namespace parsing of both attribute and element names. (xml-ns-parse-ns-attrs, xml-ns-expand-el, xml-ns-expand-attr, xml-intern-attrlist): Removed in favor of xml-maybe-do-ns to avoid un-necessary intern-ing. (xml-parse-tag): Updated assumed namespaces. Cleaned up namespace parsing. (xml-parse-attlist): Now does its own namespace parsing work. (xml-parse-dtd): Updated tag at the ;; beginning of a document). @@ -350,19 +320,25 @@ ;; Parse this node (let* ((node-name (match-string 1)) - (attr-list (xml-parse-attlist)) - (children (if (consp xml-ns) ;; take care of namespace parsing - (progn - (setq xml-ns (xml-ns-parse-ns-attrs - attr-list xml-ns)) - (list (xml-ns-expand-attr - attr-list xml-ns) - (xml-ns-expand-el - node-name xml-ns))) - (list (xml-intern-attrlist attr-list) - (intern node-name)))) + ;; Parse the attribute list. + (children (list (xml-parse-attlist xml-ns) node-name)) pos) + ;; add the xmlns:* attrs to our cache + (when (consp xml-ns) + (mapcar + (lambda (attr) + (when (and (listp (car attr)) + (eq :http://www.w3.org/2000/xmlns/ + (caar attr))) + (setq xml-ns (append (list (cons (cdar attr) + (intern (concat ":" (cdr attr))))) + xml-ns)))) + (car children))) + + ;; expand element names + (setcdr children (list (xml-maybe-do-ns (cadr children) "" xml-ns))) + ;; is this an empty element ? (if (looking-at "/>") (progn @@ -416,7 +392,7 @@ (t ;; This is not a tag. (error "XML: Invalid character"))))) -(defun xml-parse-attlist () +(defun xml-parse-attlist (&optional xml-ns) "Return the attribute-list after point. Leave point at the first non-blank character after the tag." (let ((attlist ()) @@ -424,8 +400,9 @@ (skip-syntax-forward " ") (while (looking-at (eval-when-compile (concat "\\(" xml-name-regexp "\\)\\s-*=\\s-*"))) - (setq name (match-string 1)) - (goto-char (match-end 0)) + (setq end-pos (match-end 0)) + (setq name (xml-maybe-do-ns (match-string 1) nil xml-ns)) + (goto-char end-pos) ;; See also: http://www.w3.org/TR/2000/REC-xml-20001006#AVNormalize @@ -527,7 +504,7 @@ ;; Translation of rule [45] of XML specifications ((looking-at - "]+\\)>") + "]+\\)>") (setq element (match-string 1) type (match-string-no-properties 2)) @@ -556,7 +533,15 @@ (goto-char end-pos)) ((looking-at "")) - + ((looking-at "]+\\)>") + ; Put the ENTITY in + (goto-char (match-end 0))) + ((looking-at "]+\\)>") + ; Put in the ATTLIST + (goto-char (match-end 0))) + ((looking-at "]+\\)>") + ; Put in the NOTATION + (goto-char (match-end 0))) (t (error "XML: Invalid DTD item"))) -- A choice between one man and a shovel, or a dozen men with teaspoons is clear to me, and I'm sure it is clear to you also. -- Zimran Ahmed