3 # Copyright (C) 2000, 2001 Paul F. Kinnucan, Jr.
4 # Copyright (C) 2001 David Ponce
6 # Author: Paul F. Kinnucan, Jr. <paulk@mathworks.com>
7 # David Ponce <david@dponce.com>
9 # $Id: java.bnf,v 1.15 2002/05/15 19:21:02 ponced Exp $
11 # java.bnf is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2, or (at your option)
16 # This software is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with GNU Emacs; see the file COPYING. If not, write to the
23 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 # Boston, MA 02111-1307, USA.
29 %outputfile semantic-java.el
30 %parsetable semantic-toplevel-java-bovine-table
31 %keywordtable semantic-java-keyword-table
32 %languagemode java-mode
33 %setupfunction semantic-default-java-setup
38 semantic-number-expression semantic-java-number-regexp
39 ;; Java is case sensitive
40 semantic-case-fold nil
41 ;; special handling of multiple variable declarations/statement
42 semantic-expand-nonterminal 'semantic-expand-java-nonterminal
43 ;; function to use when creating items in imenu
44 semantic-imenu-summary-function 'semantic-prototype-nonterminal
45 ;; function to use for creating the imenu
46 imenu-create-index-function 'semantic-create-imenu-index
47 ;; Character used to separation a parent/child relationship
48 semantic-type-relation-separator-character '(".")
49 semantic-command-separation-character ";"
50 document-comment-start "/**"
51 document-comment-line-prefix " *"
52 document-comment-end " */"
53 ;; speedbar and imenu buckets name
54 semantic-symbol->name-assoc-list-for-type-parts
57 (variable . "Variables")
58 (function . "Methods"))
59 semantic-symbol->name-assoc-list
61 (append semantic-symbol->name-assoc-list-for-type-parts
62 '((include . "Imports")
63 (package . "Package")))
64 ;; Semantic navigation inside 'type children
65 senator-step-at-token-ids '(function variable)
69 %token ABSTRACT "abstract"
71 "Class|Method declaration modifier: abstract {class|<type>} <name> ..."
73 %token BOOLEAN "boolean"
75 "Primitive logical quantity type (true or false)"
83 "Integral primitive type (-128 to 127)"
87 "switch(<expr>) {case <const-expr>: <stmts> ... }"
91 "try {<stmts>} catch(<parm>) {<stmts>} ... "
95 "Integral primitive type ('\u0000' to '\uffff') (0 to 65535)"
99 "Class declaration: class <name>"
103 "Unused reserved word"
105 %token CONTINUE "continue"
106 %put CONTINUE summary
107 "continue [<label>] ;"
109 %token DEFAULT "default"
111 "switch(<expr>) { ... default: <stmts>}"
115 "do <stmt> while (<expr>);"
117 %token DOUBLE "double"
119 "Primitive floating-point type (double-precision 64-bit IEEE 754)"
123 "if (<expr>) <stmt> else <stmt>"
125 %token EXTENDS "extends"
127 "SuperClass|SuperInterfaces declaration: extends <name> [, ...]"
131 "Class|Member declaration modifier: final {class|<type>} <name> ..."
133 %token FINALLY "finally"
135 "try {<stmts>} ... finally {<stmts>}"
139 "Primitive floating-point type (single-precision 32-bit IEEE 754)"
143 "for ([<init-expr>]; [<expr>]; [<update-expr>]) <stmt>"
147 "Unused reserved word"
151 "if (<expr>) <stmt> [else <stmt>]"
153 %token IMPLEMENTS "implements"
154 %put IMPLEMENTS summary
155 "Class SuperInterfaces declaration: implements <name> [, ...]"
157 %token IMPORT "import"
159 "Import package declarations: import <package>"
161 %token INSTANCEOF "instanceof"
165 "Integral primitive type (-2147483648 to 2147483647)"
167 %token INTERFACE "interface"
168 %put INTERFACE summary
169 "Interface declaration: interface <name>"
173 "Integral primitive type (-9223372036854775808 to 9223372036854775807)"
175 %token NATIVE "native"
177 "Method declaration modifier: native <type> <name> ..."
181 %token PACKAGE "package"
183 "Package declaration: package <name>"
185 %token PRIVATE "private"
187 "Access level modifier: private {class|interface|<type>} <name> ..."
189 %token PROTECTED "protected"
190 %put PROTECTED summary
191 "Access level modifier: protected {class|interface|<type>} <name> ..."
193 %token PUBLIC "public"
195 "Access level modifier: public {class|interface|<type>} <name> ..."
197 %token RETURN "return"
203 "Integral primitive type (-32768 to 32767)"
205 %token STATIC "static"
207 "Declaration modifier: static {class|interface|<type>} <name> ..."
209 %token STRICTFP "strictfp"
210 %put STRICTFP summary
211 "Declaration modifier: strictfp {class|interface|<type>} <name> ..."
215 %token SWITCH "switch"
217 "switch(<expr>) {[case <const-expr>: <stmts> ...] [default: <stmts>]}"
220 %token SYNCHRONIZED "synchronized"
221 %put SYNCHRONIZED summary
222 "synchronized (<expr>) ... | Method decl. modifier: synchronized <type> <name> ..."
230 %token THROWS "throws"
232 "Method|Constructor declaration: throws <classType>, ..."
234 %token TRANSIENT "transient"
235 %put TRANSIENT summary
236 "Field declaration modifier: transient <type> <name> ..."
240 "try {<stmts>} [catch(<parm>) {<stmts>} ...] [finally {<stmts>}]"
244 "Method return type: void <name> ..."
246 %token VOLATILE "volatile"
247 %put VOLATILE summary
248 "Field declaration modifier: volatile <type> <name> ..."
252 "while (<expr>) <stmt> | do <stmt> while (<expr>);"
254 # --------------------------
255 # Official javadoc line tags
256 # --------------------------
258 # Javadoc tags are identified by a 'javadoc' keyword property. The
259 # value of this property must be itself a property list where the
260 # following properties are recognized:
262 # - `seq' (mandatory) is the tag sequence number used to check if tags
263 # are correctly ordered in a javadoc comment block.
265 # - `usage' (mandatory) is the list of token categories for which this
266 # documentation tag is allowed.
268 # - `opt' (optional) if non-nil indicates this is an optional tag.
269 # By default tags are mandatory.
271 # - `with-name' (optional) if non-nil indicates that this tag is
272 # followed by an identifier like in "@param <var-name> description"
273 # or "@exception <class-name> description".
275 # - `with-ref' (optional) if non-nil indicates that the tag is
276 # followed by a reference like in "@see <reference>".
278 %token _AUTHOR "@author"
279 %put _AUTHOR javadoc (seq 1 usage (type))
280 %token _VERSION "@version"
281 %put _VERSION javadoc (seq 2 usage (type))
282 %token _PARAM "@param"
283 %put _PARAM javadoc (seq 3 usage (function) with-name t)
284 %token _RETURN "@return"
285 %put _RETURN javadoc (seq 4 usage (function))
286 %token _EXCEPTION "@exception"
287 %put _EXCEPTION javadoc (seq 5 usage (function) with-name t)
288 %token _THROWS "@throws"
289 %put _THROWS javadoc (seq 6 usage (function) with-name t)
291 %put _SEE javadoc (seq 7 usage (type function variable) opt t with-ref t)
292 %token _SINCE "@since"
293 %put _SINCE javadoc (seq 8 usage (type function variable) opt t)
294 %token _SERIAL "@serial"
295 %put _SERIAL javadoc (seq 9 usage (variable) opt t)
296 %token _SERIALDATA "@serialData"
297 %put _SERIALDATA javadoc (seq 10 usage (function) opt t)
298 %token _SERIALFIELD "@serialField"
299 %put _SERIALFIELD javadoc (seq 11 usage (variable) opt t)
300 %token _DEPRECATED "@deprecated"
301 %put _DEPRECATED javadoc (seq 12 usage (type function variable) opt t)
306 bovine-toplevel : package_declaration
316 type : reference_type
322 primitive_type : BOOLEAN | BYTE | SHORT | INT | LONG | CHAR | FLOAT | DOUBLE
325 reference_type : array_type
331 array_type : primitive_type dims
332 ((concat (car $1) (car $2)))
333 | qualified_name dims
334 ((concat (car $1) (car $2)))
337 qualified_name : symbol punctuation "\\." qualified_name
338 ((concat $1 $2 (car $3)))
343 ## TOP-LEVEL ENTRY: package definition.
344 ## ("NAME" package DETAIL "DOCSTRING")
345 package_declaration : PACKAGE qualified_name punctuation ";"
346 (,$2 package nil nil)
350 ## TOP-LEVEL ENTRY: import definition.
351 ## ("FILE" include SYSTEM "DOCSTRING")
352 import_declaration : IMPORT qualified_name punctuation ";"
353 (,$2 include nil nil)
354 | IMPORT qualified_name punctuation "\\." punctuation "*" punctuation ";"
355 ((concat (car $2) $3 $4) include nil nil)
358 type_declaration : punctuation ";"
360 | interface_declaration
363 modifiers_opt : modifiers
368 modifiers : modifier modifiers
369 (,(cons (car $1) ,$2))
374 modifier : PUBLIC | PROTECTED | PRIVATE | STATIC | ABSTRACT
375 | FINAL | NATIVE | SYNCHRONIZED | TRANSIENT | VOLATILE | STRICTFP
378 ## TOP-LEVEL ENTRY: class definition.
379 ## ("NAME" type "TYPE" PART-LIST PARENTS EXTRA-SPECS "DOCSTRING")
380 class_declaration : modifiers_opt CLASS qualified_name class_parents class_body
381 ( ,$3 type "class" $5 $4
382 (ASSOC typemodifiers $1)
387 # class_parents := nil | (["extends_this" | nil] ["implements_this1" ... "implements_thisN"])
388 class_parents: super interfaces
399 super : EXTENDS qualified_name
403 interfaces : IMPLEMENTS qualified_name_list
407 qualified_name_list : qualified_name punctuation "," qualified_name_list
408 (,(cons (car $1) ,$3))
413 class_body : semantic-list # ::= {class_body_declarations}
414 (EXPANDFULL $1 class_body_declarations)
417 class_body_declarations : class_declaration
419 | interface_declaration
425 #| static_initializer
426 | constructor_declaration
431 ## TOP-LEVEL ENTRY: variable definition.
432 ## ("NAME" variable "TYPE" DEFAULT-VALUE EXTRA-SPECS "DOCSTRING")
433 field_declaration : modifiers_opt type variable_declarators punctuation ";"
434 (,$3 variable ,$2 nil
435 (ASSOC typemodifiers $1)
439 ## The following rule is used by `semantic-expand-java-nonterminal' to
440 ## reparse declaration of multiple variables in the same statement.
441 ## Reparsing is done with `semantic-bovinate-from-nonterminal-full' to
442 ## get correct START END information for each variable token.
443 field_declaration_multi : modifiers_opt type variable_declarator punctuation ","
445 | modifiers_opt type variable_declarator punctuation ";"
447 | variable_declarator punctuation ","
449 | variable_declarator punctuation ";"
453 variable_declarators : variable_declarator variable_declarators_opt
454 ((cons (car $1) (car $2)))
457 variable_declarators_opt: punctuation "," variable_declarators
462 variable_declarator : variable_declarator_id variable_assign_opt
466 variable_assign_opt: punctuation "=" variable_initializer
470 variable_declarator_id : symbol dims
471 ((concat $1 (car $2)))
476 variable_initializer : array_initializer
480 method_declaration : method_header method_body
484 ## TOP-LEVEL ENTRY: method definition.
485 ## ("NAME" function "TYPE" ARG-LIST EXTRA-SPECS "DOCSTRING")
486 method_header : modifiers_opt method_type symbol formal_parameter_list_opt throws_opt
488 (ASSOC typemodifiers $1 throws $5)
498 formal_parameter_list_opt : semantic-list # ::= (formal_parameter_list)
499 (EXPANDFULL $1 formal_parameter_list)
503 formal_parameter_list : formal_parameter punctuation ","
509 formal_parameter-modifier : FINAL
513 ## TOP-LEVEL ENTRY: variable definition.
514 ## ("NAME" variable "TYPE" DEFAULT-VALUE EXTRA-SPECS "DOCSTRING")
515 formal_parameter : formal_parameter-modifier type variable_declarator_id
516 (,$3 variable ,$2 nil
517 (ASSOC typemodifiers $1)
526 throws : THROWS qualified_name_list
530 method_body : punctuation ";"
534 #static_initializer : STATIC block
537 ## TOP-LEVEL ENTRY: constructor definition.
538 ## ("NAME" function "TYPE" ARG-LIST EXTRA-SPECS "DOCSTRING")
539 constructor_declaration : modifiers_opt symbol formal_parameter_list_opt throws_opt
542 (ASSOC typemodifiers $1 throws $4)
546 constructor_body : block
549 ## TOP-LEVEL ENTRY: interface definition.
550 ## ("NAME" type "TYPE" PART-LIST PARENTS EXTRA-SPECS "DOCSTRING")
551 interface_declaration : modifiers_opt INTERFACE symbol interface_parents interface_body
552 ($3 type "interface" $5 $4
553 (ASSOC typemodifiers $1)
557 # interface_parents := nil | ("extends_this1" ... "extends_thisN")
558 interface_parents : EXTENDS qualified_name_list
563 interface_body : semantic-list # ::= { interface_body_declarations }
564 (EXPANDFULL $1 interface_body_declarations)
567 interface_body_declarations : class_declaration
569 | interface_declaration
571 | method_header punctuation ";"
577 array_initializer : semantic-list "\\`{" # ::= {expression, expression, ...}
580 block : semantic-list "\\`{" # ::= {statements}
583 primary : array_creation_expression
584 | primary_no_new_array primary_dim_opt
587 primary_dim_opt : semantic-list "\\`\\["
591 primary_no_new_array : qualified_name semantic-list "\\`(" # method_invocation
592 | class_instance_creation_expression
593 | semantic-list "\\`(" # (expression)
594 | array_type punctuation "\\." CLASS
598 class_instance_creation_expression : NEW qualified_name semantic-list "\\`("
599 semantic-list "\\`{" # ::= { class_body_declarations }
600 | NEW qualified_name semantic-list "\\`("
603 ## array_creation_expression : NEW qualified_name dims array_initializer
604 ## | NEW qualified_name dims #dim_exprs dims_opt
606 array_creation_expression : NEW array_type array_initializer
607 | NEW array_type #dim_exprs dims_opt
616 dims: semantic-list "\\`\\[" dims_opt
617 ((concat "[]" (car ,$2)))
620 field_access : primary punctuation "\\." symbol
624 postfix_expression : primary postfix_operator_opt
627 postfix_operator_opt: punctuation "[-+]" punctuation "[-+]"
631 unary_expression : punctuation "[-+^!]" unary_expression
632 | punctuation "[-+]" punctuation "[-+]" unary_expression
633 | semantic-list "\\`(" unary_expression # cast
637 operator: punctuation "[-+*/%=<>^~&|!?:.]" # added DOT as field/method access operator
641 operators: operator operators
645 operators_expression_opt: operators expression
649 expression: unary_expression operators_expression_opt