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