1 ;;; java-tags.wy -- Semantic LALR grammar for Java
3 ;; Copyright (C) 2002-2016 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
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 "]"
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 "~"
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
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"
142 "Primitive logical quantity type (true or false)"
144 %keyword BREAK "break"
150 "Integral primitive type (-128 to 127)"
154 "switch(<expr>) {case <const-expr>: <stmts> ... }"
156 %keyword CATCH "catch"
158 "try {<stmts>} catch(<parm>) {<stmts>} ... "
162 "Integral primitive type (0 to 65535)"
164 %keyword CLASS "class"
166 "Class declaration: class <name>"
168 %keyword CONST "const"
170 "Unused reserved word"
172 %keyword CONTINUE "continue"
173 %put CONTINUE summary
174 "continue [<label>] ;"
176 %keyword DEFAULT "default"
178 "switch(<expr>) { ... default: <stmts>}"
182 "do <stmt> while (<expr>);"
184 %keyword DOUBLE "double"
186 "Primitive floating-point type (double-precision 64-bit IEEE 754)"
190 "if (<expr>) <stmt> else <stmt>"
192 %keyword EXTENDS "extends"
194 "SuperClass|SuperInterfaces declaration: extends <name> [, ...]"
196 %keyword FINAL "final"
198 "Class|Member declaration modifier: final {class|<type>} <name> ..."
200 %keyword FINALLY "finally"
202 "try {<stmts>} ... finally {<stmts>}"
204 %keyword FLOAT "float"
206 "Primitive floating-point type (single-precision 32-bit IEEE 754)"
210 "for ([<init-expr>]; [<expr>]; [<update-expr>]) <stmt>"
214 "Unused reserved word"
218 "if (<expr>) <stmt> [else <stmt>]"
220 %keyword IMPLEMENTS "implements"
221 %put IMPLEMENTS summary
222 "Class SuperInterfaces declaration: implements <name> [, ...]"
224 %keyword IMPORT "import"
226 "Import package declarations: import <package>"
228 %keyword INSTANCEOF "instanceof"
232 "Integral primitive type (-2147483648 to 2147483647)"
234 %keyword INTERFACE "interface"
235 %put INTERFACE summary
236 "Interface declaration: interface <name>"
240 "Integral primitive type (-9223372036854775808 to 9223372036854775807)"
242 %keyword NATIVE "native"
244 "Method declaration modifier: native <type> <name> ..."
248 %keyword PACKAGE "package"
250 "Package declaration: package <name>"
252 %keyword PRIVATE "private"
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"
262 "Access level modifier: public {class|interface|<type>} <name> ..."
264 %keyword RETURN "return"
268 %keyword SHORT "short"
270 "Integral primitive type (-32768 to 32767)"
272 %keyword STATIC "static"
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"
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> ..."
293 %keyword THROW "throw"
297 %keyword THROWS "throws"
299 "Method|Constructor declaration: throws <classType>, ..."
301 %keyword TRANSIENT "transient"
302 %put TRANSIENT summary
303 "Field declaration modifier: transient <type> <name> ..."
307 "try {<stmts>} [catch(<parm>) {<stmts>} ...] [finally {<stmts>}]"
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"
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)
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)
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.
382 : package_declaration
387 ;;; Package statement token
388 ;; ("NAME" package DETAIL "DOCSTRING")
390 : PACKAGE qualified_name SEMICOLON
394 ;;; Include file token
395 ;; ("FILE" include SYSTEM "DOCSTRING")
397 : IMPORT qualified_name SEMICOLON
399 | IMPORT qualified_name DOT MULT SEMICOLON
400 (INCLUDE-TAG (concat $2 $3 $4) nil)
407 | interface_declaration
410 ;;; Type Declaration token
411 ;; ("NAME" type "TYPE" ( PART-LIST ) ( PARENTS ) EXTRA-SPEC "DOCSTRING")
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)
419 | EXTENDS qualified_name
425 | IMPLEMENTS qualified_name_list
431 (EXPANDFULL $1 class_member_declaration)
434 class_member_declaration
443 | constructor_declaration
444 | interface_declaration
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)
457 extends_interfaces_opt
459 | EXTENDS qualified_name_list
465 (EXPANDFULL $1 interface_member_declaration)
468 interface_member_declaration
473 | interface_declaration
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)
493 constructor_declarator
494 : IDENTIFIER formal_parameter_list
503 ;; ("NAME" function "TYPE" ( ARG-LIST ) EXTRA-SPEC "DOCSTRING")
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)
512 : IDENTIFIER formal_parameter_list dims_opt
513 (cons (concat $1 $3) $2)
518 | THROWS qualified_name_list
523 : qualified_name_list COMMA qualified_name
534 ;; Just eat {...} block!
539 formal_parameter_list
541 (EXPANDFULL $1 formal_parameters)
549 | formal_parameter COMMA
550 | formal_parameter RPAREN
554 ;; ("NAME" variable "TYPE" DEFAULT-VALUE EXTRA-SPEC "DOCSTRING")
556 : formal_parameter_modifier_opt type opt_variable_declarator_id
557 (VARIABLE-TAG $3 $2 nil :typemodifiers $1)
560 formal_parameter_modifier_opt
567 ;; ("NAME" variable "TYPE" DEFAULT-VALUE EXTRA-SPEC "DOCSTRING")
569 : modifiers_opt type variable_declarators SEMICOLON
570 (VARIABLE-TAG $3 $2 nil :typemodifiers $1)
574 : variable_declarators COMMA variable_declarator
576 ;; Set the end of the compound declaration to the end of the
578 (setcdr (cdr (car $1)) (cdr $region2))
580 | variable_declarator
585 : variable_declarator_id EQ variable_initializer
587 | variable_declarator_id
591 opt_variable_declarator_id
594 | variable_declarator_id
598 variable_declarator_id
599 : IDENTIFIER dims_opt
607 ;; Just eat expression!
715 : qualified_name dims_opt
717 | primitive_type dims_opt
722 : qualified_name DOT IDENTIFIER
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
761 semantic-lex-default-action)
763 ;;; java-tags.wy ends here