blob: bc22f4f83114664510031365455f5de38aa4b754 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
|
;;; java-tags.wy -- Semantic LALR grammar for Java
;; Copyright (C) 2002-2015 Free Software Foundation, Inc.
;;
;; Author: David Ponce <david@dponce.com>
;; Maintainer: David Ponce <david@dponce.com>
;; Created: 26 Aug 2002
;; Keywords: syntax
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
%package wisent-java-tags-wy
%provide semantic/wisent/javat-wy
%{
(declare-function semantic-parse-region "semantic"
(start end &optional nonterminal depth returnonerror))
}
%languagemode java-mode
;; The default start symbol
%start compilation_unit
;; Alternate entry points
;; - Needed by partial re-parse
%start package_declaration
%start import_declaration
%start class_declaration
%start field_declaration
%start method_declaration
%start formal_parameter
%start constructor_declaration
%start interface_declaration
;; - Needed by EXPANDFULL clauses
%start class_member_declaration
%start interface_member_declaration
%start formal_parameters
;; -----------------------------
;; Block & Parenthesis terminals
;; -----------------------------
%type <block> ;;syntax "\\s(\\|\\s)" matchdatatype block
%token <block> PAREN_BLOCK "(LPAREN RPAREN)"
%token <block> BRACE_BLOCK "(LBRACE RBRACE)"
%token <block> BRACK_BLOCK "(LBRACK RBRACK)"
%token <open-paren> LPAREN "("
%token <close-paren> RPAREN ")"
%token <open-paren> LBRACE "{"
%token <close-paren> RBRACE "}"
%token <open-paren> LBRACK "["
%token <close-paren> RBRACK "]"
;; ------------------
;; Operator terminals
;; ------------------
%type <punctuation> ;;syntax "\\(\\s.\\|\\s$\\|\\s'\\)+" matchdatatype string
%token <punctuation> NOT "!"
%token <punctuation> NOTEQ "!="
%token <punctuation> MOD "%"
%token <punctuation> MODEQ "%="
%token <punctuation> AND "&"
%token <punctuation> ANDAND "&&"
%token <punctuation> ANDEQ "&="
%token <punctuation> MULT "*"
%token <punctuation> MULTEQ "*="
%token <punctuation> PLUS "+"
%token <punctuation> PLUSPLUS "++"
%token <punctuation> PLUSEQ "+="
%token <punctuation> COMMA ","
%token <punctuation> MINUS "-"
%token <punctuation> MINUSMINUS "--"
%token <punctuation> MINUSEQ "-="
%token <punctuation> DOT "."
%token <punctuation> DIV "/"
%token <punctuation> DIVEQ "/="
%token <punctuation> COLON ":"
%token <punctuation> SEMICOLON ";"
%token <punctuation> LT "<"
%token <punctuation> LSHIFT "<<"
%token <punctuation> LSHIFTEQ "<<="
%token <punctuation> LTEQ "<="
%token <punctuation> EQ "="
%token <punctuation> EQEQ "=="
%token <punctuation> GT ">"
%token <punctuation> GTEQ ">="
%token <punctuation> RSHIFT ">>"
%token <punctuation> RSHIFTEQ ">>="
%token <punctuation> URSHIFT ">>>"
%token <punctuation> URSHIFTEQ ">>>="
%token <punctuation> QUESTION "?"
%token <punctuation> XOR "^"
%token <punctuation> XOREQ "^="
%token <punctuation> OR "|"
%token <punctuation> OREQ "|="
%token <punctuation> OROR "||"
%token <punctuation> COMP "~"
;; -----------------
;; Literal terminals
;; -----------------
%type <symbol> ;;syntax "\\(\\sw\\|\\s_\\)+"
%token <symbol> IDENTIFIER
%type <string> ;;syntax "\\s\"" matchdatatype sexp
%token <string> STRING_LITERAL
%type <number> ;;syntax semantic-lex-number-expression
%token <number> NUMBER_LITERAL
%type <unicode> syntax "\\\\u[0-9a-f][0-9a-f][0-9a-f][0-9a-f]"
%token <unicode> unicodecharacter
;; -----------------
;; Keyword terminals
;; -----------------
;; Generate a keyword analyzer
%type <keyword> ;;syntax "\\(\\sw\\|\\s_\\)+" matchdatatype keyword
%keyword ABSTRACT "abstract"
%put ABSTRACT summary
"Class|Method declaration modifier: abstract {class|<type>} <name> ..."
%keyword BOOLEAN "boolean"
%put BOOLEAN summary
"Primitive logical quantity type (true or false)"
%keyword BREAK "break"
%put BREAK summary
"break [<label>] ;"
%keyword BYTE "byte"
%put BYTE summary
"Integral primitive type (-128 to 127)"
%keyword CASE "case"
%put CASE summary
"switch(<expr>) {case <const-expr>: <stmts> ... }"
%keyword CATCH "catch"
%put CATCH summary
"try {<stmts>} catch(<parm>) {<stmts>} ... "
%keyword CHAR "char"
%put CHAR summary
"Integral primitive type (0 to 65535)"
%keyword CLASS "class"
%put CLASS summary
"Class declaration: class <name>"
%keyword CONST "const"
%put CONST summary
"Unused reserved word"
%keyword CONTINUE "continue"
%put CONTINUE summary
"continue [<label>] ;"
%keyword DEFAULT "default"
%put DEFAULT summary
"switch(<expr>) { ... default: <stmts>}"
%keyword DO "do"
%put DO summary
"do <stmt> while (<expr>);"
%keyword DOUBLE "double"
%put DOUBLE summary
"Primitive floating-point type (double-precision 64-bit IEEE 754)"
%keyword ELSE "else"
%put ELSE summary
"if (<expr>) <stmt> else <stmt>"
%keyword EXTENDS "extends"
%put EXTENDS summary
"SuperClass|SuperInterfaces declaration: extends <name> [, ...]"
%keyword FINAL "final"
%put FINAL summary
"Class|Member declaration modifier: final {class|<type>} <name> ..."
%keyword FINALLY "finally"
%put FINALLY summary
"try {<stmts>} ... finally {<stmts>}"
%keyword FLOAT "float"
%put FLOAT summary
"Primitive floating-point type (single-precision 32-bit IEEE 754)"
%keyword FOR "for"
%put FOR summary
"for ([<init-expr>]; [<expr>]; [<update-expr>]) <stmt>"
%keyword GOTO "goto"
%put GOTO summary
"Unused reserved word"
%keyword IF "if"
%put IF summary
"if (<expr>) <stmt> [else <stmt>]"
%keyword IMPLEMENTS "implements"
%put IMPLEMENTS summary
"Class SuperInterfaces declaration: implements <name> [, ...]"
%keyword IMPORT "import"
%put IMPORT summary
"Import package declarations: import <package>"
%keyword INSTANCEOF "instanceof"
%keyword INT "int"
%put INT summary
"Integral primitive type (-2147483648 to 2147483647)"
%keyword INTERFACE "interface"
%put INTERFACE summary
"Interface declaration: interface <name>"
%keyword LONG "long"
%put LONG summary
"Integral primitive type (-9223372036854775808 to 9223372036854775807)"
%keyword NATIVE "native"
%put NATIVE summary
"Method declaration modifier: native <type> <name> ..."
%keyword NEW "new"
%keyword PACKAGE "package"
%put PACKAGE summary
"Package declaration: package <name>"
%keyword PRIVATE "private"
%put PRIVATE summary
"Access level modifier: private {class|interface|<type>} <name> ..."
%keyword PROTECTED "protected"
%put PROTECTED summary
"Access level modifier: protected {class|interface|<type>} <name> ..."
%keyword PUBLIC "public"
%put PUBLIC summary
"Access level modifier: public {class|interface|<type>} <name> ..."
%keyword RETURN "return"
%put RETURN summary
"return [<expr>] ;"
%keyword SHORT "short"
%put SHORT summary
"Integral primitive type (-32768 to 32767)"
%keyword STATIC "static"
%put STATIC summary
"Declaration modifier: static {class|interface|<type>} <name> ..."
%keyword STRICTFP "strictfp"
%put STRICTFP summary
"Declaration modifier: strictfp {class|interface|<type>} <name> ..."
%keyword SUPER "super"
%keyword SWITCH "switch"
%put SWITCH summary
"switch(<expr>) {[case <const-expr>: <stmts> ...] [default: <stmts>]}"
%keyword SYNCHRONIZED "synchronized"
%put SYNCHRONIZED summary
"synchronized (<expr>) ... | Method decl. modifier: synchronized <type> <name> ..."
%keyword THIS "this"
%keyword THROW "throw"
%put THROW summary
"throw <expr> ;"
%keyword THROWS "throws"
%put THROWS summary
"Method|Constructor declaration: throws <classType>, ..."
%keyword TRANSIENT "transient"
%put TRANSIENT summary
"Field declaration modifier: transient <type> <name> ..."
%keyword TRY "try"
%put TRY summary
"try {<stmts>} [catch(<parm>) {<stmts>} ...] [finally {<stmts>}]"
%keyword VOID "void"
%put VOID summary
"Method return type: void <name> ..."
%keyword VOLATILE "volatile"
%put VOLATILE summary
"Field declaration modifier: volatile <type> <name> ..."
%keyword WHILE "while"
%put WHILE summary
"while (<expr>) <stmt> | do <stmt> while (<expr>);"
;; --------------------------
;; Official javadoc line tags
;; --------------------------
;; Javadoc tags are identified by a 'javadoc' keyword property. The
;; value of this property must be itself a property list where the
;; following properties are recognized:
;;
;; - `seq' (mandatory) is the tag sequence number used to check if tags
;; are correctly ordered in a javadoc comment block.
;;
;; - `usage' (mandatory) is the list of token categories for which this
;; documentation tag is allowed.
;;
;; - `opt' (optional) if non-nil indicates this is an optional tag.
;; By default tags are mandatory.
;;
;; - `with-name' (optional) if non-nil indicates that this tag is
;; followed by an identifier like in "@param <var-name> description"
;; or "@exception <class-name> description".
;;
;; - `with-ref' (optional) if non-nil indicates that the tag is
;; followed by a reference like in "@see <reference>".
%keyword _AUTHOR "@author"
%put _AUTHOR javadoc (seq 1 usage (type))
%keyword _VERSION "@version"
%put _VERSION javadoc (seq 2 usage (type))
%keyword _PARAM "@param"
%put _PARAM javadoc (seq 3 usage (function) with-name t)
%keyword _RETURN "@return"
%put _RETURN javadoc (seq 4 usage (function))
%keyword _EXCEPTION "@exception"
%put _EXCEPTION javadoc (seq 5 usage (function) with-name t)
%keyword _THROWS "@throws"
%put _THROWS javadoc (seq 6 usage (function) with-name t)
%keyword _SEE "@see"
%put _SEE javadoc (seq 7 usage (type function variable) opt t with-ref t)
%keyword _SINCE "@since"
%put _SINCE javadoc (seq 8 usage (type function variable) opt t)
%keyword _SERIAL "@serial"
%put _SERIAL javadoc (seq 9 usage (variable) opt t)
%keyword _SERIALDATA "@serialData"
%put _SERIALDATA javadoc (seq 10 usage (function) opt t)
%keyword _SERIALFIELD "@serialField"
%put _SERIALFIELD javadoc (seq 11 usage (variable) opt t)
%keyword _DEPRECATED "@deprecated"
%put _DEPRECATED javadoc (seq 12 usage (type function variable) opt t)
%%
;; ------------
;; LALR Grammar
;; ------------
;; This grammar is not designed to fully parse correct Java syntax. It
;; is optimized to work in an interactive environment to extract tokens
;; (tags) needed by Semantic. In some cases a syntax not allowed by
;; the Java Language Specification will be accepted by this grammar.
compilation_unit
: package_declaration
| import_declaration
| type_declaration
;
;;; Package statement token
;; ("NAME" package DETAIL "DOCSTRING")
package_declaration
: PACKAGE qualified_name SEMICOLON
(PACKAGE-TAG $2 nil)
;
;;; Include file token
;; ("FILE" include SYSTEM "DOCSTRING")
import_declaration
: IMPORT qualified_name SEMICOLON
(INCLUDE-TAG $2 nil)
| IMPORT qualified_name DOT MULT SEMICOLON
(INCLUDE-TAG (concat $2 $3 $4) nil)
;
type_declaration
: SEMICOLON
()
| class_declaration
| interface_declaration
;
;;; Type Declaration token
;; ("NAME" type "TYPE" ( PART-LIST ) ( PARENTS ) EXTRA-SPEC "DOCSTRING")
class_declaration
: modifiers_opt CLASS qualified_name superc_opt interfaces_opt class_body
(TYPE-TAG $3 $2 $6 (if (or $4 $5) (cons $4 $5)) :typemodifiers $1)
;
superc_opt
: ;;EMPTY
| EXTENDS qualified_name
(identity $2)
;
interfaces_opt
: ;;EMPTY
| IMPLEMENTS qualified_name_list
(nreverse $2)
;
class_body
: BRACE_BLOCK
(EXPANDFULL $1 class_member_declaration)
;
class_member_declaration
: LBRACE
()
| RBRACE
()
| block
()
| static_initializer
()
| constructor_declaration
| interface_declaration
| class_declaration
| method_declaration
| field_declaration
;
;;; Type Declaration token
;; ("NAME" type "TYPE" ( PART-LIST ) ( PARENTS ) EXTRA-SPEC "DOCSTRING")
interface_declaration
: modifiers_opt INTERFACE qualified_name extends_interfaces_opt interface_body
(TYPE-TAG $3 $2 $5 (if $4 (cons nil $4)) :typemodifiers $1)
;
extends_interfaces_opt
: ;;EMPTY
| EXTENDS qualified_name_list
(identity $2)
;
interface_body
: BRACE_BLOCK
(EXPANDFULL $1 interface_member_declaration)
;
interface_member_declaration
: LBRACE
()
| RBRACE
()
| interface_declaration
| class_declaration
| method_declaration
| field_declaration
;
static_initializer
: STATIC block
;
;;; Function token
;; ("NAME" function "TYPE" ( ARG-LIST ) EXTRA-SPEC "DOCSTRING")
constructor_declaration
: modifiers_opt constructor_declarator throwsc_opt constructor_body
(FUNCTION-TAG (car $2) nil (cdr $2)
:typemodifiers $1
:throws $3
:constructor-flag t)
;
constructor_declarator
: IDENTIFIER formal_parameter_list
(cons $1 $2)
;
constructor_body
: block
;
;;; Function token
;; ("NAME" function "TYPE" ( ARG-LIST ) EXTRA-SPEC "DOCSTRING")
method_declaration
: modifiers_opt VOID method_declarator throwsc_opt method_body
(FUNCTION-TAG (car $3) $2 (cdr $3) :typemodifiers $1 :throws $4)
| modifiers_opt type method_declarator throwsc_opt method_body
(FUNCTION-TAG (car $3) $2 (cdr $3) :typemodifiers $1 :throws $4)
;
method_declarator
: IDENTIFIER formal_parameter_list dims_opt
(cons (concat $1 $3) $2)
;
throwsc_opt
: ;;EMPTY
| THROWS qualified_name_list
(nreverse $2)
;
qualified_name_list
: qualified_name_list COMMA qualified_name
(cons $3 $1)
| qualified_name
(list $1)
;
method_body
: SEMICOLON
| block
;
;; Just eat {...} block!
block
: BRACE_BLOCK
;
formal_parameter_list
: PAREN_BLOCK
(EXPANDFULL $1 formal_parameters)
;
formal_parameters
: LPAREN
()
| RPAREN
()
| formal_parameter COMMA
| formal_parameter RPAREN
;
;;; Variable token
;; ("NAME" variable "TYPE" DEFAULT-VALUE EXTRA-SPEC "DOCSTRING")
formal_parameter
: formal_parameter_modifier_opt type opt_variable_declarator_id
(VARIABLE-TAG $3 $2 nil :typemodifiers $1)
;
formal_parameter_modifier_opt
: ;;EMPTY
| FINAL
(list $1)
;
;;; Variable token
;; ("NAME" variable "TYPE" DEFAULT-VALUE EXTRA-SPEC "DOCSTRING")
field_declaration
: modifiers_opt type variable_declarators SEMICOLON
(VARIABLE-TAG $3 $2 nil :typemodifiers $1)
;
variable_declarators
: variable_declarators COMMA variable_declarator
(progn
;; Set the end of the compound declaration to the end of the
;; COMMA delimiter.
(setcdr (cdr (car $1)) (cdr $region2))
(cons $3 $1))
| variable_declarator
(list $1)
;
variable_declarator
: variable_declarator_id EQ variable_initializer
(cons $1 $region)
| variable_declarator_id
(cons $1 $region)
;
opt_variable_declarator_id
: ;; EMPTY
(identity "")
| variable_declarator_id
(identity $1)
;
variable_declarator_id
: IDENTIFIER dims_opt
(concat $1 $2)
;
variable_initializer
: expression
;
;; Just eat expression!
expression
: expression term
| term
;
term
: literal
| operator
| primitive_type
| IDENTIFIER
| BRACK_BLOCK
| PAREN_BLOCK
| BRACE_BLOCK
| NEW
| CLASS
| THIS
| SUPER
;
literal
;; : NULL_LITERAL
;; | BOOLEAN_LITERAL
: STRING_LITERAL
| NUMBER_LITERAL
;
operator
: NOT
| PLUS
| PLUSPLUS
| MINUS
| MINUSMINUS
| NOTEQ
| MOD
| MODEQ
| AND
| ANDAND
| ANDEQ
| MULT
| MULTEQ
| PLUSEQ
| MINUSEQ
| DOT
| DIV
| DIVEQ
| COLON
| LT
| LSHIFT
| LSHIFTEQ
| LTEQ
| EQ
| EQEQ
| GT
| GTEQ
| RSHIFT
| RSHIFTEQ
| URSHIFT
| URSHIFTEQ
| QUESTION
| XOR
| XOREQ
| OR
| OREQ
| OROR
| COMP
| INSTANCEOF
;
primitive_type
: BOOLEAN
| CHAR
| LONG
| INT
| SHORT
| BYTE
| DOUBLE
| FLOAT
;
modifiers_opt
: ;;EMPTY
| modifiers
(nreverse $1)
;
modifiers
: modifiers modifier
(cons $2 $1)
| modifier
(list $1)
;
modifier
: STRICTFP
| VOLATILE
| TRANSIENT
| SYNCHRONIZED
| NATIVE
| FINAL
| ABSTRACT
| STATIC
| PRIVATE
| PROTECTED
| PUBLIC
;
type
: qualified_name dims_opt
(concat $1 $2)
| primitive_type dims_opt
(concat $1 $2)
;
qualified_name
: qualified_name DOT IDENTIFIER
(concat $1 $2 $3)
| IDENTIFIER
;
dims_opt
: ;;EMPTY
(identity "")
| dims
;
dims
: dims BRACK_BLOCK
(concat $1 "[]")
| BRACK_BLOCK
(identity "[]")
;
%%
;; Define the lexer for this grammar
(define-lex wisent-java-tags-lexer
"Lexical analyzer that handles Java buffers.
It ignores whitespaces, newlines and comments."
semantic-lex-ignore-whitespace
semantic-lex-ignore-newline
semantic-lex-ignore-comments
;;;; Auto-generated analyzers.
wisent-java-tags-wy--<number>-regexp-analyzer
wisent-java-tags-wy--<string>-sexp-analyzer
;; Must detect keywords before other symbols
wisent-java-tags-wy--<keyword>-keyword-analyzer
wisent-java-tags-wy--<symbol>-regexp-analyzer
wisent-java-tags-wy--<punctuation>-string-analyzer
wisent-java-tags-wy--<block>-block-analyzer
;; In theory, Unicode chars should be turned into normal chars
;; and then combined into regular ascii keywords and text. This
;; analyzer just keeps these things from making the lexer go boom.
wisent-java-tags-wy--<unicode>-regexp-analyzer
;;;;
semantic-lex-default-action)
;;; java-tags.wy ends here
|