annotate lisp/progmodes/antlr-mode.el @ 37387:20cdea777c49

*** empty log message ***
author Gerd Moellmann <gerd@gnu.org>
date Wed, 18 Apr 2001 14:21:41 +0000
parents 075cc818f566
children c18732fcfbab
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
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
3 ;; Copyright (C) 1999, 2000 Free Software Foundation, Inc.
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
4 ;;
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
5 ;; Author: Christoph.Wedler@sap.com
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
6 ;; Version: 1.4
26965
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
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
32 ;; This package provides the following features:
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
33 ;; * Syntax coloring (via font-lock) for grammar symbols and the code in
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
34 ;; actions. The latter depends on the language settings.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
35 ;; * Indentation for the current line (TAB) and selected region (C-M-\).
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
36 ;; * Support for imenu/speedbar: menu "Index" (Parser, Lexer, TreeParser).
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
37 ;; * Commands to move to previous/next rule, beginning/end of rule body etc.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
38 ;; * Commands to hide/unhide actions, upcase/downcase literals.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
39 ;; * Run ANTLR from within Emacs, create Makefile dependencies.
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
40
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
41 ;; LANGUAGE SETTINGS. This mode needs to know which language is used in
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
42 ;; actions and semantic predicated of the grammar. This information is used
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
43 ;; for syntax coloring and the creation of the Makefile dependencies. It is
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
44 ;; stored in variable `antlr-language' and automatically set according to
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
45 ;; ANTLR's file option "language", see `antlr-language-alist'. The supported
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
46 ;; languages are "Java" (java-mode) and "Cpp" (c++-mode).
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
47
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
48 ;; INDENTATION. This package supports ANTLR's (intended) indentation style
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
49 ;; 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
50 ;; `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
51 ;; block comments (it is not easy to use it for actions, esp if they come early
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
52 ;; in the rule body). By default, this package defines a tab width of 4 to be
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
53 ;; consistent to both ANTLR's conventions (TABs usage) and the
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54 ;; `c-indentation-style' "java" which sets `c-basic-offset' to 4, see
29289
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
55 ;; `antlr-tab-offset-alist'. You might want to set this variable to nil.
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
56
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57 ;; 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
58 ;; highlighted. Second, the grammar code is highlighted according to
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
59 ;; `antlr-font-lock-additional-keywords' (rule refs: dark blue, token refs:
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
60 ;; dark orange, definition: bold blue). Third, actions, semantic predicates
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
61 ;; and arguments are highlighted according to the usual font-lock keywords of
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62 ;; `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
63 ;; 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
64 ;; ANTLR keywords from Java/C++ keywords.
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
65
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
66 ;; MAKEFILE CREATION. Command \\[antlr-show-makefile-rules] shows/inserts the
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
67 ;; dependencies for all grammar files in the current directory. It considers
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
68 ;; import/export vocabularies and grammar inheritance and provides a value for
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
69 ;; the -glib option if necessary (which you have to edit if the super-grammar
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
70 ;; is not in the same directory).
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
71
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
72 ;; TODO. Support to insert/change file/grammar/rule/subrule options. imenu
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
73 ;; support for method definitions in actions is not really planned (you can
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
74 ;; send be a patch, though). This mode would become too dependent on cc-mode
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
75 ;; or I would have to do a lot of language-dependent things myself...
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
76
26965
048db40ddca6 Version 1.2 is released.
Gerd Moellmann <gerd@gnu.org>
parents: 26542
diff changeset
77 ;; Bug fixes, bug reports, improvements, and suggestions are strongly
048db40ddca6 Version 1.2 is released.
Gerd Moellmann <gerd@gnu.org>
parents: 26542
diff changeset
78 ;; appreciated. Please check the newest version first:
048db40ddca6 Version 1.2 is released.
Gerd Moellmann <gerd@gnu.org>
parents: 26542
diff changeset
79 ;; 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
80
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81 ;;; Installation:
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
83 ;; This file requires Emacs-20.3, XEmacs-20.4 or higher and package cc-mode.
26542
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 ;; 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
86 ;; load-path and the following into your ~/.emacs:
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
87 ;; (autoload 'antlr-mode "antlr-mode" nil t)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88 ;; (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
89 ;; (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
90 ;; (lambda () (speedbar-add-supported-extension ".g")))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
91
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
92 ;; 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
93 ;; (autoload 'antlr-set-tabs "antlr-mode")
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
94 ;; (add-hook 'java-mode-hook 'antlr-set-tabs)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95
29289
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
96 ;; I strongly recommend to use font-lock with a support mode like fast-lock,
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
97 ;; lazy-lock or better jit-lock (Emacs-21.1+) / lazy-shot (XEmacs).
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
98
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
99 ;; 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
100 ;; (Emacs->Programming->Languages->Antlr).
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 ;;; Code:
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 (provide 'antlr-mode)
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
105 (eval-when-compile ; required and optional libraries
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
106 (require 'cc-mode)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
107 (defvar outline-level) (defvar imenu-use-markers)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
108 (defvar imenu-create-index-function))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
109 (eval-when-compile ; Emacs: cl, easymenu
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
110 (require 'cl)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
111 (require 'easymenu))
29289
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
112 (eval-when-compile ; XEmacs: Emacs vars
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
113 (defvar inhibit-point-motion-hooks) (defvar deactivate-mark))
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
114
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
115 (eval-and-compile ; XEmacs functions, simplified
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
116 (if (featurep 'xemacs)
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
117 (defalias 'antlr-scan-sexps 'scan-sexps)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
118 (defalias 'antlr-scan-sexps 'antlr-scan-sexps-internal))
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
119 (if (fboundp 'default-directory)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
120 (defalias 'antlr-default-directory 'default-directory)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
121 (defun antlr-default-directory () default-directory))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
122 (if (fboundp 'read-shell-command)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
123 (defalias 'antlr-read-shell-command 'read-shell-command)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
124 (defun antlr-read-shell-command (prompt &optional initial-input history)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
125 (read-from-minibuffer prompt initial-input nil nil
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
126 (or history 'shell-command-history))))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
127 (if (fboundp 'with-displaying-help-buffer)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
128 (defalias 'antlr-with-displaying-help-buffer 'with-displaying-help-buffer)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
129 (defun antlr-with-displaying-help-buffer (thunk &optional name)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
130 (with-output-to-temp-buffer "*Help*"
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
131 (save-excursion (funcall thunk)))))
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
132 (if (and (fboundp 'buffer-syntactic-context)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
133 (fboundp 'buffer-syntactic-context-depth))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
134 (progn
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
135 (defalias 'antlr-invalidate-context-cache 'antlr-xemacs-bug-workaround)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
136 (defalias 'antlr-syntactic-context 'antlr-fast-syntactic-context))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
137 (defalias 'antlr-invalidate-context-cache 'ignore)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
138 (defalias 'antlr-syntactic-context 'antlr-slow-syntactic-context)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
139
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
140
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
141
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
142 ;;;;##########################################################################
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
143 ;;;; Variables
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
144 ;;;;##########################################################################
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
145
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
146
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
147 (defgroup antlr nil
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
148 "Major mode for ANTLR grammar files."
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
149 :group 'languages
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
150 :link '(emacs-commentary-link "antlr-mode.el")
26965
048db40ddca6 Version 1.2 is released.
Gerd Moellmann <gerd@gnu.org>
parents: 26542
diff changeset
151 :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
152 :prefix "antlr-")
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
153
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
154 (defconst antlr-version "1.4"
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
155 "ANTLR major mode version number.")
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
156
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
157
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
158 ;;;===========================================================================
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
159 ;;; Controlling ANTLR's code generator (language option)
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 (defvar antlr-language nil
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
163 "Major mode corresponding to ANTLR's \"language\" option.
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
164 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
165 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
166 variable list\" near the end of the file, see
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
167 `enable-local-variables'.")
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
168
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
169 (defcustom antlr-language-alist
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
170 '((java-mode "Java" nil "\"Java\"" "Java")
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
171 (c++-mode "C++" "\"Cpp\"" "Cpp"))
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
172 "List of ANTLR's supported languages.
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
173 Each element in this list looks like
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
174 (MAJOR-MODE MODELINE-STRING OPTION-VALUE...)
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 MAJOR-MODE, the major mode of the code in the grammar's actions, is the
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
177 value of `antlr-language' if the first group in the string matched by
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
178 REGEXP in `antlr-language-limit-n-regexp' is one of the OPTION-VALUEs.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
179 An OPTION-VALUE of nil denotes the fallback element. MODELINE-STRING is
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
180 also displayed in the modeline next to \"Antlr\"."
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
181 :group 'antlr
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
182 :type '(repeat (group :value (java-mode "")
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
183 (function :tag "Major mode")
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
184 (string :tag "Modeline string")
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
185 (repeat :tag "ANTLR language option" :inline t
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
186 (choice (const :tag "Default" nil)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
187 string )))))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
188
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
189 (defcustom antlr-language-limit-n-regexp
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
190 '(3000 . "language[ \t]*=[ \t]*\\(\"?[A-Z][A-Za-z_]*\"?\\)")
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
191 "Used to set a reasonable value for `antlr-language'.
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
192 Looks like (LIMIT . REGEXP). Search for REGEXP from the beginning of
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
193 the buffer to LIMIT and use the first group in the matched string to set
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
194 the language according to `antlr-language-alist'."
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
195 :group 'antlr
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
196 :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
197 regexp))
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 ;;;===========================================================================
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
201 ;;; Hide/Unhide, Indent/Tabs
26542
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
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
204 (defcustom antlr-action-visibility 3
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
205 "Visibility of actions when command `antlr-hide-actions' is used.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
206 If nil, the actions with their surrounding braces are hidden. If a
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
207 number, do not hide the braces, only hide the contents if its length is
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
208 greater than this number."
29289
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
209 :group 'antlr
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
210 :type '(choice (const :tag "Completely hidden" nil)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
211 (integer :tag "Hidden if longer than" :value 3)))
29289
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
212
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
213 (defcustom antlr-indent-comment 'tab
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
214 "*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
215 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
216 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
217 they are only changed by \\[antlr-indent-command]."
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
218 :group 'antlr
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
219 :type '(radio (const :tag "No" nil)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
220 (const :tag "Always" t)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
221 (sexp :tag "With TAB" :format "%t" :value tab)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
222
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
223 (defcustom antlr-tab-offset-alist
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
224 '((antlr-mode nil 4 nil)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
225 (java-mode "antlr" 4 nil))
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
226 "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
227 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
228 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
229 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
230 `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
231 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
232 :group 'antlr
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
233 :type '(repeat (group :value (antlr-mode nil 8 nil)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
234 (choice (const :tag "All" nil)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
235 (function :tag "Major mode"))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
236 (choice (const :tag "All" nil) regexp)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
237 (integer :tag "Tab width")
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
238 (boolean :tag "Indent-tabs-mode"))))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
239
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
240 (defvar antlr-indent-item-regexp
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
241 "[]}):;|&]\\|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
242 "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
243 See command \\[antlr-indent-command].")
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
244
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
245
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
246 ;;;===========================================================================
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
247 ;;; Run tool, create Makefile dependencies
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
248 ;;;===========================================================================
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
249
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
250 (defcustom antlr-tool-command "java antlr.Tool"
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
251 "*Command used in \\[antlr-run-tool] to run the Antlr tool.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
252 This variable should include all options passed to Antlr except the
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
253 option \"-glib\" which is automatically suggested if necessary."
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
254 :group 'antlr
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
255 :type 'string)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
256
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
257 (defcustom antlr-ask-about-save t
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
258 "*If not nil, \\[antlr-run-tool] asks which buffers to save.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
259 Otherwise, it saves all modified buffers before running without asking."
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
260 :group 'antlr
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
261 :type 'boolean)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
262
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
263 (defcustom antlr-makefile-specification
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
264 '("\n" ("GENS" "GENS%d" " \\\n\t") "$(ANTLR)")
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
265 "*Variable to specify the appearance of the generated makefile rules.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
266 This variable influences the output of \\[antlr-show-makefile-rules].
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
267 It looks like (RULE-SEP GEN-VAR-SPEC COMMAND).
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
268
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
269 RULE-SEP is the string to separate different makefile rules. COMMAND is
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
270 a string with the command which runs the Antlr tool, it should include
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
271 all options except the option \"-glib\" which is automatically added
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
272 if necessary.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
273
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
274 If GEN-VAR-SPEC is nil, each target directly consists of a list of
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
275 files. If GEN-VAR-SPEC looks like (GEN-VAR GEN-VAR-FORMAT GEN-SEP), a
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
276 Makefile variable is created for each rule target.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
277
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
278 Then, GEN-VAR is a string with the name of the variable which contains
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
279 the file names of all makefile rules. GEN-VAR-FORMAT is a format string
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
280 producing the variable of each target with substitution COUNT/%d where
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
281 COUNT starts with 1. GEN-SEP is used to separate long variable values."
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
282 :group 'antlr
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
283 :type '(list (string :tag "Rule separator")
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
284 (choice
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
285 (const :tag "Direct targets" nil)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
286 (list :tag "Variables for targets"
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
287 (string :tag "Variable for all targets")
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
288 (string :tag "Format for each target variable")
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
289 (string :tag "Variable separator")))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
290 (string :tag "ANTLR command")))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
291
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
292 (defvar antlr-file-formats-alist
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
293 '((java-mode ("%sTokenTypes.java") ("%s.java"))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
294 (c++-mode ("%sTokenTypes.hpp") ("%s.cpp" "%s.hpp")))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
295 "Language dependent formats which specify generated files.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
296 Each element in this list looks looks like
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
297 (MAJOR-MODE (VOCAB-FILE-FORMAT...) (CLASS-FILE-FORMAT...)).
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
298
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
299 The element whose MAJOR-MODE is equal to `antlr-language' is used to
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
300 specify the generated files which are language dependent. See variable
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
301 `antlr-special-file-formats' for language independent files.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
302
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
303 VOCAB-FILE-FORMAT is a format string, it specifies with substitution
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
304 VOCAB/%s the generated file for each export vocabulary VOCAB.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
305 CLASS-FILE-FORMAT is a format string, it specifies with substitution
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
306 CLASS/%s the generated file for each grammar class CLASS.")
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
307
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
308 (defvar antlr-special-file-formats '("%sTokenTypes.txt" "expanded%s.g")
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
309 "Language independent formats which specify generated files.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
310 The value looks like (VOCAB-FILE-FORMAT EXPANDED-GRAMMAR-FORMAT).
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
311
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
312 VOCAB-FILE-FORMAT is a format string, it specifies with substitution
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
313 VOCAB/%s the generated or input file for each export or import
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
314 vocabulary VOCAB, respectively. EXPANDED-GRAMMAR-FORMAT is a format
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
315 string, it specifies with substitution GRAMMAR/%s the constructed
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
316 grammar file if the file GRAMMAR.g contains a grammar class which
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
317 extends a class other than \"Lexer\", \"Parser\" or \"TreeParser\".
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
318
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
319 See variable `antlr-file-formats-alist' for language dependent
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
320 formats.")
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
321
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
322 (defvar antlr-unknown-file-formats '("?%s?.g" "?%s?")
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
323 "*Formats which specify the names of unknown files.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
324 The value looks like (SUPER-GRAMMAR-FILE-FORMAT SUPER-EVOCAB-FORMAT).
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
325
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
326 SUPER-GRAMMAR-FORMAT is a format string, it specifies with substitution
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
327 SUPER/%s the name of a grammar file for Antlr's option \"-glib\" if no
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
328 grammar file in the current directory defines the class SUPER or if it
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
329 is defined more than once. SUPER-EVOCAB-FORMAT is a format string, it
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
330 specifies with substitution SUPER/%s the name for the export vocabulary
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
331 of above mentioned class SUPER.")
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
332
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
333 (defvar antlr-help-unknown-file-text
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
334 "## The following rules contain filenames of the form
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
335 ## \"?SUPERCLASS?.g\" (and \"?SUPERCLASS?TokenTypes.txt\")
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
336 ## where SUPERCLASS is not found to be defined in any grammar file of
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
337 ## the current directory or is defined more than once. Please replace
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
338 ## these filenames by the grammar files (and their exportVocab).\n\n"
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
339 "String indicating the existence of unknown files in the Makefile.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
340 See \\[antlr-show-makefile-rules] and `antlr-unknown-file-formats'.")
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
341
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
342 (defvar antlr-help-rules-intro
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
343 "The following Makefile rules define the dependencies for all (non-
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
344 expanded) grammars in directory \"%s\".\n
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
345 They are stored in the kill-ring, i.e., you can insert them with C-y
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
346 into your Makefile. You can also invoke M-x antlr-show-makefile-rules
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
347 from within a Makefile to insert them directly.\n\n\n"
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
348 "Introduction to use with \\[antlr-show-makefile-rules].
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
349 It is a format string and used with substitution DIRECTORY/%s where
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
350 DIRECTORY is the name of the current directory.")
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
351
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
352
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
353 ;;;===========================================================================
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
354 ;;; Menu
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
355 ;;;===========================================================================
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
356
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
357 (defcustom antlr-imenu-name t
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
358 "*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
359 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
360 imenu."
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
361 :group 'antlr
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
362 :type '(choice (const :tag "No menu" nil)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
363 (const :tag "Index menu" t)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
364 (string :tag "Other menu name")))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
365
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
366 (defvar antlr-mode-map
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
367 (let ((map (make-sparse-keymap)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
368 (define-key map "\t" 'antlr-indent-command)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
369 (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
370 (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
371 (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
372 (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
373 (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
374 (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
375 (define-key map "\C-c\C-c" 'comment-region)
29289
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
376 (define-key map "\C-c\C-v" 'antlr-hide-actions)
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
377 (define-key map "\C-c\C-r" 'antlr-run-tool)
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
378 ;; I'm too lazy to define my own:
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
379 (define-key map "\ea" 'c-beginning-of-statement)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
380 (define-key map "\ee" 'c-end-of-statement)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
381 map)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
382 "Keymap used in `antlr-mode' buffers.")
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
383
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
384 (easy-menu-define antlr-mode-menu
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
385 antlr-mode-map
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
386 "Major mode menu."
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
387 '("Antlr"
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
388 ["Indent Line" antlr-indent-command
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
389 :active (not buffer-read-only)]
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
390 ["Indent for Comment" indent-for-comment
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
391 :active (not buffer-read-only)]
26965
048db40ddca6 Version 1.2 is released.
Gerd Moellmann <gerd@gnu.org>
parents: 26542
diff changeset
392 ["Comment Out Region" comment-region
048db40ddca6 Version 1.2 is released.
Gerd Moellmann <gerd@gnu.org>
parents: 26542
diff changeset
393 :active (and (not buffer-read-only)
048db40ddca6 Version 1.2 is released.
Gerd Moellmann <gerd@gnu.org>
parents: 26542
diff changeset
394 (c-region-is-active-p))]
048db40ddca6 Version 1.2 is released.
Gerd Moellmann <gerd@gnu.org>
parents: 26542
diff changeset
395 ["Uncomment Region"
048db40ddca6 Version 1.2 is released.
Gerd Moellmann <gerd@gnu.org>
parents: 26542
diff changeset
396 (comment-region (region-beginning) (region-end) '(4))
048db40ddca6 Version 1.2 is released.
Gerd Moellmann <gerd@gnu.org>
parents: 26542
diff changeset
397 :active (and (not buffer-read-only)
048db40ddca6 Version 1.2 is released.
Gerd Moellmann <gerd@gnu.org>
parents: 26542
diff changeset
398 (c-region-is-active-p))]
048db40ddca6 Version 1.2 is released.
Gerd Moellmann <gerd@gnu.org>
parents: 26542
diff changeset
399 "---"
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
400 ["Backward Rule" antlr-beginning-of-rule t]
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
401 ["Forward Rule" antlr-end-of-rule t]
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
402 ["Start of Rule Body" antlr-beginning-of-body
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
403 :active (antlr-inside-rule-p)]
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
404 ["End of Rule Body" antlr-end-of-body
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
405 :active (antlr-inside-rule-p)]
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
406 "---"
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
407 ["Backward Statement" c-beginning-of-statement t]
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
408 ["Forward Statement" c-end-of-statement t]
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
409 ["Backward Into Nomencl." c-backward-into-nomenclature t]
29289
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
410 ["Forward Into Nomencl." c-forward-into-nomenclature t]
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
411 "---"
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
412 ["Hide Actions (incl. Args)" antlr-hide-actions t]
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
413 ["Hide Actions (excl. Args)" (antlr-hide-actions 2) t]
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
414 ["Unhide All Actions" (antlr-hide-actions 0) t]
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
415 "---"
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
416 ["Run Tool on Grammar" antlr-run-tool t]
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
417 ["Show Makefile Rules" antlr-show-makefile-rules t]))
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
418
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
419
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 ;;; font-lock
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 (defcustom antlr-font-lock-maximum-decoration 'inherit
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
425 "*The maximum decoration level for fontifying actions.
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
426 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
427 according to `antlr-font-lock-additional-keywords'. Value `inherit'
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
428 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
429 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
430 fontification, see `antlr-font-lock-keywords-alist'.
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 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
433 bound to `antlr-language'. For example, with value
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
434 ((java-mode . 2) (c++-mode . 0))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
435 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
436 fontified at all."
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
437 :type '(choice (const :tag "none" none)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
438 (const :tag "inherit" inherit)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
439 (const :tag "default" nil)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
440 (const :tag "maximum" t)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
441 (integer :tag "level" 1)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
442 (repeat :menu-tag "mode specific" :tag "mode specific"
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
443 :value ((t . t))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
444 (cons :tag "Instance"
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
445 (radio :tag "Mode"
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
446 (const :tag "all" t)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
447 (symbol :tag "name"))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
448 (radio :tag "Decoration"
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
449 (const :tag "default" nil)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
450 (const :tag "maximum" t)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
451 (integer :tag "level" 1))))))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
452
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
453 (defconst antlr-no-action-keywords nil
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
454 ;; Using nil directly won't work (would use highest level, see
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
455 ;; `font-lock-choose-keywords'), but a non-symbol, i.e., (list), at `car'
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
456 ;; would break Emacs-21.0:
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
457 "Empty font-lock keywords for actions.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
458 Do not change the value of this constant.")
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
459
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
460 (defvar antlr-font-lock-keywords-alist
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
461 '((java-mode
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
462 antlr-no-action-keywords
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
463 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
464 java-font-lock-keywords-3)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
465 (c++-mode
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
466 antlr-no-action-keywords
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
467 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
468 c++-font-lock-keywords-3))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
469 "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
470 Each element in this list looks like
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
471 (MAJOR-MODE KEYWORD...)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
472
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
473 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
474 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
475 in the grammar's actions and semantic predicates, see
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
476 `antlr-font-lock-maximum-decoration'.")
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
477
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
478 (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
479 (defface antlr-font-lock-keyword-face
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
480 '((((class color) (background light)) (:foreground "black" :bold t)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
481 "ANTLR keywords."
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
482 :group 'antlr)
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 (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
485 (defface antlr-font-lock-ruledef-face
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
486 '((((class color) (background light)) (:foreground "blue" :bold t)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
487 "ANTLR rule references (definition)."
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
488 :group 'antlr)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
489
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
490 (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
491 (defface antlr-font-lock-tokendef-face
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
492 '((((class color) (background light)) (:foreground "blue" :bold t)))
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
493 "ANTLR token references (definition)."
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
494 :group 'antlr)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
495
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
496 (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
497 (defface antlr-font-lock-ruleref-face
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
498 '((((class color) (background light)) (:foreground "blue4")))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
499 "ANTLR rule references (usage)."
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
500 :group 'antlr)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
501
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
502 (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
503 (defface antlr-font-lock-tokenref-face
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
504 '((((class color) (background light)) (:foreground "orange4")))
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
505 "ANTLR token references (usage)."
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
506 :group 'antlr)
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 (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
509 (defface antlr-font-lock-literal-face
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
510 '((((class color) (background light)) (:foreground "brown4" :bold t)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
511 "ANTLR literal tokens consisting merely of letter-like characters."
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
512 :group 'antlr)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
513
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
514 (defvar antlr-font-lock-additional-keywords
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
515 `((antlr-invalidate-context-cache)
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
516 ("\\$setType[ \t]*(\\([A-Za-z\300-\326\330-\337]\\sw*\\))"
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
517 (1 antlr-font-lock-tokendef-face))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
518 ("\\$\\sw+" (0 font-lock-keyword-face))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
519 ;; the tokens are already fontified as string/docstrings:
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
520 (,(lambda (limit)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
521 (antlr-re-search-forward "\"\\(\\sw\\(\\sw\\|-\\)*\\)\"" limit))
29289
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
522 (1 antlr-font-lock-literal-face t)
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
523 ,@(and (string-match "XEmacs" emacs-version)
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
524 '((0 nil)))) ; XEmacs bug workaround
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
525 (,(lambda (limit)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
526 (antlr-re-search-forward
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
527 "^\\(class\\)[ \t]+\\([A-Za-z\300-\326\330-\337]\\sw*\\)[ \t]+\\(extends\\)[ \t]+\\([A-Za-z\300-\326\330-\337]\\sw*\\)[ \t]*;" limit))
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
528 (1 antlr-font-lock-keyword-face)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
529 (2 antlr-font-lock-ruledef-face)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
530 (3 antlr-font-lock-keyword-face)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
531 (4 (if (member (match-string 4) '("Lexer" "Parser" "TreeParser"))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
532 'antlr-font-lock-keyword-face
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
533 'font-lock-type-face)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
534 (,(lambda (limit)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
535 (antlr-re-search-forward
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
536 "\\<\\(header\\|options\\|tokens\\|exception\\|catch\\|returns\\)\\>"
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
537 limit))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
538 (1 antlr-font-lock-keyword-face))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
539 (,(lambda (limit)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
540 (antlr-re-search-forward
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
541 "^\\(private\\|public\\|protected\\)\\>\\([ \t]+\\(\\sw+\\)\\)?"
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
542 limit))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
543 (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
544 (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
545 'antlr-font-lock-tokendef-face
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
546 'antlr-font-lock-ruledef-face) nil t))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
547 (,(lambda (limit)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
548 (antlr-re-search-forward "^\\sw+" limit))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
549 (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
550 'antlr-font-lock-tokendef-face
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
551 'antlr-font-lock-ruledef-face) nil t))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
552 (,(lambda (limit)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
553 ;; 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
554 (antlr-re-search-forward "\\<\\(\\sw+\\)[ \t]*:" limit))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
555 (1 font-lock-variable-name-face))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
556 (,(lambda (limit)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
557 (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
558 ;;(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
559 (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
560 'antlr-font-lock-tokenref-face
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
561 'antlr-font-lock-ruleref-face))))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
562 "Font-lock keywords for ANTLR's normal grammar code.
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
563 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
564
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
565 (defvar antlr-font-lock-defaults
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
566 '(antlr-font-lock-keywords
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
567 nil nil ((?_ . "w") (?\( . ".") (?\) . ".")) beginning-of-defun)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
568 "Font-lock defaults used for ANTLR syntax coloring.
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
569 The SYNTAX-ALIST element is also used to initialize
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
570 `antlr-action-syntax-table'.")
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
571
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
572
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
573 ;;;===========================================================================
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
574 ;;; Internal variables
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
575 ;;;===========================================================================
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
576
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
577 (defvar antlr-mode-hook nil
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
578 "Hook called by `antlr-mode'.")
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
579
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
580 (defvar antlr-mode-syntax-table nil
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
581 "Syntax table used in `antlr-mode' buffers.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
582 If non-nil, it will be initialized in `antlr-mode'.")
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
583
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
584 ;; used for "in Java/C++ code" = syntactic-depth>0
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
585 (defvar antlr-action-syntax-table nil
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
586 "Syntax table used for ANTLR action parsing.
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
587 Initialized by `antlr-mode-syntax-table', changed by SYNTAX-ALIST in
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
588 `antlr-font-lock-defaults'. This table should be selected if you use
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
589 `buffer-syntactic-context' and `buffer-syntactic-context-depth' in order
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
590 not to confuse their context_cache.")
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
591
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
592 (defvar antlr-mode-abbrev-table nil
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
593 "Abbreviation table used in `antlr-mode' buffers.")
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
594 (define-abbrev-table 'antlr-mode-abbrev-table ())
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
595
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
596
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
597
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
598 ;;;;##########################################################################
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
599 ;;;; The Code
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
600 ;;;;##########################################################################
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
601
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
602
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
603 ;;;===========================================================================
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
604 ;;; Syntax functions -- Emacs vs XEmacs dependent
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
605 ;;;===========================================================================
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
606
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
607 ;; From help.el (XEmacs-21.1), without `copy-syntax-table'
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
608 (defmacro antlr-with-syntax-table (syntab &rest body)
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
609 "Evaluate BODY with the syntax table SYNTAB."
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
610 `(let ((stab (syntax-table)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
611 (unwind-protect
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
612 (progn (set-syntax-table ,syntab) ,@body)
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
613 (set-syntax-table stab))))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
614 (put 'antlr-with-syntax-table 'lisp-indent-function 1)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
615 (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
616
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
617 (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
618 ;; checkdoc-params: (from count dummy)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
619 "Like `scan-sexps' but with additional arguments.
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
620 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
621 instead of signaling an error."
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
622 (if no-error
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
623 (condition-case nil
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
624 (scan-sexps from count)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
625 (t nil))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
626 (scan-sexps from count)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
627
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
628 (defun antlr-xemacs-bug-workaround (&rest dummies)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
629 ;; checkdoc-params: (dummies)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
630 "Invalidate context_cache for syntactical context information."
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
631 ;; XEmacs bug workaround
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
632 (save-excursion
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
633 (set-buffer (get-buffer-create " ANTLR XEmacs bug workaround"))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
634 (buffer-syntactic-context-depth))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
635 nil)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
636
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
637 (defun antlr-fast-syntactic-context ()
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
638 "Return some syntactic context information.
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
639 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
640 `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
641 parenthesis-syntax delimiters at point otherwise.
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
642 WARNING: this may alter `match-data'."
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
643 (or (buffer-syntactic-context) (buffer-syntactic-context-depth)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
644
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
645 (defun antlr-slow-syntactic-context ()
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
646 "Return some syntactic context information.
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
647 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
648 `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
649 parenthesis-syntax delimiters at point otherwise.
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
650 WARNING: this may alter `match-data'."
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
651 (let ((orig (point)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
652 (beginning-of-defun)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
653 (let ((state (parse-partial-sexp (point) orig)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
654 (goto-char orig)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
655 (cond ((nth 3 state) 'string)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
656 ((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
657 (t (car state))))))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
658
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 ;;;===========================================================================
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
661 ;;; Misc functions
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
662 ;;;===========================================================================
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
663
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
664 (defun antlr-upcase-p (char)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
665 "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
666 ;; in XEmacs, upcase only works for ASCII
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
667 (or (and (<= ?A char) (<= char ?Z))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
668 (and (<= ?\300 char) (<= char ?\337)))) ; ?\327 is no letter
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
669
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
670 (defun antlr-re-search-forward (regexp bound)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
671 "Search forward from point for regular expression REGEXP.
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
672 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
673 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
674 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
675 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
676 and `replace-match'."
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
677 ;; 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
678 (let ((continue t))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
679 (while (and (re-search-forward regexp bound 'limit)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
680 (save-match-data
29289
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
681 (if (eq (antlr-syntactic-context) 0)
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
682 (setq continue nil)
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
683 t))))
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
684 (if continue nil (point))))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
685
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
686 (defun antlr-search-forward (string)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
687 "Search forward from point for STRING.
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
688 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
689 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
690 and actions/semantic predicates."
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
691 ;; 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
692 (let ((continue t))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
693 (while (and (search-forward string nil 'limit)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
694 (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
695 (if continue nil (point))))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
696
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
697 (defun antlr-search-backward (string)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
698 "Search backward from point for STRING.
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
699 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
700 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
701 strings and actions/semantic predicates."
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
702 ;; 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
703 (let ((continue t))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
704 (while (and (search-backward string nil 'limit)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
705 (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
706 (if continue nil (point))))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
707
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
708 (defsubst antlr-skip-sexps (count)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
709 "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
710 Return position before the comments after the last expression."
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
711 (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
712 (prog1 (point)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
713 (c-forward-syntactic-ws)))
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 ;;;===========================================================================
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
717 ;;; font-lock
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
718 ;;;===========================================================================
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-font-lock-keywords ()
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
721 "Return font-lock keywords for current buffer.
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
722 See `antlr-font-lock-additional-keywords', `antlr-language' and
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
723 `antlr-font-lock-maximum-decoration'."
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
724 (if (eq antlr-font-lock-maximum-decoration 'none)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
725 antlr-font-lock-additional-keywords
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
726 (append antlr-font-lock-additional-keywords
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
727 (eval (let ((major-mode antlr-language)) ; dynamic
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
728 (font-lock-choose-keywords
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
729 (cdr (assq antlr-language
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
730 antlr-font-lock-keywords-alist))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
731 (if (eq antlr-font-lock-maximum-decoration 'inherit)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
732 font-lock-maximum-decoration
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
733 antlr-font-lock-maximum-decoration)))))))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
734
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
735
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
736 ;;;===========================================================================
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
737 ;;; imenu support
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
738 ;;;===========================================================================
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
739
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
740 (defun antlr-imenu-create-index-function ()
26965
048db40ddca6 Version 1.2 is released.
Gerd Moellmann <gerd@gnu.org>
parents: 26542
diff changeset
741 "Return imenu index-alist for ANTLR grammar files."
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
742 (let ((items nil)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
743 (classes nil)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
744 (semi (point-max)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
745 ;; Using `imenu-progress-message' would require imenu for compilation --
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
746 ;; nobody is missing these messages...
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
747 (antlr-with-syntax-table antlr-action-syntax-table
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
748 ;; 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
749 ;; 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
750 ;; 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
751 (while semi
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
752 (goto-char semi)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
753 (if (setq semi (antlr-search-backward ";"))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
754 (progn (forward-char) (antlr-skip-exception-part t))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
755 (antlr-skip-file-prelude t))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
756 (if (looking-at "{") (antlr-skip-sexps 1))
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
757 (if (looking-at "class[ \t]+\\([A-Za-z\300-\326\330-\337]\\sw*\\)[ \t]+extends[ \t]+\\([A-Za-z\300-\326\330-\337]\\sw*\\)[ \t]*;")
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
758 (push (cons (match-string 1)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
759 (if imenu-use-markers
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
760 (copy-marker (match-beginning 1))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
761 (match-beginning 1)))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
762 classes)
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
763 (if (looking-at "p\\(ublic\\|rotected\\|rivate\\)")
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
764 (antlr-skip-sexps 1))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
765 (when (looking-at "\\sw+")
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
766 (push (cons (match-string 0)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
767 (if imenu-use-markers
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
768 (copy-marker (match-beginning 0))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
769 (match-beginning 0)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
770 items)))))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
771 (if classes (cons (cons "Classes" classes) items) items)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
772
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
773
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
774 ;;;===========================================================================
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
775 ;;; Parse grammar files (internal functions)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
776 ;;;===========================================================================
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
777
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
778 (defun antlr-skip-exception-part (skip-comment)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
779 "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
780 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
781 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
782 part."
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
783 (let ((pos (point))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
784 (class nil))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
785 (c-forward-syntactic-ws)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
786 (while (looking-at "options\\>\\|tokens\\>")
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
787 (setq class t)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
788 (setq pos (antlr-skip-sexps 2)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
789 (if class
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
790 ;; 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
791 ;; 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
792 ;; 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
793 (if (looking-at "{") (setq pos (antlr-skip-sexps 1)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
794 (while (looking-at "exception\\>")
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
795 (setq pos (antlr-skip-sexps 1))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
796 (if (looking-at "\\[") (setq pos (antlr-skip-sexps 1)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
797 (while (looking-at "catch\\>")
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
798 (setq pos (antlr-skip-sexps 3)))))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
799 (or skip-comment (goto-char pos))))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
800
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
801 (defun antlr-skip-file-prelude (skip-comment)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
802 "Skip the file prelude: the header and file options.
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
803 If SKIP-COMMENT is non-nil, also skip the comment after that part.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
804 Return the start position of the file prelude."
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
805 (let* ((pos (point))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
806 (pos0 pos))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
807 (c-forward-syntactic-ws)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
808 (if skip-comment (setq pos0 (point)))
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
809 (while (looking-at "header\\>[ \t]*\\(\"\\)?")
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
810 (setq pos (antlr-skip-sexps (if (match-beginning 1) 3 2))))
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
811 (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
812 (or skip-comment (goto-char pos))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
813 pos0))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
814
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
815 (defun antlr-next-rule (arg skip-comment)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
816 "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
817 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
818 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
819 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
820 is non-nil, move to beginning of the rule."
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
821 ;; 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
822 ;; PRE: ARG<>0
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
823 (let ((pos (point))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
824 (beg (point)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
825 ;; first look whether point is in exception part
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
826 (if (antlr-search-backward ";")
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
827 (progn
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
828 (setq beg (point))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
829 (forward-char)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
830 (antlr-skip-exception-part skip-comment))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
831 (antlr-skip-file-prelude skip-comment))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
832 (if (< arg 0)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
833 (unless (and (< (point) pos) (zerop (incf arg)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
834 ;; 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
835 (goto-char beg) ; rewind (to ";" / point)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
836 (while (and arg (<= (incf arg) 0))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
837 (if (antlr-search-backward ";")
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
838 (setq beg (point))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
839 (when (>= arg -1)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
840 ;; try file prelude:
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
841 (setq pos (antlr-skip-file-prelude skip-comment))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
842 (if (zerop arg)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
843 (if (>= (point) beg)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
844 (goto-char (if (>= pos beg) (point-min) pos)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
845 (goto-char (if (or (>= (point) beg) (= (point) pos))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
846 (point-min) pos))))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
847 (setq arg nil)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
848 (when arg ; always found a ";"
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
849 (forward-char)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
850 (antlr-skip-exception-part skip-comment)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
851 (if (<= (point) pos) ; moved backward?
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
852 (goto-char pos) ; rewind
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
853 (decf arg)) ; already moved one defun forward
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
854 (unless (zerop arg)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
855 (while (>= (decf arg) 0)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
856 (antlr-search-forward ";"))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
857 (antlr-skip-exception-part skip-comment)))))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
858
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
859 (defun antlr-outside-rule-p ()
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
860 "Non-nil if point is outside a grammar rule.
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
861 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
862 ;; 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
863 (let ((pos (point)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
864 (antlr-next-rule -1 nil)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
865 (let ((between (or (bobp) (< (point) pos))))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
866 (c-forward-syntactic-ws)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
867 (and between (> (point) pos) (goto-char pos)))))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
868
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
869
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
870 ;;;===========================================================================
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
871 ;;; Parse grammar files (commands)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
872 ;;;===========================================================================
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
873 ;; No (interactive "_") in Emacs... use `zmacs-region-stays'.
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
874
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
875 (defun antlr-inside-rule-p ()
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
876 "Non-nil if point is inside a grammar rule.
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
877 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
878 rule."
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
879 (save-excursion
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
880 (antlr-with-syntax-table antlr-action-syntax-table
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
881 (not (antlr-outside-rule-p)))))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
882
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
883 (defun antlr-end-of-rule (&optional arg)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
884 "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
885 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
886 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
887 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
888 (interactive "p")
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
889 (if (zerop arg)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
890 (antlr-end-of-body)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
891 (antlr-with-syntax-table antlr-action-syntax-table
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
892 (antlr-next-rule arg nil))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
893 (setq zmacs-region-stays t)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
894
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
895 (defun antlr-beginning-of-rule (&optional arg)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
896 "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
897 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
898 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
899 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
900 (interactive "p")
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
901 (if (zerop arg)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
902 (antlr-beginning-of-body)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
903 (antlr-with-syntax-table antlr-action-syntax-table
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
904 (antlr-next-rule (- arg) t))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
905 (setq zmacs-region-stays t)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
906
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
907 (defun antlr-end-of-body (&optional msg)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
908 "Move to position after the `;' of the current rule.
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
909 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
910 prefix arg MSG, move to `:'."
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
911 (interactive)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
912 (antlr-with-syntax-table antlr-action-syntax-table
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
913 (let ((orig (point)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
914 (if (antlr-outside-rule-p)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
915 (error "Outside an ANTLR rule"))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
916 (let ((bor (point)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
917 (when (< (antlr-skip-file-prelude t) (point))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
918 ;; Yes, we are in the file prelude
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
919 (goto-char orig)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
920 (error (or msg "The file prelude is without `;'")))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
921 (antlr-search-forward ";")
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
922 (when msg
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
923 (when (< (point)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
924 (progn (goto-char bor)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
925 (or (antlr-search-forward ":") (point-max))))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
926 (goto-char orig)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
927 (error msg))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
928 (c-forward-syntactic-ws)))))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
929 (setq zmacs-region-stays t))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
930
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
931 (defun antlr-beginning-of-body ()
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
932 "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
933 (interactive)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
934 (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
935
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
936
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
937 ;;;===========================================================================
29289
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
938 ;;; Literal normalization, Hide Actions
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
939 ;;;===========================================================================
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
940
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
941 (defun antlr-downcase-literals (&optional transform)
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
942 "Convert all literals in buffer to lower case.
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
943 If non-nil, TRANSFORM is used on literals instead of `downcase-region'."
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
944 (interactive)
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
945 (or transform (setq transform 'downcase-region))
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
946 (let ((literals 0))
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
947 (save-excursion
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
948 (goto-char (point-min))
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
949 (antlr-with-syntax-table antlr-action-syntax-table
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
950 (antlr-invalidate-context-cache)
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
951 (while (antlr-re-search-forward "\"\\(\\sw\\(\\sw\\|-\\)*\\)\"" nil)
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
952 (funcall transform (match-beginning 0) (match-end 0))
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
953 (incf literals))))
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
954 (message "Transformed %d literals" literals)))
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
955
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
956 (defun antlr-upcase-literals ()
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
957 "Convert all literals in buffer to upper case."
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
958 (interactive)
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
959 (antlr-downcase-literals 'upcase-region))
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
960
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
961 (defun antlr-hide-actions (arg &optional silent)
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
962 "Hide or unhide all actions in buffer.
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
963 Hide all actions including arguments in brackets if ARG is 1 or if
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
964 called interactively without prefix argument. Hide all actions
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
965 excluding arguments in brackets if ARG is 2 or higher. Unhide all
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
966 actions if ARG is 0 or negative. See `antlr-action-visibility'.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
967
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
968 Display a message unless optional argument SILENT is non-nil."
29289
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
969 (interactive "p")
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
970 ;; from Emacs/lazy-lock: `save-buffer-state'
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
971 (let ((modified (buffer-modified-p))
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
972 (buffer-undo-list t) (inhibit-read-only t)
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
973 (inhibit-point-motion-hooks t) deactivate-mark ; Emacs only
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
974 before-change-functions after-change-functions
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
975 buffer-file-name buffer-file-truename)
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
976 (if (> arg 0)
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
977 (let ((regexp (if (= arg 1) "[]}]" "}"))
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
978 (diff (and antlr-action-visibility
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
979 (+ (max antlr-action-visibility 0) 2))))
29289
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
980 (antlr-hide-actions 0 t)
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
981 (save-excursion
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
982 (goto-char (point-min))
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
983 (antlr-with-syntax-table antlr-action-syntax-table
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
984 (antlr-invalidate-context-cache)
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
985 (while (antlr-re-search-forward regexp nil)
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
986 (let ((beg (antlr-scan-sexps (point) -1 nil t)))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
987 (when beg
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
988 (if diff ; braces are visible
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
989 (if (> (point) (+ beg diff))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
990 (add-text-properties (1+ beg) (1- (point))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
991 '(invisible t intangible t)))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
992 ;; if actions is on line(s) of its own, hide WS
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
993 (and (looking-at "[ \t]*$")
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
994 (save-excursion
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
995 (goto-char beg)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
996 (skip-chars-backward " \t")
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
997 (and (bolp) (setq beg (point))))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
998 (beginning-of-line 2)) ; beginning of next line
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
999 (add-text-properties beg (point)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1000 '(invisible t intangible t))))))))
29289
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
1001 (or silent
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
1002 (message "Hide all actions (%s arguments)...done"
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
1003 (if (= arg 1) "including" "excluding"))))
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
1004 (remove-text-properties (point-min) (point-max)
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
1005 '(invisible nil intangible nil))
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
1006 (or silent
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
1007 (message "Unhide all actions (including arguments)...done")))
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
1008 (and (not modified) (buffer-modified-p)
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
1009 (set-buffer-modified-p nil))))
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
1010
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
1011
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
1012 ;;;===========================================================================
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1013 ;;; Compute dependencies
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1014 ;;;===========================================================================
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1015
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1016 (defun antlr-file-dependencies ()
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1017 "Return dependencies for grammar in current buffer.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1018 The result looks like (FILE (CLASSES . SUPERS) VOCABS . LANGUAGE)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1019 where CLASSES = ((CLASS . CLASS-EVOCAB) ...),
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1020 SUPERS = ((SUPER . USE-EVOCAB-P) ...), and
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1021 VOCABS = ((EVOCAB ...) . (IVOCAB ...))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1022
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1023 FILE is the current buffer's file-name without directory part and
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1024 LANGUAGE is the value of `antlr-language' in the current buffer. Each
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1025 EVOCAB is an export vocabulary and each IVOCAB is an import vocabulary.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1026
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1027 Each CLASS is a grammar class with its export vocabulary CLASS-EVOCAB.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1028 Each SUPER is a super-grammar class where USE-EVOCAB-P indicates whether
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1029 its export vocabulary is used as an import vocabulary."
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1030 (unless buffer-file-name
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1031 (error "Grammar buffer does not visit a file"))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1032 (let (classes exportVocabs importVocabs superclasses default-vocab)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1033 (antlr-with-syntax-table antlr-action-syntax-table
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1034 (goto-char (point-min))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1035 (while (antlr-re-search-forward "class[ \t]+\\([A-Za-z\300-\326\330-\337]\\sw*\\)[ \t]+extends[ \t]+\\([A-Za-z\300-\326\330-\337]\\sw*\\)[ \t]*;" nil)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1036 ;; parse class definition --------------------------------------------
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1037 (let* ((class (match-string 1))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1038 (sclass (match-string 2))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1039 ;; export vocab defaults to class name (first grammar in file)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1040 ;; or to the export vocab of the first grammar in file:
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1041 (evocab (or default-vocab class))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1042 (ivocab nil))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1043 (goto-char (match-end 0))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1044 (c-forward-syntactic-ws)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1045 (while (looking-at "options\\>\\|\\(tokens\\)\\>")
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1046 (if (match-beginning 1)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1047 (antlr-skip-sexps 2)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1048 (goto-char (match-end 0))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1049 (c-forward-syntactic-ws)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1050 ;; parse grammar option section --------------------------------
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1051 (when (eq (char-after (point)) ?\{)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1052 (let* ((beg (1+ (point)))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1053 (end (1- (antlr-skip-sexps 1)))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1054 (cont (point)))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1055 (goto-char beg)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1056 (if (re-search-forward "\\<exportVocab[ \t]*=[ \t]*\\([A-Za-z\300-\326\330-\337]\\sw*\\)" end t)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1057 (setq evocab (match-string 1)))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1058 (goto-char beg)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1059 (if (re-search-forward "\\<importVocab[ \t]*=[ \t]*\\([A-Za-z\300-\326\330-\337]\\sw*\\)" end t)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1060 (setq ivocab (match-string 1)))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1061 (goto-char cont)))))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1062 (unless (member sclass '("Parser" "Lexer" "TreeParser"))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1063 (let ((super (assoc sclass superclasses)))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1064 (if super
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1065 (or ivocab (setcdr super t))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1066 (push (cons sclass (null ivocab)) superclasses))))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1067 ;; remember class with export vocabulary:
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1068 (push (cons class evocab) classes)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1069 ;; default export vocab is export vocab of first grammar in file:
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1070 (or default-vocab (setq default-vocab evocab))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1071 (or (member evocab exportVocabs) (push evocab exportVocabs))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1072 (or (null ivocab)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1073 (member ivocab importVocabs) (push ivocab importVocabs)))))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1074 (if classes
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1075 (list* (file-name-nondirectory buffer-file-name)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1076 (cons (nreverse classes) (nreverse superclasses))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1077 (cons (nreverse exportVocabs) (nreverse importVocabs))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1078 antlr-language))))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1079
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1080 (defun antlr-directory-dependencies (dirname)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1081 "Return dependencies for all grammar files in directory DIRNAME.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1082 The result looks like ((CLASS-SPEC ...) . (FILE-DEP ...))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1083 where CLASS-SPEC = (CLASS (FILE . EVOCAB) ...).
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1084
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1085 FILE-DEP are the dependencies for each grammar file in DIRNAME, see
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1086 `antlr-file-dependencies'. For each grammar class CLASS, FILE is a
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1087 grammar file in which CLASS is defined and EVOCAB is the name of the
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1088 export vocabulary specified in that file."
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1089 (let ((grammar (directory-files dirname t "\\.g\\'")))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1090 (when grammar
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1091 (let ((temp-buffer (get-buffer-create
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1092 (generate-new-buffer-name " *temp*")))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1093 (antlr-imenu-name nil) ; dynamic-let: no imenu
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1094 (expanded-regexp (concat (format (regexp-quote
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1095 (cadr antlr-special-file-formats))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1096 ".+")
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1097 "\\'"))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1098 classes dependencies)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1099 (unwind-protect
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1100 (save-excursion
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1101 (set-buffer temp-buffer)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1102 (widen) ; just in case...
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1103 (dolist (file grammar)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1104 (when (and (file-regular-p file)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1105 (null (string-match expanded-regexp file)))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1106 (insert-file-contents file t nil nil t)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1107 (normal-mode t) ; necessary for major-mode, syntax
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1108 ; table and `antlr-language'
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1109 (when (eq major-mode 'antlr-mode)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1110 (let* ((file-deps (antlr-file-dependencies))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1111 (file (car file-deps)))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1112 (when file-deps
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1113 (dolist (class-def (caadr file-deps))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1114 (let ((file-evocab (cons file (cdr class-def)))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1115 (class-spec (assoc (car class-def) classes)))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1116 (if class-spec
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1117 (nconc (cdr class-spec) (list file-evocab))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1118 (push (list (car class-def) file-evocab)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1119 classes))))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1120 (push file-deps dependencies)))))))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1121 (kill-buffer temp-buffer))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1122 (cons (nreverse classes) (nreverse dependencies))))))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1123
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1124
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1125 ;;;===========================================================================
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1126 ;;; Compilation: run ANTLR tool
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1127 ;;;===========================================================================
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1128
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1129 (defun antlr-superclasses-glibs (supers classes)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1130 "Compute the grammar lib option for the super grammars SUPERS.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1131 Look in CLASSES for the right grammar lib files for SUPERS. SUPERS is
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1132 part SUPER in the result of `antlr-file-dependencies'. CLASSES is the
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1133 part (CLASS-SPEC ...) in the result of `antlr-directory-dependencies'.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1134
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1135 The result looks like (OPTION WITH-UNKNOWN GLIB ...). OPTION is the
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1136 complete \"-glib\" option. WITH-UNKNOWN has value t iff there is none
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1137 or more than one grammar file for at least one super grammar.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1138
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1139 Each GLIB looks like (GRAMMAR-FILE . EVOCAB). GRAMMAR-FILE is a file in
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1140 which a super-grammar is defined. EVOCAB is the value of the export
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1141 vocabulary of the super-grammar or nil if it is not needed."
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1142 ;; If the superclass is defined in the same file, that file will be included
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1143 ;; with -glib again. This will lead to a redefinition. But defining a
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1144 ;; analyzer of the same class twice in a file will lead to an error anyway...
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1145 (let (glibs unknown)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1146 (while supers
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1147 (let* ((super (pop supers))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1148 (sup-files (cdr (assoc (car super) classes)))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1149 (file (and sup-files (null (cdr sup-files)) (car sup-files))))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1150 (or file (setq unknown t)) ; not exactly one file
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1151 (push (cons (or (car file)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1152 (format (car antlr-unknown-file-formats)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1153 (car super)))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1154 (and (cdr super)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1155 (or (cdr file)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1156 (format (cadr antlr-unknown-file-formats)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1157 (car super)))))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1158 glibs)))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1159 (cons (if glibs (concat " -glib " (mapconcat 'car glibs ";")) "")
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1160 (cons unknown glibs))))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1161
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1162 (defun antlr-run-tool (command file &optional saved)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1163 "Run Antlr took COMMAND on grammar FILE.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1164 When called interactively, COMMAND is read from the minibuffer and
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1165 defaults to `antlr-tool-command' with a computed \"-glib\" option if
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1166 necessary.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1167
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1168 Save all buffers first unless optional value SAVED is non-nil. When
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1169 called interactively, the buffers are always saved, see also variable
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1170 `antlr-ask-about-save'."
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1171 (interactive
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1172 ;; code in `interactive' is not compiled: do not use cl macros (`cdadr')
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1173 (let* ((supers (cdr (cadr (save-excursion
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1174 (save-restriction
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1175 (widen)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1176 (antlr-file-dependencies))))))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1177 (glibs ""))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1178 (when supers
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1179 (save-some-buffers (not antlr-ask-about-save) nil)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1180 (setq glibs (car (antlr-superclasses-glibs
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1181 supers
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1182 (car (antlr-directory-dependencies
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1183 (antlr-default-directory)))))))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1184 (list (antlr-read-shell-command "Run Antlr on current file with: "
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1185 (concat antlr-tool-command glibs " "))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1186 buffer-file-name
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1187 supers)))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1188 (or saved (save-some-buffers (not antlr-ask-about-save)))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1189 (let ((default-directory (file-name-directory file)))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1190 (require 'compile) ; only `compile' autoload
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1191 (compile-internal (concat command " " (file-name-nondirectory file))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1192 "No more errors" "Antlr-Run")))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1193
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1194
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1195 ;;;===========================================================================
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1196 ;;; Makefile creation
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1197 ;;;===========================================================================
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1198
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1199 (defun antlr-makefile-insert-variable (number pre post)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1200 "Insert Makefile variable numbered NUMBER according to specification.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1201 Also insert strings PRE and POST before and after the variable."
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1202 (let ((spec (cadr antlr-makefile-specification)))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1203 (when spec
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1204 (insert pre
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1205 (if number (format (cadr spec) number) (car spec))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1206 post))))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1207
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1208 (defun antlr-insert-makefile-rules (&optional in-makefile)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1209 "Insert Makefile rules in the current buffer at point.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1210 IN-MAKEFILE is non-nil, if the current buffer is the Makefile. See
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1211 command `antlr-show-makefile-rules' for detail."
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1212 (let* ((dirname (antlr-default-directory))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1213 (deps0 (antlr-directory-dependencies dirname))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1214 (classes (car deps0)) ; CLASS -> (FILE . EVOCAB) ...
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1215 (deps (cdr deps0)) ; FILE -> (c . s) (ev . iv) . LANGUAGE
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1216 (with-error nil)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1217 (gen-sep (or (caddr (cadr antlr-makefile-specification)) " "))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1218 (n (and (cdr deps) (cadr antlr-makefile-specification) 0)))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1219 (or in-makefile (set-buffer standard-output))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1220 (dolist (dep deps)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1221 (let ((supers (cdadr dep))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1222 (lang (cdr (assoc (cdddr dep) antlr-file-formats-alist))))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1223 (if n (incf n))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1224 (antlr-makefile-insert-variable n "" " =")
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1225 (if supers
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1226 (insert " "
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1227 (format (cadr antlr-special-file-formats)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1228 (file-name-sans-extension (car dep)))))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1229 (dolist (class-def (caadr dep))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1230 (let ((sep gen-sep))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1231 (dolist (class-file (cadr lang))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1232 (insert sep (format class-file (car class-def)))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1233 (setq sep " "))))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1234 (dolist (evocab (caaddr dep))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1235 (let ((sep gen-sep))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1236 (dolist (vocab-file (cons (car antlr-special-file-formats)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1237 (car lang)))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1238 (insert sep (format vocab-file evocab))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1239 (setq sep " "))))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1240 (antlr-makefile-insert-variable n "\n$(" ")")
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1241 (insert ": " (car dep))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1242 (dolist (ivocab (cdaddr dep))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1243 (insert " " (format (car antlr-special-file-formats) ivocab)))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1244 (let ((glibs (antlr-superclasses-glibs supers classes)))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1245 (if (cadr glibs) (setq with-error t))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1246 (dolist (super (cddr glibs))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1247 (insert " " (car super))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1248 (if (cdr super)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1249 (insert " " (format (car antlr-special-file-formats)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1250 (cdr super)))))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1251 (insert "\n\t"
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1252 (caddr antlr-makefile-specification)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1253 (car glibs)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1254 " $<\n"
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1255 (car antlr-makefile-specification)))))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1256 (if n
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1257 (let ((i 0))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1258 (antlr-makefile-insert-variable nil "" " =")
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1259 (while (<= (incf i) n)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1260 (antlr-makefile-insert-variable i " $(" ")"))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1261 (insert "\n" (car antlr-makefile-specification))))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1262 (if (string-equal (car antlr-makefile-specification) "\n")
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1263 (backward-delete-char 1))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1264 (when with-error
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1265 (goto-char (point-min))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1266 (insert antlr-help-unknown-file-text))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1267 (unless in-makefile
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1268 (copy-region-as-kill (point-min) (point-max))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1269 (goto-char (point-min))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1270 (insert (format antlr-help-rules-intro dirname)))))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1271
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1272 ;;;###autoload
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1273 (defun antlr-show-makefile-rules ()
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1274 "Show Makefile rules for all grammar files in the current directory.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1275 If the `major-mode' of the current buffer has the value `makefile-mode',
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1276 the rules are directory inserted at point. Otherwise, a *Help* buffer
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1277 is shown with the rules which are also put into the `kill-ring' for
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1278 \\[yank].
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1279
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1280 This command considers import/export vocabularies and grammar
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1281 inheritance and provides a value for the \"-glib\" option if necessary.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1282 Customize variable `antlr-makefile-specification' for the appearance of
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1283 the rules.
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1284
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1285 If the file for a super-grammar cannot be determined, special file names
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1286 are used according to variable `antlr-unknown-file-formats' and a
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1287 commentary with value `antlr-help-unknown-file-text' is added. The
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1288 *Help* buffer always starts with the text in `antlr-help-rules-intro'."
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1289 (interactive)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1290 (if (null (eq major-mode 'makefile-mode))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1291 (antlr-with-displaying-help-buffer 'antlr-insert-makefile-rules)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1292 (push-mark)
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1293 (antlr-insert-makefile-rules t)))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1294
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1295
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1296 ;;;===========================================================================
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1297 ;;; Indentation
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1298 ;;;===========================================================================
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1299
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1300 (defun antlr-indent-line ()
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1301 "Indent the current line as ANTLR grammar code.
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1302 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
1303 multiplied by:
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1304 - the level of the paren/brace/bracket depth,
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1305 - 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
1306 exception part,
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1307 - 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
1308 line starting from the first non-blank.
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1309
26965
048db40ddca6 Version 1.2 is released.
Gerd Moellmann <gerd@gnu.org>
parents: 26542
diff changeset
1310 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
1311 `c-indent-line', see `antlr-indent-comment'."
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1312 (let ((orig (point)) bol boi indent syntax)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1313 (beginning-of-line)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1314 (setq bol (point))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1315 (skip-chars-forward " \t")
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1316 (setq boi (point))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1317 ;; check syntax at beginning of indentation ------------------------------
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1318 (antlr-with-syntax-table antlr-action-syntax-table
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1319 (antlr-invalidate-context-cache)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1320 (cond ((symbolp (setq syntax (antlr-syntactic-context)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1321 (setq indent nil)) ; block-comments, strings, (comments)
29289
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
1322 ((eq (char-after) ?#) ; cpp directive
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
1323 (setq syntax 'cpp)
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
1324 (setq indent 0)) ; indentation at 0
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1325 ((progn
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1326 (antlr-next-rule -1 t)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1327 (if (antlr-search-forward ":") (< boi (1- (point))) t))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1328 (setq indent 0)) ; in rule header
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1329 ((if (antlr-search-forward ";") (< boi (point)) t)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1330 (setq indent 2)) ; in rule body
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1331 (t
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1332 (forward-char)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1333 (antlr-skip-exception-part nil)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1334 (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
1335 ;; compute the corresponding indentation and indent ----------------------
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1336 (if (null indent)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1337 (progn
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1338 (goto-char orig)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1339 (and (eq antlr-indent-comment t)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1340 (not (eq syntax 'string))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1341 (c-indent-line)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1342 ;; do it ourselves
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1343 (goto-char boi)
29289
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
1344 (unless (symbolp syntax) ; direct indentation
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
1345 (antlr-invalidate-context-cache)
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
1346 (incf indent (antlr-syntactic-context))
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
1347 (and (> indent 0) (looking-at antlr-indent-item-regexp) (decf indent))
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
1348 (setq indent (* indent c-basic-offset)))
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1349 ;; the usual major-mode indent stuff -----------------------------------
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1350 (setq orig (- (point-max) orig))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1351 (unless (= (current-column) indent)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1352 (delete-region bol boi)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1353 (beginning-of-line)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1354 (indent-to indent))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1355 ;; If initial point was within line's indentation,
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1356 ;; 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
1357 (if (> (- (point-max) orig) (point))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1358 (goto-char (- (point-max) orig))))))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1359
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1360 (defun antlr-indent-command (&optional arg)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1361 "Indent the current line or insert tabs/spaces.
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1362 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
1363 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
1364 Otherwise, indent the current line with `antlr-indent-line'."
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1365 (interactive "P")
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1366 (if (or arg (eq last-command 'antlr-indent-command))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1367 (insert-tab arg)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1368 (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
1369 (antlr-indent-line))))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1370
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1371
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1372 ;;;===========================================================================
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1373 ;;; Mode entry
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1374 ;;;===========================================================================
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1375
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1376 (defun antlr-c-common-init ()
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1377 "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
1378 ;; X/Emacs 20 only
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1379 (make-local-variable 'paragraph-start)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1380 (make-local-variable 'paragraph-separate)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1381 (make-local-variable 'paragraph-ignore-fill-prefix)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1382 (make-local-variable 'require-final-newline)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1383 (make-local-variable 'parse-sexp-ignore-comments)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1384 (make-local-variable 'indent-line-function)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1385 (make-local-variable 'indent-region-function)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1386 (make-local-variable 'comment-start)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1387 (make-local-variable 'comment-end)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1388 (make-local-variable 'comment-column)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1389 (make-local-variable 'comment-start-skip)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1390 (make-local-variable 'comment-multi-line)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1391 (make-local-variable 'outline-regexp)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1392 (make-local-variable 'outline-level)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1393 (make-local-variable 'adaptive-fill-regexp)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1394 (make-local-variable 'adaptive-fill-mode)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1395 (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
1396 (and (boundp 'comment-line-break-function)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1397 (make-local-variable 'comment-line-break-function))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1398 ;; Emacs 19.30 and beyond only, AFAIK
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1399 (if (boundp 'fill-paragraph-function)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1400 (progn
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1401 (make-local-variable 'fill-paragraph-function)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1402 (setq fill-paragraph-function 'c-fill-paragraph)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1403 ;; now set their values
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1404 (setq paragraph-start (concat page-delimiter "\\|$")
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1405 paragraph-separate paragraph-start
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1406 paragraph-ignore-fill-prefix t
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1407 require-final-newline t
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1408 parse-sexp-ignore-comments t
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1409 indent-line-function 'c-indent-line
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1410 indent-region-function 'c-indent-region
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1411 outline-regexp "[^#\n\^M]"
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1412 outline-level 'c-outline-level
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1413 comment-column 32
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1414 comment-start-skip "/\\*+ *\\|// *"
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1415 comment-multi-line nil
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1416 comment-line-break-function 'c-comment-line-break-function
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1417 adaptive-fill-regexp nil
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1418 adaptive-fill-mode nil)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1419 ;; 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
1420 ;; buffer local value has its own alist structure.
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1421 (setq c-offsets-alist (copy-alist c-offsets-alist))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1422 ;; 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
1423 ;; ignore any byte compiler warnings you might get here
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1424 (make-local-variable 'comment-indent-function)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1425 (setq comment-indent-function 'c-comment-indent))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1426
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1427 (defun antlr-language-for-option (option-value)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1428 "Find element in `antlr-language-alist' for OPTION-VALUE."
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1429 ;; 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
1430 (let ((seq antlr-language-alist)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1431 r)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1432 (while seq
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1433 (setq r (pop seq))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1434 (if (member option-value (cddr r))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1435 (setq seq nil) ; stop
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1436 (setq r nil))) ; no result yet
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1437 r))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1438
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1439 ;;;###autoload
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1440 (defun antlr-mode ()
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1441 "Major mode for editing ANTLR grammar files.
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1442 \\{antlr-mode-map}"
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1443 (interactive)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1444 (c-initialize-cc-mode) ; for java syntax table
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1445 (kill-all-local-variables)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1446 ;; ANTLR specific ----------------------------------------------------------
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1447 (setq major-mode 'antlr-mode
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1448 mode-name "Antlr")
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1449 (setq local-abbrev-table antlr-mode-abbrev-table)
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1450 (unless antlr-mode-syntax-table
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1451 (setq antlr-mode-syntax-table (make-syntax-table))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1452 (c-populate-syntax-table antlr-mode-syntax-table))
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1453 (set-syntax-table antlr-mode-syntax-table)
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1454 (unless antlr-action-syntax-table
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1455 (let ((slist (nth 3 antlr-font-lock-defaults)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1456 (setq antlr-action-syntax-table
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1457 (copy-syntax-table antlr-mode-syntax-table))
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1458 (while slist
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1459 (modify-syntax-entry (caar slist) (cdar slist)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1460 antlr-action-syntax-table)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1461 (setq slist (cdr slist)))))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1462 (use-local-map antlr-mode-map)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1463 (make-local-variable 'antlr-language)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1464 (unless antlr-language
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1465 (save-excursion
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1466 (goto-char (point-min))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1467 (setq antlr-language
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1468 (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
1469 (car antlr-language-limit-n-regexp)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1470 t)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1471 (antlr-language-for-option (match-string 1)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1472 (antlr-language-for-option nil))))))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1473 (if (stringp (cadr (assq antlr-language antlr-language-alist)))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1474 (setq mode-name
29289
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
1475 (concat "Antlr."
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1476 (cadr (assq antlr-language antlr-language-alist)))))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1477 ;; indentation, for the C engine -------------------------------------------
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1478 (antlr-c-common-init)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1479 (setq indent-line-function 'antlr-indent-line
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1480 indent-region-function nil) ; too lazy
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1481 (setq comment-start "// "
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1482 comment-end "")
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1483 (c-set-style "java")
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1484 (if (eq antlr-language 'c++-mode)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1485 (setq c-conditional-key c-C++-conditional-key
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1486 c-comment-start-regexp c-C++-comment-start-regexp
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1487 c-class-key c-C++-class-key
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1488 c-extra-toplevel-key c-C++-extra-toplevel-key
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1489 c-access-key c-C++-access-key
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1490 c-recognize-knr-p nil)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1491 (setq c-conditional-key c-Java-conditional-key
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1492 c-comment-start-regexp c-Java-comment-start-regexp
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1493 c-class-key c-Java-class-key
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1494 c-method-key nil
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1495 c-baseclass-key nil
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1496 c-recognize-knr-p nil
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1497 c-access-key c-Java-access-key)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1498 (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
1499 (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
1500 ;; various -----------------------------------------------------------------
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1501 (make-local-variable 'font-lock-defaults)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1502 (setq font-lock-defaults antlr-font-lock-defaults)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1503 (easy-menu-add antlr-mode-menu)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1504 (make-local-variable 'imenu-create-index-function)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1505 (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
1506 (make-local-variable 'imenu-generic-expression)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1507 (setq imenu-generic-expression t) ; fool stupid test
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1508 (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
1509 (fboundp 'imenu-add-to-menubar)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1510 (imenu-add-to-menubar
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1511 (if (stringp antlr-imenu-name) antlr-imenu-name "Index")))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1512 (antlr-set-tabs)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1513 (run-hooks 'antlr-mode-hook))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1514
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1515 ;; A smarter version of `group-buffers-menu-by-mode-then-alphabetically' (in
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1516 ;; XEmacs) could use the following property. The header of the submenu would
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1517 ;; be "Antlr" instead of "Antlr.C++" or (not and!) "Antlr.Java".
29289
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
1518 (put 'antlr-mode 'mode-name "Antlr")
9ad79f5782af New commands: hide/unhide actions,
Gerd Moellmann <gerd@gnu.org>
parents: 26965
diff changeset
1519
26542
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1520 ;;;###autoload
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1521 (defun antlr-set-tabs ()
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1522 "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
1523 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
1524 (if buffer-file-name
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1525 (let ((alist antlr-tab-offset-alist) elem)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1526 (while alist
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1527 (setq elem (pop alist))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1528 (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
1529 (or (null (cadr elem))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1530 (string-match (cadr elem) buffer-file-name))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1531 (setq tab-width (caddr elem)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1532 indent-tabs-mode (cadddr elem)
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1533 alist nil))))))
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1534
0d41332e3819 Major mode for ANTLR grammar files.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1535 ;;; antlr-mode.el ends here
26965
048db40ddca6 Version 1.2 is released.
Gerd Moellmann <gerd@gnu.org>
parents: 26542
diff changeset
1536
048db40ddca6 Version 1.2 is released.
Gerd Moellmann <gerd@gnu.org>
parents: 26542
diff changeset
1537 ; LocalWords: antlr ANother ANTLR's Cpp Lexer TreeParser esp refs VALUEs ea ee
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1538 ; LocalWords: Java's Nomencl ruledef tokendef ruleref tokenref setType ader ev
26965
048db40ddca6 Version 1.2 is released.
Gerd Moellmann <gerd@gnu.org>
parents: 26542
diff changeset
1539 ; LocalWords: ivate syntab lexer treeparser lic rotected rivate bor boi AFAIK
34011
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1540 ; LocalWords: slist knr inexpr unhide jit GENS SEP GEN sTokenTypes hpp cpp DEP
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1541 ; LocalWords: VOCAB EVOCAB Antlr's TokenTypes exportVocab incl excl SUPERS gen
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1542 ; LocalWords: VOCABS IVOCAB exportVocabs importVocabs superclasses vocab kens
075cc818f566 New commands to run ANTLR from within Emacs and
Gerd Moellmann <gerd@gnu.org>
parents: 29289
diff changeset
1543 ; LocalWords: sclass evocab ivocab importVocab deps glibs supers sep dep lang