1 ;;; mim-syntax.el --- syntax checker for Mim (MDL).
3 ;; Copyright (C) 1985 Free Software Foundation, Inc.
4 ;; Principal author K. Shane Hartman
6 ;; This file is part of GNU Emacs.
8 ;; GNU Emacs is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 1, or (at your option)
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs; see the file COPYING. If not, write to
20 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25 (defun slow-syntax-check-mim ()
26 "Check Mim syntax slowly.
27 Points out the context of the error, if the syntax is incorrect."
29 (message "checking syntax...")
30 (let ((stop (point-max)) point-stack current last-bracket whoops last-point
)
32 (goto-char (point-min))
33 (while (and (not whoops
)
34 (re-search-forward "\\s(\\|\\s)\\|\"\\|[\\]" stop t
))
35 (setq current
(preceding-char))
36 (cond ((= current ?
\")
38 (progn (re-search-forward "[^\\]\"")
40 (error (setq whoops
(point)))))
42 (condition-case nil
(forward-char 1) (error nil
)))
43 ((= (char-syntax current
) ?\
))
44 (if (or (not last-bracket
)
45 (not (= (logand (lsh (aref (syntax-table) last-bracket
) -
8)
49 (setq last-point
(car point-stack
))
50 (setq last-bracket
(if last-point
(char-after (1- last-point
))))
51 (setq point-stack
(cdr point-stack
))))
53 (if last-point
(setq point-stack
(cons last-point point-stack
)))
54 (setq last-point
(point))
55 (setq last-bracket current
)))))
56 (cond ((not (or whoops last-point
))
57 (message "Syntax correct"))
60 (cond ((equal current ?
\")
61 (error "Unterminated string"))
63 (error "Extraneous %s" (char-to-string current
)))
65 (error "Mismatched %s with %s"
67 (setq whoops
(1- (point)))
68 (goto-char (1- last-point
))
69 (buffer-substring (point)
70 (min (progn (end-of-line) (point))
72 (char-to-string current
)))))
74 (goto-char last-point
)
75 (error "Unmatched %s" (char-to-string last-bracket
))))))
77 (defun fast-syntax-check-mim ()
78 "Checks Mim syntax quickly.
79 Answers correct or incorrect, cannot point out the error context."
82 (goto-char (point-min))
84 (while (and (not (eobp))
85 (equal (car (setq state
(parse-partial-sexp (point) (point-max) 0)))
87 (if (equal (car state
) 0)
88 (message "Syntax correct")
89 (error "Syntax incorrect")))))
91 ;;; mim-syntax.el ends here