1 ;;; java-tags.wy -- Semantic LALR grammar for Java
3 ;; Copyright (C) 2002-2013 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
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 "]"
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 "~"
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
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"
137 "Primitive logical quantity type (true or false)"
139 %keyword BREAK "break"
145 "Integral primitive type (-128 to 127)"
149 "switch(<expr>) {case <const-expr>: <stmts> ... }"
151 %keyword CATCH "catch"
153 "try {<stmts>} catch(<parm>) {<stmts>} ... "
157 "Integral primitive type (0 to 65535)"
159 %keyword CLASS "class"
161 "Class declaration: class <name>"
163 %keyword CONST "const"
165 "Unused reserved word"
167 %keyword CONTINUE "continue"
168 %put CONTINUE summary
169 "continue [<label>] ;"
171 %keyword DEFAULT "default"
173 "switch(<expr>) { ... default: <stmts>}"
177 "do <stmt> while (<expr>);"
179 %keyword DOUBLE "double"
181 "Primitive floating-point type (double-precision 64-bit IEEE 754)"
185 "if (<expr>) <stmt> else <stmt>"
187 %keyword EXTENDS "extends"
189 "SuperClass|SuperInterfaces declaration: extends <name> [, ...]"
191 %keyword FINAL "final"
193 "Class|Member declaration modifier: final {class|<type>} <name> ..."
195 %keyword FINALLY "finally"
197 "try {<stmts>} ... finally {<stmts>}"
199 %keyword FLOAT "float"
201 "Primitive floating-point type (single-precision 32-bit IEEE 754)"
205 "for ([<init-expr>]; [<expr>]; [<update-expr>]) <stmt>"
209 "Unused reserved word"
213 "if (<expr>) <stmt> [else <stmt>]"
215 %keyword IMPLEMENTS "implements"
216 %put IMPLEMENTS summary
217 "Class SuperInterfaces declaration: implements <name> [, ...]"
219 %keyword IMPORT "import"
221 "Import package declarations: import <package>"
223 %keyword INSTANCEOF "instanceof"
227 "Integral primitive type (-2147483648 to 2147483647)"
229 %keyword INTERFACE "interface"
230 %put INTERFACE summary
231 "Interface declaration: interface <name>"
235 "Integral primitive type (-9223372036854775808 to 9223372036854775807)"
237 %keyword NATIVE "native"
239 "Method declaration modifier: native <type> <name> ..."
243 %keyword PACKAGE "package"
245 "Package declaration: package <name>"
247 %keyword PRIVATE "private"
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"
257 "Access level modifier: public {class|interface|<type>} <name> ..."
259 %keyword RETURN "return"
263 %keyword SHORT "short"
265 "Integral primitive type (-32768 to 32767)"
267 %keyword STATIC "static"
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"
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> ..."
288 %keyword THROW "throw"
292 %keyword THROWS "throws"
294 "Method|Constructor declaration: throws <classType>, ..."
296 %keyword TRANSIENT "transient"
297 %put TRANSIENT summary
298 "Field declaration modifier: transient <type> <name> ..."
302 "try {<stmts>} [catch(<parm>) {<stmts>} ...] [finally {<stmts>}]"
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"
314 "while (<expr>) <stmt> | do <stmt> while (<expr>);"
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)
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)
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.
377 : package_declaration
382 ;;; Package statement token
383 ;; ("NAME" package DETAIL "DOCSTRING")
385 : PACKAGE qualified_name SEMICOLON
389 ;;; Include file token
390 ;; ("FILE" include SYSTEM "DOCSTRING")
392 : IMPORT qualified_name SEMICOLON
394 | IMPORT qualified_name DOT MULT SEMICOLON
395 (INCLUDE-TAG (concat $2 $3 $4) nil)
402 | interface_declaration
405 ;;; Type Declaration token
406 ;; ("NAME" type "TYPE" ( PART-LIST ) ( PARENTS ) EXTRA-SPEC "DOCSTRING")
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)
414 | EXTENDS qualified_name
420 | IMPLEMENTS qualified_name_list
426 (EXPANDFULL $1 class_member_declaration)
429 class_member_declaration
438 | constructor_declaration
439 | interface_declaration
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)
452 extends_interfaces_opt
454 | EXTENDS qualified_name_list
460 (EXPANDFULL $1 interface_member_declaration)
463 interface_member_declaration
468 | interface_declaration
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)
488 constructor_declarator
489 : IDENTIFIER formal_parameter_list
498 ;; ("NAME" function "TYPE" ( ARG-LIST ) EXTRA-SPEC "DOCSTRING")
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)
507 : IDENTIFIER formal_parameter_list dims_opt
508 (cons (concat $1 $3) $2)
513 | THROWS qualified_name_list
518 : qualified_name_list COMMA qualified_name
529 ;; Just eat {...} block!
534 formal_parameter_list
536 (EXPANDFULL $1 formal_parameters)
544 | formal_parameter COMMA
545 | formal_parameter RPAREN
549 ;; ("NAME" variable "TYPE" DEFAULT-VALUE EXTRA-SPEC "DOCSTRING")
551 : formal_parameter_modifier_opt type opt_variable_declarator_id
552 (VARIABLE-TAG $3 $2 nil :typemodifiers $1)
555 formal_parameter_modifier_opt
562 ;; ("NAME" variable "TYPE" DEFAULT-VALUE EXTRA-SPEC "DOCSTRING")
564 : modifiers_opt type variable_declarators SEMICOLON
565 (VARIABLE-TAG $3 $2 nil :typemodifiers $1)
569 : variable_declarators COMMA variable_declarator
571 ;; Set the end of the compound declaration to the end of the
573 (setcdr (cdr (car $1)) (cdr $region2))
575 | variable_declarator
580 : variable_declarator_id EQ variable_initializer
582 | variable_declarator_id
586 opt_variable_declarator_id
589 | variable_declarator_id
593 variable_declarator_id
594 : IDENTIFIER dims_opt
602 ;; Just eat expression!
710 : qualified_name dims_opt
712 | primitive_type dims_opt
717 : qualified_name DOT IDENTIFIER
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
756 semantic-lex-default-action)
758 ;;; java-tags.wy ends here