annotate lisp/psgml/psgml-parse.el @ 78:c7528f8e288d r20-0b34

Import from CVS: tag r20-0b34
author cvs
date Mon, 13 Aug 2007 09:05:42 +0200
parents 54cc21c15cbb
children 1ce6082ce73f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;;; psgml-parse.el --- Parser for SGML-editing mode with parsing support
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 74
diff changeset
2 ;; $Id: psgml-parse.el,v 1.2 1997/01/03 03:10:27 steve Exp $
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Copyright (C) 1994, 1995 Lennart Staflin
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Author: Lennart Staflin <lenst@lysator.liu.se>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Acknowledgment:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; The catalog parsing code was contributed by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; David Megginson <dmeggins@aix1.uottawa.CA>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; This program is free software; you can redistribute it and/or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; modify it under the terms of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; as published by the Free Software Foundation; either version 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; of the License, or (at your option) any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; This program is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; along with this program; if not, write to the Free Software
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; Part of major mode for editing the SGML document-markup language.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (require 'psgml)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;; Interface to psgml-dtd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (eval-and-compile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (autoload 'sgml-do-usemap-element "psgml-dtd")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (autoload 'sgml-write-dtd "psgml-dtd")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (autoload 'sgml-check-dtd-subset "psgml-dtd")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;;; Advise to do-auto-fill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (defvar sgml-auto-fill-inhibit-function nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 "If non-nil, it should be a function of no arguments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 The functions is evaluated before the standard auto-fill function,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 do-auto-fill, tries to fill a line. If the function returns a true
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 value the auto-fill is inhibited.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;;(defadvice do-auto-fill (around disable-auto-fill-hook activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;; (or (and sgml-auto-fill-inhibit-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;; (funcall sgml-auto-fill-inhibit-function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;; ad-do-it))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;;;; Variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;;; Hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (defvar sgml-open-element-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 "The hook run by `sgml-open-element'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 Theses functions are called with two arguments, the first argument is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 the opened element and the second argument is the attribute specification
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 list. It is probably best not to refer to the content or the end-tag of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 the element.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (defvar sgml-close-element-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 "The hook run by `sgml-close-element'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 These functions are invoked with `sgml-current-tree' bound to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 element just parsed.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (defvar sgml-doctype-parsed-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 "This hook is caled after the doctype has been parsed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 It can be used to load any additional information into the DTD structure.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (defvar sgml-sysid-resolve-functions nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 "This variable should contain a list of functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 Each function should take one argument, the system identifier of an entity.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 If the function can handle that identifier, it should insert the text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 of the entity into the current buffer at point and return t. If the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 system identifier is not handled the function should return nil.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;;; Internal variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (defconst sgml-pcdata-token (intern "#PCDATA"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (defvar sgml-computed-map nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 "Internal representation of entity search map.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (defvar sgml-used-entity-map nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 "The value of `sgml-current-entity-map' used to compute the map in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 `sgml-compute-map'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (defvar sgml-last-element nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 "Used to keep information about position in element structure between
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 commands.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (defconst sgml-users-of-last-element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 '(sgml-beginning-of-element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 sgml-end-of-element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 sgml-up-element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 sgml-backward-up-element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 sgml-backward-element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 sgml-forward-element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 sgml-down-element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 sgml-show-context
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 sgml-next-data-field
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 "List of commands that set the sgml-last-element variable.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (defvar sgml-parser-syntax nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 "Syntax table used during parsing.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (defvar sgml-ecat-assoc nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 "Assoc list caching parsed ecats.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (defvar sgml-catalog-assoc nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 "Assoc list caching parsed catalogs.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ;;; Variables dynamically bound to affect parsing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (defvar sgml-throw-on-warning nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 "Set to a symbol other than nil to make sgml-log-warning throw to that symbol.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (defvar sgml-throw-on-error nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 "Set to a symbol other than nil to make sgml-error throw to that symbol.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (defvar sgml-show-warnings nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 "Set to t to show warnings.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (defvar sgml-close-element-trap nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 "Can be nil for no trap, an element or t for any element.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 Tested by sgml-close-element to see if the parse should be ended.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (defvar sgml-goal 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 "Point in buffer to parse up to.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (defvar sgml-shortref-handler (function sgml-handle-shortref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 "Function called by parser to handle a short reference.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 Called with the entity as argument. The start and end of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 short reference is `sgml-markup-start' and point.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (defvar sgml-data-function nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 "Function called with parsed data.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (defvar sgml-entity-function nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 "Function called with entity referenced at current point in parse.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (defvar sgml-pi-function nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 "Function called with parsed process instruction.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (defvar sgml-signal-data-function nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 "Called when some data characters are conceptually parsed,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 e.g. a data entity reference.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (defvar sgml-throw-on-element-change nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 "Throw tag.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 ;;; Global variables active during parsing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (defvar sgml-parsing-dtd nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 "This variable is bound to `t' while parsing a DTD (subset).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (defvar sgml-rs-ignore-pos nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 "Set to position of last parsing start in current buffer.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (make-variable-buffer-local 'sgml-rs-ignore-pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (defvar sgml-dtd-info nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 "Holds the `sgml-dtd' structure describing the current DTD.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (defvar sgml-current-omittag nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 "Value of `sgml-omittag' in main buffer. Valid during parsing.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (defvar sgml-current-shorttag nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 "Value of `sgml-shorttag' in main buffer. Valid during parsing.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (defvar sgml-current-localcat nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 "Value of `sgml-local-catalogs' in main buffer. Valid during parsing.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (defvar sgml-current-local-ecat nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 "Value of `sgml-local-ecat-files' in main buffer. Valid during parsing.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
185 (defvar sgml-current-top-buffer nil
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
186 "The buffer of the document entity, the main buffer.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
187 Valid during parsing. This is used to find current directory for
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
188 catalogs.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
189
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (defvar sgml-current-state nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 "Current state in content model or model type if CDATA, RCDATA or ANY.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (defvar sgml-current-shortmap nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 "The current active short reference map.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (defvar sgml-current-tree nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 "Current parse tree node, identifies open element.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (defvar sgml-previous-tree nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 "Previous tree node in current tree.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 This is nil if no previous node.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (defvar sgml-markup-type nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 "Contains the type of markup parsed last.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 The value is a symbol:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 nil - pcdata or space
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 CDATA - CDATA or RCDATA
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 comment - comment declaration
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 doctype - doctype declaration
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 end-tag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 ignored - ignored marked section
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 ms-end - marked section start, if not ignored
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 ms-start - marked section end, if not ignored
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 pi - processing instruction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 sgml - SGML declaration
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 start-tag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 entity - general entity reference
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 param - parameter reference
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 shortref- short reference
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 mdecl - markup declaration
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (defvar sgml-top-tree nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 "Root node of parse tree during parsing.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (defvar sgml-markup-tree nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 "Tree node of markup parsed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 In case markup closed element this is different from sgml-current-tree.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 Only valid after `sgml-parse-to'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (defvar sgml-markup-start nil
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 30
diff changeset
232 "Start point of markup beeing parsed.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (defvar sgml-conref-flag nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 "This variable is set by `sgml-parse-attribute-specification-list'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 if a CONREF attribute is parsed.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (defvar sgml-no-elements nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 "Number of declared elements.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 ;;; Vars used in *param* buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (defvar sgml-previous-buffer nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (defvar sgml-current-eref nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 "This is the entity reference used to enter current entity.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 If this is nil, then current entity is main buffer.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (defvar sgml-scratch-buffer nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 "The global value of this variable is the first scratch buffer for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 entities. The entity buffers can have a buffer local value for this variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 to point to the next scratch buffer.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (defvar sgml-last-entity-buffer nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 ;;; For loading DTD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (eval-and-compile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (defconst sgml-max-single-octet-number 250
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 "Octets greater than this is the first of a two octet coding."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (defvar sgml-read-token-vector nil) ; Vector of symbols used to decode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ; token numbers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (defvar sgml-read-nodes nil) ; Vector of nodes used when reading
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 ; a finite automaton.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 ;; Buffer local variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (defvar sgml-loaded-dtd nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 "File name corresponding to current DTD.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (make-variable-buffer-local 'sgml-loaded-dtd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (defvar sgml-current-element-name nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 "Name of current element for mode line display.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 ;;;; Build parser syntax table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (setq sgml-parser-syntax (make-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (let ((i 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (while (< i 256)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (modify-syntax-entry i " " sgml-parser-syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (setq i (1+ i))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (mapconcat (function (lambda (c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (modify-syntax-entry c "w" sgml-parser-syntax)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrtsuvwxyz" "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (mapconcat (function (lambda (c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (modify-syntax-entry c "_" sgml-parser-syntax)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 "-.0123456789" "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (mapconcat (function (lambda (c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (modify-syntax-entry c "." sgml-parser-syntax)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 "</>&%#[]" ".")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 ;;(progn (set-syntax-table sgml-parser-syntax) (describe-syntax))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (defmacro sgml-with-parser-syntax (&rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (` (let ((normal-syntax-table (syntax-table)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (set-syntax-table sgml-parser-syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (progn (,@ body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (set-syntax-table normal-syntax-table)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 ;;;; State machine
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 ;; From the parsers POV a state is a mapping from tokens (in sgml it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 ;; is primitive state tokens) to states. The pairs of the mapping is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 ;; called moves.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 ;; DFAs are always represented by the start state, which is a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 ;; normal state. Normal states contain moves of two types:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 ;; 1. moves for required tokens, 2. moves for optional tokens.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 ;; By design these are keept in two different sets.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 ;; [Alt: they could perhaps have been keept in one set but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 ;; marked in different ways.]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
320 ;; The and-model groups creates too big state machines, therefor
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
321 ;; there is a datastruture called and-node.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
322
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
323 ;; A and-node is a specification for a dfa that has not been computed.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 ;; It contains a set of dfas that all have to be traversed befor going
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
325 ;; to the next state. The and-nodes are only stored in moves and are
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
326 ;; not seen by the parser. When a move is taken the and-node is converted
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
327 ;; to a and-state.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
328
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
329 ;; A and-state keeps track of which dfas still need to be
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 ;; traversed and the state of the current dfa.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 ;; move = <token, node>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
334 ;; node = normal-state | and-node
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
335
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
336 ;; and-node = <dfas, next>
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 ;; where: dfas is a set of normal-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 ;; next is a normal-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
340 ;; State = normal-state | and-state
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 ;; The parser only knows about the state type.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 ;; normal-state = <opts, reqs>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 ;; where: opts is a set of moves for optional tokens
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 ;; reqs is a set of moves for required tokens
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
347 ;; and-state = <substate, dfas, next>
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 ;; where: substate is a normal-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 ;; dfas is a set of states
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 ;; next is the next state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
352 ;; The and-state is only used during the parsing.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 ;; Primitiv functions to get data from parse state need
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
354 ;; to know both normal-state and and-state.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 ;;; Representations:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 ;;move: (token . node)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (defmacro sgml-make-move (token node)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (` (cons (, token) (, node))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (defmacro sgml-move-token (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (` (car (, x))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (defmacro sgml-move-dest (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (` (cdr (, x))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 ;; set of moves: list of moves
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (defmacro sgml-add-move-to-set (token node set)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (`(cons (cons (, token) (, node)) (, set))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (defmacro sgml-moves-lookup (token set)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (` (assq (, token) (, set))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 ;; normal-state: ('normal-state opts . reqs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (defsubst sgml-make-state ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (cons 'normal-state (cons nil nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (defmacro sgml-normal-state-p (s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (` (eq (car (, s)) 'normal-state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (defmacro sgml-state-opts (s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (` (cadr (, s))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (defmacro sgml-state-reqs (s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (` (cddr (, s))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (defmacro sgml-state-final-p (s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (`(null (sgml-state-reqs (, s)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 ;; adding moves
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 ;; *** Should these functions check for ambiguity?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 ;; What if adding a optional move for a token that has a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 ;; required move?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 ;; What about the other way?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (defsubst sgml-add-opt-move (s token dest)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (or (sgml-moves-lookup token (sgml-state-opts s))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (setf (sgml-state-opts s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (sgml-add-move-to-set token dest (sgml-state-opts s)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (defsubst sgml-add-req-move (s token dest)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (or (sgml-moves-lookup token (sgml-state-reqs s))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (setf (sgml-state-reqs s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (sgml-add-move-to-set token dest (sgml-state-reqs s)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (defsubst sgml-make-primitive-content-token (token)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (let ((s1 (sgml-make-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (s2 (sgml-make-state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (sgml-add-req-move s1 token s2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 s1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
417 ;;and-state: (state next . dfas)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
418
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
419 (defsubst sgml-make-and-state (state dfas next)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (cons state (cons next dfas)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
422 (defsubst sgml-step-and-state (state and-state)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
423 (cons state (cdr and-state)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
424
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
425 (defsubst sgml-and-state-substate (s)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (car s))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
428 (defsubst sgml-and-state-dfas (s)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (cddr s))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
431 (defsubst sgml-and-state-next (s)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (cadr s))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
435 ;;and-node: (next . dfas)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
436
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
437 (defsubst sgml-make-and-node (dfas next)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (cons next dfas))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
440 (defmacro sgml-and-node-next (n)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (` (car (, n))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
443 (defmacro sgml-and-node-dfas (n)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (` (cdr (, n))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 ;;; Using states
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 74
diff changeset
449 (defsubst sgml-final (state)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 74
diff changeset
450 (if (sgml-normal-state-p state)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 74
diff changeset
451 (sgml-state-final-p state)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 74
diff changeset
452 (sgml-final-and state)))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 74
diff changeset
453
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 74
diff changeset
454 (defun sgml-final-and (state)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 74
diff changeset
455 (and (sgml-final (sgml-and-state-substate state))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 74
diff changeset
456 (loop for s in (sgml-and-state-dfas state)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 74
diff changeset
457 always (sgml-state-final-p s))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 74
diff changeset
458 (sgml-state-final-p (sgml-and-state-next state))))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 74
diff changeset
459
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 ;; get-move: State x Token --> State|nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (defsubst sgml-get-move (state token)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 "Return a new state or nil, after traversing TOKEN from STATE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 ((sgml-normal-state-p state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (let ((c (or (sgml-moves-lookup token (sgml-state-opts state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (sgml-moves-lookup token (sgml-state-reqs state)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (if c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (let ((dest (sgml-move-dest c)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (if (sgml-normal-state-p dest)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 dest
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
472 ;; dest is a and-node
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
473 (sgml-next-sub-and (sgml-and-node-dfas dest)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
474 token
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
475 (sgml-and-node-next dest)))))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
476 (t ;state is a and-state
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
477 (sgml-get-and-move state token))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
478
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
479 (defun sgml-get-and-move (state token)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
480 ;; state is a and-state
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
481 (let ((m (sgml-get-move (sgml-and-state-substate state) token)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
482 (cond (m (cons m (cdr state)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
483 ((sgml-final (sgml-and-state-substate state))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
484 (sgml-next-sub-and (sgml-and-state-dfas state)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 token
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
486 (sgml-and-state-next state))))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
487
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
488 (defun sgml-next-sub-and (dfas token next)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 "Compute the next state, choosing from DFAS and moving by TOKEN.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 If this is not possible, but all DFAS are final, move by TOKEN in NEXT."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (let ((allfinal t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (l dfas)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (res nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 s1 s2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (while (and l (not res))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (setq s1 (car l)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 allfinal (and allfinal (sgml-state-final-p s1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 s2 (sgml-get-move s1 token)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
499 res (and s2 (sgml-make-and-state s2 (remq s1 dfas) next))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 l (cdr l)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (cond (res)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (allfinal (sgml-get-move next token)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (defsubst sgml-tokens-of-moves (moves)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (mapcar (function (lambda (m) (sgml-move-token m)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 moves))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (defun sgml-required-tokens (state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (if (sgml-normal-state-p state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (sgml-tokens-of-moves (sgml-state-reqs state))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
511 (or (sgml-required-tokens (sgml-and-state-substate state))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
512 (loop for s in (sgml-and-state-dfas state)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 nconc (sgml-tokens-of-moves (sgml-state-reqs s)))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
514 (sgml-tokens-of-moves (sgml-state-reqs (sgml-and-state-next state))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (defun sgml-optional-tokens (state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (if (sgml-normal-state-p state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (sgml-tokens-of-moves (sgml-state-opts state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (nconc
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
520 (sgml-optional-tokens (sgml-and-state-substate state))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
521 (if (sgml-final (sgml-and-state-substate state))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
522 (loop for s in (sgml-and-state-dfas state)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 nconc (sgml-tokens-of-moves (sgml-state-opts s))))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
524 (if (loop for s in (sgml-and-state-dfas state)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 always (sgml-state-final-p s))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
526 (sgml-tokens-of-moves
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
527 (sgml-state-opts (sgml-and-state-next state)))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 ;;;; Attribute Types
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 ;;; Basic Types
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 ;; name = string attribute names are lisp symbols
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 ;; attval = string attribute values are lisp strings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 ;;; Attribute Declaration Type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 ;; attdecl = <name, declared-value, default-value>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 ;; This is the result of the ATTLIST declarations in the DTD.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 ;; All attribute declarations for an element is the elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 ;; attlist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 ;;; Attribute Declaration Operations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 ;; sgml-make-attdecl: name declared-value default-value -> attdecl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 ;; sgml-attdecl-name: attdecl -> name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 ;; sgml-attdecl-declared-value: attdecl -> declared-value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 ;; sgml-attdecl-default-value: attdecl -> default-value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 ;;; Attribute Declaration List Type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 ;; attlist = attdecl*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 ;;; Attribute Declaration List Operations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 ;; sgml-lookup-attdecl: name x attlist -> attdecl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 ;;; Declared Value Type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 ;; declared-value = (token-group | notation | simpel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 ;; token-group = nametoken+
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 ;; notation = nametoken+
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 ;; simple = symbol lisp symbol corresponding to SGML type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 ;;; Declared Value Operations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 ;; sgml-declared-value-token-group: declared-value -> list of symbols
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 ;; sgml-declared-value-notation: declared-value -> list of symbols
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 ;; (empty list if not token-group/notation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 ;;; Default Value Type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 ;; default-value = (required | implied | conref | specified )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 ;; implied, conref = constant symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 ;; specified = (fixed | normal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 ;; fixed, normal = attval
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 ;;; Default Value Operations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 ;; sgml-default-value-attval: default-value -> (attval | nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 ;; sgml-default-value-type-p: type x default-value -> cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 ;;; Attribute Specification Type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 ;; attspec = <name, attval>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 ;; This is the result of parsing an attribute specification.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 ;; sgml-make-attspec: name x attval -> attspec
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 ;; sgml-attspec-name: attspec -> name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 ;; sgml-attspec-attval: attspec -> attval
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 ;;; Attribute Specification List Type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 ;; asl = attspec*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 ;; aka. attribute value list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 ;;; Code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 ;;; attdecl representation = (name declared-value default-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 (defun sgml-make-attdecl (name dcl-value default-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (list name dcl-value default-value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 (defun sgml-attdecl-name (attdecl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 (car attdecl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (defun sgml-attdecl-declared-value (attdecl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 "The declared value of ATTDECL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 It may be a symbol or (name-token-group (NAME1 ... NAMEn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 or (notation (NOT1 ... NOTn))"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 (cadr attdecl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 (defun sgml-attdecl-default-value (attdecl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 "The default value of ATTDECL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 The default value is either a symbol (required | implied | current |
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 conref) or a list with first element nil or symbol 'fixed' and second
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 element the value."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 (caddr attdecl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 ;;; attlist representation = (attspec*)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (defun sgml-lookup-attdecl (name attlist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 "Return the attribute declaration for NAME in ATTLIST."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (assoc name attlist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (defun sgml-attribute-with-declared-value (attlist declared-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 "Find the first attribute in ATTLIST that has DECLARED-VALUE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (let ((found nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (while (and attlist (not found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 (when (equal declared-value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (sgml-attdecl-declared-value (car attlist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (setq found (car attlist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (setq attlist (cdr attlist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 ;;; declared-value representation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 ;; token-group = (name-token (symbol+))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 ;; notation = (notation (symbol+))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 ;; simple = symbol lisp symbol correspoinding to SGML type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (defun sgml-make-declared-value (type &optional names)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 "Make a declared-value of TYPE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 TYPE should be a symbol. If TYPE is name-token-group or notation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 NAMES should be a list of symbols."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (if (consp names)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (list type names)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 (defun sgml-declared-value-token-group (declared-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 "Return the name token group for the DECLARED-VALUE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 This applies to name token groups. For other declared values nil is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 returned."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (and (consp declared-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (eq 'name-token-group (car declared-value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (cadr declared-value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 (defun sgml-declared-value-notation (declared-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 "Return the list of notation names for the DECLARED-VALUE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 This applies to notation declared value. For other declared values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 nil is returned."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 (and (consp declared-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 (eq 'notation (car declared-value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 (cadr declared-value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 ;;; default-value representation = symbol | ((nil | 'fixed) attval)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 (defun sgml-make-default-value (type &optional attval)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 (if attval
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (list type attval)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 (defun sgml-default-value-attval (default-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 "Return the actual default value of the declared DEFAULT-VALUE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 The actual value is a string. Return nil if no actual value."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (and (consp default-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 (cadr default-value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 (defun sgml-default-value-type-p (type default-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 "Return true if DEFAULT-VALUE is of TYPE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 Where TYPE is a symbol, one of required, implied, conref, or fixed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (or (eq type default-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 (and (consp default-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (eq type (car default-value)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 ;;; attspec representation = (symbol . string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (defun sgml-make-attspec (name attval)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 "Create an attspec from NAME and ATTVAL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 Special case, if ATTVAL is nil this is an implied attribute."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 (cons name attval))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 ;; sgml-attspec-name: attspec -> name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 (defun sgml-attspec-name (attspec)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 (car attspec))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 ;; sgml-attspec-attval: attspec -> attval
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 (defun sgml-attspec-attval (attspec)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 "Return the value of attribute specification ATTSPEC.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 If ATTSPEC is nil, nil is returned."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 (cdr attspec))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 ;;; asl representaion = (attspec*)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 (defun sgml-lookup-attspec (name asl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 (assoc name asl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 ;;;; Element content types
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 ;; The content of an element is defined as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 ;; (125 declared content | 126 content model),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 ;; 125 declared content = "CDATA" | "RCDATA" | "EMPTY"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 ;; 126 content model = (127 model group | "ANY"),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 ;; (65 ps+, 138 exceptions)?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 ;; I represent a model group with the first state of a corresponding finite
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 ;; automaton (this is a cons). Exceptions are handled separately.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 ;; The other content types are represented by symbols.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (defsubst sgml-model-group-p (model)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 (consp model))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 (defconst sgml-cdata 'CDATA)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (defconst sgml-rcdata 'RCDATA)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 (defconst sgml-empty 'EMPTY)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 (defconst sgml-any 'ANY)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 ;;;; External identifier
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 ;; extid = (pubid? sysid? dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 ;; Representation as (pubid sysid . dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 ;; where pubid = nil | string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 ;; sysid = nil | string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 ;; dir = string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 (defun sgml-make-extid (pubid sysid &optional dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 (cons pubid (cons sysid (or dir default-directory))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 (defun sgml-extid-pubid (extid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 (car extid))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 (defun sgml-extid-sysid (extid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 (if (consp (cdr extid))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (cadr extid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 (cdr extid)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 (defun sgml-extid-dir (extid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 "Directory where EXTID was declared"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 (if (consp (cdr extid))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 (cddr extid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 (defun sgml-extid-expand (file extid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 "Expand file name FILE in the context of EXTID."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 (expand-file-name file (sgml-extid-dir extid)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 ;;;; DTD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 ;; DTD = (doctype, eltypes, parameters, entities, shortmaps,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 ;; notations, dependencies, merged)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 ;; DTDsubset ~=~ DTD, but doctype is unused
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 ;; doctype = name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 ;; eltypes = oblist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 ;; parameters = entity*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 ;; entities = entity*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 ;; shortmaps = (name, shortmap)*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 ;; dependencies = file*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 ;; merged = Compiled-DTD? where Compiled-DTD = (file, DTD)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 (defstruct (sgml-dtd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (:type vector)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 (:constructor sgml-make-dtd (doctype)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 doctype ; STRING, name of doctype
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 (eltypes ; OBLIST, element types defined
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 (sgml-make-eltype-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 (parameters ; ALIST
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 (sgml-make-entity-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 (entities ; ALIST
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 (sgml-make-entity-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (shortmaps ; ALIST
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 (sgml-make-shortref-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (notations ; ??
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 (dependencies ; LIST
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 (merged ; (file . DTD)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 (undef-entities ; LIST of entity names
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 ;;;; Element type objects
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 ;; An element type object contains the information about an element type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 ;; obtained from parsing the DTD.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 ;; An element type object is represented by a symbol in a special oblist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 ;; A table of element type objects is represented by a oblist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 ;;; Element type objects
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 (defun sgml-eltype-name (et)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 (symbol-name et))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 (define-compiler-macro sgml-eltype-name (et)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 (`(symbol-name (, et))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 (defun sgml-eltype-defined (et)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 (fboundp et))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 (defun sgml-eltype-token (et)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 "Return a token for the element type"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 et)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 (define-compiler-macro sgml-eltype-token (et)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 et)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 (defun sgml-token-eltype (token)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 "Return the element type corresponding to TOKEN."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 token)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 (define-compiler-macro sgml-token-eltype (token)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 token)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 (defmacro sgml-prop-fields (&rest names)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 (cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 'progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 (loop for n in names collect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 (`(defmacro (, (intern (format "sgml-eltype-%s" n))) (et)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 (list 'get et ''(, n)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 (sgml-prop-fields
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 ;;flags ; optional tags and mixed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 ; (perhaps in value field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 ;;model ; Content type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 ; (perhaps in function field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 attlist ; List of defined attributes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 includes ; List of included elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 excludes ; List of excluded elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 shortmap ; Associated shortref map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 ; nil if none and 'empty if #empty
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 (defmacro sgml-eltype-flags (et)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 (` (symbol-value (, et))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 (defun sgml-eltype-model (et)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 (if (fboundp et)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 (symbol-function et)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 sgml-any))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 (defsetf sgml-eltype-model fset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 (defun sgml-eltype-stag-optional (et)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 (oddp (sgml-eltype-flags et)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 (defun sgml-eltype-etag-optional (et)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 (/= 0 (logand 2 (sgml-eltype-flags et))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 (defun sgml-eltype-mixed (et)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 (< 3 (sgml-eltype-flags et)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 (define-compiler-macro sgml-eltype-mixed (et)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 (`(< 3 (sgml-eltype-flags (, et)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 (defsetf sgml-eltype-stag-optional (et) (f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 (list 'sgml-set-eltype-flag et 1 f))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 (defsetf sgml-eltype-etag-optional (et) (f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 (list 'sgml-set-eltype-flag et 2 f))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 (defsetf sgml-eltype-mixed (et) (f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 (list 'sgml-set-eltype-flag et 4 f))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 (defun sgml-set-eltype-flag (et mask f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 (setf (sgml-eltype-flags et)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 (logior (logand (if (boundp et)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 (sgml-eltype-flags et)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 (lognot mask))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 (if f mask 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 (defun sgml-maybe-put (sym prop val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 (when val (put sym prop val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 (defsetf sgml-eltype-includes (et) (l)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 (list 'sgml-maybe-put et ''includes l))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 (defsetf sgml-eltype-excludes (et) (l)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 (list 'sgml-maybe-put et ''excludes l))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 (defmacro sgml-eltype-appdata (et prop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 "Get application data from element type ET with name PROP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 PROP should be a symbol, reserved names are: flags, model, attlist,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 includes, excludes, conref-regexp, mixed, stag-optional, etag-optional."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 (` (get (, et) (, prop))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 (defun sgml-eltype-all-miscdata (et)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 (loop for p on (symbol-plist et) by (function cddr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 unless (memq (car p) '(model flags includes excludes))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 nconc (list (car p) (cadr p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 (defun sgml-eltype-set-all-miscdata (et miscdata)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 (setf (symbol-plist et)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 (nconc (symbol-plist et) miscdata)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 (defun sgml-make-eltype (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 (let ((et (make-symbol name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 (setf (sgml-eltype-flags et) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 et))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 ;;; Element type tables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 (defun sgml-make-eltype-table ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 "Make an empty table of element types."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 (make-vector 73 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 (defun sgml-eltype-table-empty (eltype-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 (loop for x across eltype-table always (eq x 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 (defun sgml-merge-eltypes (eltypes1 eltypes2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 "Return the merge of two element type tables ELTYPES1 and ELTYPES2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 This may change ELTYPES1, ELTYPES2 is unchanged. Returns the new table."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 (if (sgml-eltype-table-empty eltypes1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 eltypes2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 (mapatoms
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 (function (lambda (sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 (let ((et (intern (symbol-name sym) eltypes1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 (unless (fboundp et) ; not yet defined by <!element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 (when (fboundp sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 (fset et (symbol-function sym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 (when (boundp sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 (set et (symbol-value sym))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 (setf (symbol-plist et)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 (nconc (symbol-plist et)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 (copy-list (symbol-plist sym)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 eltypes2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 eltypes1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 (defun sgml-lookup-eltype (name &optional dtd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 "Lookup the element defintion for NAME (string)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 (intern name (sgml-dtd-eltypes (or dtd sgml-dtd-info))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 (defun sgml-eltype-completion-table (eltypes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 "Make a completion table from a list, ELTYPES, of element types."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 (loop for et in eltypes as name = (sgml-eltype-name et)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 if (boundp et)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 collect (cons name name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 (defun sgml-read-element-type (prompt dtd &optional default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 "Read an element type name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 PROMPT is displayed as a prompt and DTD should be the dtd to get the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 element types from. Optional argument DEFAULT (string) will be used as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 a default for the element type name."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 (let ((name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 (completing-read prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 (sgml-dtd-eltypes dtd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 (function fboundp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 (when (equal name "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 (setq name (or default (error "Aborted"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 (sgml-lookup-eltype name dtd)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 (defun sgml-map-eltypes (fn dtd &optional collect all)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 (let ((*res* nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 (mapatoms
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 (cond ((and collect all)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 (function (lambda (a) (push (funcall fn a) *res*))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 (collect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 (function (lambda (a) (when (boundp a)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 (push (funcall fn a) *res*)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 (all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 (function (lambda (a) (funcall fn a))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 (function (lambda (a) (when (boundp a) (funcall fn a))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 (sgml-dtd-eltypes dtd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 (nreverse *res*)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 ;;;; Load a saved dtd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
983 ;;; Wing addition
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 (defmacro sgml-char-int (ch)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 (if (fboundp 'char-int)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 (` (char-int (, ch)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 ch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 (defsubst sgml-read-octet ()
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
990 ;; Wing change
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 (prog1 (sgml-char-int (following-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 (forward-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 (defsubst sgml-read-number ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 "Read a number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 A number is 1: an octet [0--sgml-max-singel-octet-number]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 or 2: two octets (n,m) interpreted as (n-t-1)*256+m+t."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 (if (> (following-char) sgml-max-single-octet-number)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 (+ (* (- (following-char) (eval-when-compile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 (1+ sgml-max-single-octet-number)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 256)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 (prog1 (char-after (1+ (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 (forward-char 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 sgml-max-single-octet-number)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 (sgml-read-octet)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 (defsubst sgml-read-peek ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 (following-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 (defun sgml-read-sexp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 (let ((standard-input (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 (read))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 (forward-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 (defsubst sgml-read-token ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 (aref sgml-read-token-vector (sgml-read-number)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 (defsubst sgml-read-node-ref ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 (aref sgml-read-nodes (sgml-read-octet)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 (defun sgml-read-model-seq ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 (loop repeat (sgml-read-number) collect (sgml-read-model)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 (defun sgml-read-token-seq ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 (loop repeat (sgml-read-number) collect (sgml-read-token)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 (defun sgml-read-moves ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 (loop repeat (sgml-read-number)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 collect (sgml-make-move (sgml-read-token) (sgml-read-node-ref))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 (defun sgml-read-model ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 (let* ((n (sgml-read-number))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 (sgml-read-nodes (make-vector n nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 (loop for i below n do (aset sgml-read-nodes i (sgml-make-state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 (loop for e across sgml-read-nodes do
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1038 (cond ((eq 255 (sgml-read-peek)) ; a and-node
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 (sgml-read-octet) ; skip
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1040 (setf (sgml-and-node-next e) (sgml-read-node-ref))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1041 (setf (sgml-and-node-dfas e) (sgml-read-model-seq)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 (t ; a normal-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 (setf (sgml-state-opts e) (sgml-read-moves))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 (setf (sgml-state-reqs e) (sgml-read-moves)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 (aref sgml-read-nodes 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 (defun sgml-read-content ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 (let ((c (sgml-read-octet)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 (cond ((eq c 0) sgml-cdata)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 ((eq c 1) sgml-rcdata)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 ((eq c 2) sgml-empty)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 ((eq c 3) sgml-any)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 ((eq c 4) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 ((eq c 128)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 (sgml-read-model)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 (defun sgml-read-decode-flag (flag mask)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 (not (zerop (logand flag mask))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 (defun sgml-read-element (et)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 (sgml-eltype-set-all-miscdata et (sgml-read-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 (let ((flags (sgml-read-octet)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 (unless (= flags 128)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 (setf (sgml-eltype-flags et) flags
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 (sgml-eltype-model et) (sgml-read-content)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 (sgml-eltype-includes et) (sgml-read-token-seq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 (sgml-eltype-excludes et) (sgml-read-token-seq)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 (defun sgml-read-dtd ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 "Decode the saved DTD in current buffer, return the DTD."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 (let ((gc-cons-threshold (max gc-cons-threshold 500000))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 temp dtd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 (setq temp (sgml-read-sexp)) ; file-version
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 ((equal temp '(sgml-saved-dtd-version 5))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 ;; Doctype -- create dtd structure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 (setq dtd (sgml-make-dtd (sgml-read-sexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 ;; Element type names -- read and create token vector
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 (setq temp (sgml-read-number)) ; # eltypes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 (setq sgml-read-token-vector (make-vector (1+ temp) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 (aset sgml-read-token-vector 0 sgml-pcdata-token)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 (loop for i from 1 to temp do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 (aset sgml-read-token-vector i
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 (sgml-lookup-eltype (sgml-read-sexp) dtd)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 ;; Element type descriptions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 (loop for i from 1 to (sgml-read-number) do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 (sgml-read-element (aref sgml-read-token-vector i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 (setf (sgml-dtd-parameters dtd) (sgml-read-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 (setf (sgml-dtd-entities dtd) (sgml-read-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 (setf (sgml-dtd-shortmaps dtd) (sgml-read-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 (setf (sgml-dtd-notations dtd) (sgml-read-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 (setf (sgml-dtd-dependencies dtd) (sgml-read-sexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 ;; New version
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 ((equal temp '(sgml-saved-dtd-version 6))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 (setq dtd (sgml-bdtd-read-dtd)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 ;; Something else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 (error "Unknown file format for saved DTD: %s" temp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 dtd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 (defun sgml-load-dtd (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 "Load a saved DTD from FILE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 (let ((tem (expand-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 (or sgml-default-dtd-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 (sgml-default-dtd-file)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107 (list (read-file-name "Load DTD from: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 (file-name-directory tem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 tem
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 (file-name-nondirectory tem)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 (setq sgml-loaded-dtd nil) ; Allow reloading of DTD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 ;; Search for 'file' on the sgml-system-path [ndw]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 (let ((real-file (car (mapcan (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 (lambda (dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 (let ((f (expand-file-name file dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 (if (file-exists-p f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 (list f)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 (cons "."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 ;; wing change -- add sgml-data-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 (append sgml-system-path
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 (list sgml-data-directory)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 (or real-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 (error "Saved DTD file %s not found" file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 (let ((cb (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 (tem nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 (dtd nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 (l (buffer-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 (find-file-type ; Allways binary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 (function (lambda (fname) 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 ;; Search loaded buffer for a already loaded DTD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 (while (and l (null tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 (set-buffer (car l))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 (if (equal sgml-loaded-dtd real-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 (setq tem (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 (setq l (cdr l)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 (tem ; loaded DTD found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 (setq dtd (sgml-pstate-dtd sgml-buffer-parse-state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 (t ; load DTD from file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 (set-buffer cb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 (sgml-push-to-entity real-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 (message "Loading DTD from %s..." real-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 (setq dtd (sgml-read-dtd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 (message "Loading DTD from %s...done" real-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 (sgml-pop-entity)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 (set-buffer cb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 (sgml-set-initial-state dtd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 (setq sgml-default-dtd-file file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 (setq sgml-loaded-dtd real-file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 ;;;; Biniary coded DTD module
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 ;;; Works on the binary coded compiled DTD (bdtd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 ;;; bdtd-load: cfile dtdfile ents -> bdtd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 ;;; bdtd-merge: bdtd dtd -> dtd?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 ;;; bdtd-read-dtd: bdtd -> dtd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 ;;; Implement by letting bdtd be implicitly the current buffer and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 ;;; dtd implicit in sgml-dtd-info.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 (defun sgml-bdtd-load (cfile dtdfile ents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 "Load the compiled dtd from CFILE into the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 If this file does not exists, is of an old version or out of date, a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 new compiled dtd will be creted from file DTDFILE and parameter entity
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 settings in ENTS."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 ;;(Assume the current buffer is a scratch buffer and is empty)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 (sgml-debug "Trying to load compiled DTD from %s..." cfile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 (or (and (file-readable-p cfile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 (let ((find-file-type ; Allways binary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 (function (lambda (fname) 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 ;; fifth arg to insert-file-contents is not available in early
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 ;; v19.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 (insert-file-contents cfile nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 (equal '(sgml-saved-dtd-version 6) (sgml-read-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 (or (sgml-up-to-date-p cfile (sgml-read-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 (if (eq 'ask sgml-recompile-out-of-date-cdtd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 (not (y-or-n-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 "Compiled DTD is out of date, recompile? "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 (not sgml-recompile-out-of-date-cdtd))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 (sgml-compile-dtd dtdfile cfile ents)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 (defun sgml-up-to-date-p (file dependencies)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 "Check if FILE is newer than all files in the list DEPENDENCIES.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 If DEPENDENCIES contains the symbol `t', FILE is not considered newer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 (if (memq t dependencies)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 (loop for f in dependencies
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 always (file-newer-than-file-p file f))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 (defun sgml-compile-dtd (dtd-file to-file ents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 "Construct a binary code compiled dtd from DTD-FILE and write it to TO-FILE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 The dtd will be constructed with the parameter entities set according
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 to ENTS. The bdtd will be left in the current buffer. The current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 buffer is assumend to be empty to start with."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 (sgml-log-message "Recompiling DTD file %s..." dtd-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 (let* ((sgml-dtd-info (sgml-make-dtd nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 (parameters (sgml-dtd-parameters sgml-dtd-info))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 (sgml-parsing-dtd t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 (push dtd-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 (sgml-dtd-dependencies sgml-dtd-info))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 (loop for (name . val) in ents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203 do (sgml-entity-declare name parameters 'text val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204 (sgml-push-to-entity dtd-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 (sgml-check-dtd-subset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 (sgml-pop-entity)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 (erase-buffer)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1208 ;; For XEmacs-20.0/Mule
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 74
diff changeset
1209 (setq file-coding-system 'noconv)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 (sgml-write-dtd sgml-dtd-info to-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 (defun sgml-check-entities (params1 params2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 "Check that PARAMS1 is compatible with PARAMS2."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 (block check-entities
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 (sgml-map-entities
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 (function (lambda (entity)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 (let ((other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 (sgml-lookup-entity (sgml-entity-name entity)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 params2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 (unless (or (null other)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 (equal entity other))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 (sgml-log-message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 "Parameter %s in complied DTD has wrong value;\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 is '%s' should be '%s'"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 (sgml-entity-name entity)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 (sgml-entity-text other)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 (sgml-entity-text entity))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 (return-from check-entities nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 params1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 (defun sgml-bdtd-merge ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 "Merge the binary coded dtd in the current buffer with the current dtd.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 The current dtd is the variable sgml-dtd-info. Return t if mereged
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 was successfull or nil if failed."
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 74
diff changeset
1237 (setq file-coding-system 'noconv)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 (sgml-read-sexp) ; skip filev
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 (let ((dependencies (sgml-read-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241 (parameters (sgml-read-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 (gc-cons-threshold (max gc-cons-threshold 500000))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 temp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 ;; Check comaptibility of parameters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 (and (sgml-check-entities (sgml-dtd-parameters sgml-dtd-info)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 parameters)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248 ;; Do the merger
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 (sgml-message "Reading compiled DTD...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250 (sgml-merge-entity-tables (sgml-dtd-parameters sgml-dtd-info)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 parameters)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 (setf (sgml-dtd-dependencies sgml-dtd-info)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 (nconc (sgml-dtd-dependencies sgml-dtd-info)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 dependencies))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 ;; Doctype
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 (setq temp (sgml-read-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257 (when (and temp (null (sgml-dtd-doctype sgml-dtd-info)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 (setf (sgml-dtd-doctype sgml-dtd-info) temp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 ;; Element type names -- read and create token vector
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261 (setq temp (sgml-read-number)) ; # eltypes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 (setq sgml-read-token-vector (make-vector (1+ temp) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263 (aset sgml-read-token-vector 0 sgml-pcdata-token)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 (loop for i from 1 to temp do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 (aset sgml-read-token-vector i
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 (sgml-lookup-eltype (sgml-read-sexp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 ;; Element type descriptions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 (loop for i from 1 to (sgml-read-number) do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269 (sgml-read-element (aref sgml-read-token-vector i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270 (sgml-merge-entity-tables (sgml-dtd-entities sgml-dtd-info)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271 (sgml-read-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272 (sgml-merge-shortmaps (sgml-dtd-shortmaps sgml-dtd-info)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 (sgml-read-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 (setf (sgml-dtd-notations sgml-dtd-info) (sgml-read-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277 (defun sgml-bdtd-read-dtd ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 "Create and return a dtd from the binary coded dtd in the current buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279 (let ((sgml-dtd-info (sgml-make-dtd nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 (sgml-bdtd-merge)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 sgml-dtd-info))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 ;;;; Set markup type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 (defsubst sgml-set-markup-type (type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 "Set the type of the markup parsed to TYPE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 The markup starts at position given by variable sgml-markup-start and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 ends at point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289 (when (and sgml-set-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290 (null sgml-current-eref))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 (sgml-set-face-for sgml-markup-start (point) type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 (setq sgml-markup-type type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 ;;;; Parsing delimiters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 (eval-and-compile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 (defconst sgml-delimiters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 '("AND" "&"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 "COM" "--"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 "CRO" "&#"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 "DSC" "]"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 "DSO" "["
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304 "DTGC" "]"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 "DTGO" "["
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 "ERO" "&"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 "ETAGO" "</"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308 "GRPC" ")"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 "GRPO" "("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 "LIT" "\""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 "LITA" "'"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 "MDC" ">"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 "MDO" "<!"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 "MINUS" "-"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315 "MSC" "]]"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 "NET" "/"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 "OPT" "?"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 "OR" "|"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 "PERO" "%"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 "PIC" ">"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 "PIO" "<?"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 "PLUS" "+"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323 "REFC" ";"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324 "REP" "*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 "RNI" "#"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 "SEQ" ","
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327 "STAGO" "<"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 "TAGC" ">"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 "VI" "="
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 ;; Some combinations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 "MS-START" "<![" ; MDO DSO
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332 "MS-END" "]]>" ; MSC MDC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 ;; Pseudo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 "NULL" ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 (defmacro sgml-is-delim (delim &optional context move offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 "Macro for matching delimiters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 Syntax: DELIM &optional CONTEXT MOVE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 where DELIM is the delimiter name (string or symbol),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 CONTEXT the contextual constraint, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 MOVE is `nil', `move' or `check'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 Test if the text following point in current buffer matches the SGML
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 delimiter DELIM. Also check the characters after the delimiter for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 CONTEXT. Applicable values for CONTEXT is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348 `gi' -- name start or TAGC if SHORTTAG YES,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 `com' -- if COM or MDC,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 `nmstart' -- name start character,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351 `stagc' -- TAGC if SHORTTAG YES,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 `digit' -- any Digit,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 string -- delimiter with that name,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 list -- any of the contextual constraints in the list."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 (or offset (setq offset 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 (let ((ds (member (upcase (format "%s" delim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 sgml-delimiters)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 (assert ds)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 (setq delim (car ds)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 ds (cadr ds))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 (cond ((eq context 'gi)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 (setq context '(nmstart stagc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 ((eq context 'com)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 (setq context '("COM" "MDC")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 ((null context)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 (setq context '(t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 ((not (listp context))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 (setq context (list context))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 (`(if (and ; This and checks that characters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 ; of the delimiter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 (,@(loop for i from 0 below (length ds) collect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373 (` (eq (, (aref ds i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 (sgml-following-char (, (+ i offset)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 (,@(loop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 for c in context collect ; context check
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 ((eq c 'nmstart) ; name start character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 (`(sgml-startnm-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 (or (sgml-following-char (, (length ds))) 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 ((eq c 'stagc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 (`(and sgml-current-shorttag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 (sgml-is-delim "TAGC" nil nil (, (length ds))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 ((eq c 'digit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386 (`(memq (sgml-following-char (, (length ds)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 ((stringp c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 (`(sgml-is-delim (, c) nil nil (, (length ds)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 ((eq c t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 (t (error "Context type: %s" c))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 (progn ; Do operations if delimiter found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 (,@ (if move (`((forward-char (, (length ds)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 (,@ (if (not (eq move 'check))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397 '(t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398 (,@ (if (eq move 'check)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 (`((sgml-delimiter-parse-error (, delim))))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 (defmacro sgml-following-char (n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 (cond ((zerop n) '(following-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403 ((= n 1) '(char-after (1+ (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404 (t (` (char-after (+ (, n) (point)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406 (defun sgml-delimiter-parse-error (delim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407 (sgml-parse-error "Delimiter %s (%s) expected"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408 delim (cadr (member delim sgml-delimiters))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 (defmacro sgml-parse-delim (delim &optional context)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 (`(sgml-is-delim (, delim) (, context) move)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 (defmacro sgml-check-delim (delim &optional context)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 (`(sgml-is-delim (, delim) (, context) check)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 (defmacro sgml-skip-upto (delim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1417 "Skip until the delimiter or first char of one of the delimiters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 If DELIM is a string/symbol this is should be a delimiter role.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419 Characters are skipped until the delimiter is recognized.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420 If DELIM is a list of delimiters, skip until a character that is first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 in any of them."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 ((consp delim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 (list 'skip-chars-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 (concat "^"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426 (loop for d in delim
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 concat (let ((ds (member (upcase (format "%s" d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428 sgml-delimiters)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429 (assert ds)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430 (let ((s (substring (cadr ds) 0 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431 (if (member s '("-" "\\"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432 (concat "\\" s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 s)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 (let ((ds (member (upcase (format "%s" delim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 sgml-delimiters)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 (assert ds)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438 (setq ds (cadr ds))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439 (if (= 1 (length ds))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 (list 'skip-chars-forward (concat "^" ds))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 (`(and (search-forward (, ds) nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 (backward-char (, (length ds))))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 ;;(macroexpand '(sgml-is-delim mdo))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 ;;(macroexpand '(sgml-parse-delim mdo))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447 ;;(macroexpand '(sgml-check-delim mdo))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 ;;;; General lexical functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451 ;;; Naming conventions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 ;;; sgml-parse-xx try to parse xx, return nil if can't else return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 ;;; some propriate non-nil value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 ;;; Except: for name/nametoken parsing, return 0 if can't.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 ;;; sgml-check-xx require xx, report error if can't parse. Return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456 ;;; aproporiate value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458 (defmacro sgml-parse-char (char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459 (` (cond ((eq (, char) (following-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 (defmacro sgml-parse-chars (char1 char2 &optional char3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464 "Parse two or three chars; return nil if can't"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465 (if (null char3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 (` (cond ((and (eq (, char1) (following-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467 (eq (, char2) (char-after (1+ (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468 (forward-char 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470 (` (cond ((and (eq (, char1) (following-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1471 (eq (, char2) (char-after (1+ (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472 (eq (, char3) (char-after (1+ (1+ (point))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473 (forward-char 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474 t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476 (defun sgml-check-char (char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1477 (cond ((not (sgml-parse-char char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1478 (sgml-parse-error "Expecting %c" char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480 (defun sgml-parse-RE ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481 (or (sgml-parse-char ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482 (sgml-parse-char ?\r)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1484 (defmacro sgml-startnm-char (c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1485 (` (eq ?w (char-syntax (, c)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487 (defun sgml-startnm-char-next ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488 (and (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1489 (sgml-startnm-char (following-char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1490
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491 (defun sgml-name-char (c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492 (and c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493 (or (sgml-startnm-char c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 (eq ?_ (char-syntax c)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496 (defun sgml-is-end-tag ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497 (sgml-is-delim "ETAGO" gi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499 (defsubst sgml-is-enabled-net ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500 (and (sgml-is-delim "NET")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 sgml-current-shorttag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502 (sgml-tree-net-enabled sgml-current-tree)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504 (defun sgml-is-start-tag ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505 (sgml-is-delim "STAGO" gi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 (defsubst sgml-parse-s (&optional shortmap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508 (if shortmap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509 (or (/= 0 (skip-chars-forward " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510 (/= 0 (skip-chars-forward "\t"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 (sgml-parse-char ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512 (sgml-parse-char ?\r))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513 (/= 0 (skip-chars-forward " \t\n\r"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515 (defsubst sgml-parse-processing-instruction ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516 (if (sgml-parse-delim "PIO")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517 (sgml-do-processing-instruction)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519 (defun sgml-do-processing-instruction ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520 (let ((start (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521 (sgml-skip-upto "PIC")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522 (when sgml-pi-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 (funcall sgml-pi-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 (buffer-substring-no-properties start (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 (sgml-check-delim "PIC")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526 (sgml-set-markup-type 'pi)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530 (defmacro sgml-general-case (string) (`(downcase (, string))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 (defmacro sgml-entity-case (string) string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533 (defun sgml-parse-name (&optional entity-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 (if (sgml-startnm-char-next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535 (let ((name (buffer-substring-no-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536 (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537 (progn (skip-syntax-forward "w_")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538 (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539 (if entity-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1540 (sgml-entity-case name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1541 (sgml-general-case name)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1542
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1543 (define-compiler-macro sgml-parse-name (&whole form &optional entity-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1544 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1545 ((memq entity-name '(nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1546 (` (if (sgml-startnm-char-next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1547 ((, (if entity-name 'sgml-entity-case 'sgml-general-case))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1548 (buffer-substring-no-properties (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1549 (progn (skip-syntax-forward "w_")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1550 (point)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1551 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1552 form)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554 (defun sgml-check-name (&optional entity-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1555 (or (sgml-parse-name entity-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1556 (sgml-parse-error "Name expected")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1557
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558 (define-compiler-macro sgml-check-name (&optional entity-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1559 (`(or (, (if entity-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1560 (`(sgml-parse-name (, entity-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1561 '(sgml-parse-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1562 (sgml-parse-error "Name expected"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1564
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1565 (defun sgml-parse-nametoken (&optional entity-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1566 "Parses a name token and returns a string or nil if no nametoken."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1567 (if (sgml-name-char (following-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1568 (let ((name (buffer-substring-no-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1569 (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1570 (progn (skip-syntax-forward "w_")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571 (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572 (if entity-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1573 (sgml-entity-case name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1574 (sgml-general-case name)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1575
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1576 (defun sgml-check-nametoken ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1577 (or (sgml-parse-nametoken)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1578 (sgml-parse-error "Name token expected")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1579
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580 ;;(defun sgml-gname-symbol (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1581 ;; "Convert a string to a general name/nametoken/numbertoken."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1582 ;; (intern (sgml-general-case string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1583
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584 ;;(defun sgml-ename-symbol (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585 ;; "Convert a string to an entity name."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1586 ;; (intern (sgml-entity-case string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1588 (defsubst sgml-parse-general-entity-ref ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589 (if (sgml-parse-delim "ERO" nmstart)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590 (sgml-do-general-entity-ref)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1591
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1592 (defun sgml-do-general-entity-ref ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1593 (sgml-do-entity-ref
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1594 (prog1 (sgml-parse-name t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1595 (or (sgml-parse-delim "REFC")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596 (sgml-parse-RE))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 (sgml-set-markup-type 'entity)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1598 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1599
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1600 (defun sgml-do-entity-ref (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1601 (let ((entity
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1602 (sgml-lookup-entity name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1603 (sgml-dtd-entities sgml-dtd-info))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604 (cond ((and (null entity)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1605 sgml-warn-about-undefined-entities)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1606 (sgml-log-warning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607 "Undefined entity %s" name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608 ((sgml-entity-data-p entity)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609 (when sgml-signal-data-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610 (funcall sgml-signal-data-function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612 (sgml-entity-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1613 (funcall sgml-entity-function entity))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614 (sgml-data-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1615 (sgml-push-to-entity entity sgml-markup-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 (funcall sgml-data-function (buffer-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1617 (sgml-pop-entity))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1619 (sgml-push-to-entity entity sgml-markup-start)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1620
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1621 (defsubst sgml-parse-parameter-entity-ref ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1622 "Parse and push to a parameter entity, return nil if no ref here."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1623 ;;(setq sgml-markup-start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1624 (if (sgml-parse-delim "PERO" nmstart)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1625 (sgml-do-parameter-entity-ref)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1626
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627 (defun sgml-do-parameter-entity-ref ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1628 (let* ((name (sgml-parse-name t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1629 (ent (sgml-lookup-entity name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1630 (sgml-dtd-parameters sgml-dtd-info))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1631 (or (sgml-parse-delim "REFC")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632 (sgml-parse-char ?\n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633 ;;(sgml-set-markup-type 'param)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634 (cond (ent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1635 (sgml-push-to-entity ent sgml-markup-start 'param))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1636 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1637 (sgml-log-warning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1638 "Undefined parameter entity %s" name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1639 t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1640
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1641 (defun sgml-parse-comment ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1642 (if (sgml-parse-delim "COM")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1643 (progn (sgml-skip-upto "COM")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1644 (sgml-check-delim "COM")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1645 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1646
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1647 (defun sgml-skip-cs ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1648 "Skip over the separator used in the catalog.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1649 Return true if not at the end of the buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1650 (while (or (sgml-parse-s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1651 (sgml-parse-comment)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1652 (not (eobp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1653
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1654 (defsubst sgml-skip-ps ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1655 "Move point forward stopping before a char that isn't a parameter separator."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1656 (while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1657 (or (sgml-parse-s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1658 (if (eobp) (sgml-pop-entity))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1659 (sgml-parse-parameter-entity-ref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660 (sgml-parse-comment))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1661
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1662 (defsubst sgml-parse-ds ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1663 ;71 ds = 5 s | EE | 60+ parameter entity reference
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1664 ; | 91 comment declaration
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665 ; | 44 processing instruction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1666 ; | 93 marked section declaration ***
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1667 (or (and (eobp) (sgml-pop-entity)) ;EE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1668 (sgml-parse-s) ;5 s
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1669 ;;(sgml-parse-comment-declaration) ;91 comment declaration
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1670 (sgml-parse-parameter-entity-ref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1671 (sgml-parse-processing-instruction)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1673 (defun sgml-skip-ds ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1674 (while (sgml-parse-ds)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1675
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1676 (defmacro sgml-parse-rni (&optional name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1677 "Parse a RNI (#) return nil if none; with optional NAME,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1678 a RNI must be followed by NAME."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1679 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1680 (name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1681 (` (if (sgml-parse-delim "RNI")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1682 (sgml-check-token (, name)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1683 (t '(sgml-parse-delim "RNI"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1684
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1685 (defun sgml-check-token (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1686 (or (equal (sgml-check-name) name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1687 (sgml-parse-error "Reserved name not expected")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1688
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1689 (defun sgml-parse-literal ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1690 "Parse a literal and return a string, if no literal return nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1691 (let (lita start value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1692 (cond ((or (sgml-parse-delim "LIT")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1693 (setq lita (sgml-parse-delim "LITA")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1694 (setq start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1695 (if lita
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1696 (sgml-skip-upto "LITA")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1697 (sgml-skip-upto "LIT"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1698 (setq value (buffer-substring-no-properties start (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1699 (if lita
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1700 (sgml-check-delim "LITA")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1701 (sgml-check-delim "LIT"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1702 value))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1703
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1704 (defun sgml-check-literal ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1705 (or (sgml-parse-literal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1706 (sgml-parse-error "A litteral expected")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1707
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1708 (defun sgml-parse-minimum-literal ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1709 "Parse a quoted SGML string and return it, if no string return nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1710 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1711 ((memq (following-char) '(?\" ?\'))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1712 (let* ((qchar (following-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1713 (blanks " \t\r\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1714 (qskip (format "^%s%c" blanks qchar))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1715 (start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1716 (value ; accumulates the literal value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1717 "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1718 (spaced ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1719 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1720 (skip-chars-forward blanks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1721 (while (not (sgml-parse-char qchar))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1722 (cond ((eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1723 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1724 (sgml-parse-error "Unterminated literal"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1725 ((sgml-parse-s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1726 (setq spaced " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1727 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1728 (setq value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1729 (concat value spaced
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1730 (buffer-substring-no-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1731 (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1732 (progn (skip-chars-forward qskip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1733 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1734 spaced ""))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1735 value))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1736
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1737 (defun sgml-check-minimum-literal ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1738 (or (sgml-parse-minimum-literal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1739 (sgml-parse-error "A minimum literal expected")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1740
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1741 (defun sgml-parse-external ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1742 "Leaves nil if no external id, or (pubid . sysid)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1743 (sgml-skip-ps)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1744 (let* ((p (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1745 (token (sgml-parse-nametoken)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1746 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1747 (token
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1748 (sgml-skip-ps)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1749 (cond ((member token '("public" "system"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1750 (let* ((pubid ; the public id
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1751 (if (string-equal token "public")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1752 (or (sgml-parse-minimum-literal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1753 (sgml-parse-error "Public identifier expected"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1754 (sysid ; the system id
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1755 (progn (sgml-skip-ps)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1756 (sgml-parse-literal))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1757 (sgml-make-extid pubid sysid)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1758 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1759 (goto-char p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1760 nil))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1761
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1762 (defun sgml-skip-tag ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1763 (when (sgml-parse-char ?<)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1764 (sgml-parse-char ?/)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1765 (unless (search-forward-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1766 "\\([^\"'<>/]\\|\"[^\"]*\"\\|'[^']*'\\)*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1767 nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1768 (sgml-error "Invalid tag"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1769 (or (sgml-parse-char ?>)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1770 (sgml-parse-char ?/))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1771
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1772
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1773 ;;;; Entity Manager
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1774
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1775 (defstruct (sgml-entity
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1776 (:type list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1777 (:constructor sgml-make-entity (name type text)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1778 name ; Name of entity (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1779 type ; Type of entity CDATA NDATA PI SDATA
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1780 text ; string or external
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1781 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1782
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1783 (defun sgml-entity-data-p (entity)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1784 "True if ENTITY is a data entity, that is not a text entity."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1785 (not (eq (sgml-entity-type entity) 'text)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1786
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1787 (defun sgml-entity-marked-undefined-p (entity)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1788 (cdddr entity))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1789
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1790
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1791 ;;; Entity tables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1792 ;; Represented by a cons-cell whose car is the default entity (or nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1793 ;; and whose cdr is as an association list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1794
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1795 (defun sgml-make-entity-table ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1796 (list nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1797
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1798 (defun sgml-lookup-entity (name entity-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1799 (or (assoc name (cdr entity-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1800 (car entity-table)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1801
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1802 (defun sgml-entity-declare (name entity-table type text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1803 "Declare an entity with name NAME in table ENTITY-TABLE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1804 TYPE should be the type of the entity (text|cdata|ndata|sdata...).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1805 TEXT is the text of the entity, a string or an external identifier.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1806 If NAME is nil, this defines the default entity."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1807 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1808 (name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1809 (unless (sgml-lookup-entity name entity-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1810 (sgml-debug "Declare entity %s %s as %S" name type text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1811 (nconc entity-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1812 (list (sgml-make-entity name type text)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1813 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1814 (unless (car entity-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1815 (sgml-debug "Declare default entity %s as %S" type text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1816 (setcar entity-table (sgml-make-entity name type text))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1817
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1818 (defun sgml-entity-completion-table (entity-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1819 "Make a completion table from the ENTITY-TABLE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1820 (cdr entity-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1821
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1822 (defun sgml-map-entities (fn entity-table &optional collect)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1823 (if collect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1824 (mapcar fn (cdr entity-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1825 (loop for e in (cdr entity-table) do (funcall fn e))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1826
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1827 (defun sgml-merge-entity-tables (tab1 tab2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1828 "Merge entity table TAB2 into TAB1. TAB1 is modified."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1829 (nconc tab1 (cdr tab2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1830 (setcar tab1 (or (car tab1) (car tab2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1831
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1832
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1833 (defun sgml-entity-insert-text (entity &optional ptype)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1834 "Insert the text of ENTITY.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1835 PTYPE can be 'param if this is a parameter entity."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1836 (let ((text (sgml-entity-text entity)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1837 (cond
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1838 ((stringp text)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1839 (insert text))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1840 (t
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1841 (sgml-insert-external-entity text
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1842 (or ptype
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1843 (sgml-entity-type entity))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1844 (sgml-entity-name entity))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1845
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1846 ;;;; External identifyer resolve
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1847
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1848 (defun sgml-cache-catalog (file cache-var parser-fun
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1849 &optional default-dir)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1850 "Return parsed catalog.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1851 FILE is the file containing the catalog. Maintains a cache of parsed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1852 catalog files in variable CACHE-VAR. The parsing is done by function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1853 PARSER-FUN that should parse the current buffer and return the parsed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1854 repreaentation of the catalog."
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1855 (setq file (file-truename (expand-file-name file default-dir)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1856 (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1857 (file-readable-p file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1858 (let ((c (assoc file (symbol-value cache-var)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1859 (modtime (elt (file-attributes file) 5)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1860 (if (and c (equal (second c) modtime))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1861 (cddr c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1862 (when c (set cache-var (delq c (symbol-value cache-var))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1863 (let (new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1864 (message "Loading %s ..." file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1865 (sgml-push-to-entity file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1866 (setq default-directory (file-name-directory file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1867 (setq new (funcall parser-fun))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1868 (sgml-pop-entity)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1869 (push (cons file (cons modtime new)) (symbol-value cache-var))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1870 (message "Loading %s ... done" file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1871 new)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1872
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1873 (defun sgml-main-directory ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1874 "Directory of the document entity."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1875 (let ((cb (current-buffer)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1876 (set-buffer sgml-current-top-buffer)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1877 (prog1 default-directory
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1878 (set-buffer cb))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1879
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1880 (defun sgml-trace-lookup (&rest args)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1881 "Log a message like `sgml-log-message', but only if `sgml-trace-entity-lookup' is set."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1882 (when sgml-trace-entity-lookup
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1883 (apply (function sgml-log-message) args)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1884
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1885
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1886 (defun sgml-catalog-lookup (files pubid type name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1887 "Look up the public identifier/entity name in catalogs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1888 FILES is a list of catalogs to use. PUBID is the public identifier
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1889 \(if any). TYPE is the entity type and NAME is the entity name."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1890 (cond ((eq type 'param)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1891 (setq name (format "%%%s" name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1892 type 'entity))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1893 ((eq type 'dtd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1894 (setq type 'doctype)))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1895 ;;(sgml-trace-lookup " [pubid='%s' type=%s name='%s']" pubid type name)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1896 (loop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1897 for f in files thereis
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1898 (let ((cat (sgml-cache-catalog f 'sgml-catalog-assoc
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1899 (function sgml-parse-catalog-buffer)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1900 (sgml-main-directory))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1901 (sgml-trace-lookup " catalog: %s %s"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1902 (expand-file-name f (sgml-main-directory))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1903 (if (null cat) "empty/non existent" "exists"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1904 (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1905 ;; Giv PUBLIC entries priority over ENTITY and DOCTYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1906 (if pubid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1907 (loop for (key cname file) in cat
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1908 thereis (if (and (eq 'public key)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1909 (string= pubid cname))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1910 (if (file-readable-p file)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1911 (progn
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1912 (sgml-trace-lookup " >> %s [by pubid]" file)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1913 file)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1914 (progn
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1915 (sgml-trace-lookup " !unreadable %s" file)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1916 nil)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1917 (loop for (key cname file) in cat
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1918 ;;do (sgml-trace-lookup " %s %s" key cname)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1919 thereis (if (and (eq type key)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1920 (or (null cname)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1921 (string= name cname)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1922 (if (file-readable-p file)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1923 (progn
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1924 (sgml-trace-lookup " >> %s [by %s %s]"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1925 file key cname)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1926 file)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1927 (progn
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1928 (sgml-trace-lookup " !unreadable %s" file)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1929 nil))))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1930
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1931 (defun sgml-path-lookup (extid type name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1932 (let* ((pubid (sgml-extid-pubid extid))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1933 (sysid (sgml-extid-sysid extid))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1934 (subst (list '(?% ?%))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1935 (when pubid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1936 (nconc subst (list (cons ?p (sgml-transliterate-file pubid)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1937 (sgml-pubid-parts pubid))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1938 (setq pubid (sgml-canonize-pubid pubid)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1939 (when sysid (nconc subst (list (cons ?s sysid))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1940 (when name (nconc subst (list (cons ?n name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1941 (when type (nconc subst (list (cons ?y (cond ((eq type 'dtd) "dtd")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1942 ((eq type 'text) "text")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1943 ((eq type 'param) "parm")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1944 (t "sgml"))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1945 (sgml-debug "Ext. file subst. = %S" subst)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1946 (loop for cand in sgml-public-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1947 thereis
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1948 (and (setq cand (sgml-subst-expand cand subst))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1949 (file-readable-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1950 (setq cand
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1951 (sgml-extid-expand (substitute-in-file-name cand)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1952 extid)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1953 (not (file-directory-p cand))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1954 cand))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1955
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1956 (defun sgml-external-file (extid &optional type name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1957 "Return file name for entity with external identifier EXTID.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1958 Optional argument TYPE should be the type of entity and NAME should be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1959 the entity name."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1960 ;; extid is (pubid . sysid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1961 (let ((pubid (sgml-extid-pubid extid)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1962 (when pubid (setq pubid (sgml-canonize-pubid pubid)))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1963 (sgml-trace-lookup "Start looking for %s entity %s public %s system %s"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1964 (or type "-")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1965 (or name "?")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1966 pubid
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1967 (sgml-extid-sysid extid))
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 74
diff changeset
1968 (or (if (and sgml-system-identifiers-are-preferred
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 74
diff changeset
1969 (sgml-extid-sysid extid))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 74
diff changeset
1970 (or (sgml-lookup-sysid-as-file extid)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 74
diff changeset
1971 (sgml-path-lookup ;Try the path also, but only using sysid
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 74
diff changeset
1972 (sgml-make-extid nil (sgml-extid-sysid extid))
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 74
diff changeset
1973 nil nil)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1974 (sgml-catalog-lookup sgml-current-localcat pubid type name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1975 (sgml-catalog-lookup sgml-catalog-files pubid type name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1976 (if (not sgml-system-identifiers-are-preferred)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1977 (sgml-lookup-sysid-as-file extid))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1978 (sgml-path-lookup extid type name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1979
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1980 (defun sgml-lookup-sysid-as-file (extid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1981 (let ((sysid (sgml-extid-sysid extid)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1982 (and sysid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1983 (loop for pat in sgml-public-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1984 never (string-match "%[Ss]" pat))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1985 (file-readable-p (setq sysid (sgml-extid-expand sysid extid)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1986 sysid)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1987
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1988 (defun sgml-insert-external-entity (extid &optional type name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1989 "Insert the contents of an external entity at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1990 EXTID is the external identifier of the entity. Optional arguments TYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1991 is the entity type and NAME is the entity name, used to find the entity.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1992 Returns nil if entity is not found."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1993 (let* ((pubid (sgml-extid-pubid extid))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1994 (sysid (sgml-extid-sysid extid)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1995 (or (if sysid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1996 (loop for fn in sgml-sysid-resolve-functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1997 thereis (funcall fn sysid)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1998 (let ((file (sgml-external-file extid type name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1999 (and file (insert-file-contents file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2000 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2001 (sgml-log-warning "External entity %s not found" name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2002 (when pubid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2003 (sgml-log-warning " Public identifier %s" pubid))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2004 (when sysid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2005 (sgml-log-warning " System identfier %s" sysid))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2006 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2007
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2008
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2009 ;; Parse a buffer full of catalogue entries.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2010 (defun sgml-parse-catalog-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2011 "Parse all entries in a catalogue."
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2012 (sgml-trace-lookup " (Parsing catalog)")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2013 (loop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2014 while (sgml-skip-cs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2015 for type = (downcase (sgml-check-cat-literal))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2016 for class = (cdr (assoc type '(("public" . public) ("dtddecl" . public)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2017 ("entity" . name) ("linktype" . name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2018 ("doctype" . name) ("sgmldecl" . noname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2019 ("document" . noname))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2020 when (not (null class))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2021 collect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2022 (let* ((name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2023 (cond ((eq class 'public)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2024 (sgml-skip-cs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2025 (sgml-canonize-pubid (sgml-check-minimum-literal)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2026 ((string= type "doctype")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2027 (sgml-general-case (sgml-check-cat-literal)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2028 ((eq class 'name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2029 (sgml-entity-case (sgml-check-cat-literal)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2030 (file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2031 (expand-file-name (sgml-check-cat-literal))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2032 (list (intern type) name file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2033
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2034
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2035 (defun sgml-check-cat-literal ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2036 "Read the next catalog token.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2037 Skips any leading spaces/comments."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2038 (sgml-skip-cs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2039 (or (sgml-parse-literal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2040 (buffer-substring-no-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2041 (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2042 (progn (skip-chars-forward "^ \r\n\t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2043 (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2044
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2045 (defconst sgml-formal-pubid-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2046 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2047 "^\\(+//\\|-//\\|\\)" ; Registered indicator [1]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2048 "\\(\\([^/]\\|/[^/]\\)+\\)" ; Owner [2]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2049 "//"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2050 "\\([^ ]+\\)" ; Text class [4]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2051 " "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2052 "\\(\\([^/]\\|/[^/]\\)*\\)" ; Text description [5]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2053 "//"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2054 "\\(\\([^/]\\|/[^/]\\)*\\)" ; Language [7]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2055 "\\(//" ; [9]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2056 "\\(\\([^/]\\|/[^/]\\)*\\)" ; Version [10]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2057 "\\)?"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2058
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2059 (defun sgml-pubid-parts (pubid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2060 (nconc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2061 (if (string-match sgml-formal-pubid-regexp pubid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2062 (nconc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2063 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2064 (cons ?o (sgml-transliterate-file (sgml-matched-string pubid 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2065 (cons ?c (downcase (sgml-matched-string pubid 4)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2066 (cons ?d (sgml-transliterate-file (sgml-matched-string pubid 5)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2067 ;; t alias for d (%T used by sgmls)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2068 (cons ?t (sgml-transliterate-file (sgml-matched-string pubid 5)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2069 (cons ?l (downcase (sgml-matched-string pubid 7))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2070 (if (match-beginning 9)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2071 (list (cons ?v (sgml-transliterate-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2072 (sgml-matched-string pubid 10)))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2073
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2074 (defun sgml-canonize-pubid (pubid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2075 (if (string-match sgml-formal-pubid-regexp pubid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2076 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2077 (sgml-matched-string pubid 1) ; registered indicator
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2078 (sgml-matched-string pubid 2) ; Owner
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2079 "//"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2080 (upcase (sgml-matched-string pubid 4)) ; class
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2081 " "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2082 (sgml-matched-string pubid 5) ; Text description
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2083 "//"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2084 (upcase (sgml-matched-string pubid 7)) ; Language
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2085 "//"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2086 (if (match-beginning 9)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2087 (sgml-matched-string pubid 10) ""))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2088
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2089 (defun sgml-transliterate-file (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2090 (mapconcat (function (lambda (c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2091 (char-to-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2092 (or (cdr-safe (assq c sgml-public-transliterations))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2093 c))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2094 string ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2095
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2096 (defun sgml-subst-expand-char (c parts)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2097 (cdr-safe (assq (downcase c) parts)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2098
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2099 (defun sgml-subst-expand (s parts)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2100 (loop for i from 0 to (1- (length s))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2101 as c = (aref s i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2102 concat (if (eq c ?%)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2103 (or (sgml-subst-expand-char (aref s (incf i)) parts)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2104 (return nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2105 (char-to-string (aref s i)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2107 (defun sgml-matched-string (string n &optional regexp noerror)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2108 (let ((res (if regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2109 (or (string-match regexp string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2110 noerror
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2111 (error "String match fail")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2112 (if (or (null regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2113 (numberp res))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2114 (substring string (match-beginning n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2115 (match-end n)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2117 ;;;; Files for SGML declaration and DOCTYPE declaration
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2118
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2119 (defun sgml-declaration ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2120 (or sgml-declaration
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2121 (if sgml-doctype
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2122 (sgml-in-file-eval sgml-doctype
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2123 '(sgml-declaration)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2124 (if sgml-parent-document
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2125 (sgml-in-file-eval (car sgml-parent-document)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2126 '(sgml-declaration)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2127 ;; *** check for sgmldecl comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2128 (sgml-external-file nil 'sgmldecl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2129 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2130 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2132 (defun sgml-in-file-eval (file expr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2133 (let ((cb (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2134 (set-buffer (find-file-noselect file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2135 (prog1 (eval expr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2136 (set-buffer cb))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2138
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2139 ;;;; Entity references and positions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2141 (defstruct (sgml-eref
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2142 (:constructor sgml-make-eref (entity start end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2143 (:type list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2144 entity
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2145 start ; type: epos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2146 end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2148 (defun sgml-make-epos (eref pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2149 (cons eref pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2150
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2151 (defun sgml-epos-eref (epos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2152 (if (consp epos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2153 (car epos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2155 (defun sgml-epos-pos (epos)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2156 "The buffer position of EPOS withing its entity."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2157 (if (consp epos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2158 (cdr epos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2159 epos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2161 (defun sgml-bpos-p (epos)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2162 "True if EPOS is a position in the main buffer."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2163 (numberp epos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2165 (defun sgml-strict-epos-p (epos)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2166 "True if EPOS is a position in an entity other then the main buffer."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2167 (consp epos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2168
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2169 (defun sgml-epos (pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2170 "Convert a buffer position POS into an epos."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2171 (if sgml-current-eref
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2172 (sgml-make-epos sgml-current-eref pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2173 pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2174
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2175 (defun sgml-epos-before (epos)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2176 "The last position in buffer not after EPOS.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2177 If EPOS is a buffer position this is the same. If EPOS is in an entity
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2178 this is the buffer position before the entity reference."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2179 (while (consp epos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2180 (setq epos (sgml-eref-start (sgml-epos-eref epos))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2181 epos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2182
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2183 (defun sgml-epos-after (epos)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2184 "The first position in buffer after EPOS.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2185 If EPOS is in an other entity, buffer position is after
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2186 entity reference leading to EPOS."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2187 (while (consp epos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2188 (setq epos (sgml-eref-end (sgml-epos-eref epos))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2189 epos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2191 (defun sgml-epos-promote (epos)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2192 "Convert position in entity structure EPOS to a buffer position.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2193 If EPOS is in an entity, the buffer position will be the position
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2194 before the entity reference if EPOS is first character in entity
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2195 text. Otherwise buffer position will be after entity reference."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2196 (while (and (consp epos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2197 (= (cdr epos) 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2198 (setq epos (sgml-eref-start (car epos))))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2199 (sgml-epos-after epos))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2201
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2202 ;;;; DTD repository
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2203 ;;compiled-dtd: extid -> Compiled-DTD?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2204 ;;extid-cdtd-name: extid -> file?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2205 ;;up-to-date-p: (file, dependencies) -> cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2207 ;; Emacs Catalogues:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2208 ;; Syntax:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2209 ;; ecat ::= (cs | ecat-entry)*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2210 ;; cs ::= (s | comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2211 ;; ecat-entry ::= (pub-entry | file-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2212 ;; pub-entry ::= ("PUBLIC", minimal literal, ent-spec?, cat literal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2213 ;; pub-entry ::= ("FILE", literal, ent-spec?, cat literal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2214 ;; ent-spec ::= ("[", (name, literal)*, "]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2215
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2216 ;; Parsed ecat = (eent*)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2217 ;; eent = (type ...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2218 ;; = ('public pubid cfile . ents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2219 ;; = ('file file cfile . ents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2221 (defun sgml-load-ecat (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2222 "Return ecat for FILE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2223 (sgml-cache-catalog
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2224 file 'sgml-ecat-assoc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2225 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2226 (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2227 (let (new type ents from to name val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2228 (while (progn (sgml-skip-cs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2229 (setq type (sgml-parse-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2230 (setq type (intern (downcase type)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2231 (setq ents nil from nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2232 (sgml-skip-cs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2233 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2234 ((eq type 'public)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2235 (setq from (sgml-canonize-pubid (sgml-check-minimum-literal))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2236 ((eq type 'file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2237 (setq from (expand-file-name (sgml-check-cat-literal)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2238 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2239 ((null from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2240 (error "Syntax error in ECAT: %s" file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2241 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2242 (sgml-skip-cs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2243 (when (sgml-parse-char ?\[)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2244 (while (progn (sgml-skip-cs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2245 (setq name (sgml-parse-name t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2246 (sgml-skip-cs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2247 (setq val (sgml-check-literal))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2248 (push (cons name val) ents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2249 (sgml-check-char ?\])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2250 (sgml-skip-cs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2251 (setq to (expand-file-name (sgml-check-cat-literal)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2252 (push (cons type (cons from (cons to ents)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2253 new))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2254 (nreverse new))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2255
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2256 (defun sgml-ecat-lookup (files pubid file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2257 "Return (file . ents) or nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2258 (let ((params (sgml-dtd-parameters sgml-dtd-info)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2259 (loop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2260 for f in files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2261 do (sgml-debug "Search ECAT %s" f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2262 thereis
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2263 (loop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2264 for (type name cfile . ents) in (sgml-load-ecat f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2265 thereis
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2266 (if (and (cond ((eq type 'public) (equal name pubid))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2267 ((eq type 'file) (equal name file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2268 (loop for (name . val) in ents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2269 for entity = (sgml-lookup-entity name params)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2270 always (and entity
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2271 (equal val (sgml-entity-text entity)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2272 (cons cfile ents))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2273
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2274 ;;(let ((sgml-dtd-info (sgml-make-dtd nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2275 ;; (sgml-ecat-lookup sgml-ecat-files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2276 ;; "-//lenst//DTD My DTD//EN//"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2277 ;; "/home/u5/lenst/src/psgml/bar.dtd"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2279
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2280 ;;;; Merge compiled dtd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2281
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2282 (defun sgml-try-merge-compiled-dtd (pubid file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2283 (when pubid (setq pubid (sgml-canonize-pubid pubid)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2284 (when file (setq file (expand-file-name file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2285 (sgml-debug "Find compiled dtd for %s %s" pubid file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2286 (let ((ce (or (sgml-ecat-lookup sgml-current-local-ecat pubid file)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2287 (sgml-ecat-lookup sgml-ecat-files pubid file))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2288 (and ce
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2289 (let ((cfile (car ce))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2290 (ents (cdr ce)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2291 (sgml-debug "Found %s" cfile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2292 (if (sgml-use-special-case)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2293 (sgml-try-merge-special-case pubid file cfile ents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2294 (and (sgml-bdtd-load cfile file ents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2295 (sgml-bdtd-merge)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2296
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2297 (defun sgml-use-special-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2298 (and (null (sgml-dtd-merged sgml-dtd-info))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2299 (sgml-eltype-table-empty (sgml-dtd-eltypes sgml-dtd-info))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2300 (eq 'dtd (sgml-entity-type (sgml-eref-entity sgml-current-eref)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2301
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2302 (defun sgml-try-merge-special-case (pubid file cfile ents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2303 (let (cdtd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2304 (sgml-debug "Merging special case")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2305 ;; Look for a compiled dtd in som other buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2306 (let ((cb (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2307 (loop for b in (buffer-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2308 until
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2309 (progn (set-buffer b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2310 (and sgml-buffer-parse-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2311 (let ((m (sgml-dtd-merged
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2312 (sgml-pstate-dtd sgml-buffer-parse-state))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2313 (and m
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2314 (string-equal cfile (car m))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2315 (setq cdtd (cdr m)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2316 (set-buffer cb))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2317 ;; Load a new compiled dtd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2318 (unless cdtd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2319 (and (sgml-bdtd-load cfile file ents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2320 (setq cdtd (sgml-bdtd-read-dtd))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2321 ;; Do the merger
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2322 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2323 ((and cdtd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2324 (sgml-check-entities (sgml-dtd-parameters sgml-dtd-info)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2325 (sgml-dtd-parameters cdtd)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2326 (setf (sgml-dtd-eltypes sgml-dtd-info)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2327 (sgml-dtd-eltypes cdtd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2328 (sgml-merge-entity-tables (sgml-dtd-entities sgml-dtd-info)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2329 (sgml-dtd-entities cdtd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2330 (sgml-merge-entity-tables (sgml-dtd-parameters sgml-dtd-info)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2331 (sgml-dtd-parameters cdtd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2332 (sgml-merge-shortmaps (sgml-dtd-shortmaps sgml-dtd-info)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2333 (sgml-dtd-shortmaps cdtd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2334 (setf (sgml-dtd-dependencies sgml-dtd-info)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2335 (nconc (sgml-dtd-dependencies sgml-dtd-info)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2336 (sgml-dtd-dependencies cdtd)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2337 (setf (sgml-dtd-merged sgml-dtd-info) (cons cfile cdtd))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2338
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2339
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2340 ;;;; Pushing and poping entities
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2341
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2342 (defun sgml-push-to-entity (entity &optional ref-start type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2343 "Set current buffer to a buffer containing the entity ENTITY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2344 ENTITY can also be a file name. Optional argument REF-START should be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2345 the start point of the entity reference. Optional argument TYPE,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2346 overrides the entity type in entity look up."
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2347 (sgml-debug "Push to %s"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2348 (cond ((stringp entity)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2349 (format "string '%s'" entity))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2350 (t
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2351 (sgml-entity-name entity))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2352 (when ref-start
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2353 ;; don't consider a RS shortref here again
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2354 (setq sgml-rs-ignore-pos ref-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2355 (unless (and sgml-scratch-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2356 (buffer-name sgml-scratch-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2357 (setq sgml-scratch-buffer (generate-new-buffer " *entity*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2358 (let ((cb (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2359 (dd default-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2360 ;;*** should eref be argument ?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2361 (eref (sgml-make-eref (if (stringp entity)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2362 (sgml-make-entity entity nil nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2363 entity)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2364 (sgml-epos (or ref-start (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2365 (sgml-epos (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2366 (set-buffer sgml-scratch-buffer)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2367 ;; For MULE to not misinterpret binary data set the mc-flag
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2368 ;; (reported by Jeffrey Friedl <jfriedl@nff.ncl.omron.co.jp>)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2369 (setq mc-flag nil)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2370 ;; For XEmacs 20.0/Mule
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 74
diff changeset
2371 (setq file-coding-system 'noconv)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2372 (when (eq sgml-scratch-buffer (default-value 'sgml-scratch-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2373 (make-local-variable 'sgml-scratch-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2374 (setq sgml-scratch-buffer nil))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2375 (when after-change-function ;***
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2376 (message "OOPS: after-change-function not NIL in scratch buffer %s: %s"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2377 (current-buffer)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2378 after-change-function)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2379 (setq before-change-function nil
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2380 after-change-function nil))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2381 (setq sgml-last-entity-buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2382 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2383 (setq default-directory dd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2384 (make-local-variable 'sgml-current-eref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2385 (setq sgml-current-eref eref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2386 (set-syntax-table sgml-parser-syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2387 (make-local-variable 'sgml-previous-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2388 (setq sgml-previous-buffer cb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2389 (setq sgml-rs-ignore-pos ; don't interpret beginning of buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2390 ; as #RS if internal entity.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2391 (if (or (stringp entity)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2392 (stringp (sgml-entity-text entity)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2393 (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2394 0))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2395 (when sgml-buffer-parse-state
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2396 (sgml-debug "-- pstate set in scratch buffer")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2397 (setq sgml-buffer-parse-state nil))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2398 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2399 ((stringp entity) ; a file name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2400 (save-excursion (insert-file-contents entity))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2401 (setq default-directory (file-name-directory entity)))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2402 ((consp (sgml-entity-text entity)) ; external id?
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2403 (let* ((extid (sgml-entity-text entity))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2404 (file
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2405 (sgml-external-file extid
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2406 (or type (sgml-entity-type entity))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2407 (sgml-entity-name entity))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2408 (when sgml-parsing-dtd
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2409 (push (or file t)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2410 (sgml-dtd-dependencies sgml-dtd-info)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2411 (sgml-debug "Push to %s = %s" extid file)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2412 (cond
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2413 ((and file sgml-parsing-dtd
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2414 (sgml-try-merge-compiled-dtd (sgml-extid-pubid extid)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2415 file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2416 (goto-char (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2417 (file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2418 ;; fifth arg not available in early v19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2419 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2420 (insert-file-contents file nil nil nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2421 (setq default-directory (file-name-directory file))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2422 (goto-char (point-min)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2423 (t ;; No file for entity
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2424 (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2425 (let* ((pubid (sgml-extid-pubid extid))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2426 (sysid (sgml-extid-sysid extid)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2427 (or (if sysid ; try the sysid hooks
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2428 (loop for fn in sgml-sysid-resolve-functions
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2429 thereis (funcall fn sysid)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2430 (progn
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2431 ;; Mark entity as not found
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2432 (setcdr (cddr entity) t) ;***
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2433 (sgml-log-warning "External entity %s not found"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2434 (sgml-entity-name entity))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2435 (when pubid
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2436 (sgml-log-warning " Public identifier %s" pubid))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2437 (when sysid
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2438 (sgml-log-warning " System identfier %s" sysid))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2439 nil))))))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2440 (t ;; internal entity
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2441 (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2442 (insert (sgml-entity-text entity)))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2444 (defun sgml-pop-entity ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2445 (cond ((and (boundp 'sgml-previous-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2446 (bufferp sgml-previous-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2447 (sgml-debug "Exit entity")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2448 (setq sgml-last-entity-buffer sgml-previous-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2449 (set-buffer sgml-previous-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2450 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2451
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2452 (defun sgml-goto-epos (epos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2453 "Goto a position in an entity given by EPOS."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2454 (assert epos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2455 (cond ((sgml-bpos-p epos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2456 (goto-char epos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2457 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2458 (let ((eref (sgml-epos-eref epos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2459 (sgml-cleanup-entities)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2460 (sgml-goto-epos (sgml-eref-end eref))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2461 (sgml-push-to-entity (sgml-eref-entity eref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2462 (sgml-epos-pos (sgml-eref-start eref))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2463 (goto-char (sgml-epos-pos epos)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2464
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2465 (defun sgml-pop-all-entities ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2466 (while (sgml-pop-entity)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2467
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2468 (defun sgml-cleanup-entities ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2469 (let ((cb (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2470 (n 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2471 (while (and sgml-scratch-buffer (buffer-name sgml-scratch-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2472 (set-buffer sgml-scratch-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2473 (assert (not (eq sgml-scratch-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2474 (default-value 'sgml-scratch-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2475 (incf n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2476 (while (> n 10)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2477 (set-buffer (prog1 sgml-previous-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2478 (kill-buffer (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2479 (decf n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2480 (set-buffer cb)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2481
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2482 (defun sgml-any-open-param/file ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2483 "Return true if there currently is a parameter or file open."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2484 (and (boundp 'sgml-previous-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2485 sgml-previous-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2486
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2487
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2488 ;;;; Parse tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2489
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2490 (defstruct (sgml-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2491 (:type vector)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2492 (:constructor sgml-make-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2493 (eltype stag-epos stag-len parent level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2494 excludes includes pstate net-enabled
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2495 conref &optional shortmap pshortmap asl)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2496 eltype ; element object
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2497 ;;start ; start point in buffer
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2498 ;;end ; end point in buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2499 stag-epos ; start-tag entity position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2500 etag-epos ; end-tag entity position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2501 stag-len ; length of start-tag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2502 etag-len ; length of end-tag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2503 parent ; parent tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2504 level ; depth of this node
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2505 excludes ; current excluded elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2506 includes ; current included elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2507 pstate ; state in parent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2508 next ; next sibling tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2509 content ; child trees
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2510 net-enabled ; if NET enabled (t this element,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2511 ; other non-nil, some parent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2512 conref ; if conref attribute used
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2513 shortmap ; shortmap at start of element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2514 pshortmap ; parents shortmap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2515 asl ; attribute specification list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2516 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2517
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2518
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2519 (defun sgml-tree-end (tree)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2520 "Buffer position after end of TREE."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2521 (let ((epos (sgml-tree-etag-epos tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2522 (len (sgml-tree-etag-len tree)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2523 (cond ((sgml-bpos-p epos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2524 (+ epos len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2525 ((zerop len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2526 (sgml-epos-promote epos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2527 (t
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2528 (sgml-epos-after epos)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2529
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2531 ;;;; (text) Element view of parse tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2532
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2533 (defmacro sgml-alias-fields (orig dest &rest fields)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2534 (let ((macs nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2535 (while fields
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2536 (push
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2537 (` (defmacro (, (intern (format "%s-%s" dest (car fields)))) (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2538 (, (format "Return %s field of ELEMENT." (car fields)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2539 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2540 '(, (intern (format "%s-%s" orig (car fields))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2541 element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2542 macs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2543 (setq fields (cdr fields)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2544 (cons 'progn macs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2545
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2546 (sgml-alias-fields sgml-tree sgml-element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2547 eltype ; element object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2548 ;; start ; start point in buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2549 stag-epos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2550 etag-epos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2551 stag-len ; length of start-tag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2552 etag-len ; length of end-tag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2553 parent ; parent tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2554 level ; depth of this node
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2555 excludes ; current excluded elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2556 includes ; current included elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2557 pstate ; state in parent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2558 net-enabled ; if NET enabled
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2559 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2560
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2561 (defun sgml-element-model (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2562 "Declared content or content model of ELEMENT."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2563 (sgml-eltype-model (sgml-tree-eltype element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2564
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2565 (defun sgml-element-name (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2566 "Return name (symbol) of ELEMENT."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2567 (sgml-tree-eltype element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2568
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2569 (defun sgml-element-gi (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2570 "Return general identifier (string) of ELEMENT."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2571 (sgml-eltype-name (sgml-tree-eltype element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2572
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2573 (defun sgml-element-appdata (element prop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2574 "Return the application data named PROP associated with the type of ELEMENT."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2575 (sgml-eltype-appdata (sgml-tree-eltype element) prop))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2576
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2577 (defmacro sgml-element-stag-optional (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2578 "True if start-tag of ELEMENT is omissible."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2579 (`(sgml-eltype-stag-optional (sgml-tree-eltype (, element)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2580
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2581 (defun sgml-element-etag-optional (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2582 "True if end-tag of ELEMENT is omissible."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2583 (sgml-eltype-etag-optional (sgml-tree-eltype element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2584
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2585 (define-compiler-macro sgml-element-etag-optional (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2586 "True if end-tag of ELEMENT is omissible."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2587 (`(sgml-eltype-etag-optional (sgml-tree-eltype (, element)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2588
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2589 (defun sgml-element-attlist (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2590 "Return the attribute specification list of ELEMENT."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2591 (sgml-eltype-attlist (sgml-tree-eltype element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2592
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2593 (defun sgml-element-mixed (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2594 "True if ELEMENT has mixed content."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2595 (sgml-eltype-mixed (sgml-tree-eltype element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2596
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2597 (define-compiler-macro sgml-element-mixed (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2598 (`(sgml-eltype-mixed (sgml-tree-eltype (, element)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2599
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2600 (defun sgml-element-start (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2601 "Position before start of ELEMENT."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2602 (sgml-epos-promote (sgml-tree-stag-epos element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2603
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2604 (defun sgml-element-stag-end (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2605 "Position after start-tag of ELEMENT."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2606 (let ((epos (sgml-tree-stag-epos element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2607 (len (sgml-tree-stag-len element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2608 (cond ((sgml-bpos-p epos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2609 (+ epos len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2610 ((zerop len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2611 (sgml-epos-promote epos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2612 (t
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2613 (sgml-epos-after epos)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2614
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2615 (defun sgml-element-empty (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2616 "True if ELEMENT is empty."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2617 (or (eq sgml-empty (sgml-element-model element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2618 (sgml-tree-conref element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2619
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2620 (defun sgml-element-data-p (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2621 "True if ELEMENT can have data characters in its content."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2622 (or (sgml-element-mixed element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2623 (eq sgml-cdata (sgml-element-model element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2624 (eq sgml-rcdata (sgml-element-model element))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2625
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2626 (defun sgml-element-context-string (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2627 "Return string describing context of ELEMENT."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2628 (if (eq element sgml-top-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2629 ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2630 (format "in %s %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2631 (sgml-element-gi element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2632 (sgml-element-context-string (sgml-tree-parent element)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2633
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2634 ;;;; Display and Mode-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2635
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2636 (defun sgml-update-display ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2637 (when (not (eq this-command 'keyboard-quit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2638 ;; Don't let point be inside an invisible region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2639 (when (and (get-text-property (point) 'invisible)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2640 (eq (get-text-property (point) 'invisible)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2641 (get-text-property (1- (point)) 'invisible)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2642 (setq sgml-last-element nil) ; May not be valid after point moved
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2643 (if (memq this-command '(backward-char previous-line backward-word))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2644 (goto-char (or (previous-single-property-change (point) 'invisible)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2645 (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2646 (goto-char (or (next-single-property-change (point) 'invisible)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2647 (point-max)))))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2648 (when (and (not executing-macro)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2649 (or sgml-live-element-indicator
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2650 sgml-set-face)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2651 (not (null sgml-buffer-parse-state))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2652 (sit-for 0))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2653 (let ((deactivate-mark nil))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2654 (sgml-need-dtd)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2655 (let ((start
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2656 (save-excursion (sgml-find-start-point (point))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2657 (sgml-pop-all-entities)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2658 (point)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2659 (eol-pos
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2660 (save-excursion (end-of-line 1) (point))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2661 (let ((quiet (< (- (point) start) 500)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2662 ;;(message "Should parse %s to %s => %s" start (point) quiet)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2663 (when (if quiet
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2664 t
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2665 (setq sgml-current-element-name "?")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2666 (sit-for 1))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2667
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2668 ;; Find current element
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2669 (cond ((and (memq this-command sgml-users-of-last-element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2670 sgml-last-element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2671 (setq sgml-current-element-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2672 (sgml-element-gi sgml-last-element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2673 (sgml-live-element-indicator
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2674 (save-excursion
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2675 (condition-case nil
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2676 (sgml-parse-to
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2677 (point) (function input-pending-p) quiet)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2678 (error
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2679 (setq sgml-current-element-name "*error*")))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2680 (unless (input-pending-p)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2681 (setq sgml-current-element-name
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2682 (sgml-element-gi sgml-current-tree))))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2683 ;; Set face on current line
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2684 (when (and sgml-set-face (not (input-pending-p)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2685 (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2686 (condition-case nil
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2687 (sgml-parse-to
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2688 eol-pos (function input-pending-p) quiet)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2689 (error nil)))))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2690 ;; Set face in rest of buffer
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2691 (sgml-fontify-buffer 6) ;*** make option for delay
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2692 ))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2693
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2694 (defun sgml-fontify-buffer (delay)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2695 (and
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2696 sgml-set-face
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2697 (null (sgml-tree-etag-epos
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2698 (sgml-pstate-top-tree sgml-buffer-parse-state)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2699 (sit-for delay)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2700 (condition-case nil
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2701 (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2702 (message "Fontifying...")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2703 (sgml-parse-until-end-of nil nil
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2704 (function input-pending-p)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2705 t)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2706 (message "Fontifying...done"))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2707 (error nil))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2708
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2709 (defun sgml-set-active-dtd-indicator (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2710 (set (make-local-variable 'sgml-active-dtd-indicator)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2711 (list (format " [%s" name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2712 '(sgml-live-element-indicator ("/" sgml-current-element-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2713 "]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2714 (force-mode-line-update))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2715
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2716 ;;;; Parser state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2717
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2718 (defstruct (sgml-pstate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2719 (:constructor sgml-make-pstate (dtd top-tree)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2720 dtd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2721 top-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2722
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2723 ;(defsubst sgml-excludes ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2724 ; (sgml-tree-excludes sgml-current-tree))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2725
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2726 ;(defsubst sgml-includes ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2727 ; (sgml-tree-includes sgml-current-tree))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2728
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2729 (defsubst sgml-current-mixed-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2730 (sgml-element-mixed sgml-current-tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2731
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2732 (defun sgml-set-initial-state (dtd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2733 "Set initial state of parsing"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2734 (make-local-variable 'before-change-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2735 (setq before-change-function 'sgml-note-change-at)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2736 (make-local-variable 'after-change-function)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2737 (setq after-change-function 'sgml-set-face-after-change)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2738 (sgml-set-active-dtd-indicator (sgml-dtd-doctype dtd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2739 (let ((top-type ; Fake element type for the top
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2740 ; node of the parse tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2741 (sgml-make-eltype "#DOC") ; was "Document (no element)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2742 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2743 (setf (sgml-eltype-model top-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2744 (sgml-make-primitive-content-token
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2745 (sgml-eltype-token
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2746 (sgml-lookup-eltype (sgml-dtd-doctype dtd) dtd))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2747 (setq sgml-buffer-parse-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2748 (sgml-make-pstate dtd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2749 (sgml-make-tree top-type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2750 0 0 nil 0 nil nil nil nil nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2751
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2752 (defun sgml-set-parse-state (tree where)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2753 "Set parse state from TREE, either from start of TREE if WHERE is start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2754 or from after TREE if WHERE is after."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2755 (setq sgml-current-tree tree
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2756 sgml-markup-tree tree
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2757 sgml-rs-ignore-pos 0 )
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2758 (let ((empty
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2759 (sgml-element-empty tree)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2760 (cond ((and (eq where 'start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2761 (not empty))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2762 (setq sgml-current-state (sgml-element-model sgml-current-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2763 sgml-current-shortmap (sgml-tree-shortmap sgml-current-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2764 sgml-previous-tree nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2765 (setq sgml-markup-type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2766 (if (and (not (zerop (sgml-tree-stag-len tree)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2767 (sgml-bpos-p (sgml-tree-stag-epos tree)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2768 'start-tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2769 sgml-markup-start (sgml-element-start sgml-current-tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2770 (sgml-goto-epos (sgml-tree-stag-epos sgml-current-tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2771 (forward-char (sgml-tree-stag-len sgml-current-tree)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2772 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2773 (setq sgml-current-state (sgml-tree-pstate sgml-current-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2774 sgml-current-shortmap (sgml-tree-pshortmap sgml-current-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2775 sgml-previous-tree sgml-current-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2776 (sgml-goto-epos (sgml-tree-etag-epos sgml-current-tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2777 (forward-char (sgml-tree-etag-len sgml-current-tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2778 (setq sgml-markup-type (if empty 'start-tag 'end-tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2779 sgml-markup-start (- (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2780 (sgml-tree-etag-len sgml-current-tree)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2781 (setq sgml-current-tree (sgml-tree-parent sgml-current-tree))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2782 (assert sgml-current-state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2783
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2784 (defsubst sgml-final-p (state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2785 ;; Test if a state/model can be ended
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2786 (or (not (sgml-model-group-p state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2787 (sgml-final state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2788
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2789 ;(defun sgml-current-element-contains-data ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2790 ; "Retrun true if the current open element is either mixed or is (r)cdata."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2791 ; (or (eq sgml-cdata sgml-current-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2792 ; (eq sgml-rcdata sgml-current-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2793 ; (sgml-current-mixed-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2794
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2795 ;(defun sgml-current-element-content-class ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2796 ; "Return a string describing the type of content in the current element.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2797 ;The type can be CDATA, RCDATA, ANY, #PCDATA or none."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2798 ; (cond ((eq sgml-cdata sgml-current-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2799 ; "CDATA")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2800 ; ((eq sgml-rcdata sgml-current-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2801 ; "RCDATA")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2802 ; ((eq sgml-any sgml-current-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2803 ; "ANY")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2804 ; ((sgml-current-mixed-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2805 ; "#PCDATA")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2806 ; (t "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2807
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2808 (defun sgml-promoted-epos (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2809 "Return an entity position for start of region START END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2810 If region is empty, choose return an epos as high in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2811 entity hierarchy as possible."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2812 ;; This does not work if the entity is entered by a shortref that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2813 ;; only is active in the current element.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2814 (let ((epos (sgml-epos start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2815 (when (= start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2816 (while (and (sgml-strict-epos-p epos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2817 (= 1 (sgml-epos-pos epos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2818 (setq epos (sgml-eref-start (sgml-epos-eref epos)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2819 epos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2820
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2821 (defun sgml-open-element (eltype conref before-tag after-tag &optional asl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2822 (unless (sgml-eltype-defined eltype)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2823 (setf (sgml-eltype-mixed eltype) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2824 (setf (sgml-eltype-etag-optional eltype) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2825 (when sgml-warn-about-undefined-elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2826 (sgml-log-warning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2827 "Start-tag of undefined element %s; assume O O ANY"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2828 (sgml-eltype-name eltype))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2829 (let* ((emap (sgml-eltype-shortmap eltype))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2830 (newmap (if emap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2831 (if (eq 'empty emap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2832 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2833 (sgml-lookup-shortref-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2834 (sgml-dtd-shortmaps sgml-dtd-info)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2835 emap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2836 sgml-current-shortmap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2837 (nt (sgml-make-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2838 eltype
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2839 (sgml-promoted-epos before-tag after-tag) ; stag-epos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2840 (- after-tag before-tag) ; stag-len
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2841 sgml-current-tree ; parent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2842 (1+ (sgml-tree-level sgml-current-tree)) ; level
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2843 (append (sgml-eltype-excludes eltype)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2844 (sgml-tree-excludes sgml-current-tree))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2845 (append (sgml-eltype-includes eltype)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2846 (sgml-tree-includes sgml-current-tree))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2847 sgml-current-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2848 (if (sgml-tree-net-enabled sgml-current-tree) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2849 conref
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2850 newmap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2851 sgml-current-shortmap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2852 asl)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2853 ;; (let ((u (sgml-tree-content sgml-current-tree)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2854 ;; (cond ((and u (> before-tag (sgml-element-start u)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2855 ;; (while (and (sgml-tree-next u)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2856 ;; (> before-tag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2857 ;; (sgml-element-start (sgml-tree-next u))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2858 ;; (setq u (sgml-tree-next u)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2859 ;; (setf (sgml-tree-next u) nt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2860 ;; (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2861 ;; (setf (sgml-tree-content sgml-current-tree) nt))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2862 ;; Install new node in tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2863 (cond (sgml-previous-tree
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2864 (sgml-debug "Open element %s: after %s"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2865 eltype (sgml-tree-eltype sgml-previous-tree))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2866 (setf (sgml-tree-next sgml-previous-tree) nt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2867 (t
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2868 (sgml-debug "Open element %s: first in %s"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2869 eltype (sgml-tree-eltype sgml-current-tree))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2870 (setf (sgml-tree-content sgml-current-tree) nt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2871 ;; Prune tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2872 ;; *** all the way up? tree-end = nil?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2873 (setf (sgml-tree-next sgml-current-tree) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2874 ;; Set new state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2875 (setq sgml-current-state (sgml-eltype-model eltype)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2876 sgml-current-shortmap newmap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2877 sgml-current-tree nt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2878 sgml-previous-tree nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2879 (assert sgml-current-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2880 (setq sgml-markup-tree sgml-current-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2881 (run-hook-with-args 'sgml-open-element-hook sgml-current-tree asl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2882 (when (sgml-element-empty sgml-current-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2883 (sgml-close-element after-tag after-tag))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2884
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2885 (defun sgml-fake-open-element (tree el &optional state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2886 (sgml-make-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2887 el 0 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2888 tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2889 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2890 (append (sgml-eltype-excludes el) (sgml-tree-excludes tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2891 (append (sgml-eltype-includes el) (sgml-tree-includes tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2892 state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2893 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2894 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2895
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2896 (defun sgml-close-element (before-tag after-tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2897 (when (or (eq sgml-close-element-trap t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2898 (eq sgml-close-element-trap sgml-current-tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2899 (setq sgml-goal (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2900 (when sgml-throw-on-element-change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2901 (throw sgml-throw-on-element-change 'end))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2902 (sgml-debug "Close element %s" (sgml-tree-eltype sgml-current-tree))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2903 (setf (sgml-tree-etag-epos sgml-current-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2904 ;;(sgml-promoted-epos before-tag after-tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2905 (sgml-epos before-tag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2906 (setf (sgml-tree-etag-len sgml-current-tree) (- after-tag before-tag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2907 (run-hooks 'sgml-close-element-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2908 (setq sgml-markup-tree sgml-current-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2909 (cond ((eq sgml-current-tree sgml-top-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2910 (unless (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2911 (sgml-error "Parse ended")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2912 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2913 (setq sgml-previous-tree sgml-current-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2914 sgml-current-state (sgml-tree-pstate sgml-current-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2915 sgml-current-shortmap (sgml-tree-pshortmap sgml-current-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2916 sgml-current-tree (sgml-tree-parent sgml-current-tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2917 (assert sgml-current-state))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2918
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2919 (defun sgml-fake-close-element (tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2920 (sgml-tree-parent tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2921
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2922 (defun sgml-note-change-at (at &optional end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2923 ;; Inform the cache that there have been some changes after AT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2924 (when sgml-buffer-parse-state
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2925 (sgml-debug "sgml-note-change-at %s" at)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2926 (let ((u (sgml-pstate-top-tree sgml-buffer-parse-state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2927 (when u
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2928 ;;(message "%d" at)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2929 (while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2930 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2931 ((and (sgml-tree-next u) ; Change clearly in next element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2932 (> at (sgml-element-stag-end (sgml-tree-next u))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2933 (setq u (sgml-tree-next u)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2934 (t ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2935 (setf (sgml-tree-next u) nil) ; Forget next element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2936 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2937 ;; If change after this element and it is ended by an end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2938 ;; tag no pruning is done. If the end of the element is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2939 ;; implied changing the tag that implied it may change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2940 ;; the extent of the element.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2941 ((and (sgml-tree-etag-epos u)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2942 (> at (sgml-tree-end u))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2943 (or (> (sgml-tree-etag-len u) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2944 (sgml-element-empty u)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2945 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2946 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2947 (setf (sgml-tree-etag-epos u) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2948 (cond;; Enter into content if change is clearly in it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2949 ((and (sgml-tree-content u)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2950 (> at (sgml-element-stag-end (sgml-tree-content u))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2951 (setq u (sgml-tree-content u)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2952 ;; Check if element has no start tag,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2953 ;; then it must be pruned as a change could create
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2954 ;; a valid start tag for the element.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2955 ((and (zerop (sgml-tree-stag-len u))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2956 (> at (sgml-element-start u)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2957 ;; restart from to with new position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2958 ;; this can't loop forever as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2959 ;; position allways gets smaller
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2960 (setq at (sgml-element-start u)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2961 u sgml-top-tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2962 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2963 (setf (sgml-tree-content u) nil))))))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2964
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2965 (defun sgml-list-implications (token type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2966 "Return a list of the tags implied by a token TOKEN.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2967 TOKEN is a token, and the list elements are either tokens or `t'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2968 Where the latter represents end-tags."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2969 (let ((state sgml-current-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2970 (tree sgml-current-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2971 (temp nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2972 (imps nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2973 (while ; Until token accepted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2974 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2975 ;; Test if accepted in state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2976 ((or (eq state sgml-any)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2977 (and (sgml-model-group-p state)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2978 (not (memq token (sgml-tree-excludes tree)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2979 (or (memq token (sgml-tree-includes tree))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2980 (sgml-get-move state token))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2981 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2982 ;; Test if end tag implied
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2983 ((or (eq state sgml-empty)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2984 (and (sgml-final-p state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2985 (not (eq tree sgml-top-tree))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2986 (unless (eq state sgml-empty) ; not realy implied
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2987 (push t imps))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2988 (setq state (sgml-tree-pstate tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2989 tree (sgml-fake-close-element tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2990 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2991 ;; Test if start-tag can be implied
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2992 ((and (setq temp (sgml-required-tokens state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2993 (null (cdr temp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2994 (setq temp (car temp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2995 tree (sgml-fake-open-element tree temp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2996 (sgml-get-move state temp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2997 state (sgml-element-model tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2998 (push temp imps)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2999 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3000 ;; No implictions and not accepted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3001 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3002 (sgml-log-warning "Out of context %s" type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3003 (setq imps nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3004 ;; Return the implications in correct order
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3005 (nreverse imps)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3006
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3007
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3008 (defun sgml-eltypes-in-state (tree state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3009 "Return list of element types (eltype) valid in STATE and TREE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3010 (let* ((req ; Required tokens
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3011 (if (sgml-model-group-p state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3012 (sgml-required-tokens state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3013 (elems ; Normally valid tokens
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3014 (if (sgml-model-group-p state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3015 (nconc req
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3016 (delq sgml-pcdata-token (sgml-optional-tokens state))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3017 ;; Modify for exceptions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3018 (loop for et in (sgml-tree-includes tree) ;*** Tokens or eltypes?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3019 unless (memq et elems) do (push et elems))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3020 (loop for et in (sgml-tree-excludes tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3021 do (setq elems (delq et elems)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3022 ;; Check for omitable start-tags
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3023 (when (and sgml-omittag-transparent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3024 (not (sgml-final-p state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3025 req
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3026 (null (cdr req)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3027 (let ((et (sgml-token-eltype (car req))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3028 (when (sgml-eltype-stag-optional et)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3029 (setq elems
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3030 (nconc elems ; *** possibility of duplicates
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3031 (sgml-eltypes-in-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3032 (sgml-fake-open-element tree et)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3033 (sgml-eltype-model et)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3034 elems))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3035
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3036 (defun sgml-current-list-of-valid-eltypes ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3037 "Returns a list of contextually valid element types (eltype)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3038 (let ((elems (sgml-eltypes-in-state sgml-current-tree sgml-current-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3039 (tree sgml-current-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3040 (state sgml-current-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3041 (when sgml-omittag-transparent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3042 (while (and tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3043 (sgml-final-p state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3044 (sgml-element-etag-optional tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3045 (setq state (sgml-tree-pstate tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3046 tree (sgml-tree-parent tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3047 (loop for e in (sgml-eltypes-in-state tree state) do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3048 (when (not (memq e elems))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3049 (setq elems (nconc elems (list e)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3050 ;; *** Filter out elements that are undefined?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3051 (sort elems (function string-lessp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3052
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3053 (defun sgml-current-list-of-endable-eltypes ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3054 "Return a list of the element types endable in current state."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3055 (let* ((elems nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3056 (tree sgml-current-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3057 (state sgml-current-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3058 (while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3059 (and (sgml-final-p state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3060 (not (eq tree sgml-top-tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3061 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3062 (setq elems
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3063 (nconc elems (list (sgml-tree-eltype tree))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3064 sgml-omittag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3065 (sgml-eltype-etag-optional (sgml-tree-eltype tree)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3066 (setq state (sgml-tree-pstate tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3067 tree (sgml-tree-parent tree)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3068 elems))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3069
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3070 ;;;; Logging of warnings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3071
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3072 (defconst sgml-log-buffer-name "*SGML LOG*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3073
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3074 (defvar sgml-log-last-size 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3075
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3076 (defun sgml-display-log ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3077 (let ((buf (get-buffer sgml-log-buffer-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3078 (when buf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3079 (display-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3080 (setq sgml-log-last-size (save-excursion (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3081 (point-max))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3082
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3083 (defun sgml-log-warning (format &rest things)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3084 (when sgml-throw-on-warning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3085 (apply 'message format things)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3086 (throw sgml-throw-on-warning t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3087 (when (or sgml-show-warnings sgml-parsing-dtd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3088 (apply 'sgml-message format things)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3089 (apply 'sgml-log-message format things)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3090
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3091 (defun sgml-log-message (format &rest things)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3092 (let ((mess (apply 'format format things))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3093 (buf (get-buffer-create sgml-log-buffer-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3094 (cb (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3095 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3096 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3097 (insert mess "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3098 (when (get-buffer-window buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3099 (setq sgml-log-last-size (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3100 (set-buffer cb)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3102 (defun sgml-error (format &rest things)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3103 (when sgml-throw-on-error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3104 (throw sgml-throw-on-error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3105 (while (and (boundp 'sgml-previous-buffer) sgml-previous-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3106 (when sgml-current-eref
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3107 (sgml-log-message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3108 "Line %s in %S "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3109 (count-lines (point-min) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3110 (sgml-entity-name (sgml-eref-entity sgml-current-eref))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3111 (sgml-pop-entity))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3112 (apply 'sgml-log-warning format things)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3113 (apply 'error format things))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3115 (defun sgml-parse-error (format &rest things)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3116 (apply 'sgml-error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3117 (concat format "; at: %s")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3118 (append things (list (buffer-substring-no-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3119 (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3120 (min (point-max) (+ (point) 12)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3122 (defun sgml-message (format &rest things)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3123 (let ((buf (get-buffer sgml-log-buffer-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3124 (when (and buf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3125 (> (save-excursion (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3126 (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3127 sgml-log-last-size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3128 (sgml-display-log)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3129 (apply 'message format things))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3131 (defun sgml-reset-log ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3132 (let ((buf (get-buffer sgml-log-buffer-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3133 (when buf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3134 (setq sgml-log-last-size
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3135 (save-excursion (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3136 (point-max))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3138 (defun sgml-clear-log ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3139 (let ((b (get-buffer sgml-log-buffer-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3140 (when b
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3141 (delete-windows-on b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3142 (kill-buffer b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3143 (setq sgml-log-last-size 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3145 (defun sgml-show-or-clear-log ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3146 "Show the *SGML LOG* buffer if it is not showing, or clear and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3147 remove it if it is showing."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3148 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3149 (cond ((and (get-buffer sgml-log-buffer-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3150 (null (get-buffer-window sgml-log-buffer-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3151 (sgml-display-log))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3152 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3153 (sgml-clear-log))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3157 ;;; This has noting to do with warnings...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3159 (defvar sgml-lazy-time 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3161 (defun sgml-lazy-message (&rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3162 (unless (= sgml-lazy-time (second (current-time)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3163 (apply 'message args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3164 (setq sgml-lazy-time (second (current-time)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3165
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3166 ;;;; Shortref maps
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3168 (eval-and-compile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3169 (defconst sgml-shortref-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3170 '(
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3171 "\t" ;&#TAB
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3172 "\n" ;&#RE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3173 "\001" ;&#RS;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3174 "\001B"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3175 "\001\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3176 "\001B\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3177 "B\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3178 " " ;&#SPACE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3179 "BB"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3180 "\"" ;&#34;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3181 "#"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3182 "%"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3183 "'"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3184 "("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3185 ")"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3186 "*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3187 "+"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3188 ","
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3189 "-"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3190 "--"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3191 ":"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3192 ";"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3193 "="
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3194 "@"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3195 "["
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3196 "]"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3197 "^"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3198 "_"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3199 "{"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3200 "|"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3201 "}"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3202 "~")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3204 (eval-and-compile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3205 (defun sgml-shortref-index (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3206 (let ((pos (member string sgml-shortref-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3207 (len (length sgml-shortref-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3208 (and pos (- len (length pos))) )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3210 (defun sgml-make-shortmap (pairs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3211 "Create a shortreference map from PAIRS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3212 Where PAIRS is a list of (delim . ename)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3213 (let ((map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3214 (make-vector (1+ (length sgml-shortref-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3215 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3216 index)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3217 (loop for p in pairs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3218 for delim = (car p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3219 for name = (cdr p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3220 do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3221 (setq index (sgml-shortref-index delim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3222 (cond ((null index)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3223 (sgml-log-warning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3224 "Illegal short reference delimiter '%s'" delim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3225 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3226 (aset map index name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3227 ;; Compute a suitable string for skip-chars-forward that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3228 ;; can be used to skip over pcdata
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3229 (aset map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3230 (eval-when-compile (length sgml-shortref-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3231 (if (some (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3232 (lambda (r) (aref map (sgml-shortref-index r))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3233 '("\001B\n" "B\n" " " "BB"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3234 "^<]/& \n\t\"#%'()*+,\\-:;=@[]\\^_{|}~"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3235 "^<]/&\n\t\"#%'()*+,\\-:;=@[]\\^_{|}~"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3236 map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3237
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3238 (defun sgml-shortmap-skipstring (map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3239 (if (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3240 ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3241 (aref map (eval-when-compile (length sgml-shortref-list)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3242
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3244 (defconst sgml-shortref-oneassq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3245 (loop for d in sgml-shortref-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3246 for c = (aref d 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3247 when (and (= 1 (length d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3248 (/= 1 c) (/= 10 c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3249 collect (cons c (sgml-shortref-index d))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3250
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3251 (defun sgml-parse-B ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3252 (/= 0 (skip-chars-forward " \t")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3253
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3254 (defun sgml-deref-shortmap (map &optional nobol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3255 "Identify shortref delimiter at point and return entity name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3256 Also move point. Return nil, either if no shortref or undefined."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3258 (macrolet
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3259 ((delim (x) (` (aref map (, (sgml-shortref-index x))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3260 (let ((i (if nobol 1 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3261 (while (numberp i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3262 (setq i
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3263 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3264 ((and (bolp) (zerop i)) ; Either "\001" "\001B"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3265 ; "\001\n" "\001B\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3266 (cond ((sgml-parse-B) ; "\001B"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3267 (if (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3268 (delim "\001B\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3269 (delim "\001B")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3270 ((sgml-parse-RE) (delim "\001\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3271 ((delim "\001"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3272 (t 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3273 ((cond ((sgml-parse-char ?\t) (setq i (delim "\t")) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3274 ((sgml-parse-char ? ) (setq i (delim " ")) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3275 (cond ((sgml-parse-B) (setq i (delim "BB"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3276 (cond ((sgml-parse-char ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3277 (delim "B\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3278 (t i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3279 ((sgml-parse-RE) (delim "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3280 ((sgml-parse-chars ?- ?-) (delim "--"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3281 ;; The other one character delimiters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3282 ((setq i (assq (following-char) sgml-shortref-oneassq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3283 (when i (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3284 (aref map (cdr i))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3285 i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3286
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3287 ;;; Table of shortref maps
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3288
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3289 (defun sgml-make-shortref-table ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3290 (list nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3291
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3292 (defun sgml-add-shortref-map (table name map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3293 (nconc table (list (cons name map))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3294
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3295 (defun sgml-lookup-shortref-map (table name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3296 (cdr (assoc name (cdr table))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3297
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3298 (defun sgml-lookup-shortref-name (table map)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3299 (car (rassq map (cdr table))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3300
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3301 (defun sgml-merge-shortmaps (tab1 tab2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3302 "Merge tables of short reference maps TAB2 into TAB1, modifying TAB1."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3303 (nconc tab1 (cdr tab2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3304
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3305 ;;;; Parse markup declarations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3306
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3307 (defun sgml-skip-until-dsc ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3308 (while (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3309 (sgml-skip-upto ("DSO" "DSC" "LITA" "LIT" "COM"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3310 (not (sgml-parse-delim "DSC")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3311 (cond ((sgml-parse-literal))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3312 ((sgml-parse-delim "DSO")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3313 (sgml-skip-until-dsc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3314 ((sgml-parse-comment))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3315 (t (forward-char 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3316
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3317 (defun sgml-skip-upto-mdc ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3318 "Move point forward until end of current markup declaration.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3319 Assumes starts with point inside a markup declaration."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3320 (while (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3321 (sgml-skip-upto ("DSO" "MDC" "LIT" "LITA" "COM"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3322 (not (sgml-is-delim "MDC")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3323 (cond ((sgml-parse-delim "DSO")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3324 (sgml-skip-until-dsc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3325 ((sgml-parse-literal))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3326 ((sgml-parse-comment))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3327 (t (forward-char 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3328
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3329 (defun sgml-do-sgml-declaration ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3330 (sgml-skip-upto-mdc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3331 (setq sgml-markup-type 'sgml))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3333 (defun sgml-do-doctype ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3334 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3335 (sgml-dtd-info ; Has doctype already been defined
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3336 (sgml-skip-upto-mdc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3337 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3338 (let (sgml-markup-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3339 (message "Parsing doctype...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3340 (sgml-setup-doctype (sgml-check-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3341 (sgml-parse-external))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3342 (message "Parsing doctype...done"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3343 (setq sgml-markup-type 'doctype))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3344
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3345 (defun sgml-check-end-of-entity (type)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3346 (unless (eobp)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3347 (sgml-parse-error "Illegal character '%c' in %s"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3348 (following-char)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3349 type)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3350
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3351 (defun sgml-setup-doctype (docname external)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3352 (let ((sgml-parsing-dtd t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3353 (setq sgml-no-elements 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3354 (setq sgml-dtd-info (sgml-make-dtd docname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3355 ;;(setq sgml-dtd-shortmaps nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3356 (sgml-skip-ps)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3357 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3358 ((sgml-parse-delim "DSO")
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3359 (let ((original-buffer (current-buffer)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3360 (sgml-check-dtd-subset)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3361 (if (eq (current-buffer) original-buffer)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3362 (sgml-check-delim "DSC")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3363 (sgml-parse-error "Illegal character '%c' in doctype declaration"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3364 (following-char))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3365 (cond (external
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3366 (sgml-push-to-entity (sgml-make-entity docname 'dtd external))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3367 (sgml-check-dtd-subset)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3368 (sgml-check-end-of-entity "DTD subset")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3369 (sgml-pop-entity)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3370 ;;; (loop for map in sgml-dtd-shortmaps do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3371 ;;; (sgml-add-shortref-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3372 ;;; (sgml-dtd-shortmaps sgml-dtd-info)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3373 ;;; (car map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3374 ;;; (sgml-make-shortmap (cdr map))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3375 (sgml-set-initial-state sgml-dtd-info)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3376 (run-hooks 'sgml-doctype-parsed-hook)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3377
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3378 (defun sgml-do-data (type &optional marked-section)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3379 "Move point forward until there is an end-tag open after point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3380 (let ((start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3381 (done nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3382 (eref sgml-current-eref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3383 sgml-signal-data-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3384 (while (not done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3385 (cond (marked-section
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3386 (skip-chars-forward (if (eq type sgml-cdata) "^]" "^&]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3387 (when sgml-data-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3388 (funcall sgml-data-function (buffer-substring-no-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3389 start (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3390 (setq done (sgml-parse-delim "MS-END")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3391 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3392 (skip-chars-forward (if (eq type sgml-cdata) "^</" "^</&"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3393 (when sgml-data-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3394 (funcall sgml-data-function (buffer-substring-no-properties start (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3395 (setq done (or (sgml-is-delim "ETAGO" gi)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3396 (sgml-is-enabled-net)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3397 (setq start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3398 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3399 (done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3400 ((eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3401 (when (eq eref sgml-current-eref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3402 (sgml-error "Unterminated %s %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3403 type (if marked-section "marked section")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3404 (sgml-pop-entity)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3405 (setq start (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3406 ((null sgml-data-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3407 (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3408 ((sgml-parse-general-entity-ref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3409 (setq start (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3410 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3411 (forward-char 1))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3412
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3413
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3414 (defun sgml-do-marked-section ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3415 (let ((status nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3416 (while (progn (sgml-skip-ps)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3417 (not (sgml-parse-char ?\[)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3418 (push (sgml-check-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3419 status))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3420 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3421 ((member "ignore" status)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3422 (sgml-skip-marked-section)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3423 (sgml-set-markup-type 'ignored))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3424 ((or (member "cdata" status)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3425 (member "rcdata" status))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3426 (when sgml-signal-data-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3427 (funcall sgml-signal-data-function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3428 (let ((type (if (member "cdata" status) sgml-cdata sgml-rcdata)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3429 (sgml-do-data type t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3430 (sgml-set-markup-type type)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3431 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3432 (sgml-set-markup-type 'ms-start)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3433
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3434 (defun sgml-skip-marked-section ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3435 (while (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3436 (sgml-skip-upto ("MS-START" "MS-END"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3437 (when (eobp) (sgml-error "Marked section unterminated"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3438 (not (sgml-parse-delim "MS-END")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3439 (cond ((sgml-parse-delim "MS-START")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3440 ;;(search-forward "[")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3441 (sgml-skip-marked-section))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3442 (t (forward-char 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3444 (defun sgml-do-usemap ()
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3445 (let (mapname)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3446 ;;(setq sgml-markup-type 'usemap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3447 (unless (sgml-parse-rni "empty")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3448 (setq mapname (sgml-check-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3449 (sgml-skip-ps)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3450 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3451 ((sgml-is-delim "MDC")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3452 (sgml-debug "USEMAP %s" (if mapname mapname "#EMPTY"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3453 (cond (sgml-dtd-info
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3454 (setq sgml-current-shortmap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3455 (if mapname
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3456 (or (sgml-lookup-shortref-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3457 (sgml-dtd-shortmaps sgml-dtd-info)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3458 mapname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3459 (sgml-error "Undefined shortref map %s" mapname)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3460 ;; If in prolog
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3461 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3462 (sgml-log-warning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3463 "USEMAP without associated element type in prolog"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3464 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3465 ;; Should be handled by psgml-dtd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3466 (sgml-do-usemap-element mapname)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3467
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3468 (defconst sgml-markup-declaration-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3469 '(("sgml" . sgml-do-sgml-declaration)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3470 ("doctype" . sgml-do-doctype)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3471 ("element" . sgml-declare-element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3472 ("entity" . sgml-declare-entity)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3473 ("usemap" . sgml-do-usemap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3474 ("shortref" . sgml-declare-shortref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3475 ("notation" . sgml-declare-notation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3476 ("attlist" . sgml-declare-attlist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3477 ("uselink" . sgml-skip-upto-mdc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3478 ("linktype" . sgml-skip-upto-mdc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3479 ("link" . sgml-skip-upto-mdc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3480 ("idlink" . sgml-skip-upto-mdc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3481 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3482
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3483 (defun sgml-parse-markup-declaration (option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3484 "Parse a markup declartion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3485 OPTION can be `prolog' if parsing the prolog or `dtd' if parsing the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3486 dtd or `ignore' if the declaration is to be ignored."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3487 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3488 ((sgml-parse-delim "MDO" (nmstart "COM" "MDC"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3489 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3490 ((sgml-startnm-char-next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3491 (setq sgml-markup-type nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3492 (let* ((tok (sgml-parse-nametoken))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3493 (rut (assoc tok sgml-markup-declaration-table)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3494 (when (and (not (memq option '(prolog ignore)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3495 (member tok '("sgml" "doctype")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3496 (sgml-error "%s declaration is only valid in prolog" tok))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3497 (when (and (not (memq option '(dtd ignore)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3498 (member tok '("element" "entity" "attlist" "notation"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3499 "shortref")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3500 (sgml-error "%s declaration is only valid in doctype" tok))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3501 (cond ((eq option 'ignore)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3502 (sgml-skip-upto-mdc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3503 (rut (sgml-skip-ps)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3504 (funcall (cdr rut)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3505 (t (sgml-parse-error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3506 "Illegal markup declaration %s" tok)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3507 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3508 (setq sgml-markup-type 'comment)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3509 (sgml-skip-ps)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3510 (sgml-check-delim "MDC")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3511 (unless (eq option 'ignore) ; Set the markup type given
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3512 (when sgml-markup-type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3513 (sgml-set-markup-type sgml-markup-type)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3514 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3515 ((sgml-parse-delim "MS-START")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3516 (sgml-do-marked-section))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3517
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3518
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3519 ;;;; Parsing attribute values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3521 (defun sgml-parse-attribute-specification-list (&optional eltype)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3522 "Parse an attribute specification list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3523 Optional argument ELTYPE, is used to resolve omitted name=.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3524 Returns a list of attspec (attribute specification)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3525 (setq sgml-conref-flag nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3526 (let ((attlist (if eltype (sgml-eltype-attlist eltype)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3527 name val asl attdecl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3528 (while (setq name (progn (sgml-parse-s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3529 (sgml-parse-nametoken)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3530 (sgml-parse-s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3531 (cond ((sgml-parse-delim "VI")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3532 (sgml-parse-s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3533 (setq val (sgml-check-attribute-value-specification))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3534 (when eltype
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3535 (or (setq attdecl (sgml-lookup-attdecl name attlist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3536 (sgml-log-warning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3537 "Attribute %s not declared for element %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3538 name (sgml-eltype-name eltype)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3539 ((null eltype)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3540 (sgml-parse-error "Expecting a ="))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3541 ((progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3542 (unless sgml-current-shorttag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3543 (sgml-log-warning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3544 "Must have attribute name when SHORTTAG NO"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3545 (setq attdecl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3546 (sgml-find-attdecl-for-value (setq val name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3547 eltype))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3548 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3549 (sgml-log-warning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3550 "%s is not in any name group for element %s."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3551 val
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3552 (sgml-eltype-name eltype))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3553 ;; *** What happens when eltype is nil ??
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3554 (when attdecl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3555 (push (sgml-make-attspec (sgml-attdecl-name attdecl) val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3556 asl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3557 (when (sgml-default-value-type-p 'conref
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3558 (sgml-attdecl-default-value attdecl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3559 (setq sgml-conref-flag t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3560 asl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3561
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3562 (defun sgml-check-attribute-value-specification ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3563 (or (sgml-parse-literal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3564 (sgml-parse-nametoken t) ; Not really a nametoken, but an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3565 ; undelimited literal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3566 (sgml-parse-error "Expecting an attribute value: literal or token")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3567
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3568 (defun sgml-find-attdecl-for-value (value eltype)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3569 "Find the attribute declaration of ELTYPE that has VALUE in its name group.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3570 VALUE is a string. Returns nil or an attdecl."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3571 (let ((al (sgml-eltype-attlist eltype))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3572 dv)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3573 (while (and al
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3574 (or (atom (setq dv (sgml-attdecl-declared-value (car al))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3575 (not (member value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3576 (sgml-declared-value-token-group dv)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3577 (setq al (cdr al)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3578 (if al (car al))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3579
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3580
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3581 ;;;; Parser driver
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3582
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3583 ;; The parser maintains a partial parse tree during the parse. This tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3584 ;; can be inspected to find information, and also be used to restart the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3585 ;; parse. The parser also has a postition in the current content model.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3586 ;; (Called a state.) The parser is used for several things:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3587 ;; 1) To find the state the parser would be in at a point in the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3588 ;; (Point in emacs sense, I.e. between chararacters).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3589 ;; 2) Identify the element containing a character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3590 ;; 3) Find end of an element.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3591 ;; 4) Find the next element.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3592 ;; 5) To find the previous element.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3593
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3594 ;; These tasks are done by a combination of parsing and traversing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3595 ;; the partial parse tree. The primitive parse operation is to parse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3596 ;; until a goal point in the buffer has been passed. In addition to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3597 ;; this it is possible to "trap" closing of elements. Either for a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3598 ;; specific element or for any element. When the trap is sprung the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3599 ;; parse is ended. This is used to extend the parse tree. When the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3600 ;; trap is used the parser is usually called with the end of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3601 ;; buffer as the goal point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3602
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3603 (defun sgml-need-dtd ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3604 "Make sure that an eventual DTD is parsed or loaded."
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3605 (sgml-pop-all-entities)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3606 (sgml-cleanup-entities)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3607 (when (null sgml-buffer-parse-state) ; first parse in this buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3608 ;;(sgml-set-initial-state) ; fall back DTD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3609 (add-hook 'pre-command-hook 'sgml-reset-log)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3610 (make-local-variable 'sgml-auto-fill-inhibit-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3611 (setq sgml-auto-fill-inhibit-function (function sgml-in-prolog-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3612 (if sgml-default-dtd-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3613 (sgml-load-dtd sgml-default-dtd-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3614 (sgml-load-doctype)))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3615 (sgml-debug "Need dtd getting state from %s" (buffer-name))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3616 (setq sgml-dtd-info (sgml-pstate-dtd sgml-buffer-parse-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3617 sgml-top-tree (sgml-pstate-top-tree sgml-buffer-parse-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3618 (sgml-set-global))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3619
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3620
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3621 (defun sgml-load-doctype ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3622 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3623 ;; Case of doctype in another file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3624 ((or sgml-parent-document sgml-doctype)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3625 (let ((dtd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3626 (save-excursion ; get DTD from parent document
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3627 (set-buffer (find-file-noselect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3628 (if (consp sgml-parent-document)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3629 (car sgml-parent-document)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3630 (or sgml-doctype sgml-parent-document))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3631 (sgml-need-dtd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3632 (sgml-pstate-dtd sgml-buffer-parse-state))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3633 (sgml-set-initial-state dtd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3634 (when (consp sgml-parent-document) ; modify DTD for child documents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3635 (sgml-modify-dtd (cdr sgml-parent-document)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3636
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3637 ;; The doctype declaration should be in the current buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3638 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3639 (save-excursion (sgml-parse-prolog)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3640
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3641
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3642 (defun sgml-modify-dtd (modifier)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3643 (setq sgml-dtd-info (sgml-pstate-dtd sgml-buffer-parse-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3644 sgml-top-tree (sgml-pstate-top-tree sgml-buffer-parse-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3645 (sgml-set-global)
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 74
diff changeset
3646 (setq sgml-current-tree sgml-top-tree)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3647 (while (stringp (cadr modifier)) ; Loop thru the context elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3648 (let ((et (sgml-lookup-eltype (car modifier))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3649 (sgml-open-element et nil (point-min) (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3650 (setq modifier (cdr modifier))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3651
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3652 (unless (stringp (car modifier))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3653 (error "wrong format of sgml-parent-document"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3654
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3655 (let* ((doctypename (car modifier))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3656 (et (sgml-lookup-eltype
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3657 (sgml-general-case (if (symbolp doctypename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3658 (symbol-name doctypename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3659 doctypename)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3660
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3661 (setq sgml-current-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3662 (sgml-make-primitive-content-token et))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3663
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3664 (when (consp (cadr modifier)) ; There are "seen" elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3665 (sgml-open-element et nil (point-min) (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3666 (loop for seenel in (cadr modifier)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3667 do (setq sgml-current-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3668 (sgml-get-move sgml-current-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3669 (sgml-lookup-eltype seenel))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3670
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3671 (let ((top (sgml-pstate-top-tree sgml-buffer-parse-state)))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3672 (setf (sgml-tree-includes top) (sgml-tree-includes sgml-current-tree))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3673 (setf (sgml-tree-excludes top) (sgml-tree-excludes sgml-current-tree))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3674 (setf (sgml-tree-shortmap top) sgml-current-shortmap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3675 (setf (sgml-eltype-model (sgml-tree-eltype top))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3676 sgml-current-state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3677
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3678
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3679 (defun sgml-set-global ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3680 (setq sgml-current-omittag sgml-omittag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3681 sgml-current-shorttag sgml-shorttag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3682 sgml-current-localcat sgml-local-catalogs
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3683 sgml-current-local-ecat sgml-local-ecat-files
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3684 sgml-current-top-buffer (current-buffer)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3685
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3686 (defun sgml-parse-prolog ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3687 "Parse the document prolog to learn the DTD."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3688 (interactive)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3689 (sgml-debug "Parse prolog in buffer %s" (buffer-name))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3690 (unless sgml-debug
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3691 (sgml-clear-log))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3692 (message "Parsing prolog...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3693 (sgml-cleanup-entities)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3694 (sgml-set-global)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3695 (setq sgml-dtd-info nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3696 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3697 (sgml-with-parser-syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3698 (while (progn (sgml-skip-ds)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3699 (setq sgml-markup-start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3700 (and (sgml-parse-markup-declaration 'prolog)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3701 (null sgml-dtd-info))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3702 (unless sgml-dtd-info ; Set up a default doctype
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3703 (let ((docname (or sgml-default-doctype-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3704 (if (sgml-parse-delim "STAGO" gi)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3705 (sgml-parse-name)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3706 (when docname
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3707 (sgml-setup-doctype docname '(nil))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3708 (unless sgml-dtd-info
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3709 (error "No document type defined by prolog"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3710 (sgml-message "Parsing prolog...done"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3711
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3712
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3713 (defun sgml-parse-until-end-of (sgml-close-element-trap &optional
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3714 cont extra-cond quiet)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3715 "Parse until the SGML-CLOSE-ELEMENT-TRAP has ended,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3716 or if it is t, any additional element has ended,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3717 or if nil, until end of buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3718 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3719 (cont (sgml-parse-continue (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3720 (t (sgml-parse-to (point-max) extra-cond quiet)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3721 (when (eobp) ; End of buffer, can imply
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3722 ; end of any open element.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3723 (while (prog1 (not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3724 (or (eq sgml-close-element-trap t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3725 (eq sgml-close-element-trap sgml-current-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3726 (eq sgml-current-tree sgml-top-tree)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3727 (sgml-implied-end-tag "buffer end" (point) (point))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3728
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3729 (defun sgml-parse-to (sgml-goal &optional extra-cond quiet)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3730 "Parse until (at least) SGML-GOAL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3731 Optional argument EXTRA-COND should be a function. This function is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3732 called in the parser loop, and the loop is exited if the function returns t.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3733 If third argument QUIT is non-nil, no \"Parsing...\" message will be displayed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3734 (sgml-need-dtd)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3735
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3736 (unless before-change-function
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3737 (message "WARN: before-change-function has been lost, restoring (%s)"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3738 (current-buffer))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3739 (setq before-change-function 'sgml-note-change-at)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3740 (setq after-change-function 'sgml-set-face-after-change)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3741 )
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3742
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3743 (sgml-find-start-point (min sgml-goal (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3744 (assert sgml-current-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3745 (let ((bigparse (and (not quiet) (> (- sgml-goal (point)) 10000))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3746 (when bigparse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3747 (sgml-message "Parsing..."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3748 (sgml-with-parser-syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3749 (sgml-parser-loop extra-cond))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3750 (when bigparse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3751 (sgml-message ""))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3752
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3753 (defun sgml-parse-continue (sgml-goal &optional extra-cond quiet)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3754 "Parse until (at least) SGML-GOAL."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3755 (assert sgml-current-tree)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3756 (unless quiet
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3757 (sgml-message "Parsing..."))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3758 (sgml-with-parser-syntax
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3759 (sgml-parser-loop extra-cond))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3760 (unless quiet
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3761 (sgml-message "")))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3762
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3763 (defun sgml-reparse-buffer (shortref-fun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3764 "Reparse the buffer and let SHORTREF-FUN take care of short references.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3765 SHORTREF-FUN is called with the entity as argument and `sgml-markup-start'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3766 pointing to start of short ref and point pointing to the end."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3767 (sgml-note-change-at (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3768 (let ((sgml-shortref-handler shortref-fun))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3769 (sgml-parse-until-end-of nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3770
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3771 (defun sgml-move-current-state (token)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3772 (setq sgml-current-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3773 (or (sgml-get-move sgml-current-state token)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3774 sgml-current-state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3775
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3776 (defun sgml-execute-implied (imps type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3777 (loop for token in imps do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3778 (if (eq t token)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3779 (sgml-implied-end-tag type sgml-markup-start sgml-markup-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3780 (sgml-move-current-state token)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3781 (when sgml-throw-on-element-change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3782 (throw sgml-throw-on-element-change 'start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3783 (sgml-open-element (sgml-token-eltype token)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3784 nil sgml-markup-start sgml-markup-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3785 (unless (and sgml-current-omittag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3786 (sgml-element-stag-optional sgml-current-tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3787 (sgml-log-warning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3788 "%s start-tag implied by %s; not minimizable"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3789 (sgml-eltype-name (sgml-token-eltype token))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3790 type)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3791
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3792 (defun sgml-do-move (token type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3793 (sgml-execute-implied (sgml-list-implications token type) type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3794 (unless (eq sgml-any sgml-current-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3795 (sgml-move-current-state token)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3796
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3797 (defun sgml-pcdata-move ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3798 "Moify parser state to reflect parsed data."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3799 (sgml-do-move sgml-pcdata-token "data character"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3800
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3801 (defsubst sgml-parse-pcdata ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3802 (/= 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3803 (if sgml-current-shortmap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3804 (skip-chars-forward (sgml-shortmap-skipstring sgml-current-shortmap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3805 (skip-chars-forward "^<]/&"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3806
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3807 (defsubst sgml-do-pcdata ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3808 ;; Parse pcdata
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3809 (sgml-pcdata-move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3810 ;;*** assume sgml-markup-start = point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3811 ;;*** should perhaps handle &#nn;?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3812 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3813 (sgml-parse-pcdata)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3814 (when sgml-data-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3815 (funcall sgml-data-function (buffer-substring-no-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3816 sgml-markup-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3817 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3818 (sgml-set-markup-type nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3819
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3820 (defun sgml-parser-loop (extra-cond)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3821 (let (tem
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3822 (sgml-signal-data-function (function sgml-pcdata-move)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3823 (while (and (eq sgml-current-tree sgml-top-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3824 (or (< (point) sgml-goal) sgml-current-eref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3825 (progn (setq sgml-markup-start (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3826 sgml-markup-type nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3827 (or (sgml-parse-s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3828 (sgml-parse-markup-declaration 'prolog)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3829 (sgml-parse-processing-instruction)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3830 (while (and (or (< (point) sgml-goal) sgml-current-eref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3831 (not (if extra-cond (funcall extra-cond))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3832 (assert sgml-current-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3833 (setq sgml-markup-start (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3834 sgml-markup-type nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3835 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3836 ((eobp) (sgml-pop-entity))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3837 ((and (or (eq sgml-current-state sgml-cdata)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3838 (eq sgml-current-state sgml-rcdata)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3839 (if (or (sgml-parse-delim "ETAGO" gi)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3840 (sgml-is-enabled-net))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3841 (sgml-do-end-tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3842 (sgml-do-data sgml-current-state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3843 ((and sgml-current-shortmap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3844 (or (setq tem (sgml-deref-shortmap sgml-current-shortmap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3845 (eq (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3846 sgml-rs-ignore-pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3847 ;; Restore position, to consider the delim for S+ or data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3848 (progn (goto-char sgml-markup-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3849 nil)))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3850 (setq sgml-rs-ignore-pos sgml-markup-start) ; don't reconsider RS
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3851 (funcall sgml-shortref-handler tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3852 ((and (not (sgml-current-mixed-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3853 (sgml-parse-s sgml-current-shortmap)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3854 ((or (sgml-parse-delim "ETAGO" gi)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3855 (sgml-is-enabled-net))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3856 (sgml-do-end-tag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3857 ((sgml-parse-delim "STAGO" gi)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3858 (sgml-do-start-tag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3859 ((sgml-parse-general-entity-ref))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3860 ((sgml-parse-markup-declaration nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3861 ((sgml-parse-delim "MS-END") ; end of marked section
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3862 (sgml-set-markup-type 'ms-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3863 ((sgml-parse-processing-instruction))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3864 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3865 (sgml-do-pcdata))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3866
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3867 (defun sgml-handle-shortref (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3868 (sgml-set-markup-type 'shortref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3869 (sgml-do-entity-ref name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3870
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3871 (defun sgml-do-start-tag ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3872 ;; Assume point after STAGO
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3873 (when sgml-throw-on-element-change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3874 (throw sgml-throw-on-element-change 'start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3875 (setq sgml-conref-flag nil)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3876 (let (net-enabled et asl)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3877 (setq et (if (sgml-is-delim "TAGC") ; empty start-tag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3878 (sgml-do-empty-start-tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3879 (sgml-lookup-eltype (sgml-check-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3880 (unless (sgml-parse-delim "TAGC") ; optimize common case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3881 (setq asl (sgml-parse-attribute-specification-list et))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3882 (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3883 (if (sgml-parse-delim "NET")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3884 (prog1 (setq net-enabled t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3885 (or sgml-current-shorttag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3886 (sgml-log-warning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3887 "NET enabling start-tag is not allowed with SHORTTAG NO"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3888 (sgml-check-tag-close)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3889 (sgml-set-markup-type 'start-tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3890 (cond ((and sgml-ignore-undefined-elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3891 (not (sgml-eltype-defined et)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3892 (when sgml-warn-about-undefined-elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3893 (sgml-log-warning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3894 "Start-tag of undefined element %s; ignored"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3895 (sgml-eltype-name et))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3896 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3897 (sgml-do-move (sgml-eltype-token et)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3898 (format "%s start-tag" (sgml-eltype-name et)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3899 (sgml-open-element et sgml-conref-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3900 sgml-markup-start (point) asl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3901 (when net-enabled
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3902 (setf (sgml-tree-net-enabled sgml-current-tree) t))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3903
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3904
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3905 (defun sgml-do-empty-start-tag ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3906 "Return eltype to use if empty start tag"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3907 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3908 ;; Document element if no element is open
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3909 ((eq sgml-current-tree sgml-top-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3910 (sgml-lookup-eltype
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3911 (sgml-dtd-doctype sgml-dtd-info)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3912 ;; If omittag use current open element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3913 (sgml-current-omittag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3914 (sgml-tree-eltype sgml-current-tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3915 ;; Find the eltype of the last closed element.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3916 ;; If element has a left sibling then use that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3917 (sgml-previous-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3918 (sgml-tree-eltype sgml-previous-tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3919 ;; No sibling, last closed must be found in enclosing element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3920 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3921 (loop named outer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3922 for current = sgml-current-tree then (sgml-tree-parent current)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3923 for parent = (sgml-tree-parent current)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3924 do;; Search for a parent with a child before current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3925 (when (eq parent sgml-top-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3926 (sgml-error "No previously closed element"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3927 (unless (eq current (sgml-tree-content parent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3928 ;; Search content of u for element before current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3929 (loop for c = (sgml-tree-content parent) then (sgml-tree-next c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3930 do (when (eq current (sgml-tree-next c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3931 (return-from outer (sgml-tree-eltype c)))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3932
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3933
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3934 (defun sgml-do-end-tag ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3935 "Assume point after </ or at / in a NET"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3936 (let ((gi "Null") ; Name of element to end or "NET"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3937 et ; Element type of end tag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3938 (found ; Set to true when found element to end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3939 t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3940 (cond ((sgml-parse-delim "TAGC") ; empty end-tag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3941 (setq et (sgml-tree-eltype sgml-current-tree)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3942 ((sgml-parse-delim "NET"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3943 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3944 (setq et (sgml-lookup-eltype (sgml-check-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3945 (sgml-parse-s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3946 (sgml-check-tag-close)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3947 (sgml-set-markup-type 'end-tag) ; This will create the overlay for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3948 ; the end-tag before the element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3949 ; is closed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3950 (when et
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3951 (setq gi (sgml-eltype-name et))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3952 (setq found ; check if there is an open element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3953 ; with the right eltype
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3954 (loop for u = sgml-current-tree then (sgml-tree-parent u)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3955 while u
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3956 thereis (eq et (sgml-tree-eltype u))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3957 (unless found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3958 (sgml-log-warning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3959 "End-tag %s does not end any open element; ignored"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3960 gi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3961 (when found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3962 (setq found nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3963 (while (not found) ; Loop until correct element to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3964 ; end is found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3965 (unless (sgml-final-p sgml-current-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3966 (sgml-log-warning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3967 "%s element can't end here, need one of %s; %s end-tag out of context"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3968 (sgml-element-gi sgml-current-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3969 (sgml-required-tokens sgml-current-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3970 gi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3971 (when (eq sgml-current-tree sgml-top-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3972 (sgml-error "%s end-tag ended document and parse" gi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3973 (setq found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3974 (or (eq et (sgml-tree-eltype sgml-current-tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3975 (and (null et) ; Null end-tag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3976 (eq t (sgml-tree-net-enabled sgml-current-tree)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3977 (unless found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3978 (sgml-implied-end-tag (format "%s end-tag" gi)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3979 sgml-markup-start sgml-markup-start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3980 (sgml-close-element sgml-markup-start (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3981
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3982 (defun sgml-is-goal-after-start (goal tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3983 (and tree
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3984 (if (sgml-bpos-p (sgml-tree-stag-epos tree))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3985 (> goal (sgml-tree-stag-epos tree))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3986 (>= goal (sgml-epos-after (sgml-tree-stag-epos tree))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3987
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3988 (defun sgml-find-start-point (goal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3989 (let ((u sgml-top-tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3990 (while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3991 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3992 ((sgml-is-goal-after-start goal (sgml-tree-next u))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3993 (setq u (sgml-tree-next u)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3994 ((and (sgml-tree-etag-epos u)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3995 (if (> (sgml-tree-etag-len u) 0) ; if threre is an end-tag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3996 (>= goal (sgml-tree-end u)) ; precisely after is after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3997 (> goal (sgml-tree-end u)))) ; else it could possibly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3998 ; become part of the element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3999 (sgml-set-parse-state u 'after)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4000 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4001 ((sgml-is-goal-after-start goal (sgml-tree-content u))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4002 (setq u (sgml-tree-content u)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4003 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4004 (sgml-set-parse-state u 'start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4005 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4006 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4007 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4008
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4009
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4010 (defun sgml-check-tag-close ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4011 (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4012 (sgml-parse-delim "TAGC")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4013 (if (or (sgml-is-delim "STAGO" gi)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4014 (sgml-is-delim "ETAGO" gi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4015 (or sgml-current-shorttag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4016 (sgml-log-warning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4017 "Unclosed tag is not allowed with SHORTTAG NO")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4018 t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4019 (sgml-error "Invalid character in markup %c"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4020 (following-char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4021
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4022 (defun sgml-implied-end-tag (type start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4023 (cond ((eq sgml-current-tree sgml-top-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4024 (unless (= start (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4025 (sgml-error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4026 "document ended by %s" type)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4027 ((not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4028 (and sgml-current-omittag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4029 (sgml-element-etag-optional sgml-current-tree)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4030 (sgml-log-warning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4031 "%s end-tag implied by %s; not minimizable"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4032 (sgml-element-gi sgml-current-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4033 type)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4034 (sgml-close-element start end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4035
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4036
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4037 ;;;; Parsing tasks and extending the element view of the parse tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4038
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4039 (defun sgml-find-context-of (pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4040 "Find the parser context for POS, returns the parse tree.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4041 Also sets sgml-current-tree and sgml-current-state. If POS is in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4042 markup, sgml-markup-type will be a symbol identifying the markup
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4043 type. It will be nil otherwise."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4044 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4045 (sgml-parse-to pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4046 (cond ((and (> (point) pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4047 sgml-markup-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4048 ;;(setq sgml-current-state sgml-markup-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4049 (cond ((memq sgml-markup-type '(start-tag end-tag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4050 (setq sgml-current-tree sgml-markup-tree))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4051 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4052 (setq sgml-markup-type nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4053 sgml-current-tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4054
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4055 (defun sgml-parse-to-here ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4056 "Find context of point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4057 See documentation of sgml-find-context-of."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4058 (sgml-find-context-of (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4059
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4060 (defun sgml-find-element-of (pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4061 "Find the element containing character at POS."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4062 (when (eq pos (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4063 (error "End of buffer"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4064 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4065 (sgml-parse-to (1+ pos)) ; Ensures that the element is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4066 ; in the tree.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4067 ;; Find p in u:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4068 ;; assert p >= start(u)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4069 ;; if next(u) and p >= start(next(u)): find p in next(u)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4070 ;; else if end(u) and p >= end(u): in parent(u) unless u is top
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4071 ;; else if content:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4072 ;; if p < start(content(u)): in u
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4073 ;; else find p in content(u)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4074 ;; else: in u
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4075 (let ((u sgml-top-tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4076 (while ; pos >= start(u)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4077 (cond ((and (sgml-tree-next u)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4078 (>= pos (sgml-element-start (sgml-tree-next u))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4079 (setq u (sgml-tree-next u))) ; continue searching next node
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4080 ((and (sgml-tree-etag-epos u)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4081 (>= pos (sgml-tree-end u)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4082 (setq u (sgml-tree-parent u)) ; must be parent node
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4083 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4084 ((and (sgml-tree-content u)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4085 (>= pos (sgml-element-start (sgml-tree-content u))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4086 (setq u (sgml-tree-content u))))) ; search content
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4087 u)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4088
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4089 (defun sgml-find-previous-element (pos &optional in-element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4090 "Find the element before POS and return it, error if non found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4091 If in IN-ELEMENT is given look for previous element in IN-ELEMENT else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4092 look in current element. If this element has no content elements but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4093 end at POS, it will be returned as previous element."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4094 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4095 ;; Parse to point; now the previous element is in the parse tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4096 (sgml-parse-to pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4097 ;; containing element may be given or obtained from parser
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4098 (or in-element (setq in-element sgml-current-tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4099 ;; in-element is the containing element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4100 (let* ((c ; this is the content of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4101 ; containing element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4102 (sgml-tree-content in-element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4103 (while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4104 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4105 ((null c) ; If c = Nil: no previous element.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4106 ;; But maybe the containing element ends at pos too.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4107 (cond ((= pos (sgml-element-end in-element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4108 (setq c in-element))) ; Previous is parent!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4109 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4110 ((<= pos (sgml-element-start c)) ; Pos before first content el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4111 (setq c nil)) ; No, previous element.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4112 ((null (sgml-tree-next c)) nil) ; No next, c must be the prev el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4113 ((>= (sgml-element-start (sgml-tree-next c)) pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4114 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4115 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4116 (setq c (sgml-tree-next c)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4117 (or c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4118 (error "No previous element in %s element"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4119 (sgml-element-gi in-element))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4121 (defun sgml-find-element-after (pos &optional in-element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4122 "Find the first element starting after POS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4123 Returns parse tree; error if no element after POS."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4124 (setq in-element (or in-element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4125 (save-excursion (sgml-find-context-of pos))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4126 (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4127 ;; First try to find element after POS in IN-ELEMENT/current element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4128 (let ((c ; content of in-element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4129 (sgml-element-content in-element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4130 (while (and c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4131 (> pos (sgml-element-start c)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4132 (setq c (sgml-element-next c)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4133 c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4134 ;; If there is no more elements IN-ELEMENT/current element try
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4135 ;; to identify the element containing the character after POS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4136 ;; If this element starts at POS, use it for element after POS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4137 (let ((el (sgml-find-element-of pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4138 (if (and el (= pos (sgml-element-start el)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4139 el))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4140 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4141 (sgml-message "") ; force display of log buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4142 (error "No more elements in %s element"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4143 (sgml-element-gi in-element)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4145 (defun sgml-element-content (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4146 "First element in content of ELEMENT, or nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4147 (when (null (or (sgml-tree-content element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4148 (sgml-tree-etag-epos element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4149 (save-excursion (sgml-parse-until-end-of t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4150 (sgml-tree-content element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4151
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4152 (defun sgml-element-next (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4153 "Next sibling of ELEMENT."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4154 (unless (sgml-tree-etag-epos element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4155 (save-excursion (sgml-parse-until-end-of element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4156 (unless (or (sgml-tree-next element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4157 (sgml-tree-etag-epos (sgml-tree-parent element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4158 (save-excursion (sgml-parse-until-end-of t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4159 (sgml-tree-next element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4161 (defun sgml-element-etag-start (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4162 "Last position in content of ELEMENT and start of end-tag, if any."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4163 (unless (sgml-tree-etag-epos element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4164 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4165 (sgml-parse-until-end-of element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4166 (assert (sgml-tree-etag-epos element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4167 (sgml-epos-promote (sgml-tree-etag-epos element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4168
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4169 (defun sgml-element-end (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4170 "First position after ELEMENT."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4171 (sgml-element-etag-start element) ; make end be defined
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4172 (sgml-tree-end element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4173
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4174 (defun sgml-read-element-name (prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4175 (sgml-parse-to-here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4176 (cond (sgml-markup-type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4177 (error "No elements allowed in markup"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4178 ((and ;;sgml-buffer-eltype-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4179 (not (eq sgml-current-state sgml-any)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4180 (let ((tab
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4181 (mapcar (function (lambda (x) (cons (symbol-name x) nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4182 (sgml-current-list-of-valid-eltypes))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4183 (cond ((null tab)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4184 (error "No element valid at this point"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4185 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4186 (completing-read prompt tab nil t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4187 (and (null (cdr tab)) (caar tab)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4188 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4189 (read-from-minibuffer prompt))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4191 (defun sgml-element-attribute-specification-list (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4192 "Return the attribute specification list for ELEMENT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4193 This is a list of (attname value) lists."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4194 ;;; (if (> (sgml-element-stag-len element) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4195 ;;; (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4196 ;;; (sgml-with-parser-syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4197 ;;; (sgml-goto-epos (sgml-element-stag-epos element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4198 ;;; (sgml-check-delim "STAGO")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4199 ;;; (sgml-check-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4200 ;;; (prog1 (sgml-parse-attribute-specification-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4201 ;;; (sgml-element-eltype element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4202 ;;; (sgml-pop-all-entities)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4203 (sgml-tree-asl element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4205 (defun sgml-find-attribute-element ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4206 "Return the element to which an attribute editing command should be applied."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4207 (let ((el (sgml-find-element-of (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4208 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4209 (sgml-parse-to (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4210 ;; If after a start-tag of an empty element return that element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4211 ;; instead of current element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4212 (if (eq sgml-markup-type 'start-tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4213 sgml-markup-tree ; the element of the start-tag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4214 el))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4215
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4216
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4217 (defun sgml-element-attval (element attribute)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4218 "Return the value of the ATTRIBUTE in ELEMENT, string or nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4219 (let ((asl (sgml-element-attribute-specification-list element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4220 (def (sgml-attdecl-default-value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4221 (sgml-lookup-attdecl attribute (sgml-element-attlist element)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4222 (or (sgml-attspec-attval (sgml-lookup-attspec attribute asl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4223 (sgml-default-value-attval def))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4226 (defun sgml-cohere-name (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4227 "Convert X into a string where X can be a string, a symbol or an element."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4228 (cond ((stringp x) x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4229 ((symbolp x) (symbol-name x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4230 (t (sgml-element-gi x))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4231
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4232 (defun sgml-start-tag-of (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4233 "Return the start-tag for ELEMENT."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4234 (format "<%s>" (sgml-cohere-name element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4236 (defun sgml-end-tag-of (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4237 "Return the end-tag for ELEMENT (token or element)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4238 (format "</%s>" (sgml-cohere-name element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4240 (defun sgml-top-element ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4241 "Return the document element."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4242 (sgml-element-content (sgml-find-context-of (point-min))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4244 (defun sgml-off-top-p (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4245 "True if ELEMENT is the pseudo element above the document element."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4246 (null (sgml-tree-parent element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4247
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4248 (defun sgml-safe-context-of (pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4249 (let ((sgml-throw-on-error 'parse-error))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4250 (catch sgml-throw-on-error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4251 (sgml-find-context-of pos))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4252
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4253 (defun sgml-safe-element-at (pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4254 (let ((sgml-throw-on-error 'parse-error))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4255 (catch sgml-throw-on-error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4256 (if (= pos (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4257 (sgml-find-context-of pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4258 (sgml-find-element-of pos)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4259
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4260 (defun sgml-in-prolog-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4261 (let ((el (sgml-safe-context-of (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4262 (or (null el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4263 (sgml-off-top-p el))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4264
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4265
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4266 ;;;; Provide
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4267
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4268 (provide 'psgml-parse)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4269
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4270 ;; Local variables:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4271 ;; byte-compile-warnings:(free-vars unresolved callargs redefine)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4272 ;; End:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4273 ;;; psgml-parse.el ends here