Mercurial > emacs
comparison lisp/xml.el @ 63282:3609dc754369
eliminate use of inefficient match-data
author | Mark A. Hershberger <mah@everybody.org> |
---|---|
date | Fri, 10 Jun 2005 15:37:37 +0000 |
parents | d0f8033496b1 |
children | 6fb026ad601f a1b34dec1104 |
comparison
equal
deleted
inserted
replaced
63281:37c3befbdf48 | 63282:3609dc754369 |
---|---|
209 (defvar xml-entity-ref (concat "&" xml-name-re ";")) | 209 (defvar xml-entity-ref (concat "&" xml-name-re ";")) |
210 ;;[69] PEReference ::= '%' Name ';' | 210 ;;[69] PEReference ::= '%' Name ';' |
211 (defvar xml-pe-reference-re (concat "%" xml-name-re ";")) | 211 (defvar xml-pe-reference-re (concat "%" xml-name-re ";")) |
212 ;;[67] Reference ::= EntityRef | CharRef | 212 ;;[67] Reference ::= EntityRef | CharRef |
213 (defvar xml-reference-re (concat "\\(?:" xml-entity-ref "\\|" xml-char-ref-re "\\)")) | 213 (defvar xml-reference-re (concat "\\(?:" xml-entity-ref "\\|" xml-char-ref-re "\\)")) |
214 ;;[10] AttValue ::= '"' ([^<&"] | Reference)* '"' | "'" ([^<&'] | Reference)* "'" | |
215 (defvar xml-att-value-re (concat "\\(?:\"\\(?:[^&\"]\\|" xml-reference-re "\\)*\"\\|" | |
216 "'\\(?:[^&']\\|" xml-reference-re "\\)*'\\)")) | |
217 ;;[56] TokenizedType ::= 'ID' [VC: ID] [VC: One ID per Element Type] [VC: ID Attribute Default] | |
218 ;; | 'IDREF' [VC: IDREF] | |
219 ;; | 'IDREFS' [VC: IDREF] | |
220 ;; | 'ENTITY' [VC: Entity Name] | |
221 ;; | 'ENTITIES' [VC: Entity Name] | |
222 ;; | 'NMTOKEN' [VC: Name Token] | |
223 ;; | 'NMTOKENS' [VC: Name Token] | |
224 (defvar xml-tokenized-type-re "\\(?:ID\\|IDREF\\|IDREFS\\|ENTITY\\|ENTITIES\\|NMTOKEN\\|NMTOKENS\\)") | |
225 ;;[58] NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')' | |
226 (defvar xml-notation-type-re (concat "\\(?:NOTATION" whitespace "(" whitespace "*" xml-name-re | |
227 "\\(?:" whitespace "*|" whitespace "*" xml-name-re "\\)*" whitespace "*)\\)")) | |
228 ;;[59] Enumeration ::= '(' S? Nmtoken (S? '|' S? Nmtoken)* S? ')' [VC: Enumeration] [VC: No Duplicate Tokens] | |
229 (defvar xml-enumeration-re (concat "\\(?:(" whitespace "*" xml-nmtoken-re | |
230 "\\(?:" whitespace "*|" whitespace "*" xml-nmtoken-re "\\)*" | |
231 whitespace ")\\)")) | |
232 ;;[57] EnumeratedType ::= NotationType | Enumeration | |
233 (defvar xml-enumerated-type-re (concat "\\(?:" xml-notation-type-re "\\|" xml-enumeration-re "\\)")) | |
234 ;;[54] AttType ::= StringType | TokenizedType | EnumeratedType | |
235 ;;[55] StringType ::= 'CDATA' | |
236 (defvar xml-att-type-re (concat "\\(?:CDATA\\|" xml-tokenized-type-re "\\|" xml-notation-type-re"\\|" xml-enumerated-type-re "\\)")) | |
237 ;;[60] DefaultDecl ::= '#REQUIRED' | '#IMPLIED' | (('#FIXED' S)? AttValue) | |
238 (defvar xml-default-decl-re (concat "\\(?:#REQUIRED\\|#IMPLIED\\|\\(?:#FIXED" whitespace "\\)*" xml-att-value-re "\\)")) | |
239 ;;[53] AttDef ::= S Name S AttType S DefaultDecl | |
240 (defvar xml-att-def-re (concat "\\(?:" whitespace "*" xml-name-re | |
241 whitespace "*" xml-att-type-re | |
242 whitespace "*" xml-default-decl-re "\\)")) | |
214 ;;[9] EntityValue ::= '"' ([^%&"] | PEReference | Reference)* '"' | 243 ;;[9] EntityValue ::= '"' ([^%&"] | PEReference | Reference)* '"' |
215 ;; | "'" ([^%&'] | PEReference | Reference)* "'" | 244 ;; | "'" ([^%&'] | PEReference | Reference)* "'" |
216 (defvar xml-entity-value-re (concat "\\(?:\"\\(?:[^%&\"]\\|" xml-pe-reference-re | 245 (defvar xml-entity-value-re (concat "\\(?:\"\\(?:[^%&\"]\\|" xml-pe-reference-re |
217 "\\|" xml-reference-re "\\)*\"\\|'\\(?:[^%&']\\|" | 246 "\\|" xml-reference-re "\\)*\"\\|'\\(?:[^%&']\\|" |
218 xml-pe-reference-re "\\|" xml-reference-re "\\)*'\\)"))) | 247 xml-pe-reference-re "\\|" xml-reference-re "\\)*'\\)"))) |
578 (forward-char) | 607 (forward-char) |
579 (if (not (eq (char-after) ?\[)) | 608 (if (not (eq (char-after) ?\[)) |
580 (error "XML: Bad DTD") | 609 (error "XML: Bad DTD") |
581 (forward-char) | 610 (forward-char) |
582 ;; Parse the rest of the DTD | 611 ;; Parse the rest of the DTD |
583 ;; Fixme: Deal with ATTLIST, NOTATION, PIs. | 612 ;; Fixme: Deal with NOTATION, PIs. |
584 (while (not (looking-at "\\s-*\\]")) | 613 (while (not (looking-at "\\s-*\\]")) |
585 (skip-syntax-forward " ") | 614 (skip-syntax-forward " ") |
586 (cond | 615 (cond |
587 | 616 |
588 ;; Translation of rule [45] of XML specifications | 617 ;; Translation of rule [45] of XML specifications |
614 element)) | 643 element)) |
615 | 644 |
616 ;; Store the element in the DTD | 645 ;; Store the element in the DTD |
617 (push (list element type) dtd) | 646 (push (list element type) dtd) |
618 (goto-char end-pos)) | 647 (goto-char end-pos)) |
648 | |
649 ;; Translation of rule [52] of XML specifications | |
650 ((looking-at (concat "<!ATTLIST[ \t\n\r]*\\(" xml-name-re | |
651 "\\)[ \t\n\r]*\\(" xml-att-def-re | |
652 "\\)*[ \t\n\r]*>")) | |
653 | |
654 ;; We don't do anything with ATTLIST currently | |
655 (goto-char (match-end 0))) | |
656 | |
619 ((looking-at "<!--") | 657 ((looking-at "<!--") |
620 (search-forward "-->")) | 658 (search-forward "-->")) |
621 ((looking-at (concat "<!ENTITY[ \t\n\r]*\\(" xml-name-re | 659 ((looking-at (concat "<!ENTITY[ \t\n\r]*\\(" xml-name-re |
622 "\\)[ \t\n\r]*\\(" xml-entity-value-re | 660 "\\)[ \t\n\r]*\\(" xml-entity-value-re |
623 "\\)[ \t\n\r]*>")) | 661 "\\)[ \t\n\r]*>")) |
624 (let ((name (buffer-substring (nth 2 (match-data)) | 662 (let ((name (match-string 1)) |
625 (nth 3 (match-data)))) | 663 (value (substring (match-string 2) 1 |
626 (value (buffer-substring (+ (nth 4 (match-data)) 1) | 664 (- (length (match-string 2)) 1)))) |
627 (- (nth 5 (match-data)) 1)))) | 665 (goto-char (match-end 0)) |
628 (goto-char (nth 1 (match-data))) | |
629 (setq xml-entity-alist | 666 (setq xml-entity-alist |
630 (append xml-entity-alist | 667 (append xml-entity-alist |
631 (list (cons name | 668 (list (cons name |
632 (with-temp-buffer | 669 (with-temp-buffer |
633 (insert value) | 670 (insert value) |
642 "\\)[ \t\n\r]+PUBLIC[ \t\n\r]+" | 679 "\\)[ \t\n\r]+PUBLIC[ \t\n\r]+" |
643 "\"[- \r\na-zA-Z0-9'()+,./:=?;!*#@$_%]*\"" | 680 "\"[- \r\na-zA-Z0-9'()+,./:=?;!*#@$_%]*\"" |
644 "\\|'[- \r\na-zA-Z0-9()+,./:=?;!*#@$_%]*'" | 681 "\\|'[- \r\na-zA-Z0-9()+,./:=?;!*#@$_%]*'" |
645 "[ \t\n\r]+\\(\"[^\"]*\"\\|'[^']*'\\)" | 682 "[ \t\n\r]+\\(\"[^\"]*\"\\|'[^']*'\\)" |
646 "[ \t\n\r]*>"))) | 683 "[ \t\n\r]*>"))) |
647 (let ((name (buffer-substring (nth 2 (match-data)) | 684 (let ((name (match-string 1)) |
648 (nth 3 (match-data)))) | 685 (file (substring (match-string 2) 1 |
649 (file (buffer-substring (+ (nth 4 (match-data)) 1) | 686 (- (length (match-string 2)) 1)))) |
650 (- (nth 5 (match-data)) 1)))) | 687 (goto-char (match-end 0)) |
651 (goto-char (nth 1 (match-data))) | |
652 (setq xml-entity-alist | 688 (setq xml-entity-alist |
653 (append xml-entity-alist | 689 (append xml-entity-alist |
654 (list (cons name (with-temp-buffer | 690 (list (cons name (with-temp-buffer |
655 (insert-file-contents file) | 691 (insert-file-contents file) |
656 (goto-char (point-min)) | 692 (goto-char (point-min)) |
675 (goto-char (match-end 0))) | 711 (goto-char (match-end 0))) |
676 (t | 712 (t |
677 (when xml-validating-parser | 713 (when xml-validating-parser |
678 (error "XML: (Validity) Invalid DTD item")))))) | 714 (error "XML: (Validity) Invalid DTD item")))))) |
679 (if (looking-at "\\s-*]>") | 715 (if (looking-at "\\s-*]>") |
680 (goto-char (nth 1 (match-data))))) | 716 (goto-char (match-end 0)))) |
681 (nreverse dtd))) | 717 (nreverse dtd))) |
682 | 718 |
683 (defun xml-parse-elem-type (string) | 719 (defun xml-parse-elem-type (string) |
684 "Convert element type STRING into a Lisp structure." | 720 "Convert element type STRING into a Lisp structure." |
685 | 721 |