Update copyright notices for 2013.
[emacs.git] / admin / grammars / java-tags.wy
blob408d0f0da29aea42f5e7504da4d8cd40129254c2
1 ;;; java-tags.wy -- Semantic LALR grammar for Java
3 ;; Copyright (C) 2002-2013 Free Software Foundation, Inc.
4 ;;
5 ;; Author: David Ponce <david@dponce.com>
6 ;; Maintainer: David Ponce <david@dponce.com>
7 ;; Created: 26 Aug 2002
8 ;; Keywords: syntax
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
25 %package wisent-java-tags-wy
26 %provide semantic/wisent/javat-wy
28 %languagemode  java-mode
30 ;; The default start symbol
31 %start compilation_unit
32 ;; Alternate entry points
33 ;;    - Needed by partial re-parse
34 %start package_declaration
35 %start import_declaration
36 %start class_declaration
37 %start field_declaration
38 %start method_declaration
39 %start formal_parameter
40 %start constructor_declaration
41 %start interface_declaration
42 ;;    - Needed by EXPANDFULL clauses
43 %start class_member_declaration
44 %start interface_member_declaration
45 %start formal_parameters
47 ;; -----------------------------
48 ;; Block & Parenthesis terminals
49 ;; -----------------------------
50 %type  <block>       ;;syntax "\\s(\\|\\s)" matchdatatype block
52 %token <block>       PAREN_BLOCK "(LPAREN RPAREN)"
53 %token <block>       BRACE_BLOCK "(LBRACE RBRACE)"
54 %token <block>       BRACK_BLOCK "(LBRACK RBRACK)"
56 %token <open-paren>  LPAREN      "("
57 %token <close-paren> RPAREN      ")"
58 %token <open-paren>  LBRACE      "{"
59 %token <close-paren> RBRACE      "}"
60 %token <open-paren>  LBRACK      "["
61 %token <close-paren> RBRACK      "]"
63 ;; ------------------
64 ;; Operator terminals
65 ;; ------------------
66 %type  <punctuation> ;;syntax "\\(\\s.\\|\\s$\\|\\s'\\)+" matchdatatype string
68 %token <punctuation> NOT         "!"
69 %token <punctuation> NOTEQ       "!="
70 %token <punctuation> MOD         "%"
71 %token <punctuation> MODEQ       "%="
72 %token <punctuation> AND         "&"
73 %token <punctuation> ANDAND      "&&"
74 %token <punctuation> ANDEQ       "&="
75 %token <punctuation> MULT        "*"
76 %token <punctuation> MULTEQ      "*="
77 %token <punctuation> PLUS        "+"
78 %token <punctuation> PLUSPLUS    "++"
79 %token <punctuation> PLUSEQ      "+="
80 %token <punctuation> COMMA       ","
81 %token <punctuation> MINUS       "-"
82 %token <punctuation> MINUSMINUS  "--"
83 %token <punctuation> MINUSEQ     "-="
84 %token <punctuation> DOT         "."
85 %token <punctuation> DIV         "/"
86 %token <punctuation> DIVEQ       "/="
87 %token <punctuation> COLON       ":"
88 %token <punctuation> SEMICOLON   ";"
89 %token <punctuation> LT          "<"
90 %token <punctuation> LSHIFT      "<<"
91 %token <punctuation> LSHIFTEQ    "<<="
92 %token <punctuation> LTEQ        "<="
93 %token <punctuation> EQ          "="
94 %token <punctuation> EQEQ        "=="
95 %token <punctuation> GT          ">"
96 %token <punctuation> GTEQ        ">="
97 %token <punctuation> RSHIFT      ">>"
98 %token <punctuation> RSHIFTEQ    ">>="
99 %token <punctuation> URSHIFT     ">>>"
100 %token <punctuation> URSHIFTEQ   ">>>="
101 %token <punctuation> QUESTION    "?"
102 %token <punctuation> XOR         "^"
103 %token <punctuation> XOREQ       "^="
104 %token <punctuation> OR          "|"
105 %token <punctuation> OREQ        "|="
106 %token <punctuation> OROR        "||"
107 %token <punctuation> COMP        "~"
109 ;; -----------------
110 ;; Literal terminals
111 ;; -----------------
112 %type  <symbol>      ;;syntax "\\(\\sw\\|\\s_\\)+"
113 %token <symbol>      IDENTIFIER
115 %type  <string>      ;;syntax "\\s\"" matchdatatype sexp
116 %token <string>      STRING_LITERAL
118 %type  <number>      ;;syntax semantic-lex-number-expression
119 %token <number>      NUMBER_LITERAL
121 %type <unicode>      syntax "\\\\u[0-9a-f][0-9a-f][0-9a-f][0-9a-f]"
122 %token <unicode>     unicodecharacter
124 ;; -----------------
125 ;; Keyword terminals
126 ;; -----------------
128 ;; Generate a keyword analyzer
129 %type  <keyword> ;;syntax "\\(\\sw\\|\\s_\\)+" matchdatatype keyword
131 %keyword ABSTRACT     "abstract"
132 %put     ABSTRACT summary
133 "Class|Method declaration modifier: abstract {class|<type>} <name> ..."
135 %keyword BOOLEAN      "boolean"
136 %put     BOOLEAN summary
137 "Primitive logical quantity type (true or false)"
139 %keyword BREAK        "break"
140 %put     BREAK summary
141 "break [<label>] ;"
143 %keyword BYTE         "byte"
144 %put     BYTE summary
145 "Integral primitive type (-128 to 127)"
147 %keyword CASE         "case"
148 %put     CASE summary
149 "switch(<expr>) {case <const-expr>: <stmts> ... }"
151 %keyword CATCH        "catch"
152 %put     CATCH summary
153 "try {<stmts>} catch(<parm>) {<stmts>} ... "
155 %keyword CHAR         "char"
156 %put     CHAR summary
157 "Integral primitive type ('\u0000' to '\uffff') (0 to 65535)"
159 %keyword CLASS        "class"
160 %put     CLASS summary
161 "Class declaration: class <name>"
163 %keyword CONST        "const"
164 %put     CONST summary
165 "Unused reserved word"
167 %keyword CONTINUE     "continue"
168 %put     CONTINUE summary
169 "continue [<label>] ;"
171 %keyword DEFAULT      "default"
172 %put     DEFAULT summary
173 "switch(<expr>) { ... default: <stmts>}"
175 %keyword DO           "do"
176 %put     DO summary
177 "do <stmt> while (<expr>);"
179 %keyword DOUBLE       "double"
180 %put     DOUBLE summary
181 "Primitive floating-point type (double-precision 64-bit IEEE 754)"
183 %keyword ELSE         "else"
184 %put     ELSE summary
185 "if (<expr>) <stmt> else <stmt>"
187 %keyword EXTENDS      "extends"
188 %put     EXTENDS summary
189 "SuperClass|SuperInterfaces declaration: extends <name> [, ...]"
191 %keyword FINAL        "final"
192 %put     FINAL summary
193 "Class|Member declaration modifier: final {class|<type>} <name> ..."
195 %keyword FINALLY      "finally"
196 %put     FINALLY summary
197 "try {<stmts>} ... finally {<stmts>}"
199 %keyword FLOAT        "float"
200 %put     FLOAT summary
201 "Primitive floating-point type (single-precision 32-bit IEEE 754)"
203 %keyword FOR          "for"
204 %put     FOR summary
205 "for ([<init-expr>]; [<expr>]; [<update-expr>]) <stmt>"
207 %keyword GOTO         "goto"
208 %put     GOTO summary
209 "Unused reserved word"
211 %keyword IF           "if"
212 %put     IF summary
213 "if (<expr>) <stmt> [else <stmt>]"
215 %keyword IMPLEMENTS   "implements"
216 %put     IMPLEMENTS summary
217 "Class SuperInterfaces declaration: implements <name> [, ...]"
219 %keyword IMPORT       "import"
220 %put     IMPORT summary
221 "Import package declarations: import <package>"
223 %keyword INSTANCEOF   "instanceof"
225 %keyword INT          "int"
226 %put     INT summary
227 "Integral primitive type (-2147483648 to 2147483647)"
229 %keyword INTERFACE    "interface"
230 %put     INTERFACE summary
231 "Interface declaration: interface <name>"
233 %keyword LONG         "long"
234 %put     LONG summary
235 "Integral primitive type (-9223372036854775808 to 9223372036854775807)"
237 %keyword NATIVE       "native"
238 %put     NATIVE summary
239 "Method declaration modifier: native <type> <name> ..."
241 %keyword NEW          "new"
243 %keyword PACKAGE      "package"
244 %put     PACKAGE summary
245 "Package declaration: package <name>"
247 %keyword PRIVATE      "private"
248 %put     PRIVATE summary
249 "Access level modifier: private {class|interface|<type>} <name> ..."
251 %keyword PROTECTED    "protected"
252 %put     PROTECTED summary
253 "Access level modifier: protected {class|interface|<type>} <name> ..."
255 %keyword PUBLIC       "public"
256 %put     PUBLIC summary
257 "Access level modifier: public {class|interface|<type>} <name> ..."
259 %keyword RETURN       "return"
260 %put     RETURN summary
261 "return [<expr>] ;"
263 %keyword SHORT        "short"
264 %put     SHORT summary
265 "Integral primitive type (-32768 to 32767)"
267 %keyword STATIC       "static"
268 %put     STATIC summary
269 "Declaration modifier: static {class|interface|<type>} <name> ..."
271 %keyword STRICTFP     "strictfp"
272 %put     STRICTFP summary
273 "Declaration modifier: strictfp {class|interface|<type>} <name> ..."
275 %keyword SUPER        "super"
277 %keyword SWITCH       "switch"
278 %put     SWITCH summary
279 "switch(<expr>) {[case <const-expr>: <stmts> ...] [default: <stmts>]}"
282 %keyword SYNCHRONIZED "synchronized"
283 %put     SYNCHRONIZED summary
284 "synchronized (<expr>) ... | Method decl. modifier: synchronized <type> <name> ..."
286 %keyword THIS         "this"
288 %keyword THROW        "throw"
289 %put     THROW summary
290 "throw <expr> ;"
292 %keyword THROWS       "throws"
293 %put     THROWS summary
294 "Method|Constructor declaration: throws <classType>, ..."
296 %keyword TRANSIENT    "transient"
297 %put     TRANSIENT summary
298 "Field declaration modifier: transient <type> <name> ..."
300 %keyword TRY          "try"
301 %put     TRY summary
302 "try {<stmts>} [catch(<parm>) {<stmts>} ...] [finally {<stmts>}]"
304 %keyword VOID         "void"
305 %put     VOID summary
306 "Method return type: void <name> ..."
308 %keyword VOLATILE     "volatile"
309 %put     VOLATILE summary
310 "Field declaration modifier: volatile <type> <name> ..."
312 %keyword WHILE        "while"
313 %put     WHILE summary
314 "while (<expr>) <stmt> | do <stmt> while (<expr>);"
315   
316 ;; --------------------------
317 ;; Official javadoc line tags
318 ;; --------------------------
320 ;; Javadoc tags are identified by a 'javadoc' keyword property.  The
321 ;; value of this property must be itself a property list where the
322 ;; following properties are recognized:
324 ;; - `seq' (mandatory) is the tag sequence number used to check if tags
325 ;;   are correctly ordered in a javadoc comment block.
327 ;; - `usage' (mandatory) is the list of token categories for which this
328 ;;   documentation tag is allowed.
330 ;; - `opt' (optional) if non-nil indicates this is an optional tag.
331 ;;   By default tags are mandatory.
333 ;; - `with-name' (optional) if non-nil indicates that this tag is
334 ;;   followed by an identifier like in "@param <var-name> description"
335 ;;   or "@exception <class-name> description".
337 ;; - `with-ref' (optional) if non-nil indicates that the tag is
338 ;;   followed by a reference like in "@see <reference>".
340 %keyword _AUTHOR      "@author"
341 %put     _AUTHOR      javadoc (seq 1 usage (type))
342 %keyword _VERSION     "@version"
343 %put     _VERSION     javadoc (seq 2 usage (type)) 
344 %keyword _PARAM       "@param"
345 %put     _PARAM       javadoc (seq 3 usage (function) with-name t) 
346 %keyword _RETURN      "@return"
347 %put     _RETURN      javadoc (seq 4 usage (function)) 
348 %keyword _EXCEPTION   "@exception"
349 %put     _EXCEPTION   javadoc (seq 5 usage (function) with-name t) 
350 %keyword _THROWS      "@throws"
351 %put     _THROWS      javadoc (seq 6 usage (function) with-name t) 
352 %keyword _SEE         "@see"
353 %put     _SEE         javadoc (seq 7 usage (type function variable) opt t with-ref t) 
354 %keyword _SINCE       "@since"
355 %put     _SINCE       javadoc (seq 8 usage (type function variable) opt t) 
356 %keyword _SERIAL      "@serial"
357 %put     _SERIAL      javadoc (seq 9 usage (variable) opt t) 
358 %keyword _SERIALDATA  "@serialData"
359 %put     _SERIALDATA  javadoc (seq 10 usage (function) opt t) 
360 %keyword _SERIALFIELD "@serialField"
361 %put     _SERIALFIELD javadoc (seq 11 usage (variable) opt t) 
362 %keyword _DEPRECATED  "@deprecated"
363 %put     _DEPRECATED  javadoc (seq 12 usage (type function variable) opt t) 
367 ;; ------------
368 ;; LALR Grammar
369 ;; ------------
371 ;; This grammar is not designed to fully parse correct Java syntax.  It
372 ;; is optimized to work in an interactive environment to extract tokens
373 ;; (tags) needed by Semantic.  In some cases a syntax not allowed by
374 ;; the Java Language Specification will be accepted by this grammar.
376 compilation_unit
377   : package_declaration
378   | import_declaration
379   | type_declaration
380   ;
382 ;;; Package statement token
383 ;; ("NAME" package DETAIL "DOCSTRING")
384 package_declaration
385   : PACKAGE qualified_name SEMICOLON
386     (PACKAGE-TAG $2 nil)
387   ;
389 ;;; Include file token
390 ;; ("FILE" include SYSTEM "DOCSTRING") 
391 import_declaration
392   : IMPORT qualified_name SEMICOLON
393     (INCLUDE-TAG $2 nil)
394   | IMPORT qualified_name DOT MULT SEMICOLON
395     (INCLUDE-TAG (concat $2 $3 $4) nil)
396   ;
398 type_declaration
399   : SEMICOLON
400     ()
401   | class_declaration
402   | interface_declaration
403   ;
405 ;;; Type Declaration token
406 ;; ("NAME" type "TYPE" ( PART-LIST ) ( PARENTS ) EXTRA-SPEC "DOCSTRING")
407 class_declaration
408   : modifiers_opt CLASS qualified_name superc_opt interfaces_opt class_body
409     (TYPE-TAG $3 $2 $6 (if (or $4 $5) (cons $4 $5)) :typemodifiers $1)
410   ;
412 superc_opt
413   : ;;EMPTY
414   | EXTENDS qualified_name
415     (identity $2)
416   ;
418 interfaces_opt
419   : ;;EMPTY
420   | IMPLEMENTS qualified_name_list
421     (nreverse $2)
422   ;
424 class_body
425   : BRACE_BLOCK
426     (EXPANDFULL $1 class_member_declaration)
427   ;
429 class_member_declaration
430   : LBRACE
431     ()
432   | RBRACE
433     ()
434   | block
435     ()
436   | static_initializer
437     ()
438   | constructor_declaration
439   | interface_declaration
440   | class_declaration
441   | method_declaration
442   | field_declaration
443   ;
445 ;;; Type Declaration token
446 ;; ("NAME" type "TYPE" ( PART-LIST ) ( PARENTS ) EXTRA-SPEC "DOCSTRING")
447 interface_declaration
448   : modifiers_opt INTERFACE qualified_name extends_interfaces_opt interface_body
449     (TYPE-TAG $3 $2 $5 (if $4 (cons nil $4)) :typemodifiers $1)
450   ;
452 extends_interfaces_opt
453   : ;;EMPTY
454   | EXTENDS qualified_name_list
455     (identity $2)
456   ;
458 interface_body
459   : BRACE_BLOCK
460     (EXPANDFULL $1 interface_member_declaration)
461   ;
463 interface_member_declaration
464   : LBRACE
465     ()
466   | RBRACE
467     ()
468   | interface_declaration
469   | class_declaration
470   | method_declaration
471   | field_declaration
472   ;
474 static_initializer
475   : STATIC block
476   ;
478 ;;; Function token
479 ;; ("NAME" function "TYPE" ( ARG-LIST ) EXTRA-SPEC "DOCSTRING") 
480 constructor_declaration
481   : modifiers_opt constructor_declarator throwsc_opt constructor_body
482     (FUNCTION-TAG (car $2) nil (cdr $2)
483                   :typemodifiers $1
484                   :throws $3
485                   :constructor-flag t)
486   ;
488 constructor_declarator
489   : IDENTIFIER formal_parameter_list
490     (cons $1 $2)
491   ;
493 constructor_body
494   : block 
495   ;
497 ;;; Function token
498 ;; ("NAME" function "TYPE" ( ARG-LIST ) EXTRA-SPEC "DOCSTRING") 
499 method_declaration
500   : modifiers_opt VOID method_declarator throwsc_opt method_body
501     (FUNCTION-TAG (car $3) $2 (cdr $3) :typemodifiers $1 :throws $4)
502   | modifiers_opt type method_declarator throwsc_opt method_body
503     (FUNCTION-TAG (car $3) $2 (cdr $3) :typemodifiers $1 :throws $4)
504   ;
506 method_declarator
507   : IDENTIFIER formal_parameter_list dims_opt
508     (cons (concat $1 $3) $2)
509   ;
511 throwsc_opt
512   : ;;EMPTY
513   | THROWS qualified_name_list
514     (nreverse $2)
515   ;
517 qualified_name_list
518   : qualified_name_list COMMA qualified_name
519     (cons $3 $1)
520   | qualified_name
521     (list $1)
522   ;
524 method_body
525   : SEMICOLON
526   | block
527   ;
529 ;; Just eat {...} block!
530 block
531   : BRACE_BLOCK
532   ;
534 formal_parameter_list
535   : PAREN_BLOCK
536     (EXPANDFULL $1 formal_parameters)
537   ;
539 formal_parameters
540   : LPAREN
541     ()
542   | RPAREN
543     ()
544   | formal_parameter COMMA
545   | formal_parameter RPAREN
546   ;
548 ;;; Variable token
549 ;; ("NAME" variable "TYPE" DEFAULT-VALUE EXTRA-SPEC "DOCSTRING")
550 formal_parameter
551   : formal_parameter_modifier_opt type opt_variable_declarator_id
552     (VARIABLE-TAG $3 $2 nil :typemodifiers $1)
553   ;
555 formal_parameter_modifier_opt
556   : ;;EMPTY
557   | FINAL
558     (list $1)
559   ;
561 ;;; Variable token
562 ;; ("NAME" variable "TYPE" DEFAULT-VALUE EXTRA-SPEC "DOCSTRING")
563 field_declaration
564   : modifiers_opt type variable_declarators SEMICOLON
565     (VARIABLE-TAG $3 $2 nil :typemodifiers $1)
566   ;
568 variable_declarators
569   : variable_declarators COMMA variable_declarator
570     (progn
571       ;; Set the end of the compound declaration to the end of the
572       ;; COMMA delimiter.
573       (setcdr (cdr (car $1)) (cdr $region2))
574       (cons $3 $1))
575   | variable_declarator
576     (list $1)
577   ;
579 variable_declarator
580   : variable_declarator_id EQ variable_initializer
581     (cons $1 $region)
582   | variable_declarator_id
583     (cons $1 $region)
584   ;
586 opt_variable_declarator_id
587   : ;; EMPTY
588     (identity "")
589   | variable_declarator_id
590     (identity $1)
591   ;
593 variable_declarator_id
594   : IDENTIFIER dims_opt
595     (concat $1 $2)
596   ;
598 variable_initializer
599   : expression
600   ;
602 ;; Just eat expression!
603 expression
604   : expression term
605   | term
606   ;
608 term
609   : literal
610   | operator
611   | primitive_type
612   | IDENTIFIER
613   | BRACK_BLOCK
614   | PAREN_BLOCK
615   | BRACE_BLOCK
616   | NEW
617   | CLASS
618   | THIS
619   | SUPER
620   ;
622 literal
623 ;;   : NULL_LITERAL
624 ;;   | BOOLEAN_LITERAL
625   : STRING_LITERAL
626   | NUMBER_LITERAL
627   ;
629 operator
630   : NOT
631   | PLUS
632   | PLUSPLUS
633   | MINUS
634   | MINUSMINUS
635   | NOTEQ
636   | MOD
637   | MODEQ
638   | AND
639   | ANDAND
640   | ANDEQ
641   | MULT
642   | MULTEQ
643   | PLUSEQ
644   | MINUSEQ
645   | DOT
646   | DIV
647   | DIVEQ
648   | COLON
649   | LT
650   | LSHIFT
651   | LSHIFTEQ
652   | LTEQ
653   | EQ
654   | EQEQ
655   | GT
656   | GTEQ
657   | RSHIFT
658   | RSHIFTEQ
659   | URSHIFT
660   | URSHIFTEQ
661   | QUESTION
662   | XOR
663   | XOREQ
664   | OR
665   | OREQ
666   | OROR
667   | COMP
668   | INSTANCEOF
669   ;
671 primitive_type
672   : BOOLEAN
673   | CHAR
674   | LONG
675   | INT
676   | SHORT
677   | BYTE
678   | DOUBLE
679   | FLOAT
680   ;
682 modifiers_opt
683   : ;;EMPTY
684   | modifiers
685     (nreverse $1)
686   ;
688 modifiers
689   : modifiers modifier
690     (cons $2 $1)
691   | modifier
692     (list $1)
693   ;
695 modifier
696   : STRICTFP
697   | VOLATILE
698   | TRANSIENT
699   | SYNCHRONIZED
700   | NATIVE
701   | FINAL
702   | ABSTRACT
703   | STATIC
704   | PRIVATE
705   | PROTECTED
706   | PUBLIC
707   ;
709 type
710   : qualified_name dims_opt
711     (concat $1 $2)
712   | primitive_type dims_opt
713     (concat $1 $2)
714   ;
716 qualified_name
717   : qualified_name DOT IDENTIFIER
718     (concat $1 $2 $3)
719   | IDENTIFIER
720   ;
722 dims_opt
723   : ;;EMPTY
724     (identity "")
725   | dims
726   ;
728 dims
729   : dims BRACK_BLOCK
730     (concat $1 "[]")
731   | BRACK_BLOCK
732     (identity "[]")
733   ;
736 ;; Define the lexer for this grammar
737 (define-lex wisent-java-tags-lexer
738   "Lexical analyzer that handles Java buffers.
739 It ignores whitespaces, newlines and comments."
740   semantic-lex-ignore-whitespace
741   semantic-lex-ignore-newline
742   semantic-lex-ignore-comments
743   ;;;; Auto-generated analyzers.
744   wisent-java-tags-wy--<number>-regexp-analyzer
745   wisent-java-tags-wy--<string>-sexp-analyzer
746   ;; Must detect keywords before other symbols
747   wisent-java-tags-wy--<keyword>-keyword-analyzer
748   wisent-java-tags-wy--<symbol>-regexp-analyzer
749   wisent-java-tags-wy--<punctuation>-string-analyzer
750   wisent-java-tags-wy--<block>-block-analyzer
751   ;; In theory, Unicode chars should be turned into normal chars
752   ;; and then combined into regular ascii keywords and text.  This
753   ;; analyzer just keeps these things from making the lexer go boom.
754   wisent-java-tags-wy--<unicode>-regexp-analyzer
755   ;;;;
756   semantic-lex-default-action)
758 ;;; java-tags.wy ends here