1 ;;; java-tags.wy -- Semantic LALR grammar for Java
3 ;; Copyright (C) 2002-2011, 2012 Free Software Foundation, Inc.
5 ;; Author: David Ponce <david@dponce.com>
6 ;; Maintainer: David Ponce <david@dponce.com>
7 ;; Created: 26 Aug 2002
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
27 %languagemode java-mode
29 ;; The default start symbol
30 %start compilation_unit
31 ;; Alternate entry points
32 ;; - Needed by partial re-parse
33 %start package_declaration
34 %start import_declaration
35 %start class_declaration
36 %start field_declaration
37 %start method_declaration
38 %start formal_parameter
39 %start constructor_declaration
40 %start interface_declaration
41 ;; - Needed by EXPANDFULL clauses
42 %start class_member_declaration
43 %start interface_member_declaration
44 %start formal_parameters
46 ;; -----------------------------
47 ;; Block & Parenthesis terminals
48 ;; -----------------------------
49 %type <block> ;;syntax "\\s(\\|\\s)" matchdatatype block
51 %token <block> PAREN_BLOCK "(LPAREN RPAREN)"
52 %token <block> BRACE_BLOCK "(LBRACE RBRACE)"
53 %token <block> BRACK_BLOCK "(LBRACK RBRACK)"
55 %token <open-paren> LPAREN "("
56 %token <close-paren> RPAREN ")"
57 %token <open-paren> LBRACE "{"
58 %token <close-paren> RBRACE "}"
59 %token <open-paren> LBRACK "["
60 %token <close-paren> RBRACK "]"
65 %type <punctuation> ;;syntax "\\(\\s.\\|\\s$\\|\\s'\\)+" matchdatatype string
67 %token <punctuation> NOT "!"
68 %token <punctuation> NOTEQ "!="
69 %token <punctuation> MOD "%"
70 %token <punctuation> MODEQ "%="
71 %token <punctuation> AND "&"
72 %token <punctuation> ANDAND "&&"
73 %token <punctuation> ANDEQ "&="
74 %token <punctuation> MULT "*"
75 %token <punctuation> MULTEQ "*="
76 %token <punctuation> PLUS "+"
77 %token <punctuation> PLUSPLUS "++"
78 %token <punctuation> PLUSEQ "+="
79 %token <punctuation> COMMA ","
80 %token <punctuation> MINUS "-"
81 %token <punctuation> MINUSMINUS "--"
82 %token <punctuation> MINUSEQ "-="
83 %token <punctuation> DOT "."
84 %token <punctuation> DIV "/"
85 %token <punctuation> DIVEQ "/="
86 %token <punctuation> COLON ":"
87 %token <punctuation> SEMICOLON ";"
88 %token <punctuation> LT "<"
89 %token <punctuation> LSHIFT "<<"
90 %token <punctuation> LSHIFTEQ "<<="
91 %token <punctuation> LTEQ "<="
92 %token <punctuation> EQ "="
93 %token <punctuation> EQEQ "=="
94 %token <punctuation> GT ">"
95 %token <punctuation> GTEQ ">="
96 %token <punctuation> RSHIFT ">>"
97 %token <punctuation> RSHIFTEQ ">>="
98 %token <punctuation> URSHIFT ">>>"
99 %token <punctuation> URSHIFTEQ ">>>="
100 %token <punctuation> QUESTION "?"
101 %token <punctuation> XOR "^"
102 %token <punctuation> XOREQ "^="
103 %token <punctuation> OR "|"
104 %token <punctuation> OREQ "|="
105 %token <punctuation> OROR "||"
106 %token <punctuation> COMP "~"
111 %type <symbol> ;;syntax "\\(\\sw\\|\\s_\\)+"
112 %token <symbol> IDENTIFIER
114 %type <string> ;;syntax "\\s\"" matchdatatype sexp
115 %token <string> STRING_LITERAL
117 %type <number> ;;syntax semantic-lex-number-expression
118 %token <number> NUMBER_LITERAL
120 %type <unicode> syntax "\\\\u[0-9a-f][0-9a-f][0-9a-f][0-9a-f]"
121 %token <unicode> unicodecharacter
127 ;; Generate a keyword analyzer
128 %type <keyword> ;;syntax "\\(\\sw\\|\\s_\\)+" matchdatatype keyword
130 %keyword ABSTRACT "abstract"
131 %put ABSTRACT summary
132 "Class|Method declaration modifier: abstract {class|<type>} <name> ..."
134 %keyword BOOLEAN "boolean"
136 "Primitive logical quantity type (true or false)"
138 %keyword BREAK "break"
144 "Integral primitive type (-128 to 127)"
148 "switch(<expr>) {case <const-expr>: <stmts> ... }"
150 %keyword CATCH "catch"
152 "try {<stmts>} catch(<parm>) {<stmts>} ... "
156 "Integral primitive type ('\u0000' to '\uffff') (0 to 65535)"
158 %keyword CLASS "class"
160 "Class declaration: class <name>"
162 %keyword CONST "const"
164 "Unused reserved word"
166 %keyword CONTINUE "continue"
167 %put CONTINUE summary
168 "continue [<label>] ;"
170 %keyword DEFAULT "default"
172 "switch(<expr>) { ... default: <stmts>}"
176 "do <stmt> while (<expr>);"
178 %keyword DOUBLE "double"
180 "Primitive floating-point type (double-precision 64-bit IEEE 754)"
184 "if (<expr>) <stmt> else <stmt>"
186 %keyword EXTENDS "extends"
188 "SuperClass|SuperInterfaces declaration: extends <name> [, ...]"
190 %keyword FINAL "final"
192 "Class|Member declaration modifier: final {class|<type>} <name> ..."
194 %keyword FINALLY "finally"
196 "try {<stmts>} ... finally {<stmts>}"
198 %keyword FLOAT "float"
200 "Primitive floating-point type (single-precision 32-bit IEEE 754)"
204 "for ([<init-expr>]; [<expr>]; [<update-expr>]) <stmt>"
208 "Unused reserved word"
212 "if (<expr>) <stmt> [else <stmt>]"
214 %keyword IMPLEMENTS "implements"
215 %put IMPLEMENTS summary
216 "Class SuperInterfaces declaration: implements <name> [, ...]"
218 %keyword IMPORT "import"
220 "Import package declarations: import <package>"
222 %keyword INSTANCEOF "instanceof"
226 "Integral primitive type (-2147483648 to 2147483647)"
228 %keyword INTERFACE "interface"
229 %put INTERFACE summary
230 "Interface declaration: interface <name>"
234 "Integral primitive type (-9223372036854775808 to 9223372036854775807)"
236 %keyword NATIVE "native"
238 "Method declaration modifier: native <type> <name> ..."
242 %keyword PACKAGE "package"
244 "Package declaration: package <name>"
246 %keyword PRIVATE "private"
248 "Access level modifier: private {class|interface|<type>} <name> ..."
250 %keyword PROTECTED "protected"
251 %put PROTECTED summary
252 "Access level modifier: protected {class|interface|<type>} <name> ..."
254 %keyword PUBLIC "public"
256 "Access level modifier: public {class|interface|<type>} <name> ..."
258 %keyword RETURN "return"
262 %keyword SHORT "short"
264 "Integral primitive type (-32768 to 32767)"
266 %keyword STATIC "static"
268 "Declaration modifier: static {class|interface|<type>} <name> ..."
270 %keyword STRICTFP "strictfp"
271 %put STRICTFP summary
272 "Declaration modifier: strictfp {class|interface|<type>} <name> ..."
274 %keyword SUPER "super"
276 %keyword SWITCH "switch"
278 "switch(<expr>) {[case <const-expr>: <stmts> ...] [default: <stmts>]}"
281 %keyword SYNCHRONIZED "synchronized"
282 %put SYNCHRONIZED summary
283 "synchronized (<expr>) ... | Method decl. modifier: synchronized <type> <name> ..."
287 %keyword THROW "throw"
291 %keyword THROWS "throws"
293 "Method|Constructor declaration: throws <classType>, ..."
295 %keyword TRANSIENT "transient"
296 %put TRANSIENT summary
297 "Field declaration modifier: transient <type> <name> ..."
301 "try {<stmts>} [catch(<parm>) {<stmts>} ...] [finally {<stmts>}]"
305 "Method return type: void <name> ..."
307 %keyword VOLATILE "volatile"
308 %put VOLATILE summary
309 "Field declaration modifier: volatile <type> <name> ..."
311 %keyword WHILE "while"
313 "while (<expr>) <stmt> | do <stmt> while (<expr>);"
315 ;; --------------------------
316 ;; Official javadoc line tags
317 ;; --------------------------
319 ;; Javadoc tags are identified by a 'javadoc' keyword property. The
320 ;; value of this property must be itself a property list where the
321 ;; following properties are recognized:
323 ;; - `seq' (mandatory) is the tag sequence number used to check if tags
324 ;; are correctly ordered in a javadoc comment block.
326 ;; - `usage' (mandatory) is the list of token categories for which this
327 ;; documentation tag is allowed.
329 ;; - `opt' (optional) if non-nil indicates this is an optional tag.
330 ;; By default tags are mandatory.
332 ;; - `with-name' (optional) if non-nil indicates that this tag is
333 ;; followed by an identifier like in "@param <var-name> description"
334 ;; or "@exception <class-name> description".
336 ;; - `with-ref' (optional) if non-nil indicates that the tag is
337 ;; followed by a reference like in "@see <reference>".
339 %keyword _AUTHOR "@author"
340 %put _AUTHOR javadoc (seq 1 usage (type))
341 %keyword _VERSION "@version"
342 %put _VERSION javadoc (seq 2 usage (type))
343 %keyword _PARAM "@param"
344 %put _PARAM javadoc (seq 3 usage (function) with-name t)
345 %keyword _RETURN "@return"
346 %put _RETURN javadoc (seq 4 usage (function))
347 %keyword _EXCEPTION "@exception"
348 %put _EXCEPTION javadoc (seq 5 usage (function) with-name t)
349 %keyword _THROWS "@throws"
350 %put _THROWS javadoc (seq 6 usage (function) with-name t)
352 %put _SEE javadoc (seq 7 usage (type function variable) opt t with-ref t)
353 %keyword _SINCE "@since"
354 %put _SINCE javadoc (seq 8 usage (type function variable) opt t)
355 %keyword _SERIAL "@serial"
356 %put _SERIAL javadoc (seq 9 usage (variable) opt t)
357 %keyword _SERIALDATA "@serialData"
358 %put _SERIALDATA javadoc (seq 10 usage (function) opt t)
359 %keyword _SERIALFIELD "@serialField"
360 %put _SERIALFIELD javadoc (seq 11 usage (variable) opt t)
361 %keyword _DEPRECATED "@deprecated"
362 %put _DEPRECATED javadoc (seq 12 usage (type function variable) opt t)
370 ;; This grammar is not designed to fully parse correct Java syntax. It
371 ;; is optimized to work in an interactive environment to extract tokens
372 ;; (tags) needed by Semantic. In some cases a syntax not allowed by
373 ;; the Java Language Specification will be accepted by this grammar.
376 : package_declaration
381 ;;; Package statement token
382 ;; ("NAME" package DETAIL "DOCSTRING")
384 : PACKAGE qualified_name SEMICOLON
388 ;;; Include file token
389 ;; ("FILE" include SYSTEM "DOCSTRING")
391 : IMPORT qualified_name SEMICOLON
393 | IMPORT qualified_name DOT MULT SEMICOLON
394 (INCLUDE-TAG (concat $2 $3 $4) nil)
401 | interface_declaration
404 ;;; Type Declaration token
405 ;; ("NAME" type "TYPE" ( PART-LIST ) ( PARENTS ) EXTRA-SPEC "DOCSTRING")
407 : modifiers_opt CLASS qualified_name superc_opt interfaces_opt class_body
408 (TYPE-TAG $3 $2 $6 (if (or $4 $5) (cons $4 $5)) :typemodifiers $1)
413 | EXTENDS qualified_name
419 | IMPLEMENTS qualified_name_list
425 (EXPANDFULL $1 class_member_declaration)
428 class_member_declaration
437 | constructor_declaration
438 | interface_declaration
444 ;;; Type Declaration token
445 ;; ("NAME" type "TYPE" ( PART-LIST ) ( PARENTS ) EXTRA-SPEC "DOCSTRING")
446 interface_declaration
447 : modifiers_opt INTERFACE IDENTIFIER extends_interfaces_opt interface_body
448 (TYPE-TAG $3 $2 $5 (if $4 (cons nil $4)) :typemodifiers $1)
451 extends_interfaces_opt
453 | EXTENDS qualified_name_list
459 (EXPANDFULL $1 interface_member_declaration)
462 interface_member_declaration
467 | interface_declaration
478 ;; ("NAME" function "TYPE" ( ARG-LIST ) EXTRA-SPEC "DOCSTRING")
479 constructor_declaration
480 : modifiers_opt constructor_declarator throwsc_opt constructor_body
481 (FUNCTION-TAG (car $2) nil (cdr $2)
487 constructor_declarator
488 : IDENTIFIER formal_parameter_list
497 ;; ("NAME" function "TYPE" ( ARG-LIST ) EXTRA-SPEC "DOCSTRING")
499 : modifiers_opt VOID method_declarator throwsc_opt method_body
500 (FUNCTION-TAG (car $3) $2 (cdr $3) :typemodifiers $1 :throws $4)
501 | modifiers_opt type method_declarator throwsc_opt method_body
502 (FUNCTION-TAG (car $3) $2 (cdr $3) :typemodifiers $1 :throws $4)
506 : IDENTIFIER formal_parameter_list dims_opt
507 (cons (concat $1 $3) $2)
512 | THROWS qualified_name_list
517 : qualified_name_list COMMA qualified_name
528 ;; Just eat {...} block!
533 formal_parameter_list
535 (EXPANDFULL $1 formal_parameters)
543 | formal_parameter COMMA
544 | formal_parameter RPAREN
548 ;; ("NAME" variable "TYPE" DEFAULT-VALUE EXTRA-SPEC "DOCSTRING")
550 : formal_parameter_modifier_opt type variable_declarator_id
551 (VARIABLE-TAG $3 $2 nil :typemodifiers $1)
554 formal_parameter_modifier_opt
561 ;; ("NAME" variable "TYPE" DEFAULT-VALUE EXTRA-SPEC "DOCSTRING")
563 : modifiers_opt type variable_declarators SEMICOLON
564 (VARIABLE-TAG $3 $2 nil :typemodifiers $1)
568 : variable_declarators COMMA variable_declarator
570 ;; Set the end of the compound declaration to the end of the
572 (setcdr (cdr (car $1)) (cdr $region2))
574 | variable_declarator
579 : variable_declarator_id EQ variable_initializer
581 | variable_declarator_id
585 variable_declarator_id
586 : IDENTIFIER dims_opt
594 ;; Just eat expression!
702 : qualified_name dims_opt
704 | primitive_type dims_opt
709 : qualified_name DOT IDENTIFIER
728 ;; Define the lexer for this grammar
729 (define-lex wisent-java-tags-lexer
730 "Lexical analyzer that handles Java buffers.
731 It ignores whitespaces, newlines and comments."
732 semantic-lex-ignore-whitespace
733 semantic-lex-ignore-newline
734 semantic-lex-ignore-comments
735 ;;;; Auto-generated analyzers.
736 wisent-java-tags-wy--<number>-regexp-analyzer
737 wisent-java-tags-wy--<string>-sexp-analyzer
738 ;; Must detect keywords before other symbols
739 wisent-java-tags-wy--<keyword>-keyword-analyzer
740 wisent-java-tags-wy--<symbol>-regexp-analyzer
741 wisent-java-tags-wy--<punctuation>-string-analyzer
742 wisent-java-tags-wy--<block>-block-analyzer
743 ;; In theory, unicode chars should be turned into normal chars
744 ;; and then combined into regular ascii keywords and text. This
745 ;; analyzer just keeps these things from making the lexer go boom.
746 wisent-java-tags-wy--<unicode>-regexp-analyzer
748 semantic-lex-default-action)
750 ;;; java-tags.wy ends here