;;; nxml-rap.el --- low-level support for random access parsing for nXML mode
-;; Copyright (C) 2003, 2004, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+;; Copyright (C) 2003-2004, 2007-2015 Free Software Foundation, Inc.
;; Author: James Clark
-;; Keywords: XML
+;; Keywords: wp, hypermedia, languages, XML
;; This file is part of GNU Emacs.
;; typical proportion of comments, CDATA sections and processing
;; instructions is small relative to other things. Secondly, to scan
;; we just search for the regexp <[!?].
-;;
-;; One problem is unclosed comments, processing instructions and CDATA
-;; sections. Suppose, for example, we encounter a <!-- but there's no
-;; matching -->. This is not an unexpected situation if the user is
-;; creating a comment. It is not helpful to treat the whole of the
-;; file starting from the <!-- onwards as a single unclosed comment
-;; token. Instead we treat just the <!-- as a piece of not well-formed
-;; markup and continue. The problem is that if at some later stage a
-;; --> gets added to the buffer after the unclosed <!--, we will need
-;; to reparse the buffer starting from the <!--. We need to keep
-;; track of these reparse dependencies; they are called dependent
-;; regions in the code.
;;; Code:
(if (>= start nxml-scan-end)
nxml-scan-end
(let ((inside-remove-start start)
- xmltok-errors
- xmltok-dependent-regions)
+ xmltok-errors)
(while (or (when (xmltok-forward-special (min end nxml-scan-end))
(when (memq xmltok-type
'(comment
(when inside-end
(setq end inside-end)
t))))
- (nxml-clear-inside inside-remove-start end)
- (nxml-clear-dependent-regions start end)
- (nxml-mark-parse-dependent-regions))
+ (nxml-clear-inside inside-remove-start end))
(when (> end nxml-scan-end)
(set-marker nxml-scan-end end))
end))
(defun nxml-scan-prolog ()
(goto-char (point-min))
(let (xmltok-dtd
- xmltok-errors
- xmltok-dependent-regions)
+ xmltok-errors)
(setq nxml-prolog-regions (xmltok-forward-prolog))
(setq nxml-prolog-end (point))
- (nxml-clear-inside (point-min) nxml-prolog-end)
- (nxml-clear-dependent-regions (point-min) nxml-prolog-end)
- (nxml-mark-parse-dependent-regions))
+ (nxml-clear-inside (point-min) nxml-prolog-end))
(when (< nxml-scan-end nxml-prolog-end)
(set-marker nxml-scan-end nxml-prolog-end)))
-;;; Dependent regions
-
-(defun nxml-adjust-start-for-dependent-regions (start end pre-change-length)
- (let ((overlays (overlays-in (1- start) start))
- (adjusted-start start))
- (while overlays
- (let* ((overlay (car overlays))
- (ostart (overlay-start overlay)))
- (when (and (eq (overlay-get overlay 'category) 'nxml-dependent)
- (< ostart adjusted-start))
- (let ((funargs (overlay-get overlay 'nxml-funargs)))
- (when (apply (car funargs)
- (append (list start
- end
- pre-change-length
- ostart
- (overlay-end overlay))
- (cdr funargs)))
- (setq adjusted-start ostart)))))
- (setq overlays (cdr overlays)))
- adjusted-start))
-
-(defun nxml-mark-parse-dependent-regions ()
- (while xmltok-dependent-regions
- (apply 'nxml-mark-parse-dependent-region
- (car xmltok-dependent-regions))
- (setq xmltok-dependent-regions
- (cdr xmltok-dependent-regions))))
-
-(defun nxml-mark-parse-dependent-region (fun start end &rest args)
- (let ((overlay (make-overlay start end nil t t)))
- (overlay-put overlay 'category 'nxml-dependent)
- (overlay-put overlay 'nxml-funargs (cons fun args))))
-
-(put 'nxml-dependent 'evaporate t)
-
-(defun nxml-clear-dependent-regions (start end)
- (let ((overlays (overlays-in start end)))
- (while overlays
- (let* ((overlay (car overlays))
- (category (overlay-get overlay 'category)))
- (when (and (eq category 'nxml-dependent)
- (<= start (overlay-start overlay)))
- (delete-overlay overlay)))
- (setq overlays (cdr overlays)))))
-
;;; Random access parsing
(defun nxml-token-after ()
(point)))
(defun nxml-tokenize-forward ()
- (let (xmltok-dependent-regions
- xmltok-errors)
+ (let (xmltok-errors)
(when (and (xmltok-forward)
(> (point) nxml-scan-end))
(cond ((memq xmltok-type '(comment
cdata-section
processing-instruction))
- (nxml-with-unmodifying-text-property-changes
- (nxml-set-inside (1+ xmltok-start) (point) xmltok-type)))
- (xmltok-dependent-regions
- (nxml-mark-parse-dependent-regions)))
+ (with-silent-modifications
+ (nxml-set-inside (1+ xmltok-start) (point) xmltok-type))))
(set-marker nxml-scan-end (point)))
xmltok-type))
"Move point backwards outside any 'inside' regions or tags.
Point will not move past `nxml-prolog-end'.
Point will either be at BOUND or a '<' character starting a tag
-outside any 'inside' regions. Ignores dependent regions.
+outside any 'inside' regions.
As a precondition, point must be >= BOUND."
(nxml-move-outside-backwards)
(when (not (equal (char-after) ?<))
(when (< nxml-scan-end pos)
(save-excursion
(goto-char nxml-scan-end)
- (let (xmltok-errors
- xmltok-dependent-regions)
+ (let (xmltok-errors)
(while (when (xmltok-forward-special pos)
(when (memq xmltok-type
'(comment
processing-instruction
cdata-section))
- (nxml-with-unmodifying-text-property-changes
+ (with-silent-modifications
(nxml-set-inside (1+ xmltok-start)
(point)
xmltok-type)))
t
(setq pos (point))
nil)))
- (nxml-clear-dependent-regions nxml-scan-end pos)
- (nxml-mark-parse-dependent-regions)
(set-marker nxml-scan-end pos))))))
;;; Element scanning
(defun nxml-scan-error (&rest args)
(signal 'nxml-scan-error args))
-(put 'nxml-scan-error
- 'error-conditions
- '(error nxml-error nxml-scan-error))
-
-(put 'nxml-scan-error
- 'error-message
- "Scan over element that is not well-formed")
+(define-error 'nxml-scan-error
+ "Scan over element that is not well-formed" 'nxml-error)
(provide 'nxml-rap)
-;; arch-tag: cba241ec-4c59-4ef3-aa51-2cf92b3dd24f
;;; nxml-rap.el ends here