declare smobs in alloc.c
[bpt/emacs.git] / admin / grammars / java-tags.wy
CommitLineData
62f43d66
CY
1;;; java-tags.wy -- Semantic LALR grammar for Java
2
ba318903 3;; Copyright (C) 2002-2014 Free Software Foundation, Inc.
469d2149
CY
4;;
5;; Author: David Ponce <david@dponce.com>
6;; Maintainer: David Ponce <david@dponce.com>
62f43d66 7;; Created: 26 Aug 2002
469d2149 8;; Keywords: syntax
62f43d66
CY
9
10;; This file is part of GNU Emacs.
11
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.
16
17;; GNU Emacs is distributed in the hope that it will be useful,
469d2149 18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
62f43d66
CY
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;; GNU General Public License for more details.
21
469d2149 22;; You should have received a copy of the GNU General Public License
62f43d66 23;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
469d2149 24
f79fbbc7 25%package wisent-java-tags-wy
62a81506 26%provide semantic/wisent/javat-wy
469d2149 27
f9b697dd
GM
28%{
29(declare-function semantic-parse-region "semantic"
30 (start end &optional nonterminal depth returnonerror))
31}
32
469d2149
CY
33%languagemode java-mode
34
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
51
52;; -----------------------------
53;; Block & Parenthesis terminals
54;; -----------------------------
55%type <block> ;;syntax "\\s(\\|\\s)" matchdatatype block
56
57%token <block> PAREN_BLOCK "(LPAREN RPAREN)"
58%token <block> BRACE_BLOCK "(LBRACE RBRACE)"
59%token <block> BRACK_BLOCK "(LBRACK RBRACK)"
60
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 "]"
67
68;; ------------------
69;; Operator terminals
70;; ------------------
71%type <punctuation> ;;syntax "\\(\\s.\\|\\s$\\|\\s'\\)+" matchdatatype string
72
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 "~"
113
114;; -----------------
115;; Literal terminals
116;; -----------------
117%type <symbol> ;;syntax "\\(\\sw\\|\\s_\\)+"
118%token <symbol> IDENTIFIER
119
120%type <string> ;;syntax "\\s\"" matchdatatype sexp
121%token <string> STRING_LITERAL
122
123%type <number> ;;syntax semantic-lex-number-expression
124%token <number> NUMBER_LITERAL
125
126%type <unicode> syntax "\\\\u[0-9a-f][0-9a-f][0-9a-f][0-9a-f]"
127%token <unicode> unicodecharacter
128
129;; -----------------
130;; Keyword terminals
131;; -----------------
132
133;; Generate a keyword analyzer
134%type <keyword> ;;syntax "\\(\\sw\\|\\s_\\)+" matchdatatype keyword
135
136%keyword ABSTRACT "abstract"
137%put ABSTRACT summary
138"Class|Method declaration modifier: abstract {class|<type>} <name> ..."
139
140%keyword BOOLEAN "boolean"
141%put BOOLEAN summary
142"Primitive logical quantity type (true or false)"
143
144%keyword BREAK "break"
145%put BREAK summary
146"break [<label>] ;"
147
148%keyword BYTE "byte"
149%put BYTE summary
150"Integral primitive type (-128 to 127)"
151
152%keyword CASE "case"
153%put CASE summary
154"switch(<expr>) {case <const-expr>: <stmts> ... }"
155
156%keyword CATCH "catch"
157%put CATCH summary
158"try {<stmts>} catch(<parm>) {<stmts>} ... "
159
160%keyword CHAR "char"
161%put CHAR summary
f5572543 162"Integral primitive type (0 to 65535)"
469d2149
CY
163
164%keyword CLASS "class"
165%put CLASS summary
166"Class declaration: class <name>"
167
168%keyword CONST "const"
169%put CONST summary
170"Unused reserved word"
171
172%keyword CONTINUE "continue"
173%put CONTINUE summary
174"continue [<label>] ;"
175
176%keyword DEFAULT "default"
177%put DEFAULT summary
178"switch(<expr>) { ... default: <stmts>}"
179
180%keyword DO "do"
181%put DO summary
182"do <stmt> while (<expr>);"
183
184%keyword DOUBLE "double"
185%put DOUBLE summary
186"Primitive floating-point type (double-precision 64-bit IEEE 754)"
187
188%keyword ELSE "else"
189%put ELSE summary
190"if (<expr>) <stmt> else <stmt>"
191
192%keyword EXTENDS "extends"
193%put EXTENDS summary
194"SuperClass|SuperInterfaces declaration: extends <name> [, ...]"
195
196%keyword FINAL "final"
197%put FINAL summary
198"Class|Member declaration modifier: final {class|<type>} <name> ..."
199
200%keyword FINALLY "finally"
201%put FINALLY summary
202"try {<stmts>} ... finally {<stmts>}"
203
204%keyword FLOAT "float"
205%put FLOAT summary
206"Primitive floating-point type (single-precision 32-bit IEEE 754)"
207
208%keyword FOR "for"
209%put FOR summary
210"for ([<init-expr>]; [<expr>]; [<update-expr>]) <stmt>"
211
212%keyword GOTO "goto"
213%put GOTO summary
214"Unused reserved word"
215
216%keyword IF "if"
217%put IF summary
218"if (<expr>) <stmt> [else <stmt>]"
219
220%keyword IMPLEMENTS "implements"
221%put IMPLEMENTS summary
222"Class SuperInterfaces declaration: implements <name> [, ...]"
223
224%keyword IMPORT "import"
225%put IMPORT summary
226"Import package declarations: import <package>"
227
228%keyword INSTANCEOF "instanceof"
229
230%keyword INT "int"
231%put INT summary
232"Integral primitive type (-2147483648 to 2147483647)"
233
234%keyword INTERFACE "interface"
235%put INTERFACE summary
236"Interface declaration: interface <name>"
237
238%keyword LONG "long"
239%put LONG summary
240"Integral primitive type (-9223372036854775808 to 9223372036854775807)"
241
242%keyword NATIVE "native"
243%put NATIVE summary
244"Method declaration modifier: native <type> <name> ..."
245
246%keyword NEW "new"
247
248%keyword PACKAGE "package"
249%put PACKAGE summary
250"Package declaration: package <name>"
251
252%keyword PRIVATE "private"
253%put PRIVATE summary
254"Access level modifier: private {class|interface|<type>} <name> ..."
255
256%keyword PROTECTED "protected"
257%put PROTECTED summary
258"Access level modifier: protected {class|interface|<type>} <name> ..."
259
260%keyword PUBLIC "public"
261%put PUBLIC summary
262"Access level modifier: public {class|interface|<type>} <name> ..."
263
264%keyword RETURN "return"
265%put RETURN summary
266"return [<expr>] ;"
267
268%keyword SHORT "short"
269%put SHORT summary
270"Integral primitive type (-32768 to 32767)"
271
272%keyword STATIC "static"
273%put STATIC summary
274"Declaration modifier: static {class|interface|<type>} <name> ..."
275
276%keyword STRICTFP "strictfp"
277%put STRICTFP summary
278"Declaration modifier: strictfp {class|interface|<type>} <name> ..."
279
280%keyword SUPER "super"
281
282%keyword SWITCH "switch"
283%put SWITCH summary
284"switch(<expr>) {[case <const-expr>: <stmts> ...] [default: <stmts>]}"
285
286
287%keyword SYNCHRONIZED "synchronized"
288%put SYNCHRONIZED summary
289"synchronized (<expr>) ... | Method decl. modifier: synchronized <type> <name> ..."
290
291%keyword THIS "this"
292
293%keyword THROW "throw"
294%put THROW summary
295"throw <expr> ;"
296
297%keyword THROWS "throws"
298%put THROWS summary
299"Method|Constructor declaration: throws <classType>, ..."
300
301%keyword TRANSIENT "transient"
302%put TRANSIENT summary
303"Field declaration modifier: transient <type> <name> ..."
304
305%keyword TRY "try"
306%put TRY summary
307"try {<stmts>} [catch(<parm>) {<stmts>} ...] [finally {<stmts>}]"
308
309%keyword VOID "void"
310%put VOID summary
311"Method return type: void <name> ..."
312
313%keyword VOLATILE "volatile"
314%put VOLATILE summary
315"Field declaration modifier: volatile <type> <name> ..."
316
317%keyword WHILE "while"
318%put WHILE summary
319"while (<expr>) <stmt> | do <stmt> while (<expr>);"
f5572543 320
469d2149
CY
321;; --------------------------
322;; Official javadoc line tags
323;; --------------------------
324
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:
328;;
329;; - `seq' (mandatory) is the tag sequence number used to check if tags
330;; are correctly ordered in a javadoc comment block.
331;;
332;; - `usage' (mandatory) is the list of token categories for which this
333;; documentation tag is allowed.
334;;
335;; - `opt' (optional) if non-nil indicates this is an optional tag.
336;; By default tags are mandatory.
337;;
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".
341;;
342;; - `with-ref' (optional) if non-nil indicates that the tag is
343;; followed by a reference like in "@see <reference>".
344
345%keyword _AUTHOR "@author"
346%put _AUTHOR javadoc (seq 1 usage (type))
347%keyword _VERSION "@version"
f5572543 348%put _VERSION javadoc (seq 2 usage (type))
469d2149 349%keyword _PARAM "@param"
f5572543 350%put _PARAM javadoc (seq 3 usage (function) with-name t)
469d2149 351%keyword _RETURN "@return"
f5572543 352%put _RETURN javadoc (seq 4 usage (function))
469d2149 353%keyword _EXCEPTION "@exception"
f5572543 354%put _EXCEPTION javadoc (seq 5 usage (function) with-name t)
469d2149 355%keyword _THROWS "@throws"
f5572543 356%put _THROWS javadoc (seq 6 usage (function) with-name t)
469d2149 357%keyword _SEE "@see"
f5572543 358%put _SEE javadoc (seq 7 usage (type function variable) opt t with-ref t)
469d2149 359%keyword _SINCE "@since"
f5572543 360%put _SINCE javadoc (seq 8 usage (type function variable) opt t)
469d2149 361%keyword _SERIAL "@serial"
f5572543 362%put _SERIAL javadoc (seq 9 usage (variable) opt t)
469d2149 363%keyword _SERIALDATA "@serialData"
f5572543 364%put _SERIALDATA javadoc (seq 10 usage (function) opt t)
469d2149 365%keyword _SERIALFIELD "@serialField"
f5572543 366%put _SERIALFIELD javadoc (seq 11 usage (variable) opt t)
469d2149 367%keyword _DEPRECATED "@deprecated"
f5572543 368%put _DEPRECATED javadoc (seq 12 usage (type function variable) opt t)
469d2149
CY
369
370%%
371
372;; ------------
373;; LALR Grammar
374;; ------------
375
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.
380
381compilation_unit
382 : package_declaration
383 | import_declaration
384 | type_declaration
385 ;
386
387;;; Package statement token
388;; ("NAME" package DETAIL "DOCSTRING")
389package_declaration
390 : PACKAGE qualified_name SEMICOLON
391 (PACKAGE-TAG $2 nil)
392 ;
393
394;;; Include file token
f5572543 395;; ("FILE" include SYSTEM "DOCSTRING")
469d2149
CY
396import_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 ;
402
403type_declaration
404 : SEMICOLON
405 ()
406 | class_declaration
407 | interface_declaration
408 ;
409
410;;; Type Declaration token
411;; ("NAME" type "TYPE" ( PART-LIST ) ( PARENTS ) EXTRA-SPEC "DOCSTRING")
412class_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 ;
416
417superc_opt
418 : ;;EMPTY
419 | EXTENDS qualified_name
420 (identity $2)
421 ;
422
423interfaces_opt
424 : ;;EMPTY
425 | IMPLEMENTS qualified_name_list
426 (nreverse $2)
427 ;
428
429class_body
430 : BRACE_BLOCK
431 (EXPANDFULL $1 class_member_declaration)
432 ;
433
434class_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 ;
449
450;;; Type Declaration token
451;; ("NAME" type "TYPE" ( PART-LIST ) ( PARENTS ) EXTRA-SPEC "DOCSTRING")
452interface_declaration
62a81506 453 : modifiers_opt INTERFACE qualified_name extends_interfaces_opt interface_body
469d2149
CY
454 (TYPE-TAG $3 $2 $5 (if $4 (cons nil $4)) :typemodifiers $1)
455 ;
456
457extends_interfaces_opt
458 : ;;EMPTY
459 | EXTENDS qualified_name_list
460 (identity $2)
461 ;
462
463interface_body
464 : BRACE_BLOCK
465 (EXPANDFULL $1 interface_member_declaration)
466 ;
467
468interface_member_declaration
469 : LBRACE
470 ()
471 | RBRACE
472 ()
473 | interface_declaration
474 | class_declaration
475 | method_declaration
476 | field_declaration
477 ;
478
479static_initializer
480 : STATIC block
481 ;
482
483;;; Function token
f5572543 484;; ("NAME" function "TYPE" ( ARG-LIST ) EXTRA-SPEC "DOCSTRING")
469d2149
CY
485constructor_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 ;
492
493constructor_declarator
494 : IDENTIFIER formal_parameter_list
495 (cons $1 $2)
496 ;
497
498constructor_body
f5572543 499 : block
469d2149
CY
500 ;
501
502;;; Function token
f5572543 503;; ("NAME" function "TYPE" ( ARG-LIST ) EXTRA-SPEC "DOCSTRING")
469d2149
CY
504method_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 ;
510
511method_declarator
512 : IDENTIFIER formal_parameter_list dims_opt
513 (cons (concat $1 $3) $2)
514 ;
515
516throwsc_opt
517 : ;;EMPTY
518 | THROWS qualified_name_list
519 (nreverse $2)
520 ;
521
522qualified_name_list
523 : qualified_name_list COMMA qualified_name
524 (cons $3 $1)
525 | qualified_name
526 (list $1)
527 ;
528
529method_body
530 : SEMICOLON
531 | block
532 ;
533
534;; Just eat {...} block!
535block
536 : BRACE_BLOCK
537 ;
538
539formal_parameter_list
540 : PAREN_BLOCK
541 (EXPANDFULL $1 formal_parameters)
542 ;
543
544formal_parameters
545 : LPAREN
546 ()
547 | RPAREN
548 ()
549 | formal_parameter COMMA
550 | formal_parameter RPAREN
551 ;
552
553;;; Variable token
554;; ("NAME" variable "TYPE" DEFAULT-VALUE EXTRA-SPEC "DOCSTRING")
555formal_parameter
62a81506 556 : formal_parameter_modifier_opt type opt_variable_declarator_id
469d2149
CY
557 (VARIABLE-TAG $3 $2 nil :typemodifiers $1)
558 ;
559
560formal_parameter_modifier_opt
561 : ;;EMPTY
562 | FINAL
563 (list $1)
564 ;
565
566;;; Variable token
567;; ("NAME" variable "TYPE" DEFAULT-VALUE EXTRA-SPEC "DOCSTRING")
568field_declaration
569 : modifiers_opt type variable_declarators SEMICOLON
570 (VARIABLE-TAG $3 $2 nil :typemodifiers $1)
571 ;
572
573variable_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 ;
583
584variable_declarator
585 : variable_declarator_id EQ variable_initializer
586 (cons $1 $region)
587 | variable_declarator_id
588 (cons $1 $region)
589 ;
590
62a81506
CY
591opt_variable_declarator_id
592 : ;; EMPTY
593 (identity "")
594 | variable_declarator_id
595 (identity $1)
596 ;
597
469d2149
CY
598variable_declarator_id
599 : IDENTIFIER dims_opt
600 (concat $1 $2)
601 ;
602
603variable_initializer
604 : expression
605 ;
606
607;; Just eat expression!
608expression
609 : expression term
610 | term
611 ;
612
613term
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 ;
626
627literal
628;; : NULL_LITERAL
629;; | BOOLEAN_LITERAL
630 : STRING_LITERAL
631 | NUMBER_LITERAL
632 ;
633
634operator
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 ;
675
676primitive_type
677 : BOOLEAN
678 | CHAR
679 | LONG
680 | INT
681 | SHORT
682 | BYTE
683 | DOUBLE
684 | FLOAT
685 ;
686
687modifiers_opt
688 : ;;EMPTY
689 | modifiers
690 (nreverse $1)
691 ;
692
693modifiers
694 : modifiers modifier
695 (cons $2 $1)
696 | modifier
697 (list $1)
698 ;
699
700modifier
701 : STRICTFP
702 | VOLATILE
703 | TRANSIENT
704 | SYNCHRONIZED
705 | NATIVE
706 | FINAL
707 | ABSTRACT
708 | STATIC
709 | PRIVATE
710 | PROTECTED
711 | PUBLIC
712 ;
713
714type
715 : qualified_name dims_opt
716 (concat $1 $2)
717 | primitive_type dims_opt
718 (concat $1 $2)
719 ;
720
721qualified_name
722 : qualified_name DOT IDENTIFIER
723 (concat $1 $2 $3)
724 | IDENTIFIER
725 ;
726
727dims_opt
728 : ;;EMPTY
729 (identity "")
730 | dims
731 ;
732
733dims
734 : dims BRACK_BLOCK
735 (concat $1 "[]")
736 | BRACK_BLOCK
737 (identity "[]")
738 ;
739
740%%
741;; Define the lexer for this grammar
742(define-lex wisent-java-tags-lexer
743 "Lexical analyzer that handles Java buffers.
744It ignores whitespaces, newlines and comments."
745 semantic-lex-ignore-whitespace
746 semantic-lex-ignore-newline
747 semantic-lex-ignore-comments
748 ;;;; Auto-generated analyzers.
f79fbbc7
CY
749 wisent-java-tags-wy--<number>-regexp-analyzer
750 wisent-java-tags-wy--<string>-sexp-analyzer
469d2149 751 ;; Must detect keywords before other symbols
f79fbbc7
CY
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
fe7a3057 756 ;; In theory, Unicode chars should be turned into normal chars
469d2149
CY
757 ;; and then combined into regular ascii keywords and text. This
758 ;; analyzer just keeps these things from making the lexer go boom.
f79fbbc7 759 wisent-java-tags-wy--<unicode>-regexp-analyzer
469d2149
CY
760 ;;;;
761 semantic-lex-default-action)
762
62f43d66 763;;; java-tags.wy ends here