;;; antlr-mode.el --- major mode for ANTLR grammar files
-;; Copyright (C) 1999-2011 Free Software Foundation, Inc.
+;; Copyright (C) 1999-2016 Free Software Foundation, Inc.
-;; Author: Christoph.Wedler@sap.com
+;; Author: Christoph Wedler <Christoph.Wedler@sap.com>
;; Keywords: languages, ANTLR, code generator
;; Version: 2.2c
;; X-URL: http://antlr-mode.sourceforge.net/
;; This file requires Emacs-20.3, XEmacs-20.4 or higher and package cc-mode.
;; If antlr-mode is not part of your distribution, put this file into your
-;; load-path and the following into your ~/.emacs:
+;; load-path and the following into your init file:
;; (autoload 'antlr-mode "antlr-mode" nil t)
;; (setq auto-mode-alist (cons '("\\.g\\'" . antlr-mode) auto-mode-alist))
;; (add-hook 'speedbar-load-hook ; would be too late in antlr-mode.el
(let ((buffer-undo-list t) (inhibit-read-only t)
,@(unless (featurep 'xemacs)
'((inhibit-point-motion-hooks t) deactivate-mark))
- before-change-functions after-change-functions
+ (inhibit-modification-hooks t)
buffer-file-name buffer-file-truename)
,@body)
(and (not ,modified) (buffer-modified-p)
(set-buffer-modified-p nil)))))))
(put 'save-buffer-state-x 'lisp-indent-function 0)
-;; get rid of byte-compile warnings
-(eval-when-compile
- (require 'cc-mode))
-
(defvar outline-level)
(defvar imenu-use-markers)
(defvar imenu-create-index-function)
(c++-mode "C++" "\"Cpp\"" "Cpp"))
"List of ANTLR's supported languages.
Each element in this list looks like
- \(MAJOR-MODE MODELINE-STRING OPTION-VALUE...)
+ (MAJOR-MODE MODELINE-STRING OPTION-VALUE...)
MAJOR-MODE, the major mode of the code in the grammar's actions, is the
value of `antlr-language' if the first group in the string matched by
REGEXP in `antlr-language-limit-n-regexp' is one of the OPTION-VALUEs.
An OPTION-VALUE of nil denotes the fallback element. MODELINE-STRING is
-also displayed in the modeline next to \"Antlr\"."
+also displayed in the mode line next to \"Antlr\"."
:group 'antlr
:type '(repeat (group :value (java-mode "")
(function :tag "Major mode")
- (string :tag "Modeline string")
+ (string :tag "Mode line string")
(repeat :tag "ANTLR language option" :inline t
(choice (const :tag "Default" nil)
string )))))
(defcustom antlr-language-limit-n-regexp
'(8192 . "language[ \t]*=[ \t]*\\(\"?[A-Z][A-Za-z_]*\"?\\)")
"Used to set a reasonable value for `antlr-language'.
-Looks like \(LIMIT \. REGEXP). Search for REGEXP from the beginning of
+Looks like \(LIMIT . REGEXP). Search for REGEXP from the beginning of
the buffer to LIMIT and use the first group in the matched string to set
the language according to `antlr-language-alist'."
:group 'antlr
(integer :tag "Hidden if longer than" :value 3)))
(defcustom antlr-indent-comment 'tab
- "*Non-nil, if the indentation should touch lines in block comments.
+ "Non-nil, if the indentation should touch lines in block comments.
If nil, no continuation line of a block comment is changed. If t, they
are changed according to `c-indentation-line'. When not nil and not t,
they are only changed by \\[antlr-indent-command]."
(boolean :tag "Indent-tabs-mode"))))
(defcustom antlr-indent-style "java"
- "*If non-nil, cc-mode indentation style used for `antlr-mode'.
+ "If non-nil, cc-mode indentation style used for `antlr-mode'.
See `c-set-style' and for details, where the most interesting part in
`c-style-alist' is the value of `c-basic-offset'."
:group 'antlr
;;;===========================================================================
(defcustom antlr-options-use-submenus t
- "*Non-nil, if the major mode menu should include option submenus.
+ "Non-nil, if the major mode menu should include option submenus.
If nil, the menu just includes a command to insert options. Otherwise,
it includes four submenus to insert file/grammar/rule/subrule options."
:group 'antlr
:type 'boolean)
(defcustom antlr-tool-version 20701
- "*The version number of the Antlr tool.
+ "The version number of the Antlr tool.
The value is an integer of the form XYYZZ which stands for vX.YY.ZZ.
This variable is used to warn about non-supported options and to supply
version correct option values when using \\[antlr-insert-option].
:type 'integer)
(defcustom antlr-options-auto-colon t
- "*Non-nil, if `:' is inserted with a rule or subrule options section.
+ "Non-nil, if `:' is inserted with a rule or subrule options section.
A `:' is only inserted if this value is non-nil, if a rule or subrule
option is inserted with \\[antlr-insert-option], if there was no rule or
subrule options section before, and if a `:' is not already present
:type '(repeat (symbol :tag "Style symbol")))
(defcustom antlr-options-push-mark t
- "*Non-nil, if inserting an option should set & push mark.
+ "Non-nil, if inserting an option should set & push mark.
If nil, never set mark when inserting an option with command
\\[antlr-insert-option]. If t, always set mark via `push-mark'. If a
number, only set mark if point was outside the options area before and
(sexp :tag "If outside options" :format "%t" :value outside)))
(defcustom antlr-options-assign-string " = "
- "*String containing `=' to use between option name and value.
+ "String containing `=' to use between option name and value.
This string is only used if the option to insert did not exist before
or if there was no `=' after it. In other words, the spacing around an
existing `=' won't be changed when changing an option value."
"Generate default exception handler for each rule? "))
("codeGenMakeSwitchThreshold" nil
(20600 antlr-read-value
- "Min number of alternatives for 'switch': "))
+ "Min number of alternatives for `switch': "))
("codeGenBitsetTestThreshold" nil
(20600 antlr-read-value
"Min size of lookahead set for bitset test: "))
Each OPTION-DEF looks like \(OPTION-NAME EXTRA-FN VALUE-SPEC...) which
defines a file/grammar/rule/subrule option with name OPTION-NAME. The
OPTION-NAMEs are used for the creation of the \"Insert XXX Option\"
-submenus, see `antlr-options-use-submenus', and to allow to insert the
-option name with completion when using \\[antlr-insert-option].
+submenus, see `antlr-options-use-submenus', and to allow the insertion
+of the option name with completion when using \\[antlr-insert-option].
If EXTRA-FN is a function, it is called at different phases of the
insertion with arguments \(PHASE OPTION-NAME). PHASE can have the
;;;===========================================================================
(defcustom antlr-tool-command "java antlr.Tool"
- "*Command used in \\[antlr-run-tool] to run the Antlr tool.
+ "Command used in \\[antlr-run-tool] to run the Antlr tool.
This variable should include all options passed to Antlr except the
option \"-glib\" which is automatically suggested if necessary."
:group 'antlr
:type 'string)
(defcustom antlr-ask-about-save t
- "*If not nil, \\[antlr-run-tool] asks which buffers to save.
+ "If not nil, \\[antlr-run-tool] asks which buffers to save.
Otherwise, it saves all modified buffers before running without asking."
:group 'antlr
:type 'boolean)
(defcustom antlr-makefile-specification
'("\n" ("GENS" "GENS%d" " \\\n\t") "$(ANTLR)")
- "*Variable to specify the appearance of the generated makefile rules.
+ "Variable to specify the appearance of the generated makefile rules.
This variable influences the output of \\[antlr-show-makefile-rules].
It looks like \(RULE-SEP GEN-VAR-SPEC COMMAND).
(c++-mode ("%sTokenTypes.hpp") ("%s.cpp" "%s.hpp")))
"Language dependent formats which specify generated files.
Each element in this list looks looks like
- \(MAJOR-MODE (VOCAB-FILE-FORMAT...) (CLASS-FILE-FORMAT...)).
+ (MAJOR-MODE (VOCAB-FILE-FORMAT...) (CLASS-FILE-FORMAT...)).
The element whose MAJOR-MODE is equal to `antlr-language' is used to
specify the generated files which are language dependent. See variable
formats.")
(defvar antlr-unknown-file-formats '("?%s?.g" "?%s?")
- "*Formats which specify the names of unknown files.
+ "Formats which specify the names of unknown files.
The value looks like \(SUPER-GRAMMAR-FILE-FORMAT SUPER-EVOCAB-FORMAT).
SUPER-GRAMMAR-FORMAT is a format string, it specifies with substitution
;;;===========================================================================
(defcustom antlr-imenu-name t ; (featurep 'xemacs) ; TODO: Emacs-21 bug?
- "*Non-nil, if a \"Index\" menu should be added to the menubar.
+ "Non-nil, if a \"Index\" menu should be added to the menubar.
If it is a string, it is used instead \"Index\". Requires package
imenu."
:group 'antlr
;;;===========================================================================
(defcustom antlr-font-lock-maximum-decoration 'inherit
- "*The maximum decoration level for fontifying actions.
+ "The maximum decoration level for fontifying actions.
Value `none' means, do not fontify actions, just normal grammar code
according to `antlr-font-lock-additional-keywords'. Value `inherit'
means, use value of `font-lock-maximum-decoration'. Any other value is
While calculating the decoration level for actions, `major-mode' is
bound to `antlr-language'. For example, with value
- \((java-mode \. 2) (c++-mode \. 0))
+ ((java-mode . 2) (c++-mode . 0))
Java actions are fontified with level 2 and C++ actions are not
fontified at all."
:group 'antlr
c++-font-lock-keywords-3))
"List of font-lock keywords for actions in the grammar.
Each element in this list looks like
- \(MAJOR-MODE KEYWORD...)
+ (MAJOR-MODE KEYWORD...)
If `antlr-language' is equal to MAJOR-MODE, the KEYWORDs are the
font-lock keywords according to `font-lock-defaults' used for the code
(antlr-re-search-forward
"^\\(private\\|public\\|protected\\)\\>[ \t]*\\(\\(\\sw+[ \t]*\\(:\\)?\\)\\)?"
limit))
- (1 font-lock-type-face) ; not XEmacs' java level-3 fruit salad
+ (1 font-lock-type-face) ; not XEmacs's java level-3 fruit salad
(3 (if (antlr-upcase-p (char-after (match-beginning 3)))
antlr-tokendef-face
antlr-ruledef-face) nil t)
(define-abbrev-table 'antlr-mode-abbrev-table ())
(defvar antlr-slow-cache-enabling-symbol 'loudly
-;; Emacs' font-lock changes buffer's tick counter, therefore this value should
+;; Emacs's font-lock changes buffer's tick counter, therefore this value should
;; be a parameter of a font-lock function, but not any other variable of
;; functions which call `antlr-slow-syntactic-context'.
"If value is a bound symbol, cache will be used even with text changes.
(or (buffer-syntactic-context) (buffer-syntactic-context-depth))
:EMACS
(let ((orig (point)) diff state
- ;; Arg, Emacs' (buffer-modified-tick) changes with font-lock. Use
+ ;; Arg, Emacs's (buffer-modified-tick) changes with font-lock. Use
;; hack that `loudly' is bound during font-locking => cache use will
;; increase from 7% to 99.99% during font-locking.
(tick (or (boundp antlr-slow-cache-enabling-symbol)
4. Ask user for confirmation if the given OPTION does not seem to be a
valid option to insert into the current file.
5. Find a correct position to insert the option.
- 6. Depending on the option, insert it the following way \(inserting an
- option also means inserting the option section if necessary\):
+ 6. Depending on the option, insert it the following way (inserting an
+ option also means inserting the option section if necessary):
- Insert the option and let user insert the value at point.
- Read a value (with completion) from the minibuffer, using a
previous value as initial contents, and insert option with value.
(defun antlr-option-kind (requested)
"Return level and location for option to insert near point.
Call function `antlr-option-level' with argument REQUESTED. If the
-result is nil, return \(REQUESTED \. error). If the result has the
-non-nil value LEVEL, return \(LEVEL \. LOCATION) where LOCATION looks
-like \(AREA \. PLACE), see `antlr-option-location'."
+result is nil, return \(REQUESTED . error). If the result has the
+non-nil value LEVEL, return \(LEVEL . LOCATION) where LOCATION looks
+like \(AREA . PLACE), see `antlr-option-location'."
(save-excursion
(save-restriction
(let ((min0 (point-min)) ; before `widen'!
(defun antlr-insert-option-do (level option old area pos)
"Insert option into buffer at position POS.
Insert option of level LEVEL and name OPTION. If OLD is non-nil, an
-options area is already exists. If OLD looks like \(BEG \. END), the
+options area is already exists. If OLD looks like \(BEG . END), the
option already exists. Then, BEG is the start position of the option
value, the position of the `=' or nil, and END is the end position of
the option value or nil.
(defun antlr-file-dependencies ()
"Return dependencies for grammar in current buffer.
-The result looks like \(FILE \(CLASSES \. SUPERS) VOCABS \. LANGUAGE)
+The result looks like \(FILE \(CLASSES . SUPERS) VOCABS . LANGUAGE)
where CLASSES = ((CLASS . CLASS-EVOCAB) ...),
SUPERS = ((SUPER . USE-EVOCAB-P) ...), and
VOCABS = ((EVOCAB ...) . (IVOCAB ...))
(defun antlr-directory-dependencies (dirname)
"Return dependencies for all grammar files in directory DIRNAME.
-The result looks like \((CLASS-SPEC ...) \. \(FILE-DEP ...))
- where CLASS-SPEC = (CLASS (FILE \. EVOCAB) ...).
+The result looks like \((CLASS-SPEC ...) . \(FILE-DEP ...))
+ where CLASS-SPEC = (CLASS (FILE . EVOCAB) ...).
FILE-DEP are the dependencies for each grammar file in DIRNAME, see
`antlr-file-dependencies'. For each grammar class CLASS, FILE is a
complete \"-glib\" option. WITH-UNKNOWN is t if there is none or more
than one grammar file for at least one super grammar.
-Each GLIB looks like \(GRAMMAR-FILE \. EVOCAB). GRAMMAR-FILE is a file
+Each GLIB looks like \(GRAMMAR-FILE . EVOCAB). GRAMMAR-FILE is a file
in which a super-grammar is defined. EVOCAB is the value of the export
vocabulary of the super-grammar or nil if it is not needed."
;; If the superclass is defined in the same file, that file will be included