/[emacs]/emacs/lisp/progmodes/antlr-mode.el
ViewVC logotype

Diff of /emacs/lisp/progmodes/antlr-mode.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.9 by monnier, Mon Dec 3 09:32:46 2001 UTC revision 1.10 by rms, Fri Dec 21 23:55:39 2001 UTC
# Line 1  Line 1 
1  ;;; antlr-mode.el --- major mode for ANTLR grammar files  ;;; antlr-mode.el --- major mode for ANTLR grammar files
2    
3  ;; Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.  ;; Copyright (C) 1999-2001 Free Software Foundation, Inc.
4  ;;  ;;
5  ;; Author: Christoph.Wedler@sap.com  ;; Author: Christoph.Wedler@sap.com
6  ;; Keywords: languages  ;; Keywords: languages
7  ;; Version: 1.4  ;; Version: 2.1
8  ;; X-URL: http://www.fmi.uni-passau.de/~wedler/antlr-mode/  ;; X-URL: http://www.fmi.uni-passau.de/~wedler/antlr-mode/
9    
10  ;; This file is part of GNU Emacs.  ;; This file is part of GNU Emacs.
# Line 26  Line 26 
26    
27  ;;; Commentary:  ;;; Commentary:
28    
29  ;; Major mode for editing ANTLR grammar files, i.e., files ending with `.g'.  ;; This Emacs extension (major mode) provides various features for editing
30  ;; ANTLR is ANother Tool for Language Recognition (an excellent alternative to  ;; ANTLR grammar files.  ANTLR is a tool for LL(k)-based language recognition
31  ;; lex/yacc), see <http://www.ANTLR.org> and <news:comp.compilers.tools.pccts>.  ;; and an excellent alternative to lex & yacc, see <http://www.ANTLR.org>.
32    ;; Some features depend on the value of ANTLR's "language" option (check the
33    ;; modeline for "Antlr.Java" or "Antlr.C++").
34    
35  ;; This package provides the following features:  ;; This package provides the following features:
36  ;;  * Syntax coloring (via font-lock) for grammar symbols and the code in  ;;  * Syntax highlighting for grammar symbols and the code in actions.
37  ;;    actions.  The latter depends on the language settings.  ;;  * Indentation (pretty-print) for the current line (TAB) and lines in the
38  ;;  * Indentation for the current line (TAB) and selected region (C-M-\).  ;;    selected region (C-M-\).  Inserting an ANTLR syntax symbol (one of
39  ;;  * Support for imenu/speedbar: menu "Index" (Parser, Lexer, TreeParser).  ;;    ":;|&(){}") might also indent the current line.
40    ;;  * Menu "Index" and Speedbar tags with all class, token and rule
41    ;;    definitions.  Jump to corresponding position by selecting an entry.
42  ;;  * Commands to move to previous/next rule, beginning/end of rule body etc.  ;;  * Commands to move to previous/next rule, beginning/end of rule body etc.
43  ;;  * Commands to hide/unhide actions, upcase/downcase literals.  ;;  * Commands to hide/unhide actions.
44    ;;  * Support to insert/change file/grammar/rule/subrule options.
45  ;;  * Run ANTLR from within Emacs, create Makefile dependencies.  ;;  * Run ANTLR from within Emacs, create Makefile dependencies.
46    
47  ;; LANGUAGE SETTINGS.  This mode needs to know which language is used in  ;; SYNTAX HIGHLIGHTING comes in three phases.  First, comments and strings are
48  ;; actions and semantic predicated of the grammar.  This information is used  ;; highlighted.  Second, the grammar code is highlighted according to
49  ;; for syntax coloring and the creation of the Makefile dependencies.  It is  ;; `antlr-font-lock-additional-keywords' (rule refs: dark blue, token refs:
50  ;; stored in variable `antlr-language' and automatically set according to  ;; dark orange, definition: bold blue).  Third, actions, semantic predicates
51  ;; ANTLR's file option "language", see `antlr-language-alist'.  The supported  ;; and arguments are highlighted according to the usual font-lock keywords of
52  ;; languages are "Java" (java-mode) and "Cpp" (c++-mode).  ;; the major-mode corresponding to ANTLR's "language" option, see also
53    ;; `antlr-font-lock-maximum-decoration'.  We define special font-lock faces for
54    ;; the grammar code to allow you to distinguish ANTLR keywords from Java/C++
55    ;; keywords.
56    
57  ;; INDENTATION.  This package supports ANTLR's (intended) indentation style  ;; INDENTATION.  This package supports ANTLR's (intended) indentation style
58  ;; which is based on a simple paren/brace/bracket depth-level calculation, see  ;; which is based on a simple paren/brace/bracket depth-level calculation, see
59  ;; `antlr-indent-line'.  The indentation engine of cc-mode is only used inside  ;; `antlr-indent-line'.  The indentation engine of cc-mode is only used inside
60  ;; block comments (it is not easy to use it for actions, esp if they come early  ;; block comments.  By default, this package defines a tab width of 4 to be
 ;; in the rule body).  By default, this package defines a tab width of 4 to be  
61  ;; consistent to both ANTLR's conventions (TABs usage) and the  ;; consistent to both ANTLR's conventions (TABs usage) and the
62  ;; `c-indentation-style' "java" which sets `c-basic-offset' to 4, see  ;; `c-indentation-style' "java" which sets `c-basic-offset' to 4, see
63  ;; `antlr-tab-offset-alist'.  You might want to set this variable to nil.  ;; `antlr-tab-offset-alist'.  You might want to set this variable to nil.
64    
65  ;; SYNTAX COLORING comes in three phases.  First, comments and strings are  ;; OPTION SUPPORT.  This package provides special support to insert or change
66  ;; highlighted.  Second, the grammar code is highlighted according to  ;; file, grammar, rule and subrule options via the menu or via the keyboard
67  ;; `antlr-font-lock-additional-keywords' (rule refs: dark blue, token refs:  ;; with completion.  For most options, you can also insert the value with
68  ;; dark orange, definition: bold blue).  Third, actions, semantic predicates  ;; completion (or select a value from a list by pressing `?').  You get a
69  ;; and arguments are highlighted according to the usual font-lock keywords of  ;; warning if an option is not supported by the version of ANTLR you are using
70  ;; `antlr-language', see also `antlr-font-lock-maximum-decoration'.  We define  ;; (`antlr-tool-version' defaults to 2.7.1), or if the option shouldn't be
71  ;; special font-lock faces for the grammar code to allow you to distinguish  ;; inserted for other reasons.  This package knows the correct position where
72  ;; ANTLR keywords from Java/C++ keywords.  ;; to insert the option and inserts "options {...}" if it is not already
73    ;; present.  For details, see the docstring of command \\[antlr-insert-option].
74    
75  ;; MAKEFILE CREATION.  Command \\[antlr-show-makefile-rules] shows/inserts the  ;; MAKEFILE CREATION.  Command \\[antlr-show-makefile-rules] shows/inserts the
76  ;; dependencies for all grammar files in the current directory.  It considers  ;; dependencies for all grammar files in the current directory.  It considers
77  ;; import/export vocabularies and grammar inheritance and provides a value for  ;; ANTLR's "language" option, import/export vocabularies and grammar
78  ;; the -glib option if necessary (which you have to edit if the super-grammar  ;; inheritance, and provides a value for the -glib option if necessary (which
79  ;; is not in the same directory).  ;; you have to edit if the super-grammar is not in the same directory).
80    
81  ;; TODO.  Support to insert/change file/grammar/rule/subrule options.  imenu  ;; TODO/WISH-LIST.  Things which might be supported in future versions:
82  ;; support for method definitions in actions is not really planned (you can  
83  ;; send be a patch, though).  This mode would become too dependent on cc-mode  ;;  * Next Version [C-c C-w].  Produce HTML document with syntax highlighted
84  ;; or I would have to do a lot of language-dependent things myself...  ;;    and hyper-links (using htmlize).
85    ;;  * Next Version [C-c C-u].  Insert/update special comments: each rule lists
86    ;;    all rules which use the current rule.  With font-lock update.
87    ;;  * Next Version.  Make hiding much more customizable.
88    ;;  * Planned [C-c C-j].  Jump to generated coding.
89    ;;  * Planned.  Further support for imenu, i.e., include entries for method
90    ;;    definitions at beginning of grammar class.
91    ;;  * Planned [C-c C-p].  Pack/unpack rule/subrule & options (one/multi-line).
92    
93    ;;  * Probably.  Show rules/dependencies for ANT like for Makefile (does ANT
94    ;;    support vocabularies and grammar inheritance?), I have to look at
95    ;;    jde-ant.el: http://jakarta.apache.org/ant/manual/OptionalTasks/antlr.html
96    ;;  * Unlikely.  Sather as generated language with syntax highlighting etc/.
97    ;;    Questions/problems: is sather-mode.el the standard mode for sather, is it
98    ;;    still supported, what is its relationship to eiffel3.el?  Requirement:
99    ;;    this mode must not depend on a Sather mode.
100    ;;  * Unlikely.  Faster syntax highlighting: sectionize the buffer into Antlr
101    ;;    and action code and run special highlighting functions on these regions.
102    ;;    Problems: code size, this mode would depend on font-lock internals.
103    
104  ;; Bug fixes, bug reports, improvements, and suggestions are strongly  ;; Bug fixes, bug reports, improvements, and suggestions are strongly
105  ;; appreciated.  Please check the newest version first:  ;; appreciated.  Please check the newest version first:
# Line 97  Line 123 
123  ;; I strongly recommend to use font-lock with a support mode like fast-lock,  ;; I strongly recommend to use font-lock with a support mode like fast-lock,
124  ;; lazy-lock or better jit-lock (Emacs-21.1+) / lazy-shot (XEmacs).  ;; lazy-lock or better jit-lock (Emacs-21.1+) / lazy-shot (XEmacs).
125    
126  ;; To customize, use `M-x customize-group RET antlr RET' or the custom browser  ;; To customize, use menu item "Antlr" -> "Customize Antlr".
 ;; (Emacs->Programming->Languages->Antlr).  
127    
128  ;;; Code:  ;;; Code:
129    
130  (provide 'antlr-mode)  (provide 'antlr-mode)
131  (eval-when-compile                      ; required and optional libraries  (eval-when-compile                      ; required and optional libraries
132    (require 'cc-mode)    (require 'cc-mode)
133      (defvar c-Java-access-key)            ; former cc-mode variable
134      (condition-case nil (require 'font-lock) (error nil))
135      (condition-case nil (require 'compile) (error nil))
136    (defvar outline-level) (defvar imenu-use-markers)    (defvar outline-level) (defvar imenu-use-markers)
137    (defvar imenu-create-index-function))    (defvar imenu-create-index-function))
138  (eval-when-compile                      ; Emacs: cl, easymenu  (eval-when-compile                      ; Emacs: cl, easymenu, XEmacs vars
139    (require 'cl)    (require 'cl)
140    (require 'easymenu))    (require 'easymenu)
141      (defvar zmacs-region-stays))
142  (eval-when-compile                      ; XEmacs: Emacs vars  (eval-when-compile                      ; XEmacs: Emacs vars
143    (defvar inhibit-point-motion-hooks) (defvar deactivate-mark))    (defvar inhibit-point-motion-hooks) (defvar deactivate-mark))
144    
# Line 117  Line 146 
146    (if (featurep 'xemacs)    (if (featurep 'xemacs)
147        (defalias 'antlr-scan-sexps 'scan-sexps)        (defalias 'antlr-scan-sexps 'scan-sexps)
148      (defalias 'antlr-scan-sexps 'antlr-scan-sexps-internal))      (defalias 'antlr-scan-sexps 'antlr-scan-sexps-internal))
149      (if (featurep 'xemacs)
150          (defalias 'antlr-scan-lists 'scan-lists)
151        (defalias 'antlr-scan-lists 'antlr-scan-lists-internal))
152    (if (fboundp 'default-directory)    (if (fboundp 'default-directory)
153        (defalias 'antlr-default-directory 'default-directory)        (defalias 'antlr-default-directory 'default-directory)
154      (defun antlr-default-directory () default-directory))      (defun antlr-default-directory () default-directory))
# Line 152  Line 184 
184    :link '(url-link "http://www.fmi.uni-passau.de/~wedler/antlr-mode/")    :link '(url-link "http://www.fmi.uni-passau.de/~wedler/antlr-mode/")
185    :prefix "antlr-")    :prefix "antlr-")
186    
187  (defconst antlr-version "1.4"  (defconst antlr-version "2.1"
188    "ANTLR major mode version number.")    "ANTLR major mode version number.")
189    
190    
# Line 172  variable list\" near the end of the file Line 204  variable list\" near the end of the file
204      (c++-mode "C++" "\"Cpp\"" "Cpp"))      (c++-mode "C++" "\"Cpp\"" "Cpp"))
205    "List of ANTLR's supported languages.    "List of ANTLR's supported languages.
206  Each element in this list looks like  Each element in this list looks like
207    (MAJOR-MODE MODELINE-STRING OPTION-VALUE...)    \(MAJOR-MODE MODELINE-STRING OPTION-VALUE...)
208    
209  MAJOR-MODE, the major mode of the code in the grammar's actions, is the  MAJOR-MODE, the major mode of the code in the grammar's actions, is the
210  value of `antlr-language' if the first group in the string matched by  value of `antlr-language' if the first group in the string matched by
# Line 188  also displayed in the modeline next to \ Line 220  also displayed in the modeline next to \
220                                          string )))))                                          string )))))
221    
222  (defcustom antlr-language-limit-n-regexp  (defcustom antlr-language-limit-n-regexp
223    '(3000 . "language[ \t]*=[ \t]*\\(\"?[A-Z][A-Za-z_]*\"?\\)")    '(8192 . "language[ \t]*=[ \t]*\\(\"?[A-Z][A-Za-z_]*\"?\\)")
224    "Used to set a reasonable value for `antlr-language'.    "Used to set a reasonable value for `antlr-language'.
225  Looks like (LIMIT . REGEXP).  Search for REGEXP from the beginning of  Looks like \(LIMIT \. REGEXP).  Search for REGEXP from the beginning of
226  the buffer to LIMIT and use the first group in the matched string to set  the buffer to LIMIT and use the first group in the matched string to set
227  the language according to `antlr-language-alist'."  the language according to `antlr-language-alist'."
228    :group 'antlr    :group 'antlr
# Line 225  they are only changed by \\[antlr-indent Line 257  they are only changed by \\[antlr-indent
257    '((antlr-mode nil 4 nil)    '((antlr-mode nil 4 nil)
258      (java-mode "antlr" 4 nil))      (java-mode "antlr" 4 nil))
259    "Alist to determine whether to use ANTLR's convention for TABs.    "Alist to determine whether to use ANTLR's convention for TABs.
260  Each element looks like (MAJOR-MODE REGEXP TAB-WIDTH INDENT-TABS-MODE).  Each element looks like \(MAJOR-MODE REGEXP TAB-WIDTH INDENT-TABS-MODE).
261  The first element whose MAJOR-MODE is nil or equal to `major-mode' and  The first element whose MAJOR-MODE is nil or equal to `major-mode' and
262  whose REGEXP is nil or matches `buffer-file-name' is used to set  whose REGEXP is nil or matches variable `buffer-file-name' is used to
263  `tab-width' and `indent-tabs-mode'.  This is useful to support both  set `tab-width' and `indent-tabs-mode'.  This is useful to support both
264  ANTLR's and Java's indentation styles.  Used by `antlr-set-tabs'."  ANTLR's and Java's indentation styles.  Used by `antlr-set-tabs'."
265    :group 'antlr    :group 'antlr
266    :type '(repeat (group :value (antlr-mode nil 8 nil)    :type '(repeat (group :value (antlr-mode nil 8 nil)
# Line 238  ANTLR's and Java's indentation styles. Line 270  ANTLR's and Java's indentation styles.
270                          (integer :tag "Tab width")                          (integer :tag "Tab width")
271                          (boolean :tag "Indent-tabs-mode"))))                          (boolean :tag "Indent-tabs-mode"))))
272    
273  (defvar antlr-indent-item-regexp  (defcustom antlr-indent-style "java"
274    "[]}):;|&]\\|default[ \t]*:\\|case[ \t]+\\('\\\\?.'\\|[0-9]+\\|[A-Za-z_][A-Za-z_0-9]*\\)[ \t]*:" ; & is local ANTLR extension    "*If non-nil, cc-mode indentation style used for `antlr-mode'.
275    See `c-set-style' for details."
276      :group 'antlr
277      :type '(choice (const nil) regexp))
278    
279    (defcustom antlr-indent-item-regexp
280      "[]}):;|&]\\|default[ \t]*:\\|case[ \t]+\\('\\\\?.'\\|[0-9]+\\|[A-Za-z_][A-Za-z_0-9]*\\)[ \t]*:" ; & is local ANTLR extension (SGML's and-connector)
281    "Regexp matching lines which should be indented by one TAB less.    "Regexp matching lines which should be indented by one TAB less.
282  See command \\[antlr-indent-command].")  See `antlr-indent-line' and command \\[antlr-indent-command]."
283      :group 'antlr
284      :type 'regexp)
285    
286    (defcustom antlr-indent-at-bol-alist
287      ;; eval-when-compile not usable with defcustom...
288      '((c++-mode . "#\\(assert\\|cpu\\|define\\|endif\\|el\\(if\\|se\\)\\|i\\(dent\\|f\\(def\\|ndef\\)?\\|mport\\|nclude\\(_next\\)?\\)\\|line\\|machine\\|pragma\\|system\\|un\\(assert\\|def\\)\\|warning\\)\\>"))
289      "Alist of regexps matching lines are indented at column 0.
290    Each element in this list looks like (MODE . REGEXP) where MODE is a
291    function and REGEXP is a regular expression.
292    
293    If `antlr-language' equals to a MODE and the line starting at the first
294    non-whitespace is matched by the corresponding REGEXP, indent the line
295    at column 0 instead according to the normal rules of `antlr-indent-line'."
296      :group 'antlr
297      :type '(repeat (cons (function :tag "Major mode") regexp)))
298    
299    
300    ;;;===========================================================================
301    ;;;  Options: customization
302    ;;;===========================================================================
303    
304    (defcustom antlr-options-use-submenus t
305      "*Non-nil, if the major mode menu should include option submenus.
306    If nil, the menu just includes a command to insert options.  Otherwise,
307    it includes four submenus to insert file/grammar/rule/subrule options."
308      :group 'antlr
309      :type 'boolean)
310    
311    (defcustom antlr-tool-version 20701
312      "*The version number of the Antlr tool.
313    The value is an integer of the form XYYZZ which stands for vX.YY.ZZ.
314    This variable is used to warn about non-supported options and to supply
315    version correct option values when using \\[antlr-insert-option].
316    
317    Don't use a number smaller than 20600 since the stored history of
318    Antlr's options starts with v2.06.00, see `antlr-options-alists'.  You
319    can make this variable buffer-local."
320      :group 'antlr
321      :type 'integer)
322    
323    (defcustom antlr-options-auto-colon t
324      "*Non-nil, if `:' is inserted with a rule or subrule options section.
325    A `:' is only inserted if this value is non-nil, if a rule or subrule
326    option is inserted with \\[antlr-insert-option], if there was no rule or
327    subrule options section before, and if a `:' is not already present
328    after the section, ignoring whitespace, comments and the init action."
329      :group 'antlr
330      :type 'boolean)
331    
332    (defcustom antlr-options-style nil
333      "List of symbols which determine the style of option values.
334    If a style symbol is present, the corresponding option value is put into
335    quotes, i.e., represented as a string, otherwise it is represented as an
336    identifier.
337    
338    The only style symbol used in the default value of `antlr-options-alist'
339    is `language-as-string'.  See also `antlr-read-value'."
340      :group 'antlr
341      :type '(repeat (symbol :tag "Style symbol")))
342    
343    (defcustom antlr-options-push-mark t
344      "*Non-nil, if inserting an option should set & push mark.
345    If nil, never set mark when inserting an option with command
346    \\[antlr-insert-option].  If t, always set mark via `push-mark'.  If a
347    number, only set mark if point was outside the options area before and
348    the number of lines between point and the insert position is greater
349    than this value.  Otherwise, only set mark if point was outside the
350    options area before."
351      :group 'antlr
352      :type '(radio (const :tag "No" nil)
353                    (const :tag "Always" t)
354                    (integer :tag "Lines between" :value 10)
355                    (sexp :tag "If outside options" :format "%t" :value outside)))
356    
357    (defcustom antlr-options-assign-string " = "
358      "*String containing `=' to use between option name and value.
359    This string is only used if the option to insert did not exist before
360    or if there was no `=' after it.  In other words, the spacing around an
361    existing `=' won't be changed when changing an option value."
362      :group 'antlr
363      :type 'string)
364    
365    
366    ;;;===========================================================================
367    ;;;  Options: definitions
368    ;;;===========================================================================
369    
370    (defvar antlr-options-headings '("file" "grammar" "rule" "subrule")
371      "Headings for the four different option kinds.
372    The standard value is (\"file\" \"grammar\" \"rule\" \"subrule\").  See
373    `antlr-options-alists'")
374    
375    (defvar antlr-options-alists
376      '(;; file options ----------------------------------------------------------
377        (("language" antlr-language-option-extra
378          (20600 antlr-read-value
379                 "Generated language: " language-as-string
380                 (("Java") ("Cpp") ("HTML") ("Diagnostic")))
381          (20700 antlr-read-value
382                 "Generated language: " language-as-string
383                 (("Java") ("Cpp") ("HTML") ("Diagnostic") ("Sather"))))
384         ("mangleLiteralPrefix" nil
385          (20600 antlr-read-value
386                 "Prefix for literals (default LITERAL_): " t))
387         ("namespace" antlr-c++-mode-extra
388          (20700 antlr-read-value
389                 "Wrap generated C++ code in namespace: " t))
390         ("namespaceStd" antlr-c++-mode-extra
391          (20701 antlr-read-value
392                 "Replace ANTLR_USE_NAMESPACE(std) by: " t))
393         ("namespaceAntlr" antlr-c++-mode-extra
394          (20701 antlr-read-value
395                 "Replace ANTLR_USE_NAMESPACE(antlr) by: " t))
396         ("genHashLines" antlr-c++-mode-extra
397          (20701 antlr-read-boolean
398                 "Include #line in generated C++ code? "))
399         )
400        ;; grammar options --------------------------------------------------------
401        (("k" nil
402          (20600 antlr-read-value
403                 "Lookahead depth: "))
404         ("importVocab" nil
405          (20600 antlr-read-value
406                 "Import vocabulary: "))
407         ("exportVocab" nil
408          (20600 antlr-read-value
409                 "Export vocabulary: "))
410         ("testLiterals" nil                ; lexer only
411          (20600 antlr-read-boolean
412                 "Test each token against literals table? "))
413         ("defaultErrorHandler" nil         ; not for lexer
414          (20600 antlr-read-boolean
415                 "Generate default exception handler for each rule? "))
416         ("codeGenMakeSwitchThreshold" nil
417          (20600 antlr-read-value
418                 "Min number of alternatives for 'switch': "))
419         ("codeGenBitsetTestThreshold" nil
420          (20600 antlr-read-value
421                 "Min size of lookahead set for bitset test: "))
422         ("analyzerDebug" nil
423          (20600 antlr-read-boolean
424                 "Display debugging info during grammar analysis? "))
425         ("codeGenDebug" nil
426          (20600 antlr-read-boolean
427                 "Display debugging info during code generation? "))
428         ("buildAST" nil                    ; not for lexer
429          (20600 antlr-read-boolean
430                 "Use automatic AST construction/transformation? "))
431         ("ASTLabelType" nil                ; not for lexer
432          (20600 antlr-read-value
433                 "Class of user-defined AST node: " t))
434         ("charVocabulary" nil              ; lexer only
435          (20600 nil
436                 "Insert character vocabulary"))
437         ("interactive" nil
438          (20600 antlr-read-boolean
439                 "Generate interactive lexer/parser? "))
440         ("caseSensitive" nil               ; lexer only
441          (20600 antlr-read-boolean
442                 "Case significant when matching characters? "))
443         ("caseSensitiveLiterals" nil       ; lexer only
444          (20600 antlr-read-boolean
445                 "Case significant when testing literals table? "))
446         ("classHeaderSuffix" nil
447          (20600 nil
448                 "Additional string for grammar class definition"))
449         ("filter" nil                      ; lexer only
450          (20600 antlr-read-boolean
451                 "Skip rule (the name, true or false): "
452                 antlr-grammar-tokens))
453         ("namespace" antlr-c++-mode-extra
454          (20700 antlr-read-value
455                 "Wrap generated C++ code for grammar in namespace: " t))
456         ("namespaceStd" antlr-c++-mode-extra
457          (20701 antlr-read-value
458                 "Replace ANTLR_USE_NAMESPACE(std) by: " t))
459         ("namespaceAntlr" antlr-c++-mode-extra
460          (20701 antlr-read-value
461                 "Replace ANTLR_USE_NAMESPACE(antlr) by: " t))
462         ("genHashLines" antlr-c++-mode-extra
463          (20701 antlr-read-boolean
464                 "Include #line in generated C++ code? "))
465    ;;;     ("autoTokenDef" nil             ; parser only
466    ;;;      (80000 antlr-read-boolean              ; default: true
467    ;;;          "Automatically define referenced token? "))
468    ;;;     ("keywordsMeltTo" nil           ; parser only
469    ;;;      (80000 antlr-read-value
470    ;;;          "Change non-matching keywords to token type: "))
471         )
472        ;; rule options ----------------------------------------------------------
473        (("testLiterals" nil                ; lexer only
474          (20600 antlr-read-boolean
475                 "Test this token against literals table? "))
476         ("defaultErrorHandler" nil         ; not for lexer
477          (20600 antlr-read-boolean
478                 "Generate default exception handler for this rule? "))
479         ("ignore" nil                      ; lexer only
480          (20600 antlr-read-value
481                 "In this rule, ignore tokens of type: " nil
482                 antlr-grammar-tokens))
483         ("paraphrase" nil                  ; lexer only
484          (20600 antlr-read-value
485                 "In messages, replace name of this token by: " t))
486         )
487        ;; subrule options -------------------------------------------------------
488        (("warnWhenFollowAmbig" nil
489          (20600 antlr-read-boolean
490                 "Display warnings for ambiguities with FOLLOW? "))
491         ("generateAmbigWarnings" nil
492          (20600 antlr-read-boolean
493                 "Display warnings for ambiguities? "))
494         ("greedy" nil
495          (20700 antlr-read-boolean
496                 "Make this optional/loop subrule greedy? "))
497         ))
498      "Definitions for Antlr's options of all four different kinds.
499    
500    The value looks like \(FILE GRAMMAR RULE SUBRULE) where each FILE,
501    GRAMMAR, RULE, and SUBRULE is a list of option definitions of the
502    corresponding kind, i.e., looks like \(OPTION-DEF...).
503    
504    Each OPTION-DEF looks like \(OPTION-NAME EXTRA-FN VALUE-SPEC...) which
505    defines a file/grammar/rule/subrule option with name OPTION-NAME.  The
506    OPTION-NAMEs are used for the creation of the \"Insert XXX Option\"
507    submenus, see `antlr-options-use-submenus', and to allow to insert the
508    option name with completion when using \\[antlr-insert-option].
509    
510    If EXTRA-FN is a function, it is called at different phases of the
511    insertion with arguments \(PHASE OPTION-NAME).  PHASE can have the
512    values `before-input' or `after-insertion', additional phases might be
513    defined in future versions of this mode.  The phase `before-input'
514    occurs before the user is asked to insert a value.  The phase
515    `after-insertion' occurs after the option value has been inserted.
516    EXTRA-FN might be called with additional arguments in future versions of
517    this mode.
518    
519    Each specification VALUE-SPEC looks like \(VERSION READ-FN ARG...).  The
520    last VALUE-SPEC in an OPTION-DEF whose VERSION is smaller or equal to
521    `antlr-tool-version' specifies how the user is asked for the value of
522    the option.
523    
524    If READ-FN is nil, the only ARG is a string which is printed at the echo
525    area to guide the user what to insert at point.  Otherwise, READ-FN is
526    called with arguments \(INIT-VALUE ARG...) to get the new value of the
527    option.  INIT-VALUE is the old value of the option or nil.
528    
529    The standard value contains the following functions as READ-FN:
530    `antlr-read-value' with ARGs = \(PROMPT AS-STRING TABLE) which reads a
531    general value, or `antlr-read-boolean' with ARGs = \(PROMPT TABLE) which
532    reads a boolean value or a member of TABLE.  PROMPT is the prompt when
533    asking for a new value.  If non-nil, TABLE is a table for completion or
534    a function evaluating to such a table.  The return value is quoted iff
535    AS-STRING is non-nil and is either t or a symbol which is a member of
536    `antlr-options-style'.")
537    
538    
539  ;;;===========================================================================  ;;;===========================================================================
# Line 265  Otherwise, it saves all modified buffers Line 557  Otherwise, it saves all modified buffers
557    '("\n" ("GENS" "GENS%d" " \\\n\t") "$(ANTLR)")    '("\n" ("GENS" "GENS%d" " \\\n\t") "$(ANTLR)")
558    "*Variable to specify the appearance of the generated makefile rules.    "*Variable to specify the appearance of the generated makefile rules.
559  This variable influences the output of \\[antlr-show-makefile-rules].  This variable influences the output of \\[antlr-show-makefile-rules].
560  It looks like (RULE-SEP GEN-VAR-SPEC COMMAND).  It looks like \(RULE-SEP GEN-VAR-SPEC COMMAND).
561    
562  RULE-SEP is the string to separate different makefile rules.  COMMAND is  RULE-SEP is the string to separate different makefile rules.  COMMAND is
563  a string with the command which runs the Antlr tool, it should include  a string with the command which runs the Antlr tool, it should include
# Line 273  all options except the option \"-glib\" Line 565  all options except the option \"-glib\"
565  if necessary.  if necessary.
566    
567  If GEN-VAR-SPEC is nil, each target directly consists of a list of  If GEN-VAR-SPEC is nil, each target directly consists of a list of
568  files.  If GEN-VAR-SPEC looks like (GEN-VAR GEN-VAR-FORMAT GEN-SEP), a  files.  If GEN-VAR-SPEC looks like \(GEN-VAR GEN-VAR-FORMAT GEN-SEP), a
569  Makefile variable is created for each rule target.  Makefile variable is created for each rule target.
570    
571  Then, GEN-VAR is a string with the name of the variable which contains  Then, GEN-VAR is a string with the name of the variable which contains
# Line 295  COUNT starts with 1.  GEN-SEP is used to Line 587  COUNT starts with 1.  GEN-SEP is used to
587      (c++-mode ("%sTokenTypes.hpp") ("%s.cpp" "%s.hpp")))      (c++-mode ("%sTokenTypes.hpp") ("%s.cpp" "%s.hpp")))
588    "Language dependent formats which specify generated files.    "Language dependent formats which specify generated files.
589  Each element in this list looks looks like  Each element in this list looks looks like
590    (MAJOR-MODE (VOCAB-FILE-FORMAT...) (CLASS-FILE-FORMAT...)).    \(MAJOR-MODE (VOCAB-FILE-FORMAT...) (CLASS-FILE-FORMAT...)).
591    
592  The element whose MAJOR-MODE is equal to `antlr-language' is used to  The element whose MAJOR-MODE is equal to `antlr-language' is used to
593  specify the generated files which are language dependent.  See variable  specify the generated files which are language dependent.  See variable
# Line 308  CLASS/%s the generated file for each gra Line 600  CLASS/%s the generated file for each gra
600    
601  (defvar antlr-special-file-formats '("%sTokenTypes.txt" "expanded%s.g")  (defvar antlr-special-file-formats '("%sTokenTypes.txt" "expanded%s.g")
602    "Language independent formats which specify generated files.    "Language independent formats which specify generated files.
603  The value looks like (VOCAB-FILE-FORMAT EXPANDED-GRAMMAR-FORMAT).  The value looks like \(VOCAB-FILE-FORMAT EXPANDED-GRAMMAR-FORMAT).
604    
605  VOCAB-FILE-FORMAT is a format string, it specifies with substitution  VOCAB-FILE-FORMAT is a format string, it specifies with substitution
606  VOCAB/%s the generated or input file for each export or import  VOCAB/%s the generated or input file for each export or import
# Line 322  formats.") Line 614  formats.")
614    
615  (defvar antlr-unknown-file-formats '("?%s?.g" "?%s?")  (defvar antlr-unknown-file-formats '("?%s?.g" "?%s?")
616    "*Formats which specify the names of unknown files.    "*Formats which specify the names of unknown files.
617  The value looks like (SUPER-GRAMMAR-FILE-FORMAT SUPER-EVOCAB-FORMAT).  The value looks like \(SUPER-GRAMMAR-FILE-FORMAT SUPER-EVOCAB-FORMAT).
618    
619  SUPER-GRAMMAR-FORMAT is a format string, it specifies with substitution  SUPER-GRAMMAR-FORMAT is a format string, it specifies with substitution
620  SUPER/%s the name of a grammar file for Antlr's option \"-glib\" if no  SUPER/%s the name of a grammar file for Antlr's option \"-glib\" if no
# Line 376  imenu." Line 668  imenu."
668      (define-key map "\C-c\C-c" 'comment-region)      (define-key map "\C-c\C-c" 'comment-region)
669      (define-key map "\C-c\C-v" 'antlr-hide-actions)      (define-key map "\C-c\C-v" 'antlr-hide-actions)
670      (define-key map "\C-c\C-r" 'antlr-run-tool)      (define-key map "\C-c\C-r" 'antlr-run-tool)
671        (define-key map "\C-c\C-o" 'antlr-insert-option)
672      ;; I'm too lazy to define my own:      ;; I'm too lazy to define my own:
673      (define-key map "\ea" 'c-beginning-of-statement)      (define-key map "\ea" 'c-beginning-of-statement)
674      (define-key map "\ee" 'c-end-of-statement)      (define-key map "\ee" 'c-end-of-statement)
675        ;; electric keys:
676        (define-key map ":" 'antlr-electric-character)
677        (define-key map ";" 'antlr-electric-character)
678        (define-key map "|" 'antlr-electric-character)
679        (define-key map "&" 'antlr-electric-character)
680        (define-key map "(" 'antlr-electric-character)
681        (define-key map ")" 'antlr-electric-character)
682        (define-key map "{" 'antlr-electric-character)
683        (define-key map "}" 'antlr-electric-character)
684      map)      map)
685    "Keymap used in `antlr-mode' buffers.")    "Keymap used in `antlr-mode' buffers.")
686    
687  (easy-menu-define antlr-mode-menu  (easy-menu-define antlr-mode-menu antlr-mode-map
688                    antlr-mode-map    "Major mode menu."
689                    "Major mode menu."    `("Antlr"
690                    '("Antlr"      ,@(if (and antlr-options-use-submenus
691                      ["Indent Line" antlr-indent-command                 (boundp 'emacs-major-version)
692                       :active (not buffer-read-only)]                 (or (featurep 'xemacs) (>= emacs-major-version 21)))
693                      ["Indent for Comment" indent-for-comment            `(("Insert File Option"
694                       :active (not buffer-read-only)]               :filter ,(lambda (x) (antlr-options-menu-filter 1 x)))
695                      ["Comment Out Region" comment-region              ("Insert Grammar Option"
696                       :active (and (not buffer-read-only)               :filter ,(lambda (x) (antlr-options-menu-filter 2 x)))
697                                    (c-region-is-active-p))]              ("Insert Rule Option"
698                      ["Uncomment Region"               :filter ,(lambda (x) (antlr-options-menu-filter 3 x)))
699                       (comment-region (region-beginning) (region-end) '(4))              ("Insert Subrule Option"
700                       :active (and (not buffer-read-only)               :filter ,(lambda (x) (antlr-options-menu-filter 4 x)))
701                                    (c-region-is-active-p))]              "---")
702                      "---"          '(["Insert Option" antlr-insert-option
703                      ["Backward Rule" antlr-beginning-of-rule t]             :active (not buffer-read-only)]))
704                      ["Forward Rule" antlr-end-of-rule t]      ("Forward/Backward"
705                      ["Start of Rule Body" antlr-beginning-of-body       ["Backward Rule" antlr-beginning-of-rule t]
706                       :active (antlr-inside-rule-p)]       ["Forward Rule" antlr-end-of-rule t]
707                      ["End of Rule Body" antlr-end-of-body       ["Start of Rule Body" antlr-beginning-of-body
708                       :active (antlr-inside-rule-p)]        :active (antlr-inside-rule-p)]
709                      "---"       ["End of Rule Body" antlr-end-of-body
710                      ["Backward Statement" c-beginning-of-statement t]        :active (antlr-inside-rule-p)]
711                      ["Forward Statement" c-end-of-statement t]       "---"
712                      ["Backward Into Nomencl." c-backward-into-nomenclature t]       ["Backward Statement" c-beginning-of-statement t]
713                      ["Forward Into Nomencl." c-forward-into-nomenclature t]       ["Forward Statement" c-end-of-statement t]
714                      "---"       ["Backward Into Nomencl." c-backward-into-nomenclature t]
715                      ["Hide Actions (incl. Args)" antlr-hide-actions t]       ["Forward Into Nomencl." c-forward-into-nomenclature t])
716                      ["Hide Actions (excl. Args)" (antlr-hide-actions 2) t]      ["Indent Region" indent-region
717                      ["Unhide All Actions" (antlr-hide-actions 0) t]       :active (and (not buffer-read-only) (c-region-is-active-p))]
718                      "---"      ["Comment Out Region" comment-region
719                      ["Run Tool on Grammar" antlr-run-tool t]       :active (and (not buffer-read-only) (c-region-is-active-p))]
720                      ["Show Makefile Rules" antlr-show-makefile-rules t]))      ["Uncomment Region"
721         (comment-region (region-beginning) (region-end) '(4))
722         :active (and (not buffer-read-only) (c-region-is-active-p))]
723        "---"
724        ["Hide Actions (incl. Args)" antlr-hide-actions t]
725        ["Hide Actions (excl. Args)" (antlr-hide-actions 2) t]
726        ["Unhide All Actions" (antlr-hide-actions 0) t]
727        "---"
728        ["Run Tool on Grammar" antlr-run-tool t]
729        ["Show Makefile Rules" antlr-show-makefile-rules t]
730        "---"
731        ["Customize Antlr" (customize-group 'antlr) t]))
732    
733    
734  ;;;===========================================================================  ;;;===========================================================================
# Line 432  fontification, see `antlr-font-lock-keyw Line 745  fontification, see `antlr-font-lock-keyw
745    
746  While calculating the decoration level for actions, `major-mode' is  While calculating the decoration level for actions, `major-mode' is
747  bound to `antlr-language'.  For example, with value  bound to `antlr-language'.  For example, with value
748    ((java-mode . 2) (c++-mode . 0))    \((java-mode \. 2) (c++-mode \. 0))
749  Java actions are fontified with level 2 and C++ actions are not  Java actions are fontified with level 2 and C++ actions are not
750  fontified at all."  fontified at all."
751    :type '(choice (const :tag "none" none)    :type '(choice (const :tag "None" none)
752                   (const :tag "inherit" inherit)                   (const :tag "Inherit" inherit)
753                   (const :tag "default" nil)                   (const :tag "Default" nil)
754                   (const :tag "maximum" t)                   (const :tag "Maximum" t)
755                   (integer :tag "level" 1)                   (integer :tag "Level" 1)
756                   (repeat :menu-tag "mode specific" :tag "mode specific"                   (repeat :menu-tag "Mode specific" :tag "Mode specific"
757                           :value ((t . t))                           :value ((t . t))
758                           (cons :tag "Instance"                           (cons :tag "Instance"
759                                 (radio :tag "Mode"                                 (radio :tag "Mode"
760                                        (const :tag "all" t)                                        (const :tag "All" t)
761                                        (symbol :tag "name"))                                        (symbol :tag "Name"))
762                                 (radio :tag "Decoration"                                 (radio :tag "Decoration"
763                                        (const :tag "default" nil)                                        (const :tag "Default" nil)
764                                        (const :tag "maximum" t)                                        (const :tag "Maximum" t)
765                                        (integer :tag "level" 1))))))                                        (integer :tag "Level" 1))))))
766    
767  (defconst antlr-no-action-keywords nil  (defconst antlr-no-action-keywords nil
768    ;; Using nil directly won't work (would use highest level, see    ;; Using nil directly won't work (would use highest level, see
# Line 469  Do not change the value of this constant Line 782  Do not change the value of this constant
782       c++-font-lock-keywords-3))       c++-font-lock-keywords-3))
783    "List of font-lock keywords for actions in the grammar.    "List of font-lock keywords for actions in the grammar.
784  Each element in this list looks like  Each element in this list looks like
785    (MAJOR-MODE KEYWORD...)    \(MAJOR-MODE KEYWORD...)
786    
787  If `antlr-language' is equal to MAJOR-MODE, the KEYWORDs are the  If `antlr-language' is equal to MAJOR-MODE, the KEYWORDs are the
788  font-lock keywords according to `font-lock-defaults' used for the code  font-lock keywords according to `font-lock-defaults' used for the code
789  in the grammar's actions and semantic predicates, see  in the grammar's actions and semantic predicates, see
790  `antlr-font-lock-maximum-decoration'.")  `antlr-font-lock-maximum-decoration'.")
791    
792    (defvar antlr-font-lock-default-face 'antlr-font-lock-default-face)
793    (defface antlr-font-lock-default-face nil
794      "Face to prevent strings from language dependent highlighting.
795    Do not change."
796      :group 'antlr)
797    
798  (defvar antlr-font-lock-keyword-face 'antlr-font-lock-keyword-face)  (defvar antlr-font-lock-keyword-face 'antlr-font-lock-keyword-face)
799  (defface antlr-font-lock-keyword-face  (defface antlr-font-lock-keyword-face
800    '((((class color) (background light)) (:foreground "black" :bold t)))    '((((class color) (background light)) (:foreground "black" :bold t)))
801    "ANTLR keywords."    "ANTLR keywords."
802    :group 'antlr)    :group 'antlr)
803    
804    (defvar antlr-font-lock-syntax-face 'antlr-font-lock-keyword-face)
805    (defface antlr-font-lock-syntax-face
806      '((((class color) (background light)) (:foreground "black" :bold t)))
807      "ANTLR syntax symbols like :, |, (, ), ...."
808      :group 'antlr)
809    
810  (defvar antlr-font-lock-ruledef-face 'antlr-font-lock-ruledef-face)  (defvar antlr-font-lock-ruledef-face 'antlr-font-lock-ruledef-face)
811  (defface antlr-font-lock-ruledef-face  (defface antlr-font-lock-ruledef-face
812    '((((class color) (background light)) (:foreground "blue" :bold t)))    '((((class color) (background light)) (:foreground "blue" :bold t)))
# Line 509  in the grammar's actions and semantic pr Line 834  in the grammar's actions and semantic pr
834  (defvar antlr-font-lock-literal-face 'antlr-font-lock-literal-face)  (defvar antlr-font-lock-literal-face 'antlr-font-lock-literal-face)
835  (defface antlr-font-lock-literal-face  (defface antlr-font-lock-literal-face
836    '((((class color) (background light)) (:foreground "brown4" :bold t)))    '((((class color) (background light)) (:foreground "brown4" :bold t)))
837    "ANTLR literal tokens consisting merely of letter-like characters."    "ANTLR special literal tokens.
838    It is used to highlight strings matched by the first regexp group of
839    `antlr-font-lock-literal-regexp'."
840    :group 'antlr)    :group 'antlr)
841    
842    (defcustom antlr-font-lock-literal-regexp "\"\\(\\sw\\(\\sw\\|-\\)*\\)\""
843      "Regexp matching literals with special syntax highlighting, or nil.
844    If nil, there is no special syntax highlighting for some literals.
845    Otherwise, it should be a regular expression which must contain a regexp
846    group.  The string matched by the first group is highlighted with
847    `antlr-font-lock-literal-face'."
848      :group 'antlr
849      :type '(choice (const :tag "None" nil) regexp))
850    
851    (defvar antlr-class-header-regexp
852      "\\(class\\)[ \t]+\\([A-Za-z\300-\326\330-\337]\\sw*\\)[ \t]+\\(extends\\)[ \t]+\\([A-Za-z\300-\326\330-\337]\\sw*\\)[ \t]*;"
853      "Regexp matching class headers.")
854    
855  (defvar antlr-font-lock-additional-keywords  (defvar antlr-font-lock-additional-keywords
856    `((antlr-invalidate-context-cache)    `((antlr-invalidate-context-cache)
857      ("\\$setType[ \t]*(\\([A-Za-z\300-\326\330-\337]\\sw*\\))"      ("\\$setType[ \t]*(\\([A-Za-z\300-\326\330-\337]\\sw*\\))"
# Line 519  in the grammar's actions and semantic pr Line 859  in the grammar's actions and semantic pr
859      ("\\$\\sw+" (0 font-lock-keyword-face))      ("\\$\\sw+" (0 font-lock-keyword-face))
860      ;; the tokens are already fontified as string/docstrings:      ;; the tokens are already fontified as string/docstrings:
861      (,(lambda (limit)      (,(lambda (limit)
862          (antlr-re-search-forward "\"\\(\\sw\\(\\sw\\|-\\)*\\)\"" limit))          (if antlr-font-lock-literal-regexp
863                (antlr-re-search-forward antlr-font-lock-literal-regexp limit)))
864       (1 antlr-font-lock-literal-face t)       (1 antlr-font-lock-literal-face t)
865       ,@(and (string-match "XEmacs" emacs-version)       ,@(and (featurep 'xemacs) '((0 nil)))) ; XEmacs bug workaround
             '((0 nil))))                ; XEmacs bug workaround  
866      (,(lambda (limit)      (,(lambda (limit)
867          (antlr-re-search-forward          (antlr-re-search-forward antlr-class-header-regexp limit))
          "^\\(class\\)[ \t]+\\([A-Za-z\300-\326\330-\337]\\sw*\\)[ \t]+\\(extends\\)[ \t]+\\([A-Za-z\300-\326\330-\337]\\sw*\\)[ \t]*;" limit))  
868       (1 antlr-font-lock-keyword-face)       (1 antlr-font-lock-keyword-face)
869       (2 antlr-font-lock-ruledef-face)       (2 antlr-font-lock-ruledef-face)
870       (3 antlr-font-lock-keyword-face)       (3 antlr-font-lock-keyword-face)
# Line 539  in the grammar's actions and semantic pr Line 878  in the grammar's actions and semantic pr
878       (1 antlr-font-lock-keyword-face))       (1 antlr-font-lock-keyword-face))
879      (,(lambda (limit)      (,(lambda (limit)
880          (antlr-re-search-forward          (antlr-re-search-forward
881           "^\\(private\\|public\\|protected\\)\\>\\([ \t]+\\(\\sw+\\)\\)?"           "^\\(private\\|public\\|protected\\)\\>[ \t]*\\(\\(\\sw+[ \t]*\\(:\\)?\\)\\)?"
882           limit))           limit))
883       (1 font-lock-type-face)            ; not XEmacs' java level-3 fruit salad       (1 font-lock-type-face)            ; not XEmacs' java level-3 fruit salad
884       (3 (if (antlr-upcase-p (char-after (match-beginning 3)))       (3 (if (antlr-upcase-p (char-after (match-beginning 3)))
885              'antlr-font-lock-tokendef-face              'antlr-font-lock-tokendef-face
886            'antlr-font-lock-ruledef-face) nil t))            'antlr-font-lock-ruledef-face) nil t)
887         (4 antlr-font-lock-syntax-face nil t))
888      (,(lambda (limit)      (,(lambda (limit)
889          (antlr-re-search-forward "^\\sw+" limit))          (antlr-re-search-forward "^\\(\\sw+\\)[ \t]*\\(:\\)?" limit))
890       (0 (if (antlr-upcase-p (char-after (match-beginning 0)))       (1 (if (antlr-upcase-p (char-after (match-beginning 0)))
891              'antlr-font-lock-tokendef-face              'antlr-font-lock-tokendef-face
892            'antlr-font-lock-ruledef-face) nil t))            'antlr-font-lock-ruledef-face) nil t)
893         (2 antlr-font-lock-syntax-face nil t))
894      (,(lambda (limit)      (,(lambda (limit)
895          ;; not only before a rule ref, also before a literal          ;; v:ruleref and v:"literal" is allowed...
896          (antlr-re-search-forward "\\<\\(\\sw+\\)[ \t]*:" limit))          (antlr-re-search-forward "\\(\\sw+\\)[ \t]*\\([=:]\\)?" limit))
897       (1 font-lock-variable-name-face))       (1 (if (match-beginning 2)
898                (if (eq (char-after (match-beginning 2)) ?=)
899                    'antlr-font-lock-default-face
900                  'font-lock-variable-name-face)
901              (if (antlr-upcase-p (char-after (match-beginning 1)))
902                  'antlr-font-lock-tokenref-face
903                'antlr-font-lock-ruleref-face)))
904         (2 antlr-font-lock-default-face nil t))
905      (,(lambda (limit)      (,(lambda (limit)
906          (antlr-re-search-forward "\\<\\(\\sw+[ \t]*=[ \t]*\\)?\\(\\sw+[ \t]*:[ \t]*\\)?\\(\\sw+\\)" limit))          (antlr-re-search-forward "[|&:;(]\\|)\\([*+?]\\|=>\\)?" limit))
907       ;;(1 antlr-font-lock-default-face nil t) ; fool java-font-lock-keywords       (0 'antlr-font-lock-syntax-face)))
      (3 (if (antlr-upcase-p (char-after (match-beginning 3)))  
             'antlr-font-lock-tokenref-face  
           'antlr-font-lock-ruleref-face))))  
908    "Font-lock keywords for ANTLR's normal grammar code.    "Font-lock keywords for ANTLR's normal grammar code.
909  See `antlr-font-lock-keywords-alist' for the keywords of actions.")  See `antlr-font-lock-keywords-alist' for the keywords of actions.")
910    
911  (defvar antlr-font-lock-defaults  (defvar antlr-font-lock-defaults
912    '(antlr-font-lock-keywords    '(antlr-font-lock-keywords
913      nil nil ((?_ . "w") (?\( . ".") (?\) . ".")) beginning-of-defun)      nil nil ((?_ . "w") (?\( . ".") (?\) . ".")) beginning-of-defun)
914    "Font-lock defaults used for ANTLR syntax coloring.    "Font-lock defaults used for ANTLR syntax highlighting.
915  The SYNTAX-ALIST element is also used to initialize  The SYNTAX-ALIST element is also used to initialize
916  `antlr-action-syntax-table'.")  `antlr-action-syntax-table'.")
917    
# Line 601  not to confuse their context_cache.") Line 946  not to confuse their context_cache.")
946  ;;;;##########################################################################  ;;;;##########################################################################
947    
948    
949    
950  ;;;===========================================================================  ;;;===========================================================================
951  ;;;  Syntax functions -- Emacs vs XEmacs dependent  ;;;  Syntax functions -- Emacs vs XEmacs dependent
952  ;;;===========================================================================  ;;;===========================================================================
# Line 618  not to confuse their context_cache.") Line 964  not to confuse their context_cache.")
964  (defun antlr-scan-sexps-internal (from count &optional dummy no-error)  (defun antlr-scan-sexps-internal (from count &optional dummy no-error)
965  ;; checkdoc-params: (from count dummy)  ;; checkdoc-params: (from count dummy)
966    "Like `scan-sexps' but with additional arguments.    "Like `scan-sexps' but with additional arguments.
967  When optional arg NO-ERROR is non-nil, `scan-sexps' will return nil  When optional arg NO-ERROR is non-nil, `antlr-scan-sexps-internal' will
968  instead of signaling an error."  return nil instead of signaling an error."
969    (if no-error    (if no-error
970        (condition-case nil        (condition-case nil
971            (scan-sexps from count)            (scan-sexps from count)
972          (t nil))          (error nil))
973      (scan-sexps from count)))      (scan-sexps from count)))
974    
975    (defun antlr-scan-lists-internal (from count depth &optional dummy no-error)
976    ;; checkdoc-params: (from count depth dummy)
977      "Like `scan-lists' but with additional arguments.
978    When optional arg NO-ERROR is non-nil, `antlr-scan-lists-internal' will
979    return nil instead of signaling an error."
980      (if no-error
981          (condition-case nil
982              (scan-lists from count depth)
983            (error nil))
984        (scan-lists from count depth)))
985    
986  (defun antlr-xemacs-bug-workaround (&rest dummies)  (defun antlr-xemacs-bug-workaround (&rest dummies)
987  ;; checkdoc-params: (dummies)  ;; checkdoc-params: (dummies)
988    "Invalidate context_cache for syntactical context information."    "Invalidate context_cache for syntactical context information."
# Line 738  See `antlr-font-lock-additional-keywords Line 1095  See `antlr-font-lock-additional-keywords
1095  ;;;  imenu support  ;;;  imenu support
1096  ;;;===========================================================================  ;;;===========================================================================
1097    
1098  (defun antlr-imenu-create-index-function ()  (defun antlr-grammar-tokens ()
1099    "Return imenu index-alist for ANTLR grammar files."    "Return alist for tokens defined in current buffer."
1100      (save-excursion (antlr-imenu-create-index-function t)))
1101    
1102    (defun antlr-imenu-create-index-function (&optional tokenrefs-only)
1103      "Return imenu index-alist for ANTLR grammar files.
1104    IF TOKENREFS-ONLY is non-nil, just return alist with tokenref names."
1105    (let ((items nil)    (let ((items nil)
1106          (classes nil)          (classes nil)
1107          (semi (point-max)))          (semi (point-max)))
# Line 751  See `antlr-font-lock-additional-keywords Line 1113  See `antlr-font-lock-additional-keywords
1113        ;; editing (you are more likely to add functions to the end of the file).        ;; editing (you are more likely to add functions to the end of the file).
1114        (while semi        (while semi
1115          (goto-char semi)          (goto-char semi)
1116          (if (setq semi (antlr-search-backward ";"))          (setq semi (antlr-search-backward ";"))
1117            (if semi
1118              (progn (forward-char) (antlr-skip-exception-part t))              (progn (forward-char) (antlr-skip-exception-part t))
1119            (antlr-skip-file-prelude t))            (antlr-skip-file-prelude t))
1120          (if (looking-at "{") (antlr-skip-sexps 1))          (if (looking-at "{") (antlr-skip-sexps 1))
1121          (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]*;")          (if (looking-at antlr-class-header-regexp)
1122              (push (cons (match-string 1)              (or tokenrefs-only
1123                          (if imenu-use-markers                  (push (cons (match-string 2)
1124                              (copy-marker (match-beginning 1))                              (if imenu-use-markers
1125                            (match-beginning 1)))                                  (copy-marker (match-beginning 2))
1126                    classes)                                (match-beginning 2)))
1127                          classes))
1128            (if (looking-at "p\\(ublic\\|rotected\\|rivate\\)")            (if (looking-at "p\\(ublic\\|rotected\\|rivate\\)")
1129                (antlr-skip-sexps 1))                (antlr-skip-sexps 1))
1130            (when (looking-at "\\sw+")            (when (looking-at "\\sw+")
1131              (push (cons (match-string 0)              (if tokenrefs-only
1132                          (if imenu-use-markers                  (if (antlr-upcase-p (char-after (point)))
1133                              (copy-marker (match-beginning 0))                      (push (list (match-string 0)) items))
1134                            (match-beginning 0)))                (push (cons (match-string 0)
1135                    items)))))                            (if imenu-use-markers
1136                                  (copy-marker (match-beginning 0))
1137                                (match-beginning 0)))
1138                        items))))))
1139      (if classes (cons (cons "Classes" classes) items) items)))      (if classes (cons (cons "Classes" classes) items) items)))
1140    
1141    
# Line 794  part." Line 1161  part."
1161          (if (looking-at "{") (setq pos (antlr-skip-sexps 1)))          (if (looking-at "{") (setq pos (antlr-skip-sexps 1)))
1162        (while (looking-at "exception\\>")        (while (looking-at "exception\\>")
1163          (setq pos (antlr-skip-sexps 1))          (setq pos (antlr-skip-sexps 1))
1164          (if (looking-at "\\[") (setq pos (antlr-skip-sexps 1)))          (when (looking-at "\\[")
1165              (setq pos (antlr-skip-sexps 1)))
1166          (while (looking-at "catch\\>")          (while (looking-at "catch\\>")
1167            (setq pos (antlr-skip-sexps 3)))))            (setq pos (antlr-skip-sexps 3)))))
1168      (or skip-comment (goto-char pos))))      (or skip-comment (goto-char pos))))
# Line 802  part." Line 1170  part."
1170  (defun antlr-skip-file-prelude (skip-comment)  (defun antlr-skip-file-prelude (skip-comment)
1171    "Skip the file prelude: the header and file options.    "Skip the file prelude: the header and file options.
1172  If SKIP-COMMENT is non-nil, also skip the comment after that part.  If SKIP-COMMENT is non-nil, also skip the comment after that part.
1173  Return the start position of the file prelude."  Return the start position of the file prelude.
1174    
1175    Hack: if SKIP-COMMENT is `header-only' only skip header and return
1176    position before the comment after the header."
1177    (let* ((pos (point))    (let* ((pos (point))
1178           (pos0 pos))           (pos0 pos))
1179      (c-forward-syntactic-ws)      (c-forward-syntactic-ws)
1180      (if skip-comment (setq pos0 (point)))      (if skip-comment (setq pos0 (point)))
1181      (while (looking-at "header\\>[ \t]*\\(\"\\)?")      (while (looking-at "header\\>[ \t]*\\(\"\\)?")
1182        (setq pos (antlr-skip-sexps (if (match-beginning 1) 3 2))))        (setq pos (antlr-skip-sexps (if (match-beginning 1) 3 2))))
1183      (if (looking-at "options\\>") (setq pos (antlr-skip-sexps 2)))      (if (eq skip-comment 'header-only)  ; a hack...
1184      (or skip-comment (goto-char pos))          pos
1185      pos0))        (when (looking-at "options\\>")
1186            (setq pos (antlr-skip-sexps 2)))
1187          (or skip-comment (goto-char pos))
1188          pos0)))
1189    
1190  (defun antlr-next-rule (arg skip-comment)  (defun antlr-next-rule (arg skip-comment)
1191    "Move forward to next end of rule.  Do it ARG many times.    "Move forward to next end of rule.  Do it ARG many times.
# Line 1011  Display a message unless optional argume Line 1385  Display a message unless optional argume
1385    
1386    
1387  ;;;===========================================================================  ;;;===========================================================================
1388    ;;;  Insert option: command
1389    ;;;===========================================================================
1390    
1391    (defun antlr-insert-option (level option &optional location)
1392      "Insert file/grammar/rule/subrule option near point.
1393    LEVEL determines option kind to insert: 1=file, 2=grammar, 3=rule,
1394    4=subrule.  OPTION is a string with the name of the option to insert.
1395    LOCATION can be specified for not calling `antlr-option-kind' twice.
1396    
1397    Inserting an option with this command works as follows:
1398    
1399     1. When called interactively, LEVEL is determined by the prefix
1400        argument or automatically deduced without prefix argument.
1401     2. Signal an error if no option of that level could be inserted, e.g.,
1402        if the buffer is read-only, the option area is outside the visible
1403        part of the buffer or a subrule/rule option should be inserted with
1404        point outside a subrule/rule.
1405     3. When called interactively, OPTION is read from the minibuffer with
1406        completion over the known options of the given LEVEL.
1407     4. Ask user for confirmation if the given OPTION does not seem to be a
1408        valid option to insert into the current file.
1409     5. Find a correct position to insert the option.
1410     6. Depending on the option, insert it the following way \(inserting an
1411        option also means inserting the option section if necessary\):
1412         - Insert the option and let user insert the value at point.
1413         - Read a value (with completion) from the minibuffer, using a
1414           previous value as initial contents, and insert option with value.
1415     7. Final action depending on the option.  For example, set the language
1416        according to a newly inserted language option.
1417    
1418    The name of all options with a specification for their values are stored
1419    in `antlr-options-alist'.  The used specification also depends on the
1420    value of `antlr-tool-version', i.e., step 4 will warn you if you use an
1421    option that has been introduced in newer version of ANTLR, and step 5
1422    will offer completion using version-correct values.
1423    
1424    If the option already exists inside the visible part of the buffer, this
1425    command can be used to change the value of that option.  Otherwise, find
1426    a correct position where the option can be inserted near point.
1427    
1428    The search for a correct position is as follows:
1429    
1430      * If search is within an area where options can be inserted, use the
1431        position of point.  Inside the options section and if point is in
1432        the middle of a option definition, skip the rest of it.
1433      * If an options section already exists, insert the options at the end.
1434        If only the beginning of the area is visible, insert at the
1435        beginning.
1436      * Otherwise, find the position where an options section can be
1437        inserted and insert a new section before any comments.  If the
1438        position before the comments is not visible, insert the new section
1439        after the comments.
1440    
1441    This function also inserts \"options {...}\" and the \":\" if necessary,
1442    see `antlr-options-auto-colon'.  See also `antlr-options-assign-string'.
1443    
1444    This command might also set the mark like \\[set-mark-command] does, see
1445    `antlr-options-push-mark'."
1446      (interactive (antlr-insert-option-interactive current-prefix-arg))
1447      (barf-if-buffer-read-only)
1448      (or location (setq location (cdr (antlr-option-kind level))))
1449      (cond ((null level)
1450             (error "Cannot deduce what kind of option to insert"))
1451            ((atom location)
1452             (error "Cannot insert any %s options around here"
1453                    (elt antlr-options-headings (1- level)))))
1454      (let ((area (car location))
1455            (place (cdr location)))
1456        (cond ((null place)         ; invisible
1457               (error (if area
1458                          "Invisible %s options, use %s to make them visible"
1459                        "Invisible area for %s options, use %s to make it visible")
1460                      (elt antlr-options-headings (1- level))
1461                      (substitute-command-keys "\\[widen]")))
1462              ((null area)                  ; without option part
1463               (antlr-insert-option-do level option nil
1464                                       (null (cdr place))
1465                                       (car place)))
1466              ((save-excursion              ; with option part, option visible
1467                 (goto-char (max (point-min) (car area)))
1468                 (re-search-forward (concat "\\(^\\|;\\)[ \t]*\\(\\<"
1469                                            (regexp-quote option)
1470                                            "\\>\\)[ \t\n]*\\(\\(=[ \t]?\\)[ \t]*\\(\\(\\sw\\|\\s_\\)+\\|\"\\([^\n\"\\]\\|[\\][^\n]\\)*\"\\)?\\)?")
1471                                    ;; 2=name, 3=4+5, 4="=", 5=value
1472                                    (min (point-max) (cdr area))
1473                                    t))
1474               (antlr-insert-option-do level option
1475                                       (cons (or (match-beginning 5)
1476                                                 (match-beginning 3))
1477                                             (match-end 5))
1478                                       (and (null (cdr place)) area)
1479                                       (or (match-beginning 5)
1480                                           (match-end 4)
1481                                           (match-end 2))))
1482              (t                            ; with option part, option not yet
1483               (antlr-insert-option-do level option t
1484                                       (and (null (cdr place)) area)
1485                                       (car place))))))
1486    
1487    (defun antlr-insert-option-interactive (arg)
1488      "Interactive specification for `antlr-insert-option'.
1489    Use prefix argument ARG to return \(LEVEL OPTION LOCATION)."
1490      (barf-if-buffer-read-only)
1491      (if arg (setq arg (prefix-numeric-value arg)))
1492      (unless (memq arg '(nil 1 2 3 4))
1493        (error "Valid prefix args: no=auto, 1=file, 2=grammar, 3=rule, 4=subrule"))
1494      (let* ((kind (antlr-option-kind arg))
1495             (level (car kind)))
1496        (if (atom (cdr kind))
1497            (list level nil (cdr kind))
1498          (let* ((table (elt antlr-options-alists (1- level)))
1499                 (completion-ignore-case t) ;dynamic
1500                 (input (completing-read (format "Insert %s option: "
1501                                                 (elt antlr-options-headings
1502                                                      (1- level)))
1503                                         table)))
1504            (list level input (cdr kind))))))
1505    
1506    (defun antlr-options-menu-filter (level menu-items)
1507      "Return items for options submenu of level LEVEL."
1508      ;; checkdoc-params: (menu-items)
1509      (let ((active (if buffer-read-only
1510                        nil
1511                      (consp (cdr-safe (cdr (antlr-option-kind level)))))))
1512        (mapcar (lambda (option)
1513                  (vector option
1514                          (list 'antlr-insert-option level option)
1515                          :active active))
1516                (sort (mapcar 'car (elt antlr-options-alists (1- level)))
1517                      'string-lessp))))
1518        
1519    
1520    ;;;===========================================================================
1521    ;;;  Insert option: determine section-kind
1522    ;;;===========================================================================
1523    
1524    (defun antlr-option-kind (requested)
1525      "Return level and location for option to insert near point.
1526    Call function `antlr-option-level' with argument REQUESTED.  If the
1527    result is nil, return \(REQUESTED \. error).  If the result has the
1528    non-nil value LEVEL, return \(LEVEL \. LOCATION) where LOCATION looks
1529    like \(AREA \. PLACE), see `antlr-option-location'."
1530      (save-excursion
1531        (save-restriction
1532          (let ((min0 (point-min))          ; before `widen'!
1533                (max0 (point-max))
1534                (orig (point))
1535                (level (antlr-option-level requested)) ; calls `widen'!
1536                pos)
1537            (cond ((null level)
1538                   (setq level requested))
1539                  ((eq level 1)             ; file options
1540                   (goto-char (point-min))
1541                   (setq pos (antlr-skip-file-prelude 'header-only)))
1542                  ((not (eq level 3))       ; grammar or subrule options
1543                   (setq pos (point))
1544                   (c-forward-syntactic-ws))
1545                  ((looking-at "^\\(private[ \t\n]\\|public[ \t\n]\\|protected[ \t\n]\\)?[ \t\n]*\\(\\(\\sw\\|\\s_\\)+\\)[ \t\n]*\\(!\\)?[ \t\n]*\\(\\[\\)?")
1546                   ;; rule options, with complete rule header
1547                   (goto-char (or (match-end 4) (match-end 3)))
1548                   (setq pos (antlr-skip-sexps (if (match-end 5) 1 0)))
1549                   (when (looking-at "returns[ \t\n]*\\[")
1550                     (goto-char (1- (match-end 0)))
1551                     (setq pos (antlr-skip-sexps 1)))))
1552            (cons level
1553                  (cond ((null pos) 'error)
1554                        ((looking-at "options[ \t\n]*{")
1555                         (goto-char (match-end 0))
1556                         (setq pos (antlr-scan-lists (point) 1 1 nil t))
1557                         (antlr-option-location orig min0 max0
1558                                                (point)
1559                                                (if pos (1- pos) (point-max))
1560                                                t))
1561                        (t
1562                         (antlr-option-location orig min0 max0
1563                                                pos (point)
1564                                                nil))))))))
1565    
1566    (defun antlr-option-level (requested)
1567      "Return level for option to insert near point.
1568    Remove any restrictions from current buffer and return level for the
1569    option to insert near point, i.e., 1, 2, 3, 4, or nil if no such option
1570    can be inserted.  If REQUESTED is non-nil, it is the only possible value
1571    to return except nil.  If REQUESTED is nil, return level for the nearest
1572    option kind, i.e., the highest number possible.
1573    
1574    If the result is 2, point is at the beginning of the class after the
1575    class definition.  If the result is 3 or 4, point is at the beginning of
1576    the rule/subrule after the init action.  Otherwise, the point position
1577    is undefined."
1578      (widen)
1579      (if (eq requested 1)
1580          1
1581        (antlr-with-syntax-table antlr-action-syntax-table
1582          (antlr-invalidate-context-cache)
1583          (let* ((orig (point))
1584                 (outsidep (antlr-outside-rule-p))
1585                 bor depth)
1586            (if (eq (char-after) ?\{) (antlr-skip-sexps 1))
1587            (setq bor (point))              ; beginning of rule (after init action)
1588            (cond ((eq requested 2)         ; grammar options required?
1589                   (let (boc)               ; beginning of class
1590                     (goto-char (point-min))
1591                     (while (and (<= (point) bor)
1592                                 (antlr-re-search-forward antlr-class-header-regexp
1593                                                          nil))
1594                       (if (<= (match-beginning 0) bor)
1595                           (setq boc (match-end 0))))
1596                     (when boc
1597                       (goto-char boc)
1598                       2)))
1599                  ((save-excursion          ; in region of file options?
1600                     (goto-char (point-min))
1601                     (antlr-skip-file-prelude t) ; ws/comment after: OK
1602                     (< orig (point)))
1603                   (and (null requested) 1))
1604                  (outsidep                 ; outside rule not OK
1605                   nil)
1606                  ((looking-at antlr-class-header-regexp) ; rule = class def?
1607                   (goto-char (match-end 0))
1608                   (and (null requested) 2))
1609                  ((eq requested 3)         ; rule options required?
1610                   (goto-char bor)
1611                   3)
1612                  ((setq depth (antlr-syntactic-grammar-depth orig bor))
1613                   (if (> depth 0)          ; move out of actions
1614                       (goto-char (scan-lists (point) -1 depth)))
1615                   (set-syntax-table antlr-mode-syntax-table)
1616                   (antlr-invalidate-context-cache)
1617                   (if (eq (antlr-syntactic-context) 0) ; not in subrule?
1618                       (unless (eq requested 4)
1619                         (goto-char bor)
1620                         3)
1621                     (goto-char (1+ (scan-lists (point) -1 1)))
1622                     4)))))))
1623    
1624    (defun antlr-option-location (orig min-vis max-vis min-area max-area withp)
1625      "Return location for the options area.
1626    ORIG is the original position of `point', MIN-VIS is `point-min' and
1627    MAX-VIS is `point-max'.  If WITHP is non-nil, there exists an option
1628    specification and it starts after the brace at MIN-AREA and stops at
1629    MAX-AREA.  If WITHP is nil, there is no area and the region where it
1630    could be inserted starts at MIN-AREA and stops at MAX-AREA.
1631    
1632    The result has the form (AREA . PLACE).  AREA is (MIN-AREA . MAX-AREA)
1633    if WITHP is non-nil, and nil otherwise.  PLACE is nil if the area is
1634    invisible, (ORIG) if ORIG is inside the area, (MIN-AREA . beginning) for
1635    a visible start position and (MAX-AREA . end) for a visible end position
1636    where the beginning is preferred if WITHP is nil and the end if WITHP is
1637    non-nil."
1638      (cons (and withp (cons min-area max-area))
1639            (cond ((and (<= min-area orig) (<= orig max-area))
1640                   ;; point in options area
1641                   (list orig))
1642                  ((and (null withp) (<= min-vis min-area) (<= min-area max-vis))
1643                   ;; use start of options area (only if not `withp')
1644                   (cons min-area 'beginning))
1645                  ((and (<= min-vis max-area) (<= max-area max-vis))
1646                   ;; use end of options area
1647                   (cons max-area 'end))
1648                  ((and withp (<= min-vis min-area) (<= min-area max-vis))
1649                   ;; use start of options area (only if `withp')
1650                   (cons min-area 'beginning)))))
1651    
1652    (defun antlr-syntactic-grammar-depth (pos beg)
1653      "Return syntactic context depth at POS.
1654    Move to POS and from there on to the beginning of the string or comment
1655    if POS is inside such a construct.  Then, return the syntactic context
1656    depth at point if the point position is smaller than BEG.
1657    WARNING: this may alter `match-data'."
1658      (goto-char pos)
1659      (let ((context (or (antlr-syntactic-context) 0)))
1660        (while (and context (not (integerp context)))
1661          (cond ((eq context 'string)
1662                 (setq context
1663                       (and (search-backward "\"" nil t)
1664                            (>= (point) beg)
1665                            (or (antlr-syntactic-context) 0))))
1666                ((memq context '(comment block-comment))
1667                 (setq context
1668                       (and (re-search-backward "/[/*]" nil t)
1669                            (>= (point) beg)
1670                            (or (antlr-syntactic-context) 0))))))
1671        context))
1672    
1673    
1674    ;;;===========================================================================
1675    ;;;  Insert options: do the insertion
1676    ;;;===========================================================================
1677    
1678    (defun antlr-insert-option-do (level option old area pos)
1679      "Insert option into buffer at position POS.
1680    Insert option of level LEVEL and name OPTION.  If OLD is non-nil, an
1681    options area is already exists.  If OLD looks like \(BEG \. END), the
1682    option already exists.  Then, BEG is the start position of the option
1683    value, the position of the `=' or nil, and END is the end position of
1684    the option value or nil.
1685    
1686    If the original point position was outside an options area, AREA is nil.
1687    Otherwise, and if an option specification already exists, AREA is a cons
1688    cell where the two values determine the area inside the braces."
1689      (let* ((spec (cdr (assoc option (elt antlr-options-alists (1- level)))))
1690             (value (antlr-option-spec level option (cdr spec) (consp old))))
1691        (if (fboundp (car spec)) (funcall (car spec) 'before-input option))
1692        ;; set mark (unless point was inside options area before)
1693        (if (cond (area (eq antlr-options-push-mark t))
1694                  ((numberp antlr-options-push-mark)
1695                   (> (count-lines (min (point) pos) (max (point) pos))
1696                      antlr-options-push-mark))
1697                  (antlr-options-push-mark))
1698            (push-mark))
1699        ;; read option value -----------------------------------------------------
1700        (goto-char pos)
1701        (if (null value)
1702            ;; no option specification found
1703            (if (y-or-n-p (format "Insert unknown %s option %s? "
1704                                  (elt antlr-options-headings (1- level))
1705                                  option))
1706                (message "Insert value for %s option %s"
1707                         (elt antlr-options-headings (1- level))
1708                         option)
1709              (error "Didn't insert unknown %s option %s"
1710                     (elt antlr-options-headings (1- level))
1711                     option))
1712          ;; option specification found
1713          (setq value (cdr value))
1714          (if (car value)
1715              (let ((initial (and (consp old) (cdr old)
1716                                  (buffer-substring (car old) (cdr old)))))
1717                (setq value (apply (car value)
1718                                   (and initial
1719                                        (if (eq (aref initial 0) ?\")
1720                                            (read initial)
1721                                          initial))
1722                                   (cdr value))))
1723            (message (cadr value))
1724            (setq value nil)))
1725        ;; insert value ----------------------------------------------------------
1726        (if (consp old)
1727            (antlr-insert-option-existing old value)
1728          (if (consp area)
1729              ;; Move outside string/comment if point is inside option spec
1730              (antlr-syntactic-grammar-depth (point) (car area)))
1731          (antlr-insert-option-space area old)
1732          (or old (antlr-insert-option-area level))
1733          (insert option " = ;")
1734          (backward-char)
1735          (if value (insert value)))
1736        ;; final -----------------------------------------------------------------
1737        (if (fboundp (car spec)) (funcall (car spec) 'after-insertion option))))
1738    
1739    (defun antlr-option-spec (level option specs existsp)
1740      "Return version correct option value specification.
1741    Return specification for option OPTION of kind level LEVEL.  SPECS
1742    should correspond to the VALUE-SPEC... in `antlr-option-alists'.
1743    EXISTSP determines whether the option already exists."
1744      (let (value)
1745        (while (and specs (>= antlr-tool-version (caar specs)))
1746          (setq value (pop specs)))
1747        (cond (value)                       ; found correct spec
1748              ((null specs) nil)            ; didn't find any specs
1749              (existsp (car specs)) ; wrong version, but already present
1750              ((y-or-n-p (format "Insert v%s %s option %s in v%s? "
1751                                 (antlr-version-string (caar specs))
1752                                 (elt antlr-options-headings (1- level))
1753                                 option
1754                                 (antlr-version-string antlr-tool-version)))
1755               (car specs))
1756              (t
1757               (error "Didn't insert v%s %s option %s in v%s"
1758                      (antlr-version-string (caar specs))
1759                      (elt antlr-options-headings (1- level))
1760                      option
1761                      (antlr-version-string antlr-tool-version))))))
1762    
1763    (defun antlr-version-string (version)
1764      "Format the Antlr version number VERSION, see `antlr-tool-version'."
1765      (let ((version100 (/ version 100)))
1766        (format "%d.%d.%d"
1767                (/ version100 100) (mod version100 100) (mod version 100))))
1768    
1769    
1770    ;;;===========================================================================
1771    ;;;  Insert options: the details (used by `antlr-insert-option-do')
1772    ;;;===========================================================================
1773    
1774    (defun antlr-insert-option-existing (old value)
1775      "Insert option value VALUE at point for existing option.
1776    For OLD, see `antlr-insert-option-do'."
1777      ;; no = => insert =
1778      (unless (car old) (insert antlr-options-assign-string))
1779      ;; with user input => insert if necessary
1780      (when value
1781        (if (cdr old)               ; with value
1782            (if (string-equal value (buffer-substring (car old) (cdr old)))
1783                (goto-char (cdr old))
1784              (delete-region (car old) (cdr old))
1785              (insert value))
1786          (insert value)))
1787      (unless (looking-at "\\([^\n=;{}/'\"]\\|'\\([^\n'\\]\\|\\\\.\\)*'\\|\"\\([^\n\"\\]\\|\\\\.\\)*\"\\)*;")
1788        ;; stuff (no =, {, } or /) at point is not followed by ";"
1789        (insert ";")
1790        (backward-char)))
1791            
1792    (defun antlr-insert-option-space (area old)
1793      "Find appropriate place to insert option, insert newlines/spaces.
1794    For AREA and OLD, see `antlr-insert-option-do'."
1795      (let ((orig (point))
1796            (open t))
1797        (skip-chars-backward " \t")
1798        (unless (bolp)
1799          (let ((before (char-after (1- (point)))))
1800            (goto-char orig)
1801            (and old                        ; with existing options area
1802                 (consp area)               ; if point inside existing area
1803                 (not (eq before ?\;))      ; if not at beginning of option
1804                                            ; => skip to end of option
1805                 (if (and (search-forward ";" (cdr area) t)
1806                          (let ((context (antlr-syntactic-context)))
1807                            (or (null context) (numberp context))))
1808                     (setq orig (point))
1809                   (goto-char orig)))
1810            (skip-chars-forward " \t")
1811            
1812            (if (looking-at "$\\|//")
1813                ;; just comment after point => skip (+ lines w/ same col comment)
1814                (let ((same (if (> (match-end 0) (match-beginning 0))
1815                                (current-column))))
1816                  (beginning-of-line 2)
1817                  (or (bolp) (insert "\n"))
1818                  (when (and same (null area)) ; or (consp area)?
1819                    (while (and (looking-at "[ \t]*\\(//\\)")
1820                                (goto-char (match-beginning 1))
1821                                (= (current-column) same))
1822                      (beginning-of-line 2)
1823                      (or (bolp) (insert "\n")))))
1824              (goto-char orig)
1825              (if (null old)
1826                  (progn (insert "\n") (antlr-indent-line))
1827                (unless (eq (char-after (1- (point))) ?\ )
1828                  (insert " "))
1829                (unless (eq (char-after (point)) ?\ )
1830                  (insert " ")
1831                  (backward-char))
1832                (setq open nil)))))
1833        (when open
1834          (beginning-of-line 1)
1835          (insert "\n")
1836          (backward-char)
1837          (antlr-indent-line))))
1838    
1839    (defun antlr-insert-option-area (level)
1840      "Insert new options area for options of level LEVEL.
1841    Used by `antlr-insert-option-do'."
1842      (insert "options {\n\n}")
1843      (when (and antlr-options-auto-colon
1844                 (memq level '(3 4))
1845                 (save-excursion
1846                   (c-forward-syntactic-ws)
1847                   (if (eq (char-after (point)) ?\{) (antlr-skip-sexps 1))
1848                   (not (eq (char-after (point)) ?\:))))
1849        (insert "\n:")
1850        (antlr-indent-line)
1851        (end-of-line 0))
1852      (backward-char 1)
1853      (antlr-indent-line)
1854      (beginning-of-line 0)
1855      (antlr-indent-line))
1856    
1857    
1858    ;;;===========================================================================
1859    ;;;  Insert options: in `antlr-options-alists'
1860    ;;;===========================================================================
1861    
1862    (defun antlr-read-value (initial-contents prompt
1863                                              &optional as-string table table-x)
1864      "Read a string from the minibuffer, possibly with completion.
1865    If INITIAL-CONTENTS is non-nil, insert it in the minibuffer initially.
1866    PROMPT is a string to prompt with, normally it ends in a colon and a
1867    space.  If AS-STRING is t or is a member \(comparison done with `eq') of
1868    `antlr-options-style', return printed representation of the user input,
1869    otherwise return the user input directly.
1870    
1871    If TABLE or TABLE-X is non-nil, read with completion.  The completion
1872    table is the resulting alist of TABLE-X concatenated with TABLE where
1873    TABLE can also be a function evaluation to an alist.
1874    
1875    Used inside `antlr-options-alists'."
1876      (let* ((table0 (and (or table table-x)
1877                          (append table-x
1878                                  (if (functionp table) (funcall table) table))))
1879             (input (if table0
1880                        (completing-read prompt table0 nil nil initial-contents)
1881                      (read-from-minibuffer prompt initial-contents))))
1882        (if (and as-string
1883                 (or (eq as-string t)
1884                     (cdr (assq as-string antlr-options-style))))
1885            (format "%S" input)
1886          input)))
1887    
1888    (defun antlr-read-boolean (initial-contents prompt &optional table)
1889      "Read a boolean value from the minibuffer, with completion.
1890    If INITIAL-CONTENTS is non-nil, insert it in the minibuffer initially.
1891    PROMPT is a string to prompt with, normally it ends in a question mark
1892    and a space.  \"(true or false) \" is appended if TABLE is nil.
1893    
1894    Read with completion over \"true\", \"false\" and the keys in TABLE, see
1895    also `antlr-read-value'.
1896    
1897    Used inside `antlr-options-alists'."
1898      (antlr-read-value initial-contents
1899                        (if table prompt (concat prompt "(true or false) "))
1900                        nil
1901                        table '(("false") ("true"))))
1902    
1903    (defun antlr-language-option-extra (phase &rest dummies)
1904    ;; checkdoc-params: (dummies)
1905      "Change language according to the new value of the \"language\" option.
1906    Call `antlr-mode' if the new language would be different from the value
1907    of `antlr-language', keeping the value of variable `font-lock-mode'.
1908    
1909    Called in PHASE `after-insertion', see `antlr-options-alists'."
1910      (when (eq phase 'after-insertion)
1911        (let ((new-language (antlr-language-option t)))
1912          (or (null new-language)
1913              (eq new-language antlr-language)
1914              (let ((font-lock (and (boundp 'font-lock-mode) font-lock-mode)))
1915                (if font-lock (font-lock-mode 0))
1916                (antlr-mode)
1917                (and font-lock (null font-lock-mode) (font-lock-mode 1)))))))
1918    
1919    (defun antlr-c++-mode-extra (phase option &rest dummies)
1920    ;; checkdoc-params: (option dummies)
1921      "Warn if C++ option is used with the wrong language.
1922    Ask user \(\"y or n\"), if a C++ only option is going to be inserted but
1923    `antlr-language' has not the value `c++-mode'.
1924    
1925    Called in PHASE `before-input', see `antlr-options-alists'."
1926      (and (eq phase 'before-input)
1927           (not (y-or-n-p (format "Insert C++ %s option? " option)))
1928           (error "Didn't insert C++ %s option with language %s"
1929                  option (cadr (assq antlr-language antlr-language-alist)))))
1930    
1931    
1932    ;;;===========================================================================
1933  ;;;  Compute dependencies  ;;;  Compute dependencies
1934  ;;;===========================================================================  ;;;===========================================================================
1935    
1936  (defun antlr-file-dependencies ()  (defun antlr-file-dependencies ()
1937    "Return dependencies for grammar in current buffer.    "Return dependencies for grammar in current buffer.
1938  The result looks like (FILE (CLASSES . SUPERS) VOCABS . LANGUAGE)  The result looks like \(FILE \(CLASSES \. SUPERS) VOCABS \. LANGUAGE)
1939  where CLASSES = ((CLASS . CLASS-EVOCAB) ...),    where CLASSES = ((CLASS . CLASS-EVOCAB) ...),
1940        SUPERS  = ((SUPER . USE-EVOCAB-P) ...), and          SUPERS  = ((SUPER . USE-EVOCAB-P) ...), and
1941        VOCABS  = ((EVOCAB ...) . (IVOCAB ...))          VOCABS  = ((EVOCAB ...) . (IVOCAB ...))
1942    
1943  FILE is the current buffer's file-name without directory part and  FILE is the current buffer's file-name without directory part and
1944  LANGUAGE is the value of `antlr-language' in the current buffer.  Each  LANGUAGE is the value of `antlr-language' in the current buffer.  Each
# Line 1033  its export vocabulary is used as an impo Line 1952  its export vocabulary is used as an impo
1952    (let (classes exportVocabs importVocabs superclasses default-vocab)    (let (classes exportVocabs importVocabs superclasses default-vocab)
1953      (antlr-with-syntax-table antlr-action-syntax-table      (antlr-with-syntax-table antlr-action-syntax-table
1954        (goto-char (point-min))        (goto-char (point-min))
1955        (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)        (while (antlr-re-search-forward antlr-class-header-regexp nil)
1956          ;; parse class definition --------------------------------------------          ;; parse class definition --------------------------------------------
1957          (let* ((class (match-string 1))          (let* ((class (match-string 2))
1958                 (sclass (match-string 2))                 (sclass (match-string 4))
1959                 ;; export vocab defaults to class name (first grammar in file)                 ;; export vocab defaults to class name (first grammar in file)
1960                 ;; or to the export vocab of the first grammar in file:                 ;; or to the export vocab of the first grammar in file:
1961                 (evocab (or default-vocab class))                 (evocab (or default-vocab class))
# Line 1048  its export vocabulary is used as an impo Line 1967  its export vocabulary is used as an impo
1967                  (antlr-skip-sexps 2)                  (antlr-skip-sexps 2)
1968                (goto-char (match-end 0))                (goto-char (match-end 0))
1969                (c-forward-syntactic-ws)                (c-forward-syntactic-ws)
1970                ;; parse grammar option section --------------------------------                ;; parse grammar option sections -------------------------------
1971                (when (eq (char-after (point)) ?\{)                (when (eq (char-after (point)) ?\{)
1972                  (let* ((beg (1+ (point)))                  (let* ((beg (1+ (point)))
1973                         (end (1- (antlr-skip-sexps 1)))                         (end (1- (antlr-skip-sexps 1)))
# Line 1080  its export vocabulary is used as an impo Line 1999  its export vocabulary is used as an impo
1999    
2000  (defun antlr-directory-dependencies (dirname)  (defun antlr-directory-dependencies (dirname)
2001    "Return dependencies for all grammar files in directory DIRNAME.    "Return dependencies for all grammar files in directory DIRNAME.
2002  The result looks like ((CLASS-SPEC ...) . (FILE-DEP ...))  The result looks like \((CLASS-SPEC ...) \. \(FILE-DEP ...))
2003  where CLASS-SPEC = (CLASS (FILE . EVOCAB) ...).    where CLASS-SPEC = (CLASS (FILE \. EVOCAB) ...).
2004    
2005  FILE-DEP are the dependencies for each grammar file in DIRNAME, see  FILE-DEP are the dependencies for each grammar file in DIRNAME, see
2006  `antlr-file-dependencies'.  For each grammar class CLASS, FILE is a  `antlr-file-dependencies'.  For each grammar class CLASS, FILE is a
# Line 1131  export vocabulary specified in that file Line 2050  export vocabulary specified in that file
2050    "Compute the grammar lib option for the super grammars SUPERS.    "Compute the grammar lib option for the super grammars SUPERS.
2051  Look in CLASSES for the right grammar lib files for SUPERS.  SUPERS is  Look in CLASSES for the right grammar lib files for SUPERS.  SUPERS is
2052  part SUPER in the result of `antlr-file-dependencies'.  CLASSES is the  part SUPER in the result of `antlr-file-dependencies'.  CLASSES is the
2053  part (CLASS-SPEC ...) in the result of `antlr-directory-dependencies'.  part \(CLASS-SPEC ...) in the result of `antlr-directory-dependencies'.
2054    
2055  The result looks like (OPTION WITH-UNKNOWN GLIB ...).  OPTION is the  The result looks like \(OPTION WITH-UNKNOWN GLIB ...).  OPTION is the
2056  complete \"-glib\" option.  WITH-UNKNOWN has value t iff there is none  complete \"-glib\" option.  WITH-UNKNOWN has value t iff there is none
2057  or more than one grammar file for at least one super grammar.  or more than one grammar file for at least one super grammar.
2058    
2059  Each GLIB looks like (GRAMMAR-FILE . EVOCAB).  GRAMMAR-FILE is a file in  Each GLIB looks like \(GRAMMAR-FILE \. EVOCAB).  GRAMMAR-FILE is a file
2060  which a super-grammar is defined.  EVOCAB is the value of the export  in which a super-grammar is defined.  EVOCAB is the value of the export
2061  vocabulary of the super-grammar or nil if it is not needed."  vocabulary of the super-grammar or nil if it is not needed."
2062    ;; If the superclass is defined in the same file, that file will be included    ;; If the superclass is defined in the same file, that file will be included
2063    ;; with -glib again.  This will lead to a redefinition.  But defining a    ;; with -glib again.  This will lead to a redefinition.  But defining a
# Line 1306  multiplied by: Line 2225  multiplied by:
2225   - plus 0/2/1, depending on the position inside the rule: header, body,   - plus 0/2/1, depending on the position inside the rule: header, body,
2226     exception part,     exception part,
2227   - minus 1 if `antlr-indent-item-regexp' matches the beginning of the   - minus 1 if `antlr-indent-item-regexp' matches the beginning of the
2228     line starting from the first non-blank.     line starting from the first non-whitespace.
2229    
2230  Lines inside block comments are not changed or indented by  Lines inside block comments are indented by `c-indent-line' according to
2231  `c-indent-line', see `antlr-indent-comment'."  `antlr-indent-comment'.
2232    (let ((orig (point)) bol boi indent syntax)  
2233      (beginning-of-line)  If `antlr-language' equals to a key in `antlr-indent-at-bol-alist' and
2234      (setq bol (point))  the line starting at the first non-whitespace is matched by the
2235      (skip-chars-forward " \t")  corresponding value, indent the line at column 0.
2236      (setq boi (point))  
2237      ;; check syntax at beginning of indentation ------------------------------  For the initialization of `c-basic-offset', see `antlr-indent-style' and,
2238      (antlr-with-syntax-table antlr-action-syntax-table  to a lesser extent, `antlr-tab-offset-alist'."
2239        (antlr-invalidate-context-cache)    (save-restriction
2240        (cond ((symbolp (setq syntax (antlr-syntactic-context)))      (let ((orig (point))
2241               (setq indent nil))         ; block-comments, strings, (comments)            (min0 (point-min))
2242              ((eq (char-after) ?#)       ; cpp directive            bol boi indent syntax)
2243               (setq syntax 'cpp)        (widen)
2244               (setq indent 0))           ; indentation at 0        (beginning-of-line)
2245              ((progn        (setq bol (point))
2246                 (antlr-next-rule -1 t)        (if (< bol min0)
2247                 (if (antlr-search-forward ":") (< boi (1- (point))) t))            (error "Beginning of current line not visible"))
2248               (setq indent 0))           ; in rule header        (skip-chars-forward " \t")
2249              ((if (antlr-search-forward ";") (< boi (point)) t)        (setq boi (point))
2250               (setq indent 2))           ; in rule body        ;; check syntax at beginning of indentation ----------------------------
2251              (t        (antlr-with-syntax-table antlr-action-syntax-table
              (forward-char)  
              (antlr-skip-exception-part nil)  
              (setq indent (if (> (point) boi) 1 0))))) ; in exception part?  
     ;; compute the corresponding indentation and indent ----------------------  
     (if (null indent)  
         (progn  
           (goto-char orig)  
           (and (eq antlr-indent-comment t)  
                (not (eq syntax 'string))  
                (c-indent-line)))  
       ;; do it ourselves  
       (goto-char boi)  
       (unless (symbolp syntax)          ; direct indentation  
2252          (antlr-invalidate-context-cache)          (antlr-invalidate-context-cache)
2253          (incf indent (antlr-syntactic-context))          (setq syntax (antlr-syntactic-context))
2254          (and (> indent 0) (looking-at antlr-indent-item-regexp) (decf indent))          (cond ((symbolp syntax)
2255          (setq indent (* indent c-basic-offset)))                 (setq indent nil))       ; block-comments, strings, (comments)
2256        ;; the usual major-mode indent stuff -----------------------------------                ((and (assq antlr-language antlr-indent-at-bol-alist)
2257        (setq orig (- (point-max) orig))                      (looking-at (cdr (assq antlr-language
2258        (unless (= (current-column) indent)                                             antlr-indent-at-bol-alist))))
2259          (delete-region bol boi)                 (setq syntax 'bol)
2260          (beginning-of-line)                 (setq indent 0))         ; indentation at 0
2261          (indent-to indent))                ((progn
2262        ;; If initial point was within line's indentation,                   (antlr-next-rule -1 t)
2263        ;; position after the indentation.  Else stay at same point in text.                   (if (antlr-search-forward ":") (< boi (1- (point))) t))
2264        (if (> (- (point-max) orig) (point))                 (setq indent 0))         ; in rule header
2265            (goto-char (- (point-max) orig))))))                ((if (antlr-search-forward ";") (< boi (point)) t)
2266                   (setq indent 2))         ; in rule body
2267                  (t
2268                   (forward-char)
2269                   (antlr-skip-exception-part nil)
2270                   (setq indent (if (> (point) boi) 1 0))))) ; in exception part?
2271          ;; compute the corresponding indentation and indent --------------------
2272          (if (null indent)
2273              ;; Use the indentation engine of cc-mode for block comments.  Using
2274              ;; it-mode for actions is not easy, especially if the actions come
2275              ;; early in the rule body.
2276              (progn
2277                (goto-char orig)
2278                (and (eq antlr-indent-comment t)
2279                     (not (eq syntax 'string))
2280                     (c-indent-line)))
2281            ;; do it ourselves
2282            (goto-char boi)
2283            (unless (symbolp syntax)                ; direct indentation
2284              (antlr-invalidate-context-cache)
2285              (incf indent (antlr-syntactic-context))
2286              (and (> indent 0) (looking-at antlr-indent-item-regexp) (decf indent))
2287              (setq indent (* indent c-basic-offset)))
2288            ;; the usual major-mode indent stuff ---------------------------------
2289            (setq orig (- (point-max) orig))
2290            (unless (= (current-column) indent)
2291              (delete-region bol boi)
2292              (beginning-of-line)
2293              (indent-to indent))
2294            ;; If initial point was within line's indentation,
2295            ;; position after the indentation.  Else stay at same point in text.
2296            (if (> (- (point-max) orig) (point))
2297                (goto-char (- (point-max) orig)))))))
2298    
2299  (defun antlr-indent-command (&optional arg)  (defun antlr-indent-command (&optional arg)
2300    "Indent the current line or insert tabs/spaces.    "Indent the current line or insert tabs/spaces.
2301  With optional prefix argument ARG or if the previous command was this  With optional prefix argument ARG or if the previous command was this
2302  command, insert ARG tabs or spaces according to `indent-tabs-mode'.  command, insert ARG tabs or spaces according to `indent-tabs-mode'.
2303  Otherwise, indent the current line with `antlr-indent-line'."  Otherwise, indent the current line with `antlr-indent-line'."
2304    (interactive "P")    (interactive "*P")
2305    (if (or arg (eq last-command 'antlr-indent-command))    (if (or arg (eq last-command 'antlr-indent-command))
2306        (insert-tab arg)        (insert-tab arg)
2307      (let ((antlr-indent-comment (and antlr-indent-comment t))) ; dynamic      (let ((antlr-indent-comment (and antlr-indent-comment t))) ; dynamic
2308        (antlr-indent-line))))        (antlr-indent-line))))
2309    
2310    (defun antlr-electric-character (&optional arg)
2311      "Insert the character you type and indent the current line.
2312    Insert the character like `self-insert-command' and indent the current
2313    line as `antlr-indent-command' does.  Do not indent the line if
2314    
2315     * this command is called with a prefix argument ARG,
2316     * there are characters except whitespaces between point and the
2317       beginning of the line, or
2318     * point is not inside a normal grammar code, { and } are also OK in
2319       actions.
2320    
2321    This command is useful for a character which has some special meaning in
2322    ANTLR's syntax and influences the auto indentation, see
2323    `antlr-indent-item-regexp'."
2324      (interactive "*P")
2325      (if (or arg
2326              (save-excursion (skip-chars-backward " \t") (not (bolp)))
2327              (antlr-with-syntax-table antlr-action-syntax-table
2328                (antlr-invalidate-context-cache)
2329                (let ((context (antlr-syntactic-context)))
2330                  (not (and (numberp context)
2331                            (or (zerop context)
2332                                (memq last-command-char '(?\{ ?\}))))))))
2333          (self-insert-command (prefix-numeric-value arg))
2334        (self-insert-command (prefix-numeric-value arg))
2335        (antlr-indent-line)))
2336    
2337    
2338  ;;;===========================================================================  ;;;===========================================================================
2339  ;;;  Mode entry  ;;;  Mode entry
# Line 1425  Otherwise, indent the current line with Line 2390  Otherwise, indent the current line with
2390    (make-local-variable 'comment-indent-function)    (make-local-variable 'comment-indent-function)
2391    (setq comment-indent-function 'c-comment-indent))    (setq comment-indent-function 'c-comment-indent))
2392    
2393  (defun antlr-language-for-option (option-value)  (defun antlr-language-option (search)
2394    "Find element in `antlr-language-alist' for OPTION-VALUE."    "Find language in `antlr-language-alist' for language option.
2395    ;; Like (find OPTION-VALUE antlr-language-alist :key 'cddr :test 'member)  If SEARCH is non-nil, find element for language option.  Otherwise, find
2396    (let ((seq antlr-language-alist)  the default language."
2397      (let ((value (and search
2398                        (save-excursion
2399                          (goto-char (point-min))
2400                          (re-search-forward (cdr antlr-language-limit-n-regexp)
2401                                             (car antlr-language-limit-n-regexp)
2402                                             t))
2403                        (match-string 1)))
2404            (seq antlr-language-alist)
2405          r)          r)
2406        ;; Like (find-VALUE antlr-language-alist :key 'cddr :test 'member)
2407      (while seq      (while seq
2408        (setq r (pop seq))        (setq r (pop seq))
2409        (if (member option-value (cddr r))        (if (member value (cddr r))
2410            (setq seq nil)                ; stop            (setq seq nil)                ; stop
2411          (setq r nil)))                  ; no result yet          (setq r nil)))                  ; no result yet
2412      r))      (car r)))
2413    
2414    
2415  ;;;###autoload  ;;;###autoload
2416  (defun antlr-mode ()  (defun antlr-mode ()
# Line 1463  Otherwise, indent the current line with Line 2438  Otherwise, indent the current line with
2438    (use-local-map antlr-mode-map)    (use-local-map antlr-mode-map)
2439    (make-local-variable 'antlr-language)    (make-local-variable 'antlr-language)
2440    (unless antlr-language    (unless antlr-language
2441      (save-excursion      (setq antlr-language
2442        (goto-char (point-min))            (or (antlr-language-option t) (antlr-language-option nil))))
       (setq antlr-language  
             (car (or (and (re-search-forward (cdr antlr-language-limit-n-regexp)  
                                         (car antlr-language-limit-n-regexp)  
                                         t)  
                           (antlr-language-for-option (match-string 1)))  
                      (antlr-language-for-option nil))))))  
2443    (if (stringp (cadr (assq antlr-language antlr-language-alist)))    (if (stringp (cadr (assq antlr-language antlr-language-alist)))
2444        (setq mode-name        (setq mode-name
2445              (concat "Antlr."              (concat "Antlr."
# Line 1540  Used in `antlr-mode'.  Also a useful fun Line 2509  Used in `antlr-mode'.  Also a useful fun
2509  ; LocalWords:  VOCAB EVOCAB Antlr's TokenTypes exportVocab incl excl SUPERS gen  ; LocalWords:  VOCAB EVOCAB Antlr's TokenTypes exportVocab incl excl SUPERS gen
2510  ; LocalWords:  VOCABS IVOCAB exportVocabs importVocabs superclasses vocab kens  ; LocalWords:  VOCABS IVOCAB exportVocabs importVocabs superclasses vocab kens
2511  ; LocalWords:  sclass evocab ivocab importVocab deps glibs supers sep dep lang  ; LocalWords:  sclass evocab ivocab importVocab deps glibs supers sep dep lang
2512    ; LocalWords:  htmlize subrule jde Sather sather eiffel SGML's XYYZZ namespace
2513    ; LocalWords:  mangleLiteralPrefix namespaceStd namespaceAntlr genHashLines AST
2514    ; LocalWords:  testLiterals defaultErrorHandler codeGenMakeSwitchThreshold XXX
2515    ; LocalWords:  codeGenBitsetTestThreshold bitset analyzerDebug codeGenDebug boc
2516    ; LocalWords:  buildAST ASTLabelType charVocabulary caseSensitive autoTokenDef
2517    ; LocalWords:  caseSensitiveLiterals classHeaderSuffix keywordsMeltTo NAMEs LL
2518    ; LocalWords:  warnWhenFollowAmbig generateAmbigWarnings ARGs tokenrefs withp
2519    ; LocalWords:  outsidep existsp JOR sert endif se ndef mport nclude pragma LE
2520    ; LocalWords:  TION ASE RSION OMPT ava serting VEL mparison AMMAR
2521    
2522  ;;; antlr-mode.el ends here  ;;; antlr-mode.el ends here

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.10

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26