Mercurial > emacs
annotate lisp/=mim-syntax.el @ 659:505130d1ddf8
*** empty log message ***
author | Eric S. Raymond <esr@snark.thyrsus.com> |
---|---|
date | Sat, 30 May 1992 22:12:04 +0000 |
parents | 63b375f17a65 |
children | 4f28bd14272c |
rev | line source |
---|---|
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
35
diff
changeset
|
1 ;;; mim-syntax.el --- syntax checker for Mim (MDL). |
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
35
diff
changeset
|
2 |
35 | 3 ;; Copyright (C) 1985 Free Software Foundation, Inc. |
4 ;; Principal author K. Shane Hartman | |
5 | |
6 ;; This file is part of GNU Emacs. | |
7 | |
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) | |
11 ;; any later version. | |
12 | |
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. | |
17 | |
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. | |
21 | |
22 | |
23 (require 'mim-mode) | |
24 | |
25 (defun slow-syntax-check-mim () | |
26 "Check Mim syntax slowly. | |
27 Points out the context of the error, if the syntax is incorrect." | |
28 (interactive) | |
29 (message "checking syntax...") | |
30 (let ((stop (point-max)) point-stack current last-bracket whoops last-point) | |
31 (save-excursion | |
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 ?\") | |
37 (condition-case nil | |
38 (progn (re-search-forward "[^\\]\"") | |
39 (setq current nil)) | |
40 (error (setq whoops (point))))) | |
41 ((= current ?\\) | |
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) | |
46 ?\177) | |
47 current))) | |
48 (setq whoops (point)) | |
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)))) | |
52 (t | |
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")) | |
58 (whoops | |
59 (goto-char whoops) | |
60 (cond ((equal current ?\") | |
61 (error "Unterminated string")) | |
62 ((not last-point) | |
63 (error "Extraneous %s" (char-to-string current))) | |
64 (t | |
65 (error "Mismatched %s with %s" | |
66 (save-excursion | |
67 (setq whoops (1- (point))) | |
68 (goto-char (1- last-point)) | |
69 (buffer-substring (point) | |
70 (min (progn (end-of-line) (point)) | |
71 whoops))) | |
72 (char-to-string current))))) | |
73 (t | |
74 (goto-char last-point) | |
75 (error "Unmatched %s" (char-to-string last-bracket)))))) | |
76 | |
77 (defun fast-syntax-check-mim () | |
78 "Checks Mim syntax quickly. | |
79 Answers correct or incorrect, cannot point out the error context." | |
80 (interactive) | |
81 (save-excursion | |
82 (goto-char (point-min)) | |
83 (let (state) | |
84 (while (and (not (eobp)) | |
85 (equal (car (setq state (parse-partial-sexp (point) (point-max) 0))) | |
86 0))) | |
87 (if (equal (car state) 0) | |
88 (message "Syntax correct") | |
89 (error "Syntax incorrect"))))) | |
90 | |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
35
diff
changeset
|
91 ;;; mim-syntax.el ends here |