1 ;;;;\filename psgml-debug.el
2 ;;;\Last edited: 2001-03-10 00:32:00 lenst
3 ;;;\RCS $Id: psgml-debug.el,v 2.31 2005/03/02 19:43:45 lenst Exp $
4 ;;;\author {Lennart Staflin}
10 (require 'psgml-parse)
13 (autoload 'sgml-translate-model "psgml-dtd" "" nil)
21 (define-key sgml-mode-map "\C-c," 'sgml-goto-cache)
22 (define-key sgml-mode-map "\C-c\C-x" 'sgml-dump-tree)
23 (define-key sgml-mode-map "\C-c." 'sgml-shortref-identify)
25 (defun sgml-this-element ()
27 (let ((tree (sgml-find-element-of (point))))
28 (sgml-dump-rec tree)))
30 (defun sgml-goto-cache ()
32 (setq sgml-dtd-info (sgml-pstate-dtd sgml-buffer-parse-state)
33 sgml-top-tree (sgml-pstate-top-tree sgml-buffer-parse-state))
34 (sgml-goto-start-point (point))
35 (message "%s" (sgml-dump-node sgml-current-tree)))
37 (defun sgml-dump-tree (arg)
41 (with-output-to-temp-buffer "*Dump*"
42 (sgml-dump-rec (sgml-pstate-top-tree sgml-buffer-parse-state))))
44 (defun sgml-auto-dump ()
45 (let ((standard-output (get-buffer-create "*Dump*"))
46 (cb (current-buffer)))
48 (when sgml-buffer-parse-state
50 (progn (set-buffer standard-output)
54 (sgml-dump-rec (sgml-pstate-top-tree sgml-buffer-parse-state))
59 (defun sgml-start-auto-dump ()
61 (add-hook 'post-command-hook
62 (function sgml-auto-dump)
65 (defun sgml-comepos (epos)
66 (if (sgml-strict-epos-p epos)
68 (sgml-entity-name (sgml-eref-entity (sgml-epos-eref epos)))
72 (defun sgml-dump-node (u)
74 "%s%s start:%s(%s) end:%s(%s) epos:%s/%s net:%s\n"
75 (make-string (sgml-tree-level u) ?. )
77 (sgml-element-start u) (sgml-tree-stag-len u)
78 (if (sgml-tree-etag-epos u) (sgml-tree-end u)) (sgml-tree-etag-len u)
79 (sgml-comepos (sgml-tree-stag-epos u))
80 (sgml-comepos (sgml-tree-etag-epos u))
81 (sgml-tree-net-enabled u)))
83 (defun sgml-dump-rec (u)
85 (princ (sgml-dump-node u))
86 (sgml-dump-rec (sgml-tree-content u))
87 (setq u (sgml-tree-next u))))
89 (defun sgml-shortref-identify ()
91 (sgml-find-context-of (point))
92 (let* ((nobol (eq (point) sgml-rs-ignore-pos))
93 (tem (sgml-deref-shortmap sgml-current-shortmap nobol)))
94 (message "%s (%s)" tem nobol)))
96 (defun sgml-lookup-shortref-name (table map)
97 (car (rassq map (cdr table))))
99 (defun sgml-show-current-map ()
101 (sgml-find-context-of (point))
102 (let ((name (sgml-lookup-shortref-name
103 (sgml-dtd-shortmaps sgml-dtd-info)
104 sgml-current-shortmap)))
105 (message "Current map: %s"
106 (or name "#EMPTY"))))
110 ;;(put 'when 'edebug-form-hook t)
111 ;;(put 'unless 'edebug-form-hook t)
112 ;;(put 'push 'edebug-form-hook '(form sexp))
113 ;;(put 'setf 'edebug-form-hook '(sexp form))
115 (setq edebug-print-level 3
116 edebug-print-length 5
117 edebug-print-circle nil
121 (unless running-xemacs ;; XEmacs change
122 (def-edebug-spec sgml-with-parser-syntax (&rest form))
123 (def-edebug-spec sgml-with-parser-syntax-ro (&rest form))
124 (def-edebug-spec sgml-skip-upto (sexp))
125 (def-edebug-spec sgml-check-delim (sexp &optional sexp))
126 (def-edebug-spec sgml-parse-delim (sexp &optional sexp))
127 (def-edebug-spec sgml-is-delim (sexp &optional sexp sexp sexp))))
131 (defun sgml-dump-dtd (&optional dtd)
134 (setq dtd (sgml-pstate-dtd sgml-buffer-parse-state)))
135 (with-output-to-temp-buffer "*DTD dump*"
136 (princ (format "Dependencies: %S\n"
137 (sgml-dtd-dependencies dtd)))
138 (loop for et being the symbols of (sgml-dtd-eltypes dtd)
139 do (sgml-dp-element et))))
141 (defun sgml-dump-element (el-name)
143 (list (completing-read "Element: "
145 (sgml-pstate-dtd sgml-buffer-parse-state))
147 (with-output-to-temp-buffer "*Element dump*"
148 (sgml-dp-element (sgml-lookup-eltype el-name))))
150 (defun sgml-dp-element (el)
152 ((sgml-eltype-defined el)
153 (princ (format "Element %s %s %s%s:\n"
154 (sgml-eltype-name el)
155 (if (sgml-eltype-stag-optional el) "O" "-")
156 (if (sgml-eltype-etag-optional el) "O" "-")
157 (if (sgml-eltype-mixed el) " mixed" "")))
159 ((sgml-model-group-p (sgml-eltype-model el))
160 (sgml-dp-model (sgml-eltype-model el)))
162 (prin1 (sgml-eltype-model el))
164 (princ (format "Exeptions: +%S -%S\n"
165 (sgml-eltype-includes el)
166 (sgml-eltype-excludes el)))
167 (princ (format "Attlist: %S\n" (sgml-eltype-attlist el)))
168 (princ (format "Plist: %S\n" (symbol-plist el))))
170 (princ (format "Undefined element %s\n" (sgml-eltype-name el)))))
174 (defun sgml-dp-model (model &optional indent)
175 (or indent (setq indent 0))
176 (let ((sgml-code-xlate (sgml-translate-model model)))
179 for x in sgml-code-xlate do
180 (cond ((sgml-normal-state-p (car x))
181 (princ (format "%s%d: opts=%s reqs=%s\n"
182 (make-string indent ? ) i
183 (sgml-untangel-moves (sgml-state-opts (car x)))
184 (sgml-untangel-moves (sgml-state-reqs (car x))))))
186 (princ (format "%s%d: and-node next=%d\n"
187 (make-string indent ? ) i
188 (sgml-code-xlate (sgml-and-node-next (car x)))))
189 (loop for m in (sgml-and-node-dfas (car x))
190 do (sgml-dp-model m (+ indent 2))))))))
192 (defun sgml-untangel-moves (moves)
194 collect (list (sgml-move-token m)
195 (sgml-code-xlate (sgml-move-dest m)))))
200 (defun sgml-dump-state ()
202 (with-output-to-temp-buffer "*State dump*"
203 (sgml-dp-state sgml-current-state)))
205 (defun sgml-dp-state (state &optional indent)
206 (or indent (setq indent 0))
208 ((sgml-normal-state-p state)
209 (sgml-dp-model state indent))
211 (princ (format "%sand-state\n" (make-string indent ? )))
212 (sgml-dp-state (sgml-and-state-substate state) (+ 2 indent))
213 (princ (format "%s--next\n" (make-string indent ? )))
214 (sgml-dp-state (sgml-and-state-next state) (+ 2 indent))
215 (princ (format "%s--dfas\n" (make-string indent ? )))
216 (loop for m in (sgml-and-state-dfas state)
217 do (sgml-dp-model m (+ indent 2))
218 (princ (format "%s--\n" (make-string indent ? )))))))
221 ;;;; Build autoloads for all interactive functions in psgml-parse
223 (defun sgml-build-autoloads ()
225 (with-output-to-temp-buffer "*autoload*"
227 for file in '("psgml-parse" "psgml-edit" "psgml-dtd"
228 "psgml-info" "psgml-charent")
230 (set-buffer (find-file-noselect (concat file ".el")))
231 (goto-char (point-min))
234 (re-search-forward "^(defun +\\([^ ]+\\)" nil t))
235 (let ((name (buffer-substring (match-beginning 1)
238 (forward-sexp 1) ; skip argument list
239 (skip-chars-forward " \n\t")
240 (when (eq ?\" (following-char)) ; doc string
241 (setq doc (buffer-substring (point)
242 (progn (forward-sexp 1)
244 (skip-chars-forward " \n\t")
245 (when (looking-at "(interactive")
247 (message "No doc for %s" name))
249 "(autoload '%s \"%s\" %s t)\n"
250 name file doc))))))))
252 ;;;; Test psgml with sgmls test cases
254 (defun test-sgml (start)
257 (sgml-show-warnings t))
258 (with-output-to-temp-buffer "*Testing psgml*"
261 (setq file (format "/u2/src/sgmls-1.1/test/test%03d.sgm"
263 (file-exists-p file))
264 (princ (format "*** File test%03d ***\n" start))
266 (condition-case errcode
269 ;;(sgml-next-trouble-spot)
270 (sgml-parse-until-end-of nil))
274 (if (get-buffer sgml-log-buffer-name)
275 (princ (save-excursion
276 (set-buffer sgml-log-buffer-name)
281 (kill-buffer (current-buffer))
282 (setq start (1+ start))))))
287 (defun profile-sgml (&optional file)
289 (or file (setq file (expand-file-name "~/work/sigmalink/BBB/config/configspec.xml")))
292 (sgml-instrument-parser)
296 (sgml-reparse-buffer (function sgml-handle-shortref)))
299 (defun sgml-instrument-parser ()
302 (setq elp-function-list nil)
304 (setq elp-function-list
308 sgml-parse-markup-declaration
309 sgml-do-processing-instruction
311 sgml-tree-net-enabled
317 sgml-do-general-entity-ref
320 sgml-shortmap-skipstring
322 sgml-parse-attribute-specification-list
326 sgml-list-implications
327 sgml-move-current-state
328 sgml-do-empty-start-tag
330 sgml-startnm-char-next
337 (elp-instrument-list))
340 (defun sgml-instrument-dtd-parser ()
343 (setq elp-function-list nil)
345 (setq elp-function-list
349 sgml-parse-markup-declaration
350 sgml-check-doctype-body
352 sgml-check-dtd-subset
357 sgml-declare-shortref
359 sgml-parse-parameter-literal
360 sgml-check-element-type
361 sgml-check-primitive-content-token
362 sgml-check-model-group
363 ;; In sgml-check-model-group
376 sgml-do-parameter-entity-ref
378 sgml-make-primitive-content-token
383 sgml-remove-redundant-states-1
385 (elp-instrument-list))