Mercurial > emacs
annotate lisp/progmodes/antlr-mode.el @ 26659:98c01a50be97
(speedbar-xemacs20p): Remove compatibility code for
Emacs versions without custom.el.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Tue, 30 Nov 1999 14:09:13 +0000 |
parents | 0d41332e3819 |
children | 048db40ddca6 |
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 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
3 ;; Copyright (C) 1999 Free Software Foundation, Inc. |
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 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
6 ;; Version: $Id: antlr-mode.el,v 1.2 1999/11/11 14:40:51 wedler Exp $ |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
7 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
8 ;; This file is part of GNU Emacs. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
9 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
10 ;; 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
|
11 ;; 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
|
12 ;; 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
|
13 ;; any later version. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
14 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
15 ;; 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
|
16 ;; 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
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
18 ;; GNU General Public License for more details. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
19 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
20 ;; 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
|
21 ;; 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
|
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
23 ;; Boston, MA 02111-1307, USA. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
24 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
25 ;;; Commentary: |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
26 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
27 ;; 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
|
28 ;; 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
|
29 ;; 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
|
30 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
31 ;; 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
|
32 ;; 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
|
33 ;; 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
|
34 ;; package uses features of the Emacs package cc-mode. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
35 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
36 ;; This package provides the following features: |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
37 ;; * Indentation for the current line (TAB) and selected region (C-M-\). |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
38 ;; * Syntax coloring (via font-lock) with language dependend coloring. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
39 ;; * Support for imenu/speedbar: menu "Index" (Parser, Lexer, TreeParser). |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
40 ;; * 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
|
41 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
42 ;; INDENTATION. This package supports ANTLR's (intended) indentation style |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
43 ;; 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
|
44 ;; `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
|
45 ;; 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
|
46 ;; 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
|
47 ;; 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
|
48 ;; `c-indentation-style' "java" which sets `c-basic-offset' to 4, see |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
49 ;; `antlr-tab-offset-alist'. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
50 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
51 ;; 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
|
52 ;; highlighted. Second, the grammar code is highlighted according to |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
53 ;; `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
|
54 ;; definition: ditto+bold). Third, actions, semantic predicates and arguments |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
55 ;; 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
|
56 ;; `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
|
57 ;; 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
|
58 ;; ANTLR keywords from Java/C++ keywords. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
59 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
60 ;;; Installation: |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
61 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
62 ;; 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
|
63 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
64 ;; 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
|
65 ;; load-path and the following into your ~/.emacs: |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
66 ;; (autoload 'antlr-mode "antlr-mode" nil t) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
67 ;; (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
|
68 ;; (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
|
69 ;; (lambda () (speedbar-add-supported-extension ".g"))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
70 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
71 ;; 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
|
72 ;; (autoload 'antlr-set-tabs "antlr-mode") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
73 ;; (add-hook 'java-mode-hook 'antlr-set-tabs) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
74 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
75 ;; 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
|
76 ;; (Emacs->Programming->Languages->Antlr). |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
77 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
78 ;;; Code: |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
79 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
80 (provide 'antlr-mode) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
81 (eval-when-compile (require 'cl)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
82 (require 'easymenu) ; Emacs |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
83 (eval-when-compile (require 'cc-mode)) ; shut up most warnings |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
84 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
85 (eval-and-compile |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
86 (if (string-match "XEmacs" emacs-version) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
87 (defalias 'antlr-scan-sexps 'scan-sexps) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
88 (defalias 'antlr-scan-sexps 'antlr-scan-sexps-internal)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
89 (if (and (fboundp 'buffer-syntactic-context) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
90 (fboundp 'buffer-syntactic-context-depth)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
91 (progn |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
92 (defalias 'antlr-invalidate-context-cache 'antlr-xemacs-bug-workaround) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
93 (defalias 'antlr-syntactic-context 'antlr-fast-syntactic-context)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
94 (defalias 'antlr-invalidate-context-cache 'ignore) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
95 (defalias 'antlr-syntactic-context 'antlr-slow-syntactic-context))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
96 |
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 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
99 ;;;;########################################################################## |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
100 ;;;; Variables |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
101 ;;;;########################################################################## |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
102 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
103 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
104 (defgroup antlr nil |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
105 "Major mode for ANTLR grammar files." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
106 :group 'languages |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
107 :link '(emacs-commentary-link "antlr-mode.el") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
108 :prefix "antlr-") |
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 (defconst antlr-version "1.2" |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
111 "ANTLR major mode version number.") |
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 |
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 ;;; Controlling ANTLR's code generator (language option) |
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 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
118 (defvar antlr-language nil |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
119 "Major mode corresponding to ANTLR's \"language\" option. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
120 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
|
121 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
|
122 variable list\" near the end of the file, see |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
123 `enable-local-variables'.") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
124 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
125 (defcustom antlr-language-alist |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
126 '((java-mode "Java" nil "Java") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
127 (c++-mode "C++" "Cpp")) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
128 "List of ANTLR's supported languages. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
129 Each element in this list looks like |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
130 (MAJOR-MODE MODELINE-STRING OPTION-VALUE...) |
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 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
|
133 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
|
134 `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
|
135 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
|
136 also displayed in the modeline next to \"Antlr\"." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
137 :group 'antlr |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
138 :type '(repeat (group :value (java-mode "") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
139 (function :tag "Major mode") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
140 (string :tag "Modeline string") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
141 (repeat :tag "ANTLR language option" :inline t |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
142 (choice (const :tag "Default" nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
143 string ))))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
144 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
145 (defcustom antlr-language-limit-n-regexp |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
146 '(3000 . "language[ \t]*=[ \t]*\"\\([A-Z][A-Za-z_]*\\)\"") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
147 "Used to set a reasonable value for `antlr-language'. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
148 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
|
149 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
|
150 `antlr-language-alist'." |
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 '(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
|
153 regexp)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
154 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
155 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
156 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
157 ;;; Indent/Tabs |
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 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
160 (defcustom antlr-indent-comment 'tab |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
161 "*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
|
162 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
|
163 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
|
164 they are only changed by \\[antlr-indent-command]." |
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 '(radio (const :tag "No" nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
167 (const :tag "Always" t) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
168 (sexp :tag "With TAB" :format "%t" :value tab))) |
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 (defcustom antlr-tab-offset-alist |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
171 '((antlr-mode nil 4 t) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
172 (java-mode "antlr" 4 t)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
173 "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
|
174 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
|
175 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
|
176 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
|
177 `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
|
178 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
|
179 :group 'antlr |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
180 :type '(repeat (group :value (antlr-mode nil 8 nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
181 (choice (const :tag "All" nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
182 (function :tag "Major mode")) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
183 (choice (const :tag "All" nil) regexp) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
184 (integer :tag "Tab width") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
185 (boolean :tag "Indent-tabs-mode")))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
186 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
187 (defvar antlr-indent-item-regexp |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
188 "[]}):;|&]\\|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
|
189 "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
|
190 See command \\[antlr-indent-command].") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
191 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
192 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
193 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
194 ;;; Menu |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
195 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
196 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
197 (defcustom antlr-imenu-name t |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
198 "*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
|
199 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
|
200 imenu." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
201 :group 'antlr |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
202 :type '(choice (const :tag "No menu" nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
203 (const :tag "Index menu" t) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
204 (string :tag "Other menu name"))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
205 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
206 (defvar antlr-mode-map |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
207 (let ((map (make-sparse-keymap))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
208 (define-key map "\t" 'antlr-indent-command) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
209 (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
|
210 (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
|
211 (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
|
212 (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
|
213 (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
|
214 (define-key map "\C-c\C-b" 'c-backward-into-nomenclature) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
215 ;; I'm too lazy to define my own: |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
216 (define-key map "\ea" 'c-beginning-of-statement) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
217 (define-key map "\ee" 'c-end-of-statement) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
218 map) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
219 "Keymap used in `antlr-mode' buffers.") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
220 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
221 (easy-menu-define antlr-mode-menu |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
222 antlr-mode-map |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
223 "Major mode menu." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
224 '("Antlr" |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
225 ["Indent Line" antlr-indent-command |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
226 :active (not buffer-read-only)] |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
227 ["Indent for Comment" indent-for-comment |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
228 :active (not buffer-read-only)] |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
229 ["Backward Rule" antlr-beginning-of-rule t] |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
230 ["Forward Rule" antlr-end-of-rule t] |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
231 ["Start of Rule Body" antlr-beginning-of-body |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
232 :active (antlr-inside-rule-p)] |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
233 ["End of Rule Body" antlr-end-of-body |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
234 :active (antlr-inside-rule-p)] |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
235 "---" |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
236 ["Backward Statement" c-beginning-of-statement t] |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
237 ["Forward Statement" c-end-of-statement t] |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
238 ["Backward Into Nomencl." c-backward-into-nomenclature t] |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
239 ["Forward Into Nomencl." c-forward-into-nomenclature t])) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
240 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
241 |
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 ;;; font-lock |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
244 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
245 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
246 (defcustom antlr-font-lock-maximum-decoration 'inherit |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
247 "*The maximum decoration level for fontifying actions. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
248 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
|
249 according to `antlr-font-lock-additional-keywords'. Value `inherit' |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
250 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
|
251 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
|
252 fontification, see `antlr-font-lock-keywords-alist'. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
253 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
254 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
|
255 bound to `antlr-language'. For example, with value |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
256 ((java-mode . 2) (c++-mode . 0)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
257 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
|
258 fontified at all." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
259 :type '(choice (const :tag "none" none) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
260 (const :tag "inherit" inherit) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
261 (const :tag "default" nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
262 (const :tag "maximum" t) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
263 (integer :tag "level" 1) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
264 (repeat :menu-tag "mode specific" :tag "mode specific" |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
265 :value ((t . t)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
266 (cons :tag "Instance" |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
267 (radio :tag "Mode" |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
268 (const :tag "all" t) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
269 (symbol :tag "name")) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
270 (radio :tag "Decoration" |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
271 (const :tag "default" nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
272 (const :tag "maximum" t) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
273 (integer :tag "level" 1)))))) |
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 (defvar antlr-font-lock-keywords-alist |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
276 '((java-mode |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
277 (list) ; nil won't work (would use level-3) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
278 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
|
279 java-font-lock-keywords-3) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
280 (c++-mode |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
281 (list) ; nil won't work (would use level-3) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
282 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
|
283 c++-font-lock-keywords-3)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
284 "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
|
285 Each element in this list looks like |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
286 (MAJOR-MODE KEYWORD...) |
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 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
|
289 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
|
290 in the grammar's actions and semantic predicates, see |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
291 `antlr-font-lock-maximum-decoration'.") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
292 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
293 (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
|
294 (defface antlr-font-lock-keyword-face |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
295 '((((class color) (background light)) (:foreground "black" :bold t))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
296 "ANTLR keywords." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
297 :group 'antlr) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
298 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
299 (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
|
300 (defface antlr-font-lock-ruledef-face |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
301 '((((class color) (background light)) (:foreground "blue" :bold t))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
302 "ANTLR rule references (definition)." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
303 :group 'antlr) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
304 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
305 (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
|
306 (defface antlr-font-lock-tokendef-face |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
307 '((((class color) (background light)) (:foreground "brown3" :bold t))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
308 "ANTLR token references (definition)." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
309 :group 'antlr) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
310 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
311 (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
|
312 (defface antlr-font-lock-ruleref-face |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
313 '((((class color) (background light)) (:foreground "blue4"))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
314 "ANTLR rule references (usage)." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
315 :group 'antlr) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
316 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
317 (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
|
318 (defface antlr-font-lock-tokenref-face |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
319 '((((class color) (background light)) (:foreground "brown4"))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
320 "ANTLR token references (usage)." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
321 :group 'antlr) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
322 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
323 (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
|
324 (defface antlr-font-lock-literal-face |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
325 '((((class color) (background light)) (:foreground "brown4" :bold t))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
326 "ANTLR literal tokens consisting merely of letter-like characters." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
327 :group 'antlr) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
328 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
329 (defvar antlr-font-lock-additional-keywords |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
330 `((antlr-invalidate-context-cache) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
331 ("\\$setType[ \t]*(\\([A-Z\300-\326\330-\337]\\sw*\\))" |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
332 (1 antlr-font-lock-tokendef-face)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
333 ("\\$\\sw+" (0 font-lock-keyword-face)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
334 ;; the tokens are already fontified as string/docstrings: |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
335 (,(lambda (limit) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
336 (antlr-re-search-forward "\"\\(\\sw\\(\\sw\\|-\\)*\\)\"" limit)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
337 (1 antlr-font-lock-literal-face t)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
338 (,(lambda (limit) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
339 (antlr-re-search-forward |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
340 "^\\(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
|
341 (1 antlr-font-lock-keyword-face) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
342 (2 antlr-font-lock-ruledef-face) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
343 (3 antlr-font-lock-keyword-face) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
344 (4 (if (member (match-string 4) '("Lexer" "Parser" "TreeParser")) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
345 'antlr-font-lock-keyword-face |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
346 'font-lock-type-face))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
347 (,(lambda (limit) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
348 (antlr-re-search-forward |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
349 "\\<\\(header\\|options\\|tokens\\|exception\\|catch\\|returns\\)\\>" |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
350 limit)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
351 (1 antlr-font-lock-keyword-face)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
352 (,(lambda (limit) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
353 (antlr-re-search-forward |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
354 "^\\(private\\|public\\|protected\\)\\>\\([ \t]+\\(\\sw+\\)\\)?" |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
355 limit)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
356 (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
|
357 (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
|
358 'antlr-font-lock-tokendef-face |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
359 'antlr-font-lock-ruledef-face) nil t)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
360 (,(lambda (limit) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
361 (antlr-re-search-forward "^\\sw+" limit)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
362 (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
|
363 'antlr-font-lock-tokendef-face |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
364 'antlr-font-lock-ruledef-face) nil t)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
365 (,(lambda (limit) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
366 ;; 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
|
367 (antlr-re-search-forward "\\<\\(\\sw+\\)[ \t]*:" limit)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
368 (1 font-lock-variable-name-face)) |
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+[ \t]*=[ \t]*\\)?\\(\\sw+[ \t]*:[ \t]*\\)?\\(\\sw+\\)" limit)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
371 ;;(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
|
372 (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
|
373 'antlr-font-lock-tokenref-face |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
374 'antlr-font-lock-ruleref-face)))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
375 "Font-lock keywords for ANTLR's normal grammar code. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
376 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
|
377 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
378 (defvar antlr-font-lock-defaults |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
379 '(antlr-font-lock-keywords |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
380 nil nil ((?_ . "w") (?\( . ".") (?\) . ".")) beginning-of-defun) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
381 "Font-lock defaults used for ANTLR syntax coloring. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
382 The SYNTAX-ALIST element is also used to initialize |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
383 `antlr-action-syntax-table'.") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
384 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
385 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
386 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
387 ;;; Internal variables |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
388 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
389 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
390 (defvar antlr-mode-hook nil |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
391 "Hook called by `antlr-mode'.") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
392 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
393 ;; used for "in Java/C++ code" = syntactic-depth>0 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
394 (defvar antlr-action-syntax-table nil |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
395 "Syntax table used for ANTLR action parsing. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
396 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
|
397 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
|
398 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
|
399 `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
|
400 context_cache.") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
401 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
402 (defvar antlr-mode-abbrev-table nil |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
403 "Abbreviation table used in `antlr-mode' buffers.") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
404 (define-abbrev-table 'antlr-mode-abbrev-table ()) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
405 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
406 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
407 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
408 ;;;;########################################################################## |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
409 ;;;; The Code |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
410 ;;;;########################################################################## |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
411 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
412 |
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 ;;; Syntax functions -- Emacs vs XEmacs dependent |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
415 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
416 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
417 ;; From help.el (XEmacs-21.1) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
418 (defmacro antlr-with-syntax-table (syntab &rest body) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
419 `(let ((stab (syntax-table))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
420 (unwind-protect |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
421 (progn (set-syntax-table (copy-syntax-table ,syntab)) ,@body) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
422 (set-syntax-table stab)))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
423 (put 'antlr-with-syntax-table 'lisp-indent-function 1) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
424 (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
|
425 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
426 (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
|
427 ;; checkdoc-params: (from count dummy) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
428 "Like `scan-sexps' but with additional arguments. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
429 When optional arg NO-ERROR is non-nil, `scan-sexps' will return nil |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
430 instead of signalling an error." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
431 (if no-error |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
432 (condition-case nil |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
433 (scan-sexps from count) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
434 (t nil)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
435 (scan-sexps from count))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
436 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
437 (defun antlr-xemacs-bug-workaround (&rest dummies) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
438 ;; checkdoc-params: (dummies) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
439 "Invalidate context_cache for syntactical context information." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
440 ;; XEmacs bug workaround |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
441 (save-excursion |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
442 (set-buffer (get-buffer-create " ANTLR XEmacs bug workaround")) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
443 (buffer-syntactic-context-depth)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
444 nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
445 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
446 (defun antlr-fast-syntactic-context () |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
447 "Return some syntactic context information. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
448 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
|
449 `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
|
450 parenthesis-syntax delimiters at point otherwise. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
451 WARNING: this may alter `match-data'." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
452 (or (buffer-syntactic-context) (buffer-syntactic-context-depth))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
453 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
454 (defun antlr-slow-syntactic-context () |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
455 "Return some syntactic context information. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
456 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
|
457 `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
|
458 parenthesis-syntax delimiters at point otherwise. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
459 WARNING: this may alter `match-data'." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
460 (let ((orig (point))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
461 (beginning-of-defun) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
462 (let ((state (parse-partial-sexp (point) orig))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
463 (goto-char orig) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
464 (cond ((nth 3 state) 'string) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
465 ((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
|
466 (t (car state)))))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
467 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
468 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
469 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
470 ;;; Misc functions |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
471 ;;;=========================================================================== |
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-upcase-p (char) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
474 "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
|
475 ;; in XEmacs, upcase only works for ASCII |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
476 (or (and (<= ?A char) (<= char ?Z)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
477 (and (<= ?\300 char) (<= char ?\337)))) ; ?\327 is no letter |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
478 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
479 (defun antlr-re-search-forward (regexp bound) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
480 "Search forward from point for regular expression REGEXP. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
481 Set point to the end of the occurrence found, and return point. Return |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
482 nil if no occurence was found. Do not search within comments, strings |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
483 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
|
484 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
|
485 and `replace-match'." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
486 ;; 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
|
487 (let ((continue t)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
488 (while (and (re-search-forward regexp bound 'limit) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
489 (save-match-data |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
490 (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
|
491 (if continue nil (point)))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
492 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
493 (defun antlr-search-forward (string) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
494 "Search forward from point for STRING. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
495 Set point to the end of the occurrence found, and return point. Return |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
496 nil if no occurence was found. Do not search within comments, strings |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
497 and actions/semantic predicates." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
498 ;; 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
|
499 (let ((continue t)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
500 (while (and (search-forward string nil 'limit) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
501 (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
|
502 (if continue nil (point)))) |
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 (defun antlr-search-backward (string) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
505 "Search backward from point for STRING. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
506 Set point to the beginning of the occurrence found, and return point. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
507 Return nil if no occurence was found. Do not search within comments, |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
508 strings and actions/semantic predicates." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
509 ;; 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
|
510 (let ((continue t)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
511 (while (and (search-backward string nil 'limit) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
512 (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
|
513 (if continue nil (point)))) |
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 (defsubst antlr-skip-sexps (count) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
516 "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
|
517 Return position before the comments after the last expression." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
518 (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
|
519 (prog1 (point) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
520 (c-forward-syntactic-ws))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
521 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
522 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
523 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
524 ;;; font-lock |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
525 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
526 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
527 (defun antlr-font-lock-keywords () |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
528 "Return font-lock keywords for current buffer. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
529 See `antlr-font-lock-additional-keywords', `antlr-language' and |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
530 `antlr-font-lock-maximum-decoration'." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
531 (if (eq antlr-font-lock-maximum-decoration 'none) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
532 antlr-font-lock-additional-keywords |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
533 (append antlr-font-lock-additional-keywords |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
534 (eval (let ((major-mode antlr-language)) ; dynamic |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
535 (font-lock-choose-keywords |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
536 (cdr (assq antlr-language |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
537 antlr-font-lock-keywords-alist)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
538 (if (eq antlr-font-lock-maximum-decoration 'inherit) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
539 font-lock-maximum-decoration |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
540 antlr-font-lock-maximum-decoration))))))) |
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 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
543 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
544 ;;; imenu support |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
545 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
546 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
547 (defun antlr-imenu-create-index-function () |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
548 "Return imenu index-alist for ANTLR gramar files." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
549 (let ((items nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
550 (lexer nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
551 (parser nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
552 (treeparser nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
553 (misc nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
554 (classes nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
555 (semi (point-max))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
556 ;; Using `imenu-progress-message' would require imenu for compilation -- |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
557 ;; nobody is missing these messages... |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
558 (antlr-with-syntax-table antlr-action-syntax-table |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
559 ;; 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
|
560 ;; 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
|
561 ;; 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
|
562 (while semi |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
563 (goto-char semi) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
564 (if (setq semi (antlr-search-backward ";")) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
565 (progn (forward-char) (antlr-skip-exception-part t)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
566 (antlr-skip-file-prelude t)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
567 (if (looking-at "{") (antlr-skip-sexps 1)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
568 (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
|
569 (progn |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
570 (push (cons (match-string 1) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
571 (if imenu-use-markers |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
572 (copy-marker (match-beginning 1)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
573 (match-beginning 1))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
574 classes) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
575 (if items |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
576 (let ((super (match-string 2))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
577 (cond ((string-equal super "Parser") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
578 (setq parser (nconc items parser))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
579 ((string-equal super "Lexer") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
580 (setq lexer (nconc items lexer))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
581 ((string-equal super "TreeParser") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
582 (setq treeparser (nconc items treeparser))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
583 (t |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
584 (setq misc (nconc items misc)))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
585 (setq items nil)))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
586 (if (looking-at "p\\(ublic\\|rotected\\|rivate\\)") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
587 (antlr-skip-sexps 1)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
588 (when (looking-at "\\sw+") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
589 (push (cons (match-string 0) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
590 (if imenu-use-markers |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
591 (copy-marker (match-beginning 0)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
592 (match-beginning 0))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
593 items))))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
594 (or items ; outside any class |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
595 (prog1 (setq items misc) (setq misc nil)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
596 (prog1 (setq items parser) (setq parser nil)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
597 (prog1 (setq items lexer) (setq lexer nil)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
598 (prog1 (setq items treeparser) (setq treeparser nil))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
599 (if misc (push (cons "Miscellaneous" misc) items)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
600 (if treeparser (push (cons "TreeParser" treeparser) items)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
601 (if lexer (push (cons "Lexer" lexer) items)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
602 (if parser (push (cons "Parser" parser) items)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
603 (if classes (cons (cons "Classes" classes) items) items))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
604 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
605 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
606 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
607 ;;; Parse grammar files (internal functions) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
608 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
609 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
610 (defun antlr-skip-exception-part (skip-comment) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
611 "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
|
612 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
|
613 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
|
614 part." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
615 (let ((pos (point)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
616 (class nil)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
617 (c-forward-syntactic-ws) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
618 (while (looking-at "options\\>\\|tokens\\>") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
619 (setq class t) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
620 (setq pos (antlr-skip-sexps 2))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
621 (if class |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
622 ;; 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
|
623 ;; 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
|
624 ;; 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
|
625 (if (looking-at "{") (setq pos (antlr-skip-sexps 1))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
626 (while (looking-at "exception\\>") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
627 (setq pos (antlr-skip-sexps 1)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
628 (if (looking-at "\\[") (setq pos (antlr-skip-sexps 1))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
629 (while (looking-at "catch\\>") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
630 (setq pos (antlr-skip-sexps 3))))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
631 (or skip-comment (goto-char pos)))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
632 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
633 (defun antlr-skip-file-prelude (skip-comment) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
634 "Skip the file prelude: the header and file options. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
635 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
|
636 (let* ((pos (point)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
637 (pos0 pos)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
638 (c-forward-syntactic-ws) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
639 (if skip-comment (setq pos0 (point))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
640 (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
|
641 (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
|
642 (or skip-comment (goto-char pos)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
643 pos0)) |
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 (defun antlr-next-rule (arg skip-comment) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
646 "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
|
647 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
|
648 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
|
649 rule. The behaviour is not defined when ARG is zero. If SKIP-COMMENT |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
650 is non-nil, move to beginning of the rule." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
651 ;; 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
|
652 ;; PRE: ARG<>0 |
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 (beg (point))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
655 ;; first look whether point is in exception part |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
656 (if (antlr-search-backward ";") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
657 (progn |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
658 (setq beg (point)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
659 (forward-char) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
660 (antlr-skip-exception-part skip-comment)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
661 (antlr-skip-file-prelude skip-comment)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
662 (if (< arg 0) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
663 (unless (and (< (point) pos) (zerop (incf arg))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
664 ;; 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
|
665 (goto-char beg) ; rewind (to ";" / point) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
666 (while (and arg (<= (incf arg) 0)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
667 (if (antlr-search-backward ";") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
668 (setq beg (point)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
669 (when (>= arg -1) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
670 ;; try file prelude: |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
671 (setq pos (antlr-skip-file-prelude skip-comment)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
672 (if (zerop arg) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
673 (if (>= (point) beg) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
674 (goto-char (if (>= pos beg) (point-min) pos))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
675 (goto-char (if (or (>= (point) beg) (= (point) pos)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
676 (point-min) pos)))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
677 (setq arg nil))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
678 (when arg ; always found a ";" |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
679 (forward-char) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
680 (antlr-skip-exception-part skip-comment))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
681 (if (<= (point) pos) ; moved backward? |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
682 (goto-char pos) ; rewind |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
683 (decf arg)) ; already moved one defun forward |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
684 (unless (zerop arg) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
685 (while (>= (decf arg) 0) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
686 (antlr-search-forward ";")) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
687 (antlr-skip-exception-part skip-comment))))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
688 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
689 (defun antlr-outside-rule-p () |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
690 "Non-nil if point is outside a grammar rule. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
691 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
|
692 ;; 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
|
693 (let ((pos (point))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
694 (antlr-next-rule -1 nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
695 (let ((between (or (bobp) (< (point) pos)))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
696 (c-forward-syntactic-ws) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
697 (and between (> (point) pos) (goto-char pos))))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
698 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
699 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
700 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
701 ;;; Parse grammar files (commands) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
702 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
703 ;; No (interactive "_") in Emacs... use `zmacs-region-stays'. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
704 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
705 (defun antlr-inside-rule-p () |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
706 "Non-nil if point is inside a grammar rule. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
707 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
|
708 rule." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
709 (save-excursion |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
710 (antlr-with-syntax-table antlr-action-syntax-table |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
711 (not (antlr-outside-rule-p))))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
712 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
713 (defun antlr-end-of-rule (&optional arg) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
714 "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
|
715 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
|
716 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
|
717 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
|
718 (interactive "p") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
719 (if (zerop arg) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
720 (antlr-end-of-body) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
721 (antlr-with-syntax-table antlr-action-syntax-table |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
722 (antlr-next-rule arg nil)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
723 (setq zmacs-region-stays t))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
724 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
725 (defun antlr-beginning-of-rule (&optional arg) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
726 "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
|
727 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
|
728 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
|
729 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
|
730 (interactive "p") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
731 (if (zerop arg) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
732 (antlr-beginning-of-body) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
733 (antlr-with-syntax-table antlr-action-syntax-table |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
734 (antlr-next-rule (- arg) t)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
735 (setq zmacs-region-stays t))) |
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 (defun antlr-end-of-body (&optional msg) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
738 "Move to position after the `;' of the current rule. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
739 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
|
740 prefix arg MSG, move to `:'." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
741 (interactive) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
742 (antlr-with-syntax-table antlr-action-syntax-table |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
743 (let ((orig (point))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
744 (if (antlr-outside-rule-p) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
745 (error "Outside an ANTLR rule")) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
746 (let ((bor (point))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
747 (when (< (antlr-skip-file-prelude t) (point)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
748 ;; Yes, we are in the file prelude |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
749 (goto-char orig) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
750 (error (or msg "The file prelude is without `;'"))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
751 (antlr-search-forward ";") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
752 (when msg |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
753 (when (< (point) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
754 (progn (goto-char bor) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
755 (or (antlr-search-forward ":") (point-max)))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
756 (goto-char orig) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
757 (error msg)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
758 (c-forward-syntactic-ws))))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
759 (setq zmacs-region-stays t)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
760 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
761 (defun antlr-beginning-of-body () |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
762 "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
|
763 (interactive) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
764 (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
|
765 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
766 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
767 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
768 ;;; Indentation |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
769 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
770 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
771 (defun antlr-indent-line () |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
772 "Indent the current line as ANTLR grammar code. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
773 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
|
774 multiplied by: |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
775 - the level of the paren/brace/bracket depth, |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
776 - 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
|
777 exception part, |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
778 - 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
|
779 line starting from the first non-blank. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
780 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
781 Lines inside block commments are not changed or indented by |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
782 `c-indent-line', see `antlr-indent-comment'." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
783 (let ((orig (point)) bol boi indent syntax) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
784 (beginning-of-line) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
785 (setq bol (point)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
786 (skip-chars-forward " \t") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
787 (setq boi (point)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
788 ;; check syntax at beginning of indentation ------------------------------ |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
789 (antlr-with-syntax-table antlr-action-syntax-table |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
790 (antlr-invalidate-context-cache) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
791 (cond ((symbolp (setq syntax (antlr-syntactic-context))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
792 (setq indent nil)) ; block-comments, strings, (comments) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
793 ((progn |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
794 (antlr-next-rule -1 t) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
795 (if (antlr-search-forward ":") (< boi (1- (point))) t)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
796 (setq indent 0)) ; in rule header |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
797 ((if (antlr-search-forward ";") (< boi (point)) t) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
798 (setq indent 2)) ; in rule body |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
799 (t |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
800 (forward-char) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
801 (antlr-skip-exception-part nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
802 (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
|
803 ;; compute the corresponding indentation and indent ---------------------- |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
804 (if (null indent) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
805 (progn |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
806 (goto-char orig) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
807 (and (eq antlr-indent-comment t) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
808 (not (eq syntax 'string)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
809 (c-indent-line))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
810 ;; do it ourselves |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
811 (goto-char boi) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
812 (antlr-invalidate-context-cache) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
813 (incf indent (antlr-syntactic-context)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
814 (and (> indent 0) (looking-at antlr-indent-item-regexp) (decf indent)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
815 (setq indent (* indent c-basic-offset)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
816 ;; the usual major-mode indent stuff: |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
817 (setq orig (- (point-max) orig)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
818 (unless (= (current-column) indent) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
819 (delete-region bol boi) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
820 (beginning-of-line) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
821 (indent-to indent)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
822 ;; If initial point was within line's indentation, |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
823 ;; 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
|
824 (if (> (- (point-max) orig) (point)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
825 (goto-char (- (point-max) orig)))))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
826 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
827 (defun antlr-indent-command (&optional arg) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
828 "Indent the current line or insert tabs/spaces. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
829 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
|
830 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
|
831 Otherwise, indent the current line with `antlr-indent-line'." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
832 (interactive "P") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
833 (if (or arg (eq last-command 'antlr-indent-command)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
834 (insert-tab arg) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
835 (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
|
836 (antlr-indent-line)))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
837 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
838 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
839 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
840 ;;; Mode entry |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
841 ;;;=========================================================================== |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
842 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
843 (defun antlr-c-common-init () |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
844 "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
|
845 ;; X/Emacs 20 only |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
846 (make-local-variable 'paragraph-start) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
847 (make-local-variable 'paragraph-separate) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
848 (make-local-variable 'paragraph-ignore-fill-prefix) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
849 (make-local-variable 'require-final-newline) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
850 (make-local-variable 'parse-sexp-ignore-comments) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
851 (make-local-variable 'indent-line-function) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
852 (make-local-variable 'indent-region-function) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
853 (make-local-variable 'comment-start) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
854 (make-local-variable 'comment-end) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
855 (make-local-variable 'comment-column) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
856 (make-local-variable 'comment-start-skip) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
857 (make-local-variable 'comment-multi-line) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
858 (make-local-variable 'outline-regexp) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
859 (make-local-variable 'outline-level) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
860 (make-local-variable 'adaptive-fill-regexp) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
861 (make-local-variable 'adaptive-fill-mode) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
862 (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
|
863 (and (boundp 'comment-line-break-function) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
864 (make-local-variable 'comment-line-break-function)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
865 ;; Emacs 19.30 and beyond only, AFAIK |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
866 (if (boundp 'fill-paragraph-function) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
867 (progn |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
868 (make-local-variable 'fill-paragraph-function) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
869 (setq fill-paragraph-function 'c-fill-paragraph))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
870 ;; now set their values |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
871 (setq paragraph-start (concat page-delimiter "\\|$") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
872 paragraph-separate paragraph-start |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
873 paragraph-ignore-fill-prefix t |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
874 require-final-newline t |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
875 parse-sexp-ignore-comments t |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
876 indent-line-function 'c-indent-line |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
877 indent-region-function 'c-indent-region |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
878 outline-regexp "[^#\n\^M]" |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
879 outline-level 'c-outline-level |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
880 comment-column 32 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
881 comment-start-skip "/\\*+ *\\|// *" |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
882 comment-multi-line nil |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
883 comment-line-break-function 'c-comment-line-break-function |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
884 adaptive-fill-regexp nil |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
885 adaptive-fill-mode nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
886 ;; 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
|
887 ;; buffer local value has its own alist structure. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
888 (setq c-offsets-alist (copy-alist c-offsets-alist)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
889 ;; 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
|
890 ;; ignore any byte compiler warnings you might get here |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
891 (make-local-variable 'comment-indent-function) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
892 (setq comment-indent-function 'c-comment-indent)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
893 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
894 (defun antlr-language-for-option (option-value) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
895 "Find element in `antlr-language-alist' for OPTION-VALUE." |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
896 ;; 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
|
897 (let ((seq antlr-language-alist) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
898 r) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
899 (while seq |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
900 (setq r (pop seq)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
901 (if (member option-value (cddr r)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
902 (setq seq nil) ; stop |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
903 (setq r nil))) ; no result yet |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
904 r)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
905 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
906 ;;;###autoload |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
907 (defun antlr-mode () |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
908 "Major mode for editing ANTLR grammar files. |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
909 \\{antlr-mode-map}" |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
910 (interactive) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
911 (c-initialize-cc-mode) ; for java syntax table |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
912 (kill-all-local-variables) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
913 ;; ANTLR specific ---------------------------------------------------------- |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
914 (setq major-mode 'antlr-mode |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
915 mode-name "Antlr") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
916 (setq local-abbrev-table antlr-mode-abbrev-table) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
917 (set-syntax-table java-mode-syntax-table) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
918 (unless antlr-action-syntax-table |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
919 (let ((slist (nth 3 antlr-font-lock-defaults))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
920 (setq antlr-action-syntax-table |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
921 (copy-syntax-table java-mode-syntax-table)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
922 (while slist |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
923 (modify-syntax-entry (caar slist) (cdar slist) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
924 antlr-action-syntax-table) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
925 (setq slist (cdr slist))))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
926 (use-local-map antlr-mode-map) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
927 (make-local-variable 'antlr-language) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
928 (unless antlr-language |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
929 (save-excursion |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
930 (goto-char (point-min)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
931 (setq antlr-language |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
932 (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
|
933 (car antlr-language-limit-n-regexp) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
934 t) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
935 (antlr-language-for-option (match-string 1))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
936 (antlr-language-for-option nil)))))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
937 (if (stringp (cadr (assq antlr-language antlr-language-alist))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
938 (setq mode-name |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
939 (concat "Antlr/" |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
940 (cadr (assq antlr-language antlr-language-alist))))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
941 ;; indentation, for the C engine ------------------------------------------- |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
942 (antlr-c-common-init) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
943 (setq indent-line-function 'antlr-indent-line |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
944 indent-region-function nil) ; too lazy |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
945 (setq comment-start "// " |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
946 comment-end "") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
947 (c-set-style "java") |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
948 (if (eq antlr-language 'c++-mode) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
949 (setq c-conditional-key c-C++-conditional-key |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
950 c-comment-start-regexp c-C++-comment-start-regexp |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
951 c-class-key c-C++-class-key |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
952 c-extra-toplevel-key c-C++-extra-toplevel-key |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
953 c-access-key c-C++-access-key |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
954 c-recognize-knr-p nil) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
955 (setq c-conditional-key c-Java-conditional-key |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
956 c-comment-start-regexp c-Java-comment-start-regexp |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
957 c-class-key c-Java-class-key |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
958 c-method-key nil |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
959 c-baseclass-key nil |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
960 c-recognize-knr-p nil |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
961 c-access-key c-Java-access-key) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
962 (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
|
963 (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
|
964 ;; various ----------------------------------------------------------------- |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
965 (make-local-variable 'font-lock-defaults) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
966 (setq font-lock-defaults antlr-font-lock-defaults) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
967 (easy-menu-add antlr-mode-menu) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
968 (make-local-variable 'imenu-create-index-function) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
969 (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
|
970 (make-local-variable 'imenu-generic-expression) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
971 (setq imenu-generic-expression t) ; fool stupid test |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
972 (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
|
973 (fboundp 'imenu-add-to-menubar) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
974 (imenu-add-to-menubar |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
975 (if (stringp antlr-imenu-name) antlr-imenu-name "Index"))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
976 (antlr-set-tabs) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
977 (run-hooks 'antlr-mode-hook)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
978 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
979 ;;;###autoload |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
980 (defun antlr-set-tabs () |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
981 "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
|
982 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
|
983 (if buffer-file-name |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
984 (let ((alist antlr-tab-offset-alist) elem) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
985 (while alist |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
986 (setq elem (pop alist)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
987 (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
|
988 (or (null (cadr elem)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
989 (string-match (cadr elem) buffer-file-name)) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
990 (setq tab-width (caddr elem) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
991 indent-tabs-mode (cadddr elem) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
992 alist nil)))))) |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
993 |
0d41332e3819
Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
994 ;;; antlr-mode.el ends here |