Mercurial > emacs
annotate lisp/progmodes/antlr-mode.el @ 31973:ad9838a9349c
(diff-mode-map, diff-minor-mode-prefix):
Avoid user-reserved bindings.
(diff-mode, diff-minor-mode): Drop make-local-hook (done by add-hook).
(diff-header-face): Revert to grey85.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Fri, 29 Sep 2000 02:25:32 +0000 |
parents | 9ad79f5782af |
children | 075cc818f566 |
rev | line source |
---|---|
26542
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1 ;;; antlr-mode.el --- Major mode for ANTLR grammar files |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
2 |
29289
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
3 ;; Copyright (C) 1999-2000 Free Software Foundation, Inc. |
26542
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
4 ;; |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
5 ;; Author: Christoph.Wedler@sap.com |
26965 | 6 ;; Version: $Id: antlr-mode.el,v 1.2 1999/12/16 19:30:34 wedler Exp $ |
7 ;; X-URL: http://www.fmi.uni-passau.de/~wedler/antlr-mode/ | |
26542
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
8 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
9 ;; This file is part of GNU Emacs. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
10 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
11 ;; GNU Emacs is free software; you can redistribute it and/or modify |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
12 ;; it under the terms of the GNU General Public License as published by |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
13 ;; the Free Software Foundation; either version 2, or (at your option) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
14 ;; any later version. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
15 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
16 ;; GNU Emacs is distributed in the hope that it will be useful, |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
19 ;; GNU General Public License for more details. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
20 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
21 ;; You should have received a copy of the GNU General Public License |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
24 ;; Boston, MA 02111-1307, USA. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
25 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
26 ;;; Commentary: |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
27 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
28 ;; Major mode for editing ANTLR grammar files, i.e., files ending with `.g'. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
29 ;; ANTLR is ANother Tool for Language Recognition (an excellent alternative to |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
30 ;; lex/yacc), see <http://www.ANTLR.org> and <news:comp.compilers.tools.pccts>. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
31 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
32 ;; Variable `antlr-language' is set according to the language in actions and |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
33 ;; semantic predicates of the grammar (see ANTLR's file option "language"). |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
34 ;; The supported languages are "Java" (java-mode) and "Cpp" (c++-mode). This |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
35 ;; package uses features of the Emacs package cc-mode. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
36 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
37 ;; This package provides the following features: |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
38 ;; * Indentation for the current line (TAB) and selected region (C-M-\). |
26965 | 39 ;; * Syntax coloring (via font-lock) with language dependent coloring. |
26542
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
40 ;; * Support for imenu/speedbar: menu "Index" (Parser, Lexer, TreeParser). |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
41 ;; * Direct move to previous/next rule, beginning/end of rule body etc. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
42 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
43 ;; INDENTATION. This package supports ANTLR's (intended) indentation style |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
44 ;; which is based on a simple paren/brace/bracket depth-level calculation, see |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
45 ;; `antlr-indent-line'. The indentation engine of cc-mode is only used inside |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
46 ;; block comments (it is not easy to use it for actions, esp if they come early |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
47 ;; in the rule body). By default, this package uses TABs for a basic offset of |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
48 ;; 4 to be consistent to both ANTLR's conventions (TABs usage) and the |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
49 ;; `c-indentation-style' "java" which sets `c-basic-offset' to 4, see |
29289
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
50 ;; `antlr-tab-offset-alist'. You might want to set this variable to nil. |
26542
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
51 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
52 ;; SYNTAX COLORING comes in three phases. First, comments and strings are |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
53 ;; highlighted. Second, the grammar code is highlighted according to |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
54 ;; `antlr-font-lock-additional-keywords' (rule refs: blue, token refs: brown, |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
55 ;; definition: ditto+bold). Third, actions, semantic predicates and arguments |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
56 ;; are highlighted according to the usual font-lock keywords of |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
57 ;; `antlr-language', see also `antlr-font-lock-maximum-decoration'. We define |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
58 ;; special font-lock faces for the grammar code to allow you to distinguish |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
59 ;; ANTLR keywords from Java/C++ keywords. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
60 |
26965 | 61 ;; Bug fixes, bug reports, improvements, and suggestions are strongly |
62 ;; appreciated. Please check the newest version first: | |
63 ;; http://www.fmi.uni-passau.de/~wedler/antlr-mode/changes.html | |
64 | |
26542
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
65 ;;; Installation: |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
66 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
67 ;; This file requires Emacs-20.3, XEmacs-20.4 or higher. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
68 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
69 ;; If antlr-mode is not part of your distribution, put this file into your |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
70 ;; load-path and the following into your ~/.emacs: |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
71 ;; (autoload 'antlr-mode "antlr-mode" nil t) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
72 ;; (setq auto-mode-alist (cons '("\\.g\\'" . antlr-mode) auto-mode-alist)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
73 ;; (add-hook 'speedbar-load-hook ; would be too late in antlr-mode.el |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
74 ;; (lambda () (speedbar-add-supported-extension ".g"))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
75 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
76 ;; If you edit ANTLR's source files, you might also want to use |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
77 ;; (autoload 'antlr-set-tabs "antlr-mode") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
78 ;; (add-hook 'java-mode-hook 'antlr-set-tabs) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
79 |
29289
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
80 ;; I strongly recommend to use font-lock with a support mode like fast-lock, |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
81 ;; lazy-lock or better jit-lock (Emacs-21.1+) / lazy-shot (XEmacs). |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
82 |
26542
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
83 ;; To customize, use `M-x customize-group RET antlr RET' or the custom browser |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
84 ;; (Emacs->Programming->Languages->Antlr). |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
85 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
86 ;;; Code: |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
87 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
88 (provide 'antlr-mode) |
29289
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
89 (eval-when-compile (require 'cc-mode)) ; shut up most warnings |
26542
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
90 (require 'easymenu) ; Emacs |
29289
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
91 (eval-when-compile ; optional libraries |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
92 (defvar outline-level) (defvar imenu-use-markers)) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
93 (eval-when-compile ; Emacs: cl, XEmacs vars |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
94 (require 'cl)) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
95 (eval-when-compile ; XEmacs: Emacs vars |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
96 (defvar inhibit-point-motion-hooks) (defvar deactivate-mark)) |
26542
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
97 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
98 (eval-and-compile |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
99 (if (string-match "XEmacs" emacs-version) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
100 (defalias 'antlr-scan-sexps 'scan-sexps) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
101 (defalias 'antlr-scan-sexps 'antlr-scan-sexps-internal)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
102 (if (and (fboundp 'buffer-syntactic-context) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
103 (fboundp 'buffer-syntactic-context-depth)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
104 (progn |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
105 (defalias 'antlr-invalidate-context-cache 'antlr-xemacs-bug-workaround) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
106 (defalias 'antlr-syntactic-context 'antlr-fast-syntactic-context)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
107 (defalias 'antlr-invalidate-context-cache 'ignore) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
108 (defalias 'antlr-syntactic-context 'antlr-slow-syntactic-context))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
109 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
110 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
111 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
112 ;;;;########################################################################## |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
113 ;;;; Variables |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
114 ;;;;########################################################################## |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
115 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
116 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
117 (defgroup antlr nil |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
118 "Major mode for ANTLR grammar files." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
119 :group 'languages |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
120 :link '(emacs-commentary-link "antlr-mode.el") |
26965 | 121 :link '(url-link "http://www.fmi.uni-passau.de/~wedler/antlr-mode/") |
26542
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
122 :prefix "antlr-") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
123 |
29289
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
124 (defconst antlr-version "1.3" |
26542
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
125 "ANTLR major mode version number.") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
126 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
127 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
128 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
129 ;;; Controlling ANTLR's code generator (language option) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
130 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
131 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
132 (defvar antlr-language nil |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
133 "Major mode corresponding to ANTLR's \"language\" option. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
134 Set via `antlr-language-alist'. The only useful place to change this |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
135 buffer-local variable yourself is in `antlr-mode-hook' or in the \"local |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
136 variable list\" near the end of the file, see |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
137 `enable-local-variables'.") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
138 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
139 (defcustom antlr-language-alist |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
140 '((java-mode "Java" nil "Java") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
141 (c++-mode "C++" "Cpp")) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
142 "List of ANTLR's supported languages. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
143 Each element in this list looks like |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
144 (MAJOR-MODE MODELINE-STRING OPTION-VALUE...) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
145 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
146 MAJOR-MODE, the major mode of the code in the grammar's actions, is the |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
147 value of `antlr-language' if the first regexp group matched by REGEXP in |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
148 `antlr-language-limit-n-regexp' is one of the OPTION-VALUEs. An |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
149 OPTION-VALUE of nil denotes the fallback element. MODELINE-STRING is |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
150 also displayed in the modeline next to \"Antlr\"." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
151 :group 'antlr |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
152 :type '(repeat (group :value (java-mode "") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
153 (function :tag "Major mode") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
154 (string :tag "Modeline string") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
155 (repeat :tag "ANTLR language option" :inline t |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
156 (choice (const :tag "Default" nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
157 string ))))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
158 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
159 (defcustom antlr-language-limit-n-regexp |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
160 '(3000 . "language[ \t]*=[ \t]*\"\\([A-Z][A-Za-z_]*\\)\"") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
161 "Used to set a reasonable value for `antlr-language'. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
162 Looks like (LIMIT . REGEXP). Search for REGEXP from the beginning of |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
163 the buffer to LIMIT to set the language according to |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
164 `antlr-language-alist'." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
165 :group 'antlr |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
166 :type '(cons (choice :tag "Limit" (const :tag "No" nil) (integer :value 0)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
167 regexp)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
168 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
169 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
170 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
171 ;;; Indent/Tabs |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
172 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
173 |
29289
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
174 (defcustom antlr-tiny-action-length 3 |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
175 "Maximal number of characters in actions never to hide. |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
176 See command `antlr-hide-actions'." |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
177 :group 'antlr |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
178 :type 'integer) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
179 |
26542
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
180 (defcustom antlr-indent-comment 'tab |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
181 "*Non-nil, if the indentation should touch lines in block comments. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
182 If nil, no continuation line of a block comment is changed. If t, they |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
183 are changed according to `c-indentation-line'. When not nil and not t, |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
184 they are only changed by \\[antlr-indent-command]." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
185 :group 'antlr |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
186 :type '(radio (const :tag "No" nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
187 (const :tag "Always" t) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
188 (sexp :tag "With TAB" :format "%t" :value tab))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
189 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
190 (defcustom antlr-tab-offset-alist |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
191 '((antlr-mode nil 4 t) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
192 (java-mode "antlr" 4 t)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
193 "Alist to determine whether to use ANTLR's convention for TABs. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
194 Each element looks like (MAJOR-MODE REGEXP TAB-WIDTH INDENT-TABS-MODE). |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
195 The first element whose MAJOR-MODE is nil or equal to `major-mode' and |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
196 whose REGEXP is nil or matches `buffer-file-name' is used to set |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
197 `tab-width' and `indent-tabs-mode'. This is useful to support both |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
198 ANTLR's and Java's indentation styles. Used by `antlr-set-tabs'." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
199 :group 'antlr |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
200 :type '(repeat (group :value (antlr-mode nil 8 nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
201 (choice (const :tag "All" nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
202 (function :tag "Major mode")) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
203 (choice (const :tag "All" nil) regexp) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
204 (integer :tag "Tab width") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
205 (boolean :tag "Indent-tabs-mode")))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
206 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
207 (defvar antlr-indent-item-regexp |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
208 "[]}):;|&]\\|default[ \t]*:\\|case[ \t]+\\('\\\\?.'\\|[0-9]+\\|[A-Za-z_][A-Za-z_0-9]*\\)[ \t]*:" ; & is local ANTLR extension |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
209 "Regexp matching lines which should be indented by one TAB less. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
210 See command \\[antlr-indent-command].") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
211 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
212 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
213 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
214 ;;; Menu |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
215 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
216 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
217 (defcustom antlr-imenu-name t |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
218 "*Non-nil, if a \"Index\" menu should be added to the menubar. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
219 If it is a string, it is used instead \"Index\". Requires package |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
220 imenu." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
221 :group 'antlr |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
222 :type '(choice (const :tag "No menu" nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
223 (const :tag "Index menu" t) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
224 (string :tag "Other menu name"))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
225 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
226 (defvar antlr-mode-map |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
227 (let ((map (make-sparse-keymap))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
228 (define-key map "\t" 'antlr-indent-command) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
229 (define-key map "\e\C-a" 'antlr-beginning-of-rule) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
230 (define-key map "\e\C-e" 'antlr-end-of-rule) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
231 (define-key map "\C-c\C-a" 'antlr-beginning-of-body) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
232 (define-key map "\C-c\C-e" 'antlr-end-of-body) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
233 (define-key map "\C-c\C-f" 'c-forward-into-nomenclature) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
234 (define-key map "\C-c\C-b" 'c-backward-into-nomenclature) |
26965 | 235 (define-key map "\C-c\C-c" 'comment-region) |
29289
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
236 (define-key map "\C-c\C-v" 'antlr-hide-actions) |
26542
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
237 ;; I'm too lazy to define my own: |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
238 (define-key map "\ea" 'c-beginning-of-statement) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
239 (define-key map "\ee" 'c-end-of-statement) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
240 map) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
241 "Keymap used in `antlr-mode' buffers.") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
242 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
243 (easy-menu-define antlr-mode-menu |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
244 antlr-mode-map |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
245 "Major mode menu." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
246 '("Antlr" |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
247 ["Indent Line" antlr-indent-command |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
248 :active (not buffer-read-only)] |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
249 ["Indent for Comment" indent-for-comment |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
250 :active (not buffer-read-only)] |
26965 | 251 ["Comment Out Region" comment-region |
252 :active (and (not buffer-read-only) | |
253 (c-region-is-active-p))] | |
254 ["Uncomment Region" | |
255 (comment-region (region-beginning) (region-end) '(4)) | |
256 :active (and (not buffer-read-only) | |
257 (c-region-is-active-p))] | |
258 "---" | |
26542
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
259 ["Backward Rule" antlr-beginning-of-rule t] |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
260 ["Forward Rule" antlr-end-of-rule t] |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
261 ["Start of Rule Body" antlr-beginning-of-body |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
262 :active (antlr-inside-rule-p)] |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
263 ["End of Rule Body" antlr-end-of-body |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
264 :active (antlr-inside-rule-p)] |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
265 "---" |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
266 ["Backward Statement" c-beginning-of-statement t] |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
267 ["Forward Statement" c-end-of-statement t] |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
268 ["Backward Into Nomencl." c-backward-into-nomenclature t] |
29289
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
269 ["Forward Into Nomencl." c-forward-into-nomenclature t] |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
270 "---" |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
271 ["Hide Actions (incl. Args)" antlr-hide-actions t] |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
272 ["Hide Actions (excl. Args)" (antlr-hide-actions 2) t] |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
273 ["Unhide All Actions" (antlr-hide-actions 0) t])) |
26542
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
274 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
275 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
276 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
277 ;;; font-lock |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
278 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
279 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
280 (defcustom antlr-font-lock-maximum-decoration 'inherit |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
281 "*The maximum decoration level for fontifying actions. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
282 Value `none' means, do not fontify actions, just normal grammar code |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
283 according to `antlr-font-lock-additional-keywords'. Value `inherit' |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
284 means, use value of `font-lock-maximum-decoration'. Any other value is |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
285 interpreted as in `font-lock-maximum-decoration' with no level-0 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
286 fontification, see `antlr-font-lock-keywords-alist'. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
287 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
288 While calculating the decoration level for actions, `major-mode' is |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
289 bound to `antlr-language'. For example, with value |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
290 ((java-mode . 2) (c++-mode . 0)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
291 Java actions are fontified with level 2 and C++ actions are not |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
292 fontified at all." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
293 :type '(choice (const :tag "none" none) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
294 (const :tag "inherit" inherit) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
295 (const :tag "default" nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
296 (const :tag "maximum" t) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
297 (integer :tag "level" 1) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
298 (repeat :menu-tag "mode specific" :tag "mode specific" |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
299 :value ((t . t)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
300 (cons :tag "Instance" |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
301 (radio :tag "Mode" |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
302 (const :tag "all" t) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
303 (symbol :tag "name")) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
304 (radio :tag "Decoration" |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
305 (const :tag "default" nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
306 (const :tag "maximum" t) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
307 (integer :tag "level" 1)))))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
308 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
309 (defvar antlr-font-lock-keywords-alist |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
310 '((java-mode |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
311 (list) ; nil won't work (would use level-3) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
312 java-font-lock-keywords-1 java-font-lock-keywords-2 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
313 java-font-lock-keywords-3) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
314 (c++-mode |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
315 (list) ; nil won't work (would use level-3) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
316 c++-font-lock-keywords-1 c++-font-lock-keywords-2 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
317 c++-font-lock-keywords-3)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
318 "List of font-lock keywords for actions in the grammar. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
319 Each element in this list looks like |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
320 (MAJOR-MODE KEYWORD...) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
321 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
322 If `antlr-language' is equal to MAJOR-MODE, the KEYWORDs are the |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
323 font-lock keywords according to `font-lock-defaults' used for the code |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
324 in the grammar's actions and semantic predicates, see |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
325 `antlr-font-lock-maximum-decoration'.") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
326 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
327 (defvar antlr-font-lock-keyword-face 'antlr-font-lock-keyword-face) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
328 (defface antlr-font-lock-keyword-face |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
329 '((((class color) (background light)) (:foreground "black" :bold t))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
330 "ANTLR keywords." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
331 :group 'antlr) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
332 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
333 (defvar antlr-font-lock-ruledef-face 'antlr-font-lock-ruledef-face) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
334 (defface antlr-font-lock-ruledef-face |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
335 '((((class color) (background light)) (:foreground "blue" :bold t))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
336 "ANTLR rule references (definition)." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
337 :group 'antlr) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
338 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
339 (defvar antlr-font-lock-tokendef-face 'antlr-font-lock-tokendef-face) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
340 (defface antlr-font-lock-tokendef-face |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
341 '((((class color) (background light)) (:foreground "brown3" :bold t))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
342 "ANTLR token references (definition)." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
343 :group 'antlr) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
344 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
345 (defvar antlr-font-lock-ruleref-face 'antlr-font-lock-ruleref-face) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
346 (defface antlr-font-lock-ruleref-face |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
347 '((((class color) (background light)) (:foreground "blue4"))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
348 "ANTLR rule references (usage)." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
349 :group 'antlr) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
350 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
351 (defvar antlr-font-lock-tokenref-face 'antlr-font-lock-tokenref-face) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
352 (defface antlr-font-lock-tokenref-face |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
353 '((((class color) (background light)) (:foreground "brown4"))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
354 "ANTLR token references (usage)." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
355 :group 'antlr) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
356 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
357 (defvar antlr-font-lock-literal-face 'antlr-font-lock-literal-face) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
358 (defface antlr-font-lock-literal-face |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
359 '((((class color) (background light)) (:foreground "brown4" :bold t))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
360 "ANTLR literal tokens consisting merely of letter-like characters." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
361 :group 'antlr) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
362 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
363 (defvar antlr-font-lock-additional-keywords |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
364 `((antlr-invalidate-context-cache) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
365 ("\\$setType[ \t]*(\\([A-Z\300-\326\330-\337]\\sw*\\))" |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
366 (1 antlr-font-lock-tokendef-face)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
367 ("\\$\\sw+" (0 font-lock-keyword-face)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
368 ;; the tokens are already fontified as string/docstrings: |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
369 (,(lambda (limit) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
370 (antlr-re-search-forward "\"\\(\\sw\\(\\sw\\|-\\)*\\)\"" limit)) |
29289
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
371 (1 antlr-font-lock-literal-face t) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
372 ,@(and (string-match "XEmacs" emacs-version) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
373 '((0 nil)))) ; XEmacs bug workaround |
26542
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
374 (,(lambda (limit) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
375 (antlr-re-search-forward |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
376 "^\\(class\\)[ \t]+\\([A-Z\300-\326\330-\337]\\sw*\\)[ \t]+\\(extends\\)[ \t]+\\([A-Z\300-\326\330-\337]\\sw*\\)[ \t]*;" limit)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
377 (1 antlr-font-lock-keyword-face) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
378 (2 antlr-font-lock-ruledef-face) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
379 (3 antlr-font-lock-keyword-face) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
380 (4 (if (member (match-string 4) '("Lexer" "Parser" "TreeParser")) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
381 'antlr-font-lock-keyword-face |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
382 'font-lock-type-face))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
383 (,(lambda (limit) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
384 (antlr-re-search-forward |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
385 "\\<\\(header\\|options\\|tokens\\|exception\\|catch\\|returns\\)\\>" |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
386 limit)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
387 (1 antlr-font-lock-keyword-face)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
388 (,(lambda (limit) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
389 (antlr-re-search-forward |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
390 "^\\(private\\|public\\|protected\\)\\>\\([ \t]+\\(\\sw+\\)\\)?" |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
391 limit)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
392 (1 font-lock-type-face) ; not XEmacs' java level-3 fruit salad |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
393 (3 (if (antlr-upcase-p (char-after (match-beginning 3))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
394 'antlr-font-lock-tokendef-face |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
395 'antlr-font-lock-ruledef-face) nil t)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
396 (,(lambda (limit) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
397 (antlr-re-search-forward "^\\sw+" limit)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
398 (0 (if (antlr-upcase-p (char-after (match-beginning 0))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
399 'antlr-font-lock-tokendef-face |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
400 'antlr-font-lock-ruledef-face) nil t)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
401 (,(lambda (limit) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
402 ;; not only before a rule ref, also before a literal |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
403 (antlr-re-search-forward "\\<\\(\\sw+\\)[ \t]*:" limit)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
404 (1 font-lock-variable-name-face)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
405 (,(lambda (limit) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
406 (antlr-re-search-forward "\\<\\(\\sw+[ \t]*=[ \t]*\\)?\\(\\sw+[ \t]*:[ \t]*\\)?\\(\\sw+\\)" limit)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
407 ;;(1 antlr-font-lock-default-face nil t) ; fool java-font-lock-keywords |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
408 (3 (if (antlr-upcase-p (char-after (match-beginning 3))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
409 'antlr-font-lock-tokenref-face |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
410 'antlr-font-lock-ruleref-face)))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
411 "Font-lock keywords for ANTLR's normal grammar code. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
412 See `antlr-font-lock-keywords-alist' for the keywords of actions.") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
413 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
414 (defvar antlr-font-lock-defaults |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
415 '(antlr-font-lock-keywords |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
416 nil nil ((?_ . "w") (?\( . ".") (?\) . ".")) beginning-of-defun) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
417 "Font-lock defaults used for ANTLR syntax coloring. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
418 The SYNTAX-ALIST element is also used to initialize |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
419 `antlr-action-syntax-table'.") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
420 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
421 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
422 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
423 ;;; Internal variables |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
424 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
425 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
426 (defvar antlr-mode-hook nil |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
427 "Hook called by `antlr-mode'.") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
428 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
429 ;; used for "in Java/C++ code" = syntactic-depth>0 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
430 (defvar antlr-action-syntax-table nil |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
431 "Syntax table used for ANTLR action parsing. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
432 Initialized by `java-mode-syntax-table', i.e., the syntax table used for |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
433 grammar files, changed by SYNTAX-ALIST in `antlr-font-lock-defaults'. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
434 This table should be selected if you use `buffer-syntactic-context' and |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
435 `buffer-syntactic-context-depth' in order not to confuse their |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
436 context_cache.") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
437 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
438 (defvar antlr-mode-abbrev-table nil |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
439 "Abbreviation table used in `antlr-mode' buffers.") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
440 (define-abbrev-table 'antlr-mode-abbrev-table ()) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
441 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
442 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
443 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
444 ;;;;########################################################################## |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
445 ;;;; The Code |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
446 ;;;;########################################################################## |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
447 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
448 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
449 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
450 ;;; Syntax functions -- Emacs vs XEmacs dependent |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
451 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
452 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
453 ;; From help.el (XEmacs-21.1) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
454 (defmacro antlr-with-syntax-table (syntab &rest body) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
455 `(let ((stab (syntax-table))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
456 (unwind-protect |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
457 (progn (set-syntax-table (copy-syntax-table ,syntab)) ,@body) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
458 (set-syntax-table stab)))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
459 (put 'antlr-with-syntax-table 'lisp-indent-function 1) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
460 (put 'antlr-with-syntax-table 'edebug-form-spec '(form body)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
461 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
462 (defun antlr-scan-sexps-internal (from count &optional dummy no-error) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
463 ;; checkdoc-params: (from count dummy) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
464 "Like `scan-sexps' but with additional arguments. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
465 When optional arg NO-ERROR is non-nil, `scan-sexps' will return nil |
26965 | 466 instead of signaling an error." |
26542
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
467 (if no-error |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
468 (condition-case nil |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
469 (scan-sexps from count) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
470 (t nil)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
471 (scan-sexps from count))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
472 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
473 (defun antlr-xemacs-bug-workaround (&rest dummies) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
474 ;; checkdoc-params: (dummies) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
475 "Invalidate context_cache for syntactical context information." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
476 ;; XEmacs bug workaround |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
477 (save-excursion |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
478 (set-buffer (get-buffer-create " ANTLR XEmacs bug workaround")) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
479 (buffer-syntactic-context-depth)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
480 nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
481 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
482 (defun antlr-fast-syntactic-context () |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
483 "Return some syntactic context information. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
484 Return `string' if point is within a string, `block-comment' or |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
485 `comment' is point is within a comment or the depth within all |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
486 parenthesis-syntax delimiters at point otherwise. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
487 WARNING: this may alter `match-data'." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
488 (or (buffer-syntactic-context) (buffer-syntactic-context-depth))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
489 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
490 (defun antlr-slow-syntactic-context () |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
491 "Return some syntactic context information. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
492 Return `string' if point is within a string, `block-comment' or |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
493 `comment' is point is within a comment or the depth within all |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
494 parenthesis-syntax delimiters at point otherwise. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
495 WARNING: this may alter `match-data'." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
496 (let ((orig (point))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
497 (beginning-of-defun) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
498 (let ((state (parse-partial-sexp (point) orig))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
499 (goto-char orig) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
500 (cond ((nth 3 state) 'string) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
501 ((nth 4 state) 'comment) ; block-comment? -- we don't care |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
502 (t (car state)))))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
503 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
504 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
505 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
506 ;;; Misc functions |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
507 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
508 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
509 (defun antlr-upcase-p (char) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
510 "Non-nil, if CHAR is an uppercase character (if CHAR was a char)." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
511 ;; in XEmacs, upcase only works for ASCII |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
512 (or (and (<= ?A char) (<= char ?Z)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
513 (and (<= ?\300 char) (<= char ?\337)))) ; ?\327 is no letter |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
514 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
515 (defun antlr-re-search-forward (regexp bound) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
516 "Search forward from point for regular expression REGEXP. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
517 Set point to the end of the occurrence found, and return point. Return |
26965 | 518 nil if no occurrence was found. Do not search within comments, strings |
26542
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
519 and actions/semantic predicates. BOUND bounds the search; it is a |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
520 buffer position. See also the functions `match-beginning', `match-end' |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
521 and `replace-match'." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
522 ;; WARNING: Should only be used with `antlr-action-syntax-table'! |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
523 (let ((continue t)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
524 (while (and (re-search-forward regexp bound 'limit) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
525 (save-match-data |
29289
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
526 (if (eq (antlr-syntactic-context) 0) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
527 (setq continue nil) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
528 t)))) |
26542
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
529 (if continue nil (point)))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
530 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
531 (defun antlr-search-forward (string) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
532 "Search forward from point for STRING. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
533 Set point to the end of the occurrence found, and return point. Return |
26965 | 534 nil if no occurrence was found. Do not search within comments, strings |
26542
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
535 and actions/semantic predicates." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
536 ;; WARNING: Should only be used with `antlr-action-syntax-table'! |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
537 (let ((continue t)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
538 (while (and (search-forward string nil 'limit) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
539 (if (eq (antlr-syntactic-context) 0) (setq continue nil) t))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
540 (if continue nil (point)))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
541 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
542 (defun antlr-search-backward (string) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
543 "Search backward from point for STRING. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
544 Set point to the beginning of the occurrence found, and return point. |
26965 | 545 Return nil if no occurrence was found. Do not search within comments, |
26542
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
546 strings and actions/semantic predicates." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
547 ;; WARNING: Should only be used with `antlr-action-syntax-table'! |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
548 (let ((continue t)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
549 (while (and (search-backward string nil 'limit) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
550 (if (eq (antlr-syntactic-context) 0) (setq continue nil) t))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
551 (if continue nil (point)))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
552 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
553 (defsubst antlr-skip-sexps (count) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
554 "Skip the next COUNT balanced expressions and the comments after it. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
555 Return position before the comments after the last expression." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
556 (goto-char (or (antlr-scan-sexps (point) count nil t) (point-max))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
557 (prog1 (point) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
558 (c-forward-syntactic-ws))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
559 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
560 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
561 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
562 ;;; font-lock |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
563 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
564 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
565 (defun antlr-font-lock-keywords () |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
566 "Return font-lock keywords for current buffer. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
567 See `antlr-font-lock-additional-keywords', `antlr-language' and |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
568 `antlr-font-lock-maximum-decoration'." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
569 (if (eq antlr-font-lock-maximum-decoration 'none) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
570 antlr-font-lock-additional-keywords |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
571 (append antlr-font-lock-additional-keywords |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
572 (eval (let ((major-mode antlr-language)) ; dynamic |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
573 (font-lock-choose-keywords |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
574 (cdr (assq antlr-language |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
575 antlr-font-lock-keywords-alist)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
576 (if (eq antlr-font-lock-maximum-decoration 'inherit) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
577 font-lock-maximum-decoration |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
578 antlr-font-lock-maximum-decoration))))))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
579 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
580 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
581 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
582 ;;; imenu support |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
583 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
584 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
585 (defun antlr-imenu-create-index-function () |
26965 | 586 "Return imenu index-alist for ANTLR grammar files." |
26542
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
587 (let ((items nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
588 (lexer nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
589 (parser nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
590 (treeparser nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
591 (misc nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
592 (classes nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
593 (semi (point-max))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
594 ;; Using `imenu-progress-message' would require imenu for compilation -- |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
595 ;; nobody is missing these messages... |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
596 (antlr-with-syntax-table antlr-action-syntax-table |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
597 ;; We stick to the imenu standard and search backwards, although I don't |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
598 ;; think this is right. It is slower and more likely not to work during |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
599 ;; editing (you are more likely to add functions to the end of the file). |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
600 (while semi |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
601 (goto-char semi) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
602 (if (setq semi (antlr-search-backward ";")) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
603 (progn (forward-char) (antlr-skip-exception-part t)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
604 (antlr-skip-file-prelude t)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
605 (if (looking-at "{") (antlr-skip-sexps 1)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
606 (if (looking-at "class[ \t]+\\([A-Z\300-\326\330-\337]\\sw*\\)[ \t]+extends[ \t]+\\([A-Z\300-\326\330-\337]\\sw*\\)[ \t]*;") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
607 (progn |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
608 (push (cons (match-string 1) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
609 (if imenu-use-markers |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
610 (copy-marker (match-beginning 1)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
611 (match-beginning 1))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
612 classes) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
613 (if items |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
614 (let ((super (match-string 2))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
615 (cond ((string-equal super "Parser") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
616 (setq parser (nconc items parser))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
617 ((string-equal super "Lexer") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
618 (setq lexer (nconc items lexer))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
619 ((string-equal super "TreeParser") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
620 (setq treeparser (nconc items treeparser))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
621 (t |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
622 (setq misc (nconc items misc)))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
623 (setq items nil)))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
624 (if (looking-at "p\\(ublic\\|rotected\\|rivate\\)") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
625 (antlr-skip-sexps 1)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
626 (when (looking-at "\\sw+") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
627 (push (cons (match-string 0) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
628 (if imenu-use-markers |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
629 (copy-marker (match-beginning 0)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
630 (match-beginning 0))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
631 items))))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
632 (or items ; outside any class |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
633 (prog1 (setq items misc) (setq misc nil)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
634 (prog1 (setq items parser) (setq parser nil)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
635 (prog1 (setq items lexer) (setq lexer nil)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
636 (prog1 (setq items treeparser) (setq treeparser nil))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
637 (if misc (push (cons "Miscellaneous" misc) items)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
638 (if treeparser (push (cons "TreeParser" treeparser) items)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
639 (if lexer (push (cons "Lexer" lexer) items)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
640 (if parser (push (cons "Parser" parser) items)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
641 (if classes (cons (cons "Classes" classes) items) items))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
642 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
643 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
644 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
645 ;;; Parse grammar files (internal functions) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
646 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
647 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
648 (defun antlr-skip-exception-part (skip-comment) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
649 "Skip exception part of current rule, i.e., everything after `;'. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
650 This also includes the options and tokens part of a grammar class |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
651 header. If SKIP-COMMENT is non-nil, also skip the comment after that |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
652 part." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
653 (let ((pos (point)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
654 (class nil)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
655 (c-forward-syntactic-ws) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
656 (while (looking-at "options\\>\\|tokens\\>") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
657 (setq class t) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
658 (setq pos (antlr-skip-sexps 2))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
659 (if class |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
660 ;; Problem: an action only belongs to a class def, not a normal rule. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
661 ;; But checking the current rule type is too expensive => only expect |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
662 ;; an action if we have found an option or tokens part. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
663 (if (looking-at "{") (setq pos (antlr-skip-sexps 1))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
664 (while (looking-at "exception\\>") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
665 (setq pos (antlr-skip-sexps 1)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
666 (if (looking-at "\\[") (setq pos (antlr-skip-sexps 1))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
667 (while (looking-at "catch\\>") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
668 (setq pos (antlr-skip-sexps 3))))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
669 (or skip-comment (goto-char pos)))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
670 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
671 (defun antlr-skip-file-prelude (skip-comment) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
672 "Skip the file prelude: the header and file options. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
673 If SKIP-COMMENT is non-nil, also skip the comment after that part." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
674 (let* ((pos (point)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
675 (pos0 pos)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
676 (c-forward-syntactic-ws) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
677 (if skip-comment (setq pos0 (point))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
678 (if (looking-at "header\\>") (setq pos (antlr-skip-sexps 2))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
679 (if (looking-at "options\\>") (setq pos (antlr-skip-sexps 2))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
680 (or skip-comment (goto-char pos)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
681 pos0)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
682 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
683 (defun antlr-next-rule (arg skip-comment) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
684 "Move forward to next end of rule. Do it ARG many times. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
685 A grammar class header and the file prelude are also considered as a |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
686 rule. Negative argument ARG means move back to ARGth preceding end of |
26965 | 687 rule. The behavior is not defined when ARG is zero. If SKIP-COMMENT |
26542
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
688 is non-nil, move to beginning of the rule." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
689 ;; WARNING: Should only be used with `antlr-action-syntax-table'! |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
690 ;; PRE: ARG<>0 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
691 (let ((pos (point)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
692 (beg (point))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
693 ;; first look whether point is in exception part |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
694 (if (antlr-search-backward ";") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
695 (progn |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
696 (setq beg (point)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
697 (forward-char) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
698 (antlr-skip-exception-part skip-comment)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
699 (antlr-skip-file-prelude skip-comment)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
700 (if (< arg 0) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
701 (unless (and (< (point) pos) (zerop (incf arg))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
702 ;; if we have moved backward, we already moved one defun backward |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
703 (goto-char beg) ; rewind (to ";" / point) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
704 (while (and arg (<= (incf arg) 0)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
705 (if (antlr-search-backward ";") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
706 (setq beg (point)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
707 (when (>= arg -1) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
708 ;; try file prelude: |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
709 (setq pos (antlr-skip-file-prelude skip-comment)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
710 (if (zerop arg) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
711 (if (>= (point) beg) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
712 (goto-char (if (>= pos beg) (point-min) pos))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
713 (goto-char (if (or (>= (point) beg) (= (point) pos)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
714 (point-min) pos)))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
715 (setq arg nil))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
716 (when arg ; always found a ";" |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
717 (forward-char) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
718 (antlr-skip-exception-part skip-comment))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
719 (if (<= (point) pos) ; moved backward? |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
720 (goto-char pos) ; rewind |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
721 (decf arg)) ; already moved one defun forward |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
722 (unless (zerop arg) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
723 (while (>= (decf arg) 0) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
724 (antlr-search-forward ";")) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
725 (antlr-skip-exception-part skip-comment))))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
726 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
727 (defun antlr-outside-rule-p () |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
728 "Non-nil if point is outside a grammar rule. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
729 Move to the beginning of the current rule if point is inside a rule." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
730 ;; WARNING: Should only be used with `antlr-action-syntax-table'! |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
731 (let ((pos (point))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
732 (antlr-next-rule -1 nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
733 (let ((between (or (bobp) (< (point) pos)))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
734 (c-forward-syntactic-ws) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
735 (and between (> (point) pos) (goto-char pos))))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
736 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
737 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
738 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
739 ;;; Parse grammar files (commands) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
740 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
741 ;; No (interactive "_") in Emacs... use `zmacs-region-stays'. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
742 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
743 (defun antlr-inside-rule-p () |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
744 "Non-nil if point is inside a grammar rule. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
745 A grammar class header and the file prelude are also considered as a |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
746 rule." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
747 (save-excursion |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
748 (antlr-with-syntax-table antlr-action-syntax-table |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
749 (not (antlr-outside-rule-p))))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
750 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
751 (defun antlr-end-of-rule (&optional arg) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
752 "Move forward to next end of rule. Do it ARG [default: 1] many times. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
753 A grammar class header and the file prelude are also considered as a |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
754 rule. Negative argument ARG means move back to ARGth preceding end of |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
755 rule. If ARG is zero, run `antlr-end-of-body'." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
756 (interactive "p") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
757 (if (zerop arg) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
758 (antlr-end-of-body) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
759 (antlr-with-syntax-table antlr-action-syntax-table |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
760 (antlr-next-rule arg nil)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
761 (setq zmacs-region-stays t))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
762 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
763 (defun antlr-beginning-of-rule (&optional arg) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
764 "Move backward to preceding beginning of rule. Do it ARG many times. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
765 A grammar class header and the file prelude are also considered as a |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
766 rule. Negative argument ARG means move forward to ARGth next beginning |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
767 of rule. If ARG is zero, run `antlr-beginning-of-body'." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
768 (interactive "p") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
769 (if (zerop arg) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
770 (antlr-beginning-of-body) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
771 (antlr-with-syntax-table antlr-action-syntax-table |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
772 (antlr-next-rule (- arg) t)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
773 (setq zmacs-region-stays t))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
774 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
775 (defun antlr-end-of-body (&optional msg) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
776 "Move to position after the `;' of the current rule. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
777 A grammar class header is also considered as a rule. With optional |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
778 prefix arg MSG, move to `:'." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
779 (interactive) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
780 (antlr-with-syntax-table antlr-action-syntax-table |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
781 (let ((orig (point))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
782 (if (antlr-outside-rule-p) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
783 (error "Outside an ANTLR rule")) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
784 (let ((bor (point))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
785 (when (< (antlr-skip-file-prelude t) (point)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
786 ;; Yes, we are in the file prelude |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
787 (goto-char orig) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
788 (error (or msg "The file prelude is without `;'"))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
789 (antlr-search-forward ";") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
790 (when msg |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
791 (when (< (point) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
792 (progn (goto-char bor) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
793 (or (antlr-search-forward ":") (point-max)))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
794 (goto-char orig) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
795 (error msg)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
796 (c-forward-syntactic-ws))))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
797 (setq zmacs-region-stays t)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
798 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
799 (defun antlr-beginning-of-body () |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
800 "Move to the first element after the `:' of the current rule." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
801 (interactive) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
802 (antlr-end-of-body "Class headers and the file prelude are without `:'")) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
803 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
804 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
805 ;;;=========================================================================== |
29289
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
806 ;;; Literal normalization, Hide Actions |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
807 ;;;=========================================================================== |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
808 |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
809 (defun antlr-downcase-literals (&optional transform) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
810 "Convert all literals in buffer to lower case. |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
811 If non-nil, TRANSFORM is used on literals instead of `downcase-region'." |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
812 (interactive) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
813 (or transform (setq transform 'downcase-region)) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
814 (let ((literals 0)) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
815 (save-excursion |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
816 (goto-char (point-min)) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
817 (antlr-with-syntax-table antlr-action-syntax-table |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
818 (antlr-invalidate-context-cache) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
819 (while (antlr-re-search-forward "\"\\(\\sw\\(\\sw\\|-\\)*\\)\"" nil) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
820 (funcall transform (match-beginning 0) (match-end 0)) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
821 (incf literals)))) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
822 (message "Transformed %d literals" literals))) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
823 |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
824 (defun antlr-upcase-literals () |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
825 "Convert all literals in buffer to upper case." |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
826 (interactive) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
827 (antlr-downcase-literals 'upcase-region)) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
828 |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
829 (defun antlr-hide-actions (arg &optional silent) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
830 "Hide or unhide all actions in buffer. |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
831 Hide all actions including arguments in brackets if ARG is 1 or if |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
832 called interactively without prefix argument. Hide all actions |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
833 excluding arguments in brackets if ARG is 2 or higher. Unhide all |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
834 actions if ARG is 0 or negative. Never hide actions whose character |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
835 length is shorter or equal to `antlr-tiny-action-length'." |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
836 (interactive "p") |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
837 ;; from Emacs/lazy-lock: `save-buffer-state' |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
838 (let ((modified (buffer-modified-p)) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
839 (buffer-undo-list t) (inhibit-read-only t) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
840 (inhibit-point-motion-hooks t) deactivate-mark ; Emacs only |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
841 before-change-functions after-change-functions |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
842 buffer-file-name buffer-file-truename) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
843 (if (> arg 0) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
844 (let ((regexp (if (= arg 1) "[]}]" "}")) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
845 (diff (+ (max antlr-tiny-action-length 0) 2))) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
846 (antlr-hide-actions 0 t) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
847 (save-excursion |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
848 (goto-char (point-min)) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
849 (antlr-with-syntax-table antlr-action-syntax-table |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
850 (antlr-invalidate-context-cache) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
851 (while (antlr-re-search-forward regexp nil) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
852 (let* ((end (point)) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
853 (beg (antlr-scan-sexps (point) -1 nil t))) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
854 (and beg (> end (+ beg diff)) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
855 (add-text-properties (1+ beg) (1- end) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
856 '(invisible t intangible t))))))) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
857 (or silent |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
858 (message "Hide all actions (%s arguments)...done" |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
859 (if (= arg 1) "including" "excluding")))) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
860 (remove-text-properties (point-min) (point-max) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
861 '(invisible nil intangible nil)) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
862 (or silent |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
863 (message "Unhide all actions (including arguments)...done"))) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
864 (and (not modified) (buffer-modified-p) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
865 (set-buffer-modified-p nil)))) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
866 |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
867 |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
868 ;;;=========================================================================== |
26542
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
869 ;;; Indentation |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
870 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
871 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
872 (defun antlr-indent-line () |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
873 "Indent the current line as ANTLR grammar code. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
874 The indentation of non-comment lines are calculated by `c-basic-offset', |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
875 multiplied by: |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
876 - the level of the paren/brace/bracket depth, |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
877 - plus 0/2/1, depending on the position inside the rule: header, body, |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
878 exception part, |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
879 - minus 1 if `antlr-indent-item-regexp' matches the beginning of the |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
880 line starting from the first non-blank. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
881 |
26965 | 882 Lines inside block comments are not changed or indented by |
26542
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
883 `c-indent-line', see `antlr-indent-comment'." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
884 (let ((orig (point)) bol boi indent syntax) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
885 (beginning-of-line) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
886 (setq bol (point)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
887 (skip-chars-forward " \t") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
888 (setq boi (point)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
889 ;; check syntax at beginning of indentation ------------------------------ |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
890 (antlr-with-syntax-table antlr-action-syntax-table |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
891 (antlr-invalidate-context-cache) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
892 (cond ((symbolp (setq syntax (antlr-syntactic-context))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
893 (setq indent nil)) ; block-comments, strings, (comments) |
29289
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
894 ((eq (char-after) ?#) ; cpp directive |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
895 (setq syntax 'cpp) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
896 (setq indent 0)) ; indentation at 0 |
26542
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
897 ((progn |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
898 (antlr-next-rule -1 t) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
899 (if (antlr-search-forward ":") (< boi (1- (point))) t)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
900 (setq indent 0)) ; in rule header |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
901 ((if (antlr-search-forward ";") (< boi (point)) t) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
902 (setq indent 2)) ; in rule body |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
903 (t |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
904 (forward-char) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
905 (antlr-skip-exception-part nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
906 (setq indent (if (> (point) boi) 1 0))))) ; in exception part? |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
907 ;; compute the corresponding indentation and indent ---------------------- |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
908 (if (null indent) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
909 (progn |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
910 (goto-char orig) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
911 (and (eq antlr-indent-comment t) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
912 (not (eq syntax 'string)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
913 (c-indent-line))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
914 ;; do it ourselves |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
915 (goto-char boi) |
29289
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
916 (unless (symbolp syntax) ; direct indentation |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
917 (antlr-invalidate-context-cache) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
918 (incf indent (antlr-syntactic-context)) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
919 (and (> indent 0) (looking-at antlr-indent-item-regexp) (decf indent)) |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
920 (setq indent (* indent c-basic-offset))) |
26542
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
921 ;; the usual major-mode indent stuff: |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
922 (setq orig (- (point-max) orig)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
923 (unless (= (current-column) indent) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
924 (delete-region bol boi) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
925 (beginning-of-line) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
926 (indent-to indent)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
927 ;; If initial point was within line's indentation, |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
928 ;; position after the indentation. Else stay at same point in text. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
929 (if (> (- (point-max) orig) (point)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
930 (goto-char (- (point-max) orig)))))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
931 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
932 (defun antlr-indent-command (&optional arg) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
933 "Indent the current line or insert tabs/spaces. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
934 With optional prefix argument ARG or if the previous command was this |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
935 command, insert ARG tabs or spaces according to `indent-tabs-mode'. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
936 Otherwise, indent the current line with `antlr-indent-line'." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
937 (interactive "P") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
938 (if (or arg (eq last-command 'antlr-indent-command)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
939 (insert-tab arg) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
940 (let ((antlr-indent-comment (and antlr-indent-comment t))) ; dynamic |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
941 (antlr-indent-line)))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
942 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
943 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
944 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
945 ;;; Mode entry |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
946 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
947 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
948 (defun antlr-c-common-init () |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
949 "Like `c-common-init' except menu, auto-hungry and c-style stuff." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
950 ;; X/Emacs 20 only |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
951 (make-local-variable 'paragraph-start) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
952 (make-local-variable 'paragraph-separate) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
953 (make-local-variable 'paragraph-ignore-fill-prefix) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
954 (make-local-variable 'require-final-newline) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
955 (make-local-variable 'parse-sexp-ignore-comments) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
956 (make-local-variable 'indent-line-function) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
957 (make-local-variable 'indent-region-function) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
958 (make-local-variable 'comment-start) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
959 (make-local-variable 'comment-end) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
960 (make-local-variable 'comment-column) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
961 (make-local-variable 'comment-start-skip) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
962 (make-local-variable 'comment-multi-line) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
963 (make-local-variable 'outline-regexp) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
964 (make-local-variable 'outline-level) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
965 (make-local-variable 'adaptive-fill-regexp) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
966 (make-local-variable 'adaptive-fill-mode) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
967 (make-local-variable 'imenu-generic-expression) ;set in the mode functions |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
968 (and (boundp 'comment-line-break-function) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
969 (make-local-variable 'comment-line-break-function)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
970 ;; Emacs 19.30 and beyond only, AFAIK |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
971 (if (boundp 'fill-paragraph-function) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
972 (progn |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
973 (make-local-variable 'fill-paragraph-function) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
974 (setq fill-paragraph-function 'c-fill-paragraph))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
975 ;; now set their values |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
976 (setq paragraph-start (concat page-delimiter "\\|$") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
977 paragraph-separate paragraph-start |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
978 paragraph-ignore-fill-prefix t |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
979 require-final-newline t |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
980 parse-sexp-ignore-comments t |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
981 indent-line-function 'c-indent-line |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
982 indent-region-function 'c-indent-region |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
983 outline-regexp "[^#\n\^M]" |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
984 outline-level 'c-outline-level |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
985 comment-column 32 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
986 comment-start-skip "/\\*+ *\\|// *" |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
987 comment-multi-line nil |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
988 comment-line-break-function 'c-comment-line-break-function |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
989 adaptive-fill-regexp nil |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
990 adaptive-fill-mode nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
991 ;; we have to do something special for c-offsets-alist so that the |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
992 ;; buffer local value has its own alist structure. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
993 (setq c-offsets-alist (copy-alist c-offsets-alist)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
994 ;; setup the comment indent variable in a Emacs version portable way |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
995 ;; ignore any byte compiler warnings you might get here |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
996 (make-local-variable 'comment-indent-function) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
997 (setq comment-indent-function 'c-comment-indent)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
998 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
999 (defun antlr-language-for-option (option-value) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1000 "Find element in `antlr-language-alist' for OPTION-VALUE." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1001 ;; Like (find OPTION-VALUE antlr-language-alist :key 'cddr :test 'member) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1002 (let ((seq antlr-language-alist) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1003 r) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1004 (while seq |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1005 (setq r (pop seq)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1006 (if (member option-value (cddr r)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1007 (setq seq nil) ; stop |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1008 (setq r nil))) ; no result yet |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1009 r)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1010 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1011 ;;;###autoload |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1012 (defun antlr-mode () |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1013 "Major mode for editing ANTLR grammar files. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1014 \\{antlr-mode-map}" |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1015 (interactive) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1016 (c-initialize-cc-mode) ; for java syntax table |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1017 (kill-all-local-variables) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1018 ;; ANTLR specific ---------------------------------------------------------- |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1019 (setq major-mode 'antlr-mode |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1020 mode-name "Antlr") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1021 (setq local-abbrev-table antlr-mode-abbrev-table) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1022 (set-syntax-table java-mode-syntax-table) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1023 (unless antlr-action-syntax-table |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1024 (let ((slist (nth 3 antlr-font-lock-defaults))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1025 (setq antlr-action-syntax-table |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1026 (copy-syntax-table java-mode-syntax-table)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1027 (while slist |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1028 (modify-syntax-entry (caar slist) (cdar slist) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1029 antlr-action-syntax-table) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1030 (setq slist (cdr slist))))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1031 (use-local-map antlr-mode-map) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1032 (make-local-variable 'antlr-language) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1033 (unless antlr-language |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1034 (save-excursion |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1035 (goto-char (point-min)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1036 (setq antlr-language |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1037 (car (or (and (re-search-forward (cdr antlr-language-limit-n-regexp) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1038 (car antlr-language-limit-n-regexp) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1039 t) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1040 (antlr-language-for-option (match-string 1))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1041 (antlr-language-for-option nil)))))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1042 (if (stringp (cadr (assq antlr-language antlr-language-alist))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1043 (setq mode-name |
29289
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
1044 (concat "Antlr." |
26542
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1045 (cadr (assq antlr-language antlr-language-alist))))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1046 ;; indentation, for the C engine ------------------------------------------- |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1047 (antlr-c-common-init) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1048 (setq indent-line-function 'antlr-indent-line |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1049 indent-region-function nil) ; too lazy |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1050 (setq comment-start "// " |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1051 comment-end "") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1052 (c-set-style "java") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1053 (if (eq antlr-language 'c++-mode) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1054 (setq c-conditional-key c-C++-conditional-key |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1055 c-comment-start-regexp c-C++-comment-start-regexp |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1056 c-class-key c-C++-class-key |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1057 c-extra-toplevel-key c-C++-extra-toplevel-key |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1058 c-access-key c-C++-access-key |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1059 c-recognize-knr-p nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1060 (setq c-conditional-key c-Java-conditional-key |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1061 c-comment-start-regexp c-Java-comment-start-regexp |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1062 c-class-key c-Java-class-key |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1063 c-method-key nil |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1064 c-baseclass-key nil |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1065 c-recognize-knr-p nil |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1066 c-access-key c-Java-access-key) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1067 (and (boundp 'c-inexpr-class-key) (boundp 'c-Java-inexpr-class-key) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1068 (setq c-inexpr-class-key c-Java-inexpr-class-key))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1069 ;; various ----------------------------------------------------------------- |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1070 (make-local-variable 'font-lock-defaults) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1071 (setq font-lock-defaults antlr-font-lock-defaults) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1072 (easy-menu-add antlr-mode-menu) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1073 (make-local-variable 'imenu-create-index-function) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1074 (setq imenu-create-index-function 'antlr-imenu-create-index-function) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1075 (make-local-variable 'imenu-generic-expression) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1076 (setq imenu-generic-expression t) ; fool stupid test |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1077 (and antlr-imenu-name ; there should be a global variable... |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1078 (fboundp 'imenu-add-to-menubar) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1079 (imenu-add-to-menubar |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1080 (if (stringp antlr-imenu-name) antlr-imenu-name "Index"))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1081 (antlr-set-tabs) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1082 (run-hooks 'antlr-mode-hook)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1083 |
29289
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
1084 ;; In XEmacs, a smarter version of `buffers-menu-grouping-function' could use |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
1085 ;; the following property. The header of the submenu would be "Antlr" instead |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
1086 ;; of "Antlr/C++" or "Antlr/Java" (depending on the buffer ordering). |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
1087 (put 'antlr-mode 'mode-name "Antlr") |
9ad79f5782af
New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents:
26965
diff
changeset
|
1088 |
26542
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1089 ;;;###autoload |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1090 (defun antlr-set-tabs () |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1091 "Use ANTLR's convention for TABs according to `antlr-tab-offset-alist'. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1092 Used in `antlr-mode'. Also a useful function in `java-mode-hook'." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1093 (if buffer-file-name |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1094 (let ((alist antlr-tab-offset-alist) elem) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1095 (while alist |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1096 (setq elem (pop alist)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1097 (and (or (null (car elem)) (eq (car elem) major-mode)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1098 (or (null (cadr elem)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1099 (string-match (cadr elem) buffer-file-name)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1100 (setq tab-width (caddr elem) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1101 indent-tabs-mode (cadddr elem) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1102 alist nil)))))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1103 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1104 ;;; antlr-mode.el ends here |
26965 | 1105 |
1106 ; LocalWords: antlr ANother ANTLR's Cpp Lexer TreeParser esp refs VALUEs ea ee | |
1107 ; LocalWords: Java's Nomencl ruledef tokendef ruleref tokenref setType ader | |
1108 ; LocalWords: ivate syntab lexer treeparser lic rotected rivate bor boi AFAIK | |
1109 ; LocalWords: slist knr inexpr |