Update copyright year to 2014 by running admin/update-copyright.
[emacs.git] / admin / grammars / java-tags.wy
blob9ff27f3a2be685be7d26aefec47ee294fc147c34
1 ;;; java-tags.wy -- Semantic LALR grammar for Java
3 ;; Copyright (C) 2002-2014 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
29 (declare-function semantic-parse-region "semantic"
30                   (start end &optional nonterminal depth returnonerror))
33 %languagemode  java-mode
35 ;; The default start symbol
36 %start compilation_unit
37 ;; Alternate entry points
38 ;;    - Needed by partial re-parse
39 %start package_declaration
40 %start import_declaration
41 %start class_declaration
42 %start field_declaration
43 %start method_declaration
44 %start formal_parameter
45 %start constructor_declaration
46 %start interface_declaration
47 ;;    - Needed by EXPANDFULL clauses
48 %start class_member_declaration
49 %start interface_member_declaration
50 %start formal_parameters
52 ;; -----------------------------
53 ;; Block & Parenthesis terminals
54 ;; -----------------------------
55 %type  <block>       ;;syntax "\\s(\\|\\s)" matchdatatype block
57 %token <block>       PAREN_BLOCK "(LPAREN RPAREN)"
58 %token <block>       BRACE_BLOCK "(LBRACE RBRACE)"
59 %token <block>       BRACK_BLOCK "(LBRACK RBRACK)"
61 %token <open-paren>  LPAREN      "("
62 %token <close-paren> RPAREN      ")"
63 %token <open-paren>  LBRACE      "{"
64 %token <close-paren> RBRACE      "}"
65 %token <open-paren>  LBRACK      "["
66 %token <close-paren> RBRACK      "]"
68 ;; ------------------
69 ;; Operator terminals
70 ;; ------------------
71 %type  <punctuation> ;;syntax "\\(\\s.\\|\\s$\\|\\s'\\)+" matchdatatype string
73 %token <punctuation> NOT         "!"
74 %token <punctuation> NOTEQ       "!="
75 %token <punctuation> MOD         "%"
76 %token <punctuation> MODEQ       "%="
77 %token <punctuation> AND         "&"
78 %token <punctuation> ANDAND      "&&"
79 %token <punctuation> ANDEQ       "&="
80 %token <punctuation> MULT        "*"
81 %token <punctuation> MULTEQ      "*="
82 %token <punctuation> PLUS        "+"
83 %token <punctuation> PLUSPLUS    "++"
84 %token <punctuation> PLUSEQ      "+="
85 %token <punctuation> COMMA       ","
86 %token <punctuation> MINUS       "-"
87 %token <punctuation> MINUSMINUS  "--"
88 %token <punctuation> MINUSEQ     "-="
89 %token <punctuation> DOT         "."
90 %token <punctuation> DIV         "/"
91 %token <punctuation> DIVEQ       "/="
92 %token <punctuation> COLON       ":"
93 %token <punctuation> SEMICOLON   ";"
94 %token <punctuation> LT          "<"
95 %token <punctuation> LSHIFT      "<<"
96 %token <punctuation> LSHIFTEQ    "<<="
97 %token <punctuation> LTEQ        "<="
98 %token <punctuation> EQ          "="
99 %token <punctuation> EQEQ        "=="
100 %token <punctuation> GT          ">"
101 %token <punctuation> GTEQ        ">="
102 %token <punctuation> RSHIFT      ">>"
103 %token <punctuation> RSHIFTEQ    ">>="
104 %token <punctuation> URSHIFT     ">>>"
105 %token <punctuation> URSHIFTEQ   ">>>="
106 %token <punctuation> QUESTION    "?"
107 %token <punctuation> XOR         "^"
108 %token <punctuation> XOREQ       "^="
109 %token <punctuation> OR          "|"
110 %token <punctuation> OREQ        "|="
111 %token <punctuation> OROR        "||"
112 %token <punctuation> COMP        "~"
114 ;; -----------------
115 ;; Literal terminals
116 ;; -----------------
117 %type  <symbol>      ;;syntax "\\(\\sw\\|\\s_\\)+"
118 %token <symbol>      IDENTIFIER
120 %type  <string>      ;;syntax "\\s\"" matchdatatype sexp
121 %token <string>      STRING_LITERAL
123 %type  <number>      ;;syntax semantic-lex-number-expression
124 %token <number>      NUMBER_LITERAL
126 %type <unicode>      syntax "\\\\u[0-9a-f][0-9a-f][0-9a-f][0-9a-f]"
127 %token <unicode>     unicodecharacter
129 ;; -----------------
130 ;; Keyword terminals
131 ;; -----------------
133 ;; Generate a keyword analyzer
134 %type  <keyword> ;;syntax "\\(\\sw\\|\\s_\\)+" matchdatatype keyword
136 %keyword ABSTRACT     "abstract"
137 %put     ABSTRACT summary
138 "Class|Method declaration modifier: abstract {class|<type>} <name> ..."
140 %keyword BOOLEAN      "boolean"
141 %put     BOOLEAN summary
142 "Primitive logical quantity type (true or false)"
144 %keyword BREAK        "break"
145 %put     BREAK summary
146 "break [<label>] ;"
148 %keyword BYTE         "byte"
149 %put     BYTE summary
150 "Integral primitive type (-128 to 127)"
152 %keyword CASE         "case"
153 %put     CASE summary
154 "switch(<expr>) {case <const-expr>: <stmts> ... }"
156 %keyword CATCH        "catch"
157 %put     CATCH summary
158 "try {<stmts>} catch(<parm>) {<stmts>} ... "
160 %keyword CHAR         "char"
161 %put     CHAR summary
162 "Integral primitive type (0 to 65535)"
164 %keyword CLASS        "class"
165 %put     CLASS summary
166 "Class declaration: class <name>"
168 %keyword CONST        "const"
169 %put     CONST summary
170 "Unused reserved word"
172 %keyword CONTINUE     "continue"
173 %put     CONTINUE summary
174 "continue [<label>] ;"
176 %keyword DEFAULT      "default"
177 %put     DEFAULT summary
178 "switch(<expr>) { ... default: <stmts>}"
180 %keyword DO           "do"
181 %put     DO summary
182 "do <stmt> while (<expr>);"
184 %keyword DOUBLE       "double"
185 %put     DOUBLE summary
186 "Primitive floating-point type (double-precision 64-bit IEEE 754)"
188 %keyword ELSE         "else"
189 %put     ELSE summary
190 "if (<expr>) <stmt> else <stmt>"
192 %keyword EXTENDS      "extends"
193 %put     EXTENDS summary
194 "SuperClass|SuperInterfaces declaration: extends <name> [, ...]"
196 %keyword FINAL        "final"
197 %put     FINAL summary
198 "Class|Member declaration modifier: final {class|<type>} <name> ..."
200 %keyword FINALLY      "finally"
201 %put     FINALLY summary
202 "try {<stmts>} ... finally {<stmts>}"
204 %keyword FLOAT        "float"
205 %put     FLOAT summary
206 "Primitive floating-point type (single-precision 32-bit IEEE 754)"
208 %keyword FOR          "for"
209 %put     FOR summary
210 "for ([<init-expr>]; [<expr>]; [<update-expr>]) <stmt>"
212 %keyword GOTO         "goto"
213 %put     GOTO summary
214 "Unused reserved word"
216 %keyword IF           "if"
217 %put     IF summary
218 "if (<expr>) <stmt> [else <stmt>]"
220 %keyword IMPLEMENTS   "implements"
221 %put     IMPLEMENTS summary
222 "Class SuperInterfaces declaration: implements <name> [, ...]"
224 %keyword IMPORT       "import"
225 %put     IMPORT summary
226 "Import package declarations: import <package>"
228 %keyword INSTANCEOF   "instanceof"
230 %keyword INT          "int"
231 %put     INT summary
232 "Integral primitive type (-2147483648 to 2147483647)"
234 %keyword INTERFACE    "interface"
235 %put     INTERFACE summary
236 "Interface declaration: interface <name>"
238 %keyword LONG         "long"
239 %put     LONG summary
240 "Integral primitive type (-9223372036854775808 to 9223372036854775807)"
242 %keyword NATIVE       "native"
243 %put     NATIVE summary
244 "Method declaration modifier: native <type> <name> ..."
246 %keyword NEW          "new"
248 %keyword PACKAGE      "package"
249 %put     PACKAGE summary
250 "Package declaration: package <name>"
252 %keyword PRIVATE      "private"
253 %put     PRIVATE summary
254 "Access level modifier: private {class|interface|<type>} <name> ..."
256 %keyword PROTECTED    "protected"
257 %put     PROTECTED summary
258 "Access level modifier: protected {class|interface|<type>} <name> ..."
260 %keyword PUBLIC       "public"
261 %put     PUBLIC summary
262 "Access level modifier: public {class|interface|<type>} <name> ..."
264 %keyword RETURN       "return"
265 %put     RETURN summary
266 "return [<expr>] ;"
268 %keyword SHORT        "short"
269 %put     SHORT summary
270 "Integral primitive type (-32768 to 32767)"
272 %keyword STATIC       "static"
273 %put     STATIC summary
274 "Declaration modifier: static {class|interface|<type>} <name> ..."
276 %keyword STRICTFP     "strictfp"
277 %put     STRICTFP summary
278 "Declaration modifier: strictfp {class|interface|<type>} <name> ..."
280 %keyword SUPER        "super"
282 %keyword SWITCH       "switch"
283 %put     SWITCH summary
284 "switch(<expr>) {[case <const-expr>: <stmts> ...] [default: <stmts>]}"
287 %keyword SYNCHRONIZED "synchronized"
288 %put     SYNCHRONIZED summary
289 "synchronized (<expr>) ... | Method decl. modifier: synchronized <type> <name> ..."
291 %keyword THIS         "this"
293 %keyword THROW        "throw"
294 %put     THROW summary
295 "throw <expr> ;"
297 %keyword THROWS       "throws"
298 %put     THROWS summary
299 "Method|Constructor declaration: throws <classType>, ..."
301 %keyword TRANSIENT    "transient"
302 %put     TRANSIENT summary
303 "Field declaration modifier: transient <type> <name> ..."
305 %keyword TRY          "try"
306 %put     TRY summary
307 "try {<stmts>} [catch(<parm>) {<stmts>} ...] [finally {<stmts>}]"
309 %keyword VOID         "void"
310 %put     VOID summary
311 "Method return type: void <name> ..."
313 %keyword VOLATILE     "volatile"
314 %put     VOLATILE summary
315 "Field declaration modifier: volatile <type> <name> ..."
317 %keyword WHILE        "while"
318 %put     WHILE summary
319 "while (<expr>) <stmt> | do <stmt> while (<expr>);"
321 ;; --------------------------
322 ;; Official javadoc line tags
323 ;; --------------------------
325 ;; Javadoc tags are identified by a 'javadoc' keyword property.  The
326 ;; value of this property must be itself a property list where the
327 ;; following properties are recognized:
329 ;; - `seq' (mandatory) is the tag sequence number used to check if tags
330 ;;   are correctly ordered in a javadoc comment block.
332 ;; - `usage' (mandatory) is the list of token categories for which this
333 ;;   documentation tag is allowed.
335 ;; - `opt' (optional) if non-nil indicates this is an optional tag.
336 ;;   By default tags are mandatory.
338 ;; - `with-name' (optional) if non-nil indicates that this tag is
339 ;;   followed by an identifier like in "@param <var-name> description"
340 ;;   or "@exception <class-name> description".
342 ;; - `with-ref' (optional) if non-nil indicates that the tag is
343 ;;   followed by a reference like in "@see <reference>".
345 %keyword _AUTHOR      "@author"
346 %put     _AUTHOR      javadoc (seq 1 usage (type))
347 %keyword _VERSION     "@version"
348 %put     _VERSION     javadoc (seq 2 usage (type))
349 %keyword _PARAM       "@param"
350 %put     _PARAM       javadoc (seq 3 usage (function) with-name t)
351 %keyword _RETURN      "@return"
352 %put     _RETURN      javadoc (seq 4 usage (function))
353 %keyword _EXCEPTION   "@exception"
354 %put     _EXCEPTION   javadoc (seq 5 usage (function) with-name t)
355 %keyword _THROWS      "@throws"
356 %put     _THROWS      javadoc (seq 6 usage (function) with-name t)
357 %keyword _SEE         "@see"
358 %put     _SEE         javadoc (seq 7 usage (type function variable) opt t with-ref t)
359 %keyword _SINCE       "@since"
360 %put     _SINCE       javadoc (seq 8 usage (type function variable) opt t)
361 %keyword _SERIAL      "@serial"
362 %put     _SERIAL      javadoc (seq 9 usage (variable) opt t)
363 %keyword _SERIALDATA  "@serialData"
364 %put     _SERIALDATA  javadoc (seq 10 usage (function) opt t)
365 %keyword _SERIALFIELD "@serialField"
366 %put     _SERIALFIELD javadoc (seq 11 usage (variable) opt t)
367 %keyword _DEPRECATED  "@deprecated"
368 %put     _DEPRECATED  javadoc (seq 12 usage (type function variable) opt t)
372 ;; ------------
373 ;; LALR Grammar
374 ;; ------------
376 ;; This grammar is not designed to fully parse correct Java syntax.  It
377 ;; is optimized to work in an interactive environment to extract tokens
378 ;; (tags) needed by Semantic.  In some cases a syntax not allowed by
379 ;; the Java Language Specification will be accepted by this grammar.
381 compilation_unit
382   : package_declaration
383   | import_declaration
384   | type_declaration
385   ;
387 ;;; Package statement token
388 ;; ("NAME" package DETAIL "DOCSTRING")
389 package_declaration
390   : PACKAGE qualified_name SEMICOLON
391     (PACKAGE-TAG $2 nil)
392   ;
394 ;;; Include file token
395 ;; ("FILE" include SYSTEM "DOCSTRING")
396 import_declaration
397   : IMPORT qualified_name SEMICOLON
398     (INCLUDE-TAG $2 nil)
399   | IMPORT qualified_name DOT MULT SEMICOLON
400     (INCLUDE-TAG (concat $2 $3 $4) nil)
401   ;
403 type_declaration
404   : SEMICOLON
405     ()
406   | class_declaration
407   | interface_declaration
408   ;
410 ;;; Type Declaration token
411 ;; ("NAME" type "TYPE" ( PART-LIST ) ( PARENTS ) EXTRA-SPEC "DOCSTRING")
412 class_declaration
413   : modifiers_opt CLASS qualified_name superc_opt interfaces_opt class_body
414     (TYPE-TAG $3 $2 $6 (if (or $4 $5) (cons $4 $5)) :typemodifiers $1)
415   ;
417 superc_opt
418   : ;;EMPTY
419   | EXTENDS qualified_name
420     (identity $2)
421   ;
423 interfaces_opt
424   : ;;EMPTY
425   | IMPLEMENTS qualified_name_list
426     (nreverse $2)
427   ;
429 class_body
430   : BRACE_BLOCK
431     (EXPANDFULL $1 class_member_declaration)
432   ;
434 class_member_declaration
435   : LBRACE
436     ()
437   | RBRACE
438     ()
439   | block
440     ()
441   | static_initializer
442     ()
443   | constructor_declaration
444   | interface_declaration
445   | class_declaration
446   | method_declaration
447   | field_declaration
448   ;
450 ;;; Type Declaration token
451 ;; ("NAME" type "TYPE" ( PART-LIST ) ( PARENTS ) EXTRA-SPEC "DOCSTRING")
452 interface_declaration
453   : modifiers_opt INTERFACE qualified_name extends_interfaces_opt interface_body
454     (TYPE-TAG $3 $2 $5 (if $4 (cons nil $4)) :typemodifiers $1)
455   ;
457 extends_interfaces_opt
458   : ;;EMPTY
459   | EXTENDS qualified_name_list
460     (identity $2)
461   ;
463 interface_body
464   : BRACE_BLOCK
465     (EXPANDFULL $1 interface_member_declaration)
466   ;
468 interface_member_declaration
469   : LBRACE
470     ()
471   | RBRACE
472     ()
473   | interface_declaration
474   | class_declaration
475   | method_declaration
476   | field_declaration
477   ;
479 static_initializer
480   : STATIC block
481   ;
483 ;;; Function token
484 ;; ("NAME" function "TYPE" ( ARG-LIST ) EXTRA-SPEC "DOCSTRING")
485 constructor_declaration
486   : modifiers_opt constructor_declarator throwsc_opt constructor_body
487     (FUNCTION-TAG (car $2) nil (cdr $2)
488                   :typemodifiers $1
489                   :throws $3
490                   :constructor-flag t)
491   ;
493 constructor_declarator
494   : IDENTIFIER formal_parameter_list
495     (cons $1 $2)
496   ;
498 constructor_body
499   : block
500   ;
502 ;;; Function token
503 ;; ("NAME" function "TYPE" ( ARG-LIST ) EXTRA-SPEC "DOCSTRING")
504 method_declaration
505   : modifiers_opt VOID method_declarator throwsc_opt method_body
506     (FUNCTION-TAG (car $3) $2 (cdr $3) :typemodifiers $1 :throws $4)
507   | modifiers_opt type method_declarator throwsc_opt method_body
508     (FUNCTION-TAG (car $3) $2 (cdr $3) :typemodifiers $1 :throws $4)
509   ;
511 method_declarator
512   : IDENTIFIER formal_parameter_list dims_opt
513     (cons (concat $1 $3) $2)
514   ;
516 throwsc_opt
517   : ;;EMPTY
518   | THROWS qualified_name_list
519     (nreverse $2)
520   ;
522 qualified_name_list
523   : qualified_name_list COMMA qualified_name
524     (cons $3 $1)
525   | qualified_name
526     (list $1)
527   ;
529 method_body
530   : SEMICOLON
531   | block
532   ;
534 ;; Just eat {...} block!
535 block
536   : BRACE_BLOCK
537   ;
539 formal_parameter_list
540   : PAREN_BLOCK
541     (EXPANDFULL $1 formal_parameters)
542   ;
544 formal_parameters
545   : LPAREN
546     ()
547   | RPAREN
548     ()
549   | formal_parameter COMMA
550   | formal_parameter RPAREN
551   ;
553 ;;; Variable token
554 ;; ("NAME" variable "TYPE" DEFAULT-VALUE EXTRA-SPEC "DOCSTRING")
555 formal_parameter
556   : formal_parameter_modifier_opt type opt_variable_declarator_id
557     (VARIABLE-TAG $3 $2 nil :typemodifiers $1)
558   ;
560 formal_parameter_modifier_opt
561   : ;;EMPTY
562   | FINAL
563     (list $1)
564   ;
566 ;;; Variable token
567 ;; ("NAME" variable "TYPE" DEFAULT-VALUE EXTRA-SPEC "DOCSTRING")
568 field_declaration
569   : modifiers_opt type variable_declarators SEMICOLON
570     (VARIABLE-TAG $3 $2 nil :typemodifiers $1)
571   ;
573 variable_declarators
574   : variable_declarators COMMA variable_declarator
575     (progn
576       ;; Set the end of the compound declaration to the end of the
577       ;; COMMA delimiter.
578       (setcdr (cdr (car $1)) (cdr $region2))
579       (cons $3 $1))
580   | variable_declarator
581     (list $1)
582   ;
584 variable_declarator
585   : variable_declarator_id EQ variable_initializer
586     (cons $1 $region)
587   | variable_declarator_id
588     (cons $1 $region)
589   ;
591 opt_variable_declarator_id
592   : ;; EMPTY
593     (identity "")
594   | variable_declarator_id
595     (identity $1)
596   ;
598 variable_declarator_id
599   : IDENTIFIER dims_opt
600     (concat $1 $2)
601   ;
603 variable_initializer
604   : expression
605   ;
607 ;; Just eat expression!
608 expression
609   : expression term
610   | term
611   ;
613 term
614   : literal
615   | operator
616   | primitive_type
617   | IDENTIFIER
618   | BRACK_BLOCK
619   | PAREN_BLOCK
620   | BRACE_BLOCK
621   | NEW
622   | CLASS
623   | THIS
624   | SUPER
625   ;
627 literal
628 ;;   : NULL_LITERAL
629 ;;   | BOOLEAN_LITERAL
630   : STRING_LITERAL
631   | NUMBER_LITERAL
632   ;
634 operator
635   : NOT
636   | PLUS
637   | PLUSPLUS
638   | MINUS
639   | MINUSMINUS
640   | NOTEQ
641   | MOD
642   | MODEQ
643   | AND
644   | ANDAND
645   | ANDEQ
646   | MULT
647   | MULTEQ
648   | PLUSEQ
649   | MINUSEQ
650   | DOT
651   | DIV
652   | DIVEQ
653   | COLON
654   | LT
655   | LSHIFT
656   | LSHIFTEQ
657   | LTEQ
658   | EQ
659   | EQEQ
660   | GT
661   | GTEQ
662   | RSHIFT
663   | RSHIFTEQ
664   | URSHIFT
665   | URSHIFTEQ
666   | QUESTION
667   | XOR
668   | XOREQ
669   | OR
670   | OREQ
671   | OROR
672   | COMP
673   | INSTANCEOF
674   ;
676 primitive_type
677   : BOOLEAN
678   | CHAR
679   | LONG
680   | INT
681   | SHORT
682   | BYTE
683   | DOUBLE
684   | FLOAT
685   ;
687 modifiers_opt
688   : ;;EMPTY
689   | modifiers
690     (nreverse $1)
691   ;
693 modifiers
694   : modifiers modifier
695     (cons $2 $1)
696   | modifier
697     (list $1)
698   ;
700 modifier
701   : STRICTFP
702   | VOLATILE
703   | TRANSIENT
704   | SYNCHRONIZED
705   | NATIVE
706   | FINAL
707   | ABSTRACT
708   | STATIC
709   | PRIVATE
710   | PROTECTED
711   | PUBLIC
712   ;
714 type
715   : qualified_name dims_opt
716     (concat $1 $2)
717   | primitive_type dims_opt
718     (concat $1 $2)
719   ;
721 qualified_name
722   : qualified_name DOT IDENTIFIER
723     (concat $1 $2 $3)
724   | IDENTIFIER
725   ;
727 dims_opt
728   : ;;EMPTY
729     (identity "")
730   | dims
731   ;
733 dims
734   : dims BRACK_BLOCK
735     (concat $1 "[]")
736   | BRACK_BLOCK
737     (identity "[]")
738   ;
741 ;; Define the lexer for this grammar
742 (define-lex wisent-java-tags-lexer
743   "Lexical analyzer that handles Java buffers.
744 It ignores whitespaces, newlines and comments."
745   semantic-lex-ignore-whitespace
746   semantic-lex-ignore-newline
747   semantic-lex-ignore-comments
748   ;;;; Auto-generated analyzers.
749   wisent-java-tags-wy--<number>-regexp-analyzer
750   wisent-java-tags-wy--<string>-sexp-analyzer
751   ;; Must detect keywords before other symbols
752   wisent-java-tags-wy--<keyword>-keyword-analyzer
753   wisent-java-tags-wy--<symbol>-regexp-analyzer
754   wisent-java-tags-wy--<punctuation>-string-analyzer
755   wisent-java-tags-wy--<block>-block-analyzer
756   ;; In theory, Unicode chars should be turned into normal chars
757   ;; and then combined into regular ascii keywords and text.  This
758   ;; analyzer just keeps these things from making the lexer go boom.
759   wisent-java-tags-wy--<unicode>-regexp-analyzer
760   ;;;;
761   semantic-lex-default-action)
763 ;;; java-tags.wy ends here