1 ;;; wisent-java-tags.wy -- Semantic LALR grammar for Java
3 ;; Copyright (C) 2002, 2007 David Ponce
4 ;; Copyright (C) 2007 Eric Ludlam
6 ;; Author: David Ponce <david@dponce.com>
7 ;; Maintainer: David Ponce <david@dponce.com>
8 ;; Created: 25 Feb 2002
10 ;; X-RCS: $Id: wisent-java-tags.wy,v 1.1 2007-11-26 15:12:32 michaels Exp $
12 ;; This file is not part of GNU Emacs.
14 ;; This program is free software; you can redistribute it and/or
15 ;; modify it under the terms of the GNU General Public License as
16 ;; published by the Free Software Foundation; either version 2, or (at
17 ;; your option) any later version.
19 ;; This software is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 ;; General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 ;; Boston, MA 02110-1301, USA.
29 ;;%package wisent-java-tags-wy
31 %languagemode java-mode
33 ;; The default start symbol
34 %start compilation_unit
35 ;; Alternate entry points
36 ;; - Needed by partial re-parse
37 %start package_declaration
38 %start import_declaration
39 %start class_declaration
40 %start field_declaration
41 %start method_declaration
42 %start formal_parameter
43 %start constructor_declaration
44 %start interface_declaration
45 ;; - Needed by EXPANDFULL clauses
46 %start class_member_declaration
47 %start interface_member_declaration
48 %start formal_parameters
50 ;; -----------------------------
51 ;; Block & Parenthesis terminals
52 ;; -----------------------------
53 %type <block> ;;syntax "\\s(\\|\\s)" matchdatatype block
55 %token <block> PAREN_BLOCK "(LPAREN RPAREN)"
56 %token <block> BRACE_BLOCK "(LBRACE RBRACE)"
57 %token <block> BRACK_BLOCK "(LBRACK RBRACK)"
59 %token <open-paren> LPAREN "("
60 %token <close-paren> RPAREN ")"
61 %token <open-paren> LBRACE "{"
62 %token <close-paren> RBRACE "}"
63 %token <open-paren> LBRACK "["
64 %token <close-paren> RBRACK "]"
69 %type <punctuation> ;;syntax "\\(\\s.\\|\\s$\\|\\s'\\)+" matchdatatype string
71 %token <punctuation> NOT "!"
72 %token <punctuation> NOTEQ "!="
73 %token <punctuation> MOD "%"
74 %token <punctuation> MODEQ "%="
75 %token <punctuation> AND "&"
76 %token <punctuation> ANDAND "&&"
77 %token <punctuation> ANDEQ "&="
78 %token <punctuation> MULT "*"
79 %token <punctuation> MULTEQ "*="
80 %token <punctuation> PLUS "+"
81 %token <punctuation> PLUSPLUS "++"
82 %token <punctuation> PLUSEQ "+="
83 %token <punctuation> COMMA ","
84 %token <punctuation> MINUS "-"
85 %token <punctuation> MINUSMINUS "--"
86 %token <punctuation> MINUSEQ "-="
87 %token <punctuation> DOT "."
88 %token <punctuation> DIV "/"
89 %token <punctuation> DIVEQ "/="
90 %token <punctuation> COLON ":"
91 %token <punctuation> SEMICOLON ";"
92 %token <punctuation> LT "<"
93 %token <punctuation> LSHIFT "<<"
94 %token <punctuation> LSHIFTEQ "<<="
95 %token <punctuation> LTEQ "<="
96 %token <punctuation> EQ "="
97 %token <punctuation> EQEQ "=="
98 %token <punctuation> GT ">"
99 %token <punctuation> GTEQ ">="
100 %token <punctuation> RSHIFT ">>"
101 %token <punctuation> RSHIFTEQ ">>="
102 %token <punctuation> URSHIFT ">>>"
103 %token <punctuation> URSHIFTEQ ">>>="
104 %token <punctuation> QUESTION "?"
105 %token <punctuation> XOR "^"
106 %token <punctuation> XOREQ "^="
107 %token <punctuation> OR "|"
108 %token <punctuation> OREQ "|="
109 %token <punctuation> OROR "||"
110 %token <punctuation> COMP "~"
115 %type <symbol> ;;syntax "\\(\\sw\\|\\s_\\)+"
116 %token <symbol> IDENTIFIER
118 %type <string> ;;syntax "\\s\"" matchdatatype sexp
119 %token <string> STRING_LITERAL
121 %type <number> ;;syntax semantic-lex-number-expression
122 %token <number> NUMBER_LITERAL
124 %type <unicode> syntax "\\\\u[0-9a-f][0-9a-f][0-9a-f][0-9a-f]"
125 %token <unicode> unicodecharacter
131 ;; Generate a keyword analyzer
132 %type <keyword> ;;syntax "\\(\\sw\\|\\s_\\)+" matchdatatype keyword
134 %keyword ABSTRACT "abstract"
135 %put ABSTRACT summary
136 "Class|Method declaration modifier: abstract {class|<type>} <name> ..."
138 %keyword BOOLEAN "boolean"
140 "Primitive logical quantity type (true or false)"
142 %keyword BREAK "break"
148 "Integral primitive type (-128 to 127)"
152 "switch(<expr>) {case <const-expr>: <stmts> ... }"
154 %keyword CATCH "catch"
156 "try {<stmts>} catch(<parm>) {<stmts>} ... "
160 "Integral primitive type ('\u0000' to '\uffff') (0 to 65535)"
162 %keyword CLASS "class"
164 "Class declaration: class <name>"
166 %keyword CONST "const"
168 "Unused reserved word"
170 %keyword CONTINUE "continue"
171 %put CONTINUE summary
172 "continue [<label>] ;"
174 %keyword DEFAULT "default"
176 "switch(<expr>) { ... default: <stmts>}"
180 "do <stmt> while (<expr>);"
182 %keyword DOUBLE "double"
184 "Primitive floating-point type (double-precision 64-bit IEEE 754)"
188 "if (<expr>) <stmt> else <stmt>"
190 %keyword EXTENDS "extends"
192 "SuperClass|SuperInterfaces declaration: extends <name> [, ...]"
194 %keyword FINAL "final"
196 "Class|Member declaration modifier: final {class|<type>} <name> ..."
198 %keyword FINALLY "finally"
200 "try {<stmts>} ... finally {<stmts>}"
202 %keyword FLOAT "float"
204 "Primitive floating-point type (single-precision 32-bit IEEE 754)"
208 "for ([<init-expr>]; [<expr>]; [<update-expr>]) <stmt>"
212 "Unused reserved word"
216 "if (<expr>) <stmt> [else <stmt>]"
218 %keyword IMPLEMENTS "implements"
219 %put IMPLEMENTS summary
220 "Class SuperInterfaces declaration: implements <name> [, ...]"
222 %keyword IMPORT "import"
224 "Import package declarations: import <package>"
226 %keyword INSTANCEOF "instanceof"
230 "Integral primitive type (-2147483648 to 2147483647)"
232 %keyword INTERFACE "interface"
233 %put INTERFACE summary
234 "Interface declaration: interface <name>"
238 "Integral primitive type (-9223372036854775808 to 9223372036854775807)"
240 %keyword NATIVE "native"
242 "Method declaration modifier: native <type> <name> ..."
246 %keyword PACKAGE "package"
248 "Package declaration: package <name>"
250 %keyword PRIVATE "private"
252 "Access level modifier: private {class|interface|<type>} <name> ..."
254 %keyword PROTECTED "protected"
255 %put PROTECTED summary
256 "Access level modifier: protected {class|interface|<type>} <name> ..."
258 %keyword PUBLIC "public"
260 "Access level modifier: public {class|interface|<type>} <name> ..."
262 %keyword RETURN "return"
266 %keyword SHORT "short"
268 "Integral primitive type (-32768 to 32767)"
270 %keyword STATIC "static"
272 "Declaration modifier: static {class|interface|<type>} <name> ..."
274 %keyword STRICTFP "strictfp"
275 %put STRICTFP summary
276 "Declaration modifier: strictfp {class|interface|<type>} <name> ..."
278 %keyword SUPER "super"
280 %keyword SWITCH "switch"
282 "switch(<expr>) {[case <const-expr>: <stmts> ...] [default: <stmts>]}"
285 %keyword SYNCHRONIZED "synchronized"
286 %put SYNCHRONIZED summary
287 "synchronized (<expr>) ... | Method decl. modifier: synchronized <type> <name> ..."
291 %keyword THROW "throw"
295 %keyword THROWS "throws"
297 "Method|Constructor declaration: throws <classType>, ..."
299 %keyword TRANSIENT "transient"
300 %put TRANSIENT summary
301 "Field declaration modifier: transient <type> <name> ..."
305 "try {<stmts>} [catch(<parm>) {<stmts>} ...] [finally {<stmts>}]"
309 "Method return type: void <name> ..."
311 %keyword VOLATILE "volatile"
312 %put VOLATILE summary
313 "Field declaration modifier: volatile <type> <name> ..."
315 %keyword WHILE "while"
317 "while (<expr>) <stmt> | do <stmt> while (<expr>);"
319 ;; --------------------------
320 ;; Official javadoc line tags
321 ;; --------------------------
323 ;; Javadoc tags are identified by a 'javadoc' keyword property. The
324 ;; value of this property must be itself a property list where the
325 ;; following properties are recognized:
327 ;; - `seq' (mandatory) is the tag sequence number used to check if tags
328 ;; are correctly ordered in a javadoc comment block.
330 ;; - `usage' (mandatory) is the list of token categories for which this
331 ;; documentation tag is allowed.
333 ;; - `opt' (optional) if non-nil indicates this is an optional tag.
334 ;; By default tags are mandatory.
336 ;; - `with-name' (optional) if non-nil indicates that this tag is
337 ;; followed by an identifier like in "@param <var-name> description"
338 ;; or "@exception <class-name> description".
340 ;; - `with-ref' (optional) if non-nil indicates that the tag is
341 ;; followed by a reference like in "@see <reference>".
343 %keyword _AUTHOR "@author"
344 %put _AUTHOR javadoc (seq 1 usage (type))
345 %keyword _VERSION "@version"
346 %put _VERSION javadoc (seq 2 usage (type))
347 %keyword _PARAM "@param"
348 %put _PARAM javadoc (seq 3 usage (function) with-name t)
349 %keyword _RETURN "@return"
350 %put _RETURN javadoc (seq 4 usage (function))
351 %keyword _EXCEPTION "@exception"
352 %put _EXCEPTION javadoc (seq 5 usage (function) with-name t)
353 %keyword _THROWS "@throws"
354 %put _THROWS javadoc (seq 6 usage (function) with-name t)
356 %put _SEE javadoc (seq 7 usage (type function variable) opt t with-ref t)
357 %keyword _SINCE "@since"
358 %put _SINCE javadoc (seq 8 usage (type function variable) opt t)
359 %keyword _SERIAL "@serial"
360 %put _SERIAL javadoc (seq 9 usage (variable) opt t)
361 %keyword _SERIALDATA "@serialData"
362 %put _SERIALDATA javadoc (seq 10 usage (function) opt t)
363 %keyword _SERIALFIELD "@serialField"
364 %put _SERIALFIELD javadoc (seq 11 usage (variable) opt t)
365 %keyword _DEPRECATED "@deprecated"
366 %put _DEPRECATED javadoc (seq 12 usage (type function variable) opt t)
374 ;; This grammar is not designed to fully parse correct Java syntax. It
375 ;; is optimized to work in an interactive environment to extract tokens
376 ;; (tags) needed by Semantic. In some cases a syntax not allowed by
377 ;; the Java Language Specification will be accepted by this grammar.
380 : package_declaration
385 ;;; Package statement token
386 ;; ("NAME" package DETAIL "DOCSTRING")
388 : PACKAGE qualified_name SEMICOLON
392 ;;; Include file token
393 ;; ("FILE" include SYSTEM "DOCSTRING")
395 : IMPORT qualified_name SEMICOLON
397 | IMPORT qualified_name DOT MULT SEMICOLON
398 (INCLUDE-TAG (concat $2 $3 $4) nil)
405 | interface_declaration
408 ;;; Type Declaration token
409 ;; ("NAME" type "TYPE" ( PART-LIST ) ( PARENTS ) EXTRA-SPEC "DOCSTRING")
411 : modifiers_opt CLASS qualified_name superc_opt interfaces_opt class_body
412 (TYPE-TAG $3 $2 $6 (if (or $4 $5) (cons $4 $5)) :typemodifiers $1)
417 | EXTENDS qualified_name
423 | IMPLEMENTS qualified_name_list
429 (EXPANDFULL $1 class_member_declaration)
432 class_member_declaration
441 | constructor_declaration
442 | interface_declaration
448 ;;; Type Declaration token
449 ;; ("NAME" type "TYPE" ( PART-LIST ) ( PARENTS ) EXTRA-SPEC "DOCSTRING")
450 interface_declaration
451 : modifiers_opt INTERFACE IDENTIFIER extends_interfaces_opt interface_body
452 (TYPE-TAG $3 $2 $5 (if $4 (cons nil $4)) :typemodifiers $1)
455 extends_interfaces_opt
457 | EXTENDS qualified_name_list
463 (EXPANDFULL $1 interface_member_declaration)
466 interface_member_declaration
471 | interface_declaration
482 ;; ("NAME" function "TYPE" ( ARG-LIST ) EXTRA-SPEC "DOCSTRING")
483 constructor_declaration
484 : modifiers_opt constructor_declarator throwsc_opt constructor_body
485 (FUNCTION-TAG (car $2) nil (cdr $2)
491 constructor_declarator
492 : IDENTIFIER formal_parameter_list
501 ;; ("NAME" function "TYPE" ( ARG-LIST ) EXTRA-SPEC "DOCSTRING")
503 : modifiers_opt VOID method_declarator throwsc_opt method_body
504 (FUNCTION-TAG (car $3) $2 (cdr $3) :typemodifiers $1 :throws $4)
505 | modifiers_opt type method_declarator throwsc_opt method_body
506 (FUNCTION-TAG (car $3) $2 (cdr $3) :typemodifiers $1 :throws $4)
510 : IDENTIFIER formal_parameter_list dims_opt
511 (cons (concat $1 $3) $2)
516 | THROWS qualified_name_list
521 : qualified_name_list COMMA qualified_name
532 ;; Just eat {...} block!
537 formal_parameter_list
539 (EXPANDFULL $1 formal_parameters)
547 | formal_parameter COMMA
548 | formal_parameter RPAREN
552 ;; ("NAME" variable "TYPE" DEFAULT-VALUE EXTRA-SPEC "DOCSTRING")
554 : formal_parameter_modifier_opt type variable_declarator_id
555 (VARIABLE-TAG $3 $2 nil :typemodifiers $1)
558 formal_parameter_modifier_opt
565 ;; ("NAME" variable "TYPE" DEFAULT-VALUE EXTRA-SPEC "DOCSTRING")
567 : modifiers_opt type variable_declarators SEMICOLON
568 (VARIABLE-TAG $3 $2 nil :typemodifiers $1)
572 : variable_declarators COMMA variable_declarator
574 ;; Set the end of the compound declaration to the end of the
576 (setcdr (cdr (car $1)) (cdr $region2))
578 | variable_declarator
583 : variable_declarator_id EQ variable_initializer
585 | variable_declarator_id
589 variable_declarator_id
590 : IDENTIFIER dims_opt
598 ;; Just eat expression!
706 : qualified_name dims_opt
708 | primitive_type dims_opt
713 : qualified_name DOT IDENTIFIER
732 ;; Define the lexer for this grammar
733 (define-lex wisent-java-tags-lexer
734 "Lexical analyzer that handles Java buffers.
735 It ignores whitespaces, newlines and comments."
736 semantic-lex-ignore-whitespace
737 semantic-lex-ignore-newline
738 semantic-lex-ignore-comments
739 ;;;; Auto-generated analyzers.
740 wisent-java-tags-wy--<number>-regexp-analyzer
741 wisent-java-tags-wy--<string>-sexp-analyzer
742 ;; Must detect keywords before other symbols
743 wisent-java-tags-wy--<keyword>-keyword-analyzer
744 wisent-java-tags-wy--<symbol>-regexp-analyzer
745 wisent-java-tags-wy--<punctuation>-string-analyzer
746 wisent-java-tags-wy--<block>-block-analyzer
747 ;; In theory, unicode chars should be turned into normal chars
748 ;; and then combined into regular ascii keywords and text. This
749 ;; analyzer just keeps these things from making the lexer go boom.
750 wisent-java-tags-wy--<unicode>-regexp-analyzer
752 semantic-lex-default-action)
754 ;;; wisent-java-tags.wy ends here