annotate lisp/progmodes/antlr-mode.el @ 28177:ff69c2cd80c1

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