forked from GoogleCloudPlatform/cloud-debug-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava_expression.g
More file actions
791 lines (689 loc) · 19.3 KB
/
java_expression.g
File metadata and controls
791 lines (689 loc) · 19.3 KB
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
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
//
// Copyright 2015 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ANTLR2 grammar for Java Cloud Debugger expression compiler.
// This grammar was inspired by this ANTLR3 grammar:
// third_party/antlr3/java_grammar/Java.g
header "post_include_hpp" {
#include "common.h"
#include "java_expression.h"
#include "messages.h"
#include "model.h"
}
options {
language="Cpp";
namespace="devtools::cdbg";
}
//
// LEXER
//
class JavaExpressionLexer extends Lexer;
options {
k = 3; // Set lookahead.
charVocabulary = '\3'..'\377';
}
// Tokens:
tokens {
// We need a few "imaginary" tokens to inject common AST nodes in different
// places. This technique allows common treatment for all such places in
// tree walking.
STATEMENT;
BINARY_EXPRESSION;
UNARY_EXPRESSION;
PARENTHESES_EXPRESSION;
TYPE_CAST;
TYPE_NAME;
PRIMARY_SELECTOR;
DOT_SELECTOR;
METHOD_CALL;
EXPRESSION_LIST;
JNULL = "null";
TRUE = "true";
FALSE = "false";
// No explicit lexer rule exists for DOT. See NumericLiteral lexer rule for
// details.
DOT;
// Numeric literals.
HEX_NUMERIC_LITERAL;
OCT_NUMERIC_LITERAL;
FP_NUMERIC_LITERAL;
DEC_NUMERIC_LITERAL;
}
protected HexDigit
: '0'..'9' | 'a'..'f' | 'A'..'F'
;
protected DecDigit
: '0'..'9'
;
protected OctDigit
: '0'..'7'
;
NumericLiteral
: ("0x") => "0x" (HexDigit)+ ('l' | 'L')?
// hex: 0x12AB, 0x34CDL
{ $setType(HEX_NUMERIC_LITERAL); }
| ('0' OctDigit) => '0' (OctDigit)+ ('l' | 'L')?
// oct: 01234, 05670L
{ $setType(OCT_NUMERIC_LITERAL); }
| ((DecDigit)* '.' DecDigit) => (DecDigit)* '.' (DecDigit)+ ('d' | 'D' | 'f' | 'F')?
// fp: 12.3, .4, 5.6f, .6d
{ $setType(FP_NUMERIC_LITERAL); }
| ((DecDigit)+ ('d' | 'D' | 'f' | 'F')) => (DecDigit)+ ('d' | 'D' | 'f' | 'F')
// fp: 12f, 34d
{ $setType(FP_NUMERIC_LITERAL); }
| (DecDigit)+ ('l' | 'L')?
// dec: 123, 456L
{ $setType(DEC_NUMERIC_LITERAL); }
| '.'
{ $setType(DOT); }
;
CharacterLiteral
: '\''! SingleCharacter '\''!
| '\''! EscapeSequence '\''!
;
protected SingleCharacter
: ~('\'' | '\\')
;
StringLiteral
: '"'! (StringCharacters)? '"'!
;
protected StringCharacters
: (StringCharacter)+
;
protected StringCharacter
: ~('"' | '\\')
| EscapeSequence
;
protected EscapeSequence
: '\\' ('b' | 't' | 'n' | 'f' | 'r' | '"' | '\'' | '\\')
| OctalEscape
| UnicodeEscape
;
protected OctalEscape
: ('\\' OctDigit) => '\\' OctDigit
| ('\\' OctDigit OctDigit) => '\\' OctDigit OctDigit
| '\\' ZeroToThree OctDigit OctDigit
;
protected UnicodeEscape
: '\\' 'u' HexDigit HexDigit HexDigit HexDigit
;
protected ZeroToThree
: ('0'..'3')
;
// Only ASCII characters are supported right now.
// TODO(vlif): add support for Unicode characters in Java identifiers.
Identifier
: ( 'a'..'z' | 'A'..'Z' | '$' | '_' )
( 'a'..'z' | 'A'..'Z' | '0'..'9' | '$' | '_' )*
;
LPAREN : "(";
RPAREN : ")";
LBRACE : "{";
RBRACE : "}";
LBRACK : "[";
RBRACK : "]";
SEMI : ";";
COMMA : ",";
ASSIGN : "=";
CMP_GT : ">";
CMP_LT : "<";
BANG : "!";
TILDE : "~";
QUESTION : "?";
COLON : ":";
EQUAL : "==";
CMP_LE : "<=";
CMP_GE : ">=";
NOTEQUAL : "!=";
AND : "&&";
OR : "||";
ADD : "+";
SUB : "-";
MUL : "*";
DIV : "/";
BITAND : "&";
BITOR : "|";
CARET : "^";
MOD : "%";
SHIFT_LEFT : "<<";
SHIFT_RIGHT_S : ">>";
SHIFT_RIGHT_U : ">>>";
// Skip whitespaces and comments.
WS
: ('\t' | '\r' | '\n' | ' ')+
{ $setType(antlr::Token::SKIP); }
;
COMMENT
: "/*" ( { LA(2) != '/' }? '*' | ~('*') )* "*/"
{ $setType(antlr::Token::SKIP); }
;
LINE_COMMENT
: ("//" (~('\r' | '\n'))*)
{ $setType(antlr::Token::SKIP); }
;
//
// PARSER
//
class JavaExpressionParser extends Parser;
options {
k = 2; // Set lookahead.
buildAST = true;
importVocab = JavaExpressionLexer;
}
{
public:
// Init or re-init the parser
void Init() {
errors_.clear();
initializeASTFactory(fact_);
setASTFactory(&fact_);
}
void reportError(const string& s) {
errors_.push_back(s);
}
void reportError(const antlr::RecognitionException& ex) {
errors_.push_back(ex.getMessage());
}
int num_errors() { return errors_.size(); }
const std::vector<string>& errors() { return errors_; }
private:
std::vector<string> errors_;
antlr::ASTFactory fact_;
}
statement
: expression
{ #statement = #([STATEMENT, "statement"], #statement); }
EOF!
;
expression
: conditionalExpression
;
expressionList
: expression
(
COMMA! expressionList
)?
{ #expressionList = #([EXPRESSION_LIST, "expression_list"], #expressionList); }
;
conditionalExpression
: conditionalOrExpression
(QUESTION^ expression COLON conditionalExpression)?
;
conditionalOrExpression
: conditionalAndExpression
(
{ #conditionalOrExpression = #([BINARY_EXPRESSION, "binary_expression"], #conditionalOrExpression); }
OR conditionalAndExpression
)*
;
conditionalAndExpression
: inclusiveOrExpression
(
{ #conditionalAndExpression = #([BINARY_EXPRESSION, "binary_expression"], #conditionalAndExpression); }
AND inclusiveOrExpression
)*
;
inclusiveOrExpression
: exclusiveOrExpression
(
{ #inclusiveOrExpression = #([BINARY_EXPRESSION, "binary_expression"], #inclusiveOrExpression); }
BITOR exclusiveOrExpression
)*
;
exclusiveOrExpression
: andExpression
(
{ #exclusiveOrExpression = #([BINARY_EXPRESSION, "binary_expression"], #exclusiveOrExpression); }
CARET andExpression
)*
;
andExpression
: equalityExpression
(
{ #andExpression = #([BINARY_EXPRESSION, "binary_expression"], #andExpression); }
BITAND equalityExpression
)*
;
equalityExpression
: relationalExpression
(
{ #equalityExpression = #([BINARY_EXPRESSION, "binary_expression"], #equalityExpression); }
(EQUAL | NOTEQUAL) relationalExpression
)*
;
relationalExpression
: shiftExpression
(
{ #relationalExpression = #([BINARY_EXPRESSION, "binary_expression"], #relationalExpression); }
(CMP_LE | CMP_GE | CMP_LT | CMP_GT) shiftExpression
)*
;
shiftExpression
: additiveExpression
(
{ #shiftExpression = #([BINARY_EXPRESSION, "binary_expression"], #shiftExpression); }
(SHIFT_LEFT | SHIFT_RIGHT_S | SHIFT_RIGHT_U) additiveExpression
)*
;
additiveExpression
: multiplicativeExpression
(
{ #additiveExpression = #([BINARY_EXPRESSION, "binary_expression"], #additiveExpression); }
(ADD | SUB) multiplicativeExpression
)*
;
multiplicativeExpression
: unaryExpression
(
{ #multiplicativeExpression = #([BINARY_EXPRESSION, "binary_expression"], #multiplicativeExpression); }
(MUL | DIV | MOD) unaryExpression
)*
;
unaryExpression
: (ADD | SUB) unaryExpression
{ #unaryExpression = #([UNARY_EXPRESSION, "unary_expression"], #unaryExpression); }
| unaryExpressionNotPlusMinus
;
unaryExpressionNotPlusMinus
: (TILDE | BANG) unaryExpression
{ #unaryExpressionNotPlusMinus = #([UNARY_EXPRESSION, "unary_expression"], #unaryExpressionNotPlusMinus); }
| (castExpression) => castExpression
| primary
(
{ #unaryExpressionNotPlusMinus = #([PRIMARY_SELECTOR, "primary_selector"], #unaryExpressionNotPlusMinus); }
selector
)*
;
castExpression
: LPAREN! classOrInterfaceType RPAREN! unaryExpressionNotPlusMinus
{ #castExpression = #([TYPE_CAST, "type_cast"], #castExpression); }
;
primary
: LPAREN! expression RPAREN!
{ #primary = #([PARENTHESES_EXPRESSION, "parentheses_expression"], #primary); }
| Identifier
(
arguments
{ #primary = #([METHOD_CALL, "method_call"], #primary); }
)?
| literal
;
arguments
: LPAREN! (expressionList)? RPAREN!
;
selector
: DOT!
Identifier
(
arguments
{ #selector = #([METHOD_CALL, "method_call"], #selector); }
)?
{ #selector = #([DOT_SELECTOR, "dot_selector"], #selector); }
| LBRACK^ expression RBRACK
;
literal
: HEX_NUMERIC_LITERAL
| OCT_NUMERIC_LITERAL
| FP_NUMERIC_LITERAL
| DEC_NUMERIC_LITERAL
| CharacterLiteral
| StringLiteral
| TRUE
| FALSE
| JNULL
;
// TODO(vlif): add support for generic types.
classOrInterfaceType
: Identifier
(
DOT!
classOrInterfaceType
)?
{ #classOrInterfaceType = #([TYPE_NAME, "type_name"], #classOrInterfaceType); }
;
//
// TREE WALKING (COMPILATION)
//
class JavaExpressionCompiler extends TreeParser;
options {
importVocab = JavaExpressionLexer;
}
{
public:
// Since the process of compilation and evaluation is recursive and uses OS
// stack, very deep expression trees can cause stack overflow. "MaxTreeDepth"
// limits the maximum recursion depth to a safe threshold.
static constexpr int kMaxTreeDepth = 25;
void Init() {
}
std::unique_ptr<JavaExpression> Walk(antlr::RefAST ast) {
ResetErrorMessage();
if (!VerifyMaxDepth(ast, kMaxTreeDepth)) {
LOG(WARNING) << "The parsed expression tree is too deep";
SetErrorMessage({ ExpressionTreeTooDeep });
return nullptr;
}
std::unique_ptr<JavaExpression> expression(statement(ast));
if (expression == nullptr) {
// Set generic error message if specific error wasn't set.
SetErrorMessage({ ExpressionParserError });
}
return expression;
}
// Getter for the formatted error message. The error message will only be
// set when "Walk" fails.
const FormatMessageModel& error_message() const { return error_message_; }
private:
void ResetErrorMessage() {
error_message_ = FormatMessageModel();
}
void SetErrorMessage(FormatMessageModel new_error_message) {
if (error_message_.format.empty()) {
error_message_ = std::move(new_error_message);
}
}
void reportError(const antlr::RecognitionException& ex) {
reportError(ex.getMessage());
}
void reportError(const std::string& msg) {
LOG(ERROR) << "Internal parser error: " << msg;
}
// Verifies that the maximum depth of the subtree "node" does
// not exceed "max_depth".
static bool VerifyMaxDepth(antlr::RefAST node, int max_depth) {
if (max_depth == 0) {
return false;
}
DCHECK(node != nullptr);
antlr::RefAST child_node = node->getFirstChild();
while (child_node != nullptr) {
if (!VerifyMaxDepth(child_node, max_depth - 1)) {
return false;
}
child_node = child_node->getNextSibling();
}
return true;
}
private:
// Formatted localizable error message reported back to the user. The
// message template are defined in "messages.h" file. Empty
// "error_message_.format" indicates that the error message is not available.
// Only first error message encountered is captured. Subsequent error
// messages are ignored.
FormatMessageModel error_message_;
}
statement returns [JavaExpression* root] {
root = nullptr;
}
: #(STATEMENT root=expression)
;
expression returns [JavaExpression* je] {
JavaExpression* a = nullptr;
JavaExpression* b = nullptr;
JavaExpression* c = nullptr;
JavaExpressionSelector* s = nullptr;
MethodArguments* r = nullptr;
BinaryJavaExpression::Type binary_expression_type;
UnaryJavaExpression::Type unary_expression_type;
std::list<std::vector<jchar>> string_sequence;
string type;
je = nullptr;
}
: #(QUESTION a=expression b=expression COLON c=expression) {
if ((a == nullptr) || (b == nullptr) || (c == nullptr)) {
reportError("NULL argument in conditional expression");
delete a;
delete b;
delete c;
je = nullptr;
} else {
je = new ConditionalJavaExpression(a, b, c);
}
}
| #(PARENTHESES_EXPRESSION je=expression)
| #(BINARY_EXPRESSION a=expression binary_expression_type=binary_expression_token b=expression) {
if ((a == nullptr) || (b == nullptr)) {
reportError("NULL argument in binary expression");
delete a;
delete b;
je = nullptr;
} else {
je = new BinaryJavaExpression(binary_expression_type, a, b);
}
}
| #(UNARY_EXPRESSION unary_expression_type=unary_expression_token a=expression) {
if (a == nullptr) {
reportError("NULL argument in unary expression");
je = nullptr;
} else {
je = new UnaryJavaExpression(unary_expression_type, a);
}
}
| identifier_node:Identifier {
je = new JavaIdentifier(identifier_node->getText());
}
| hex_numeric_literal_node:HEX_NUMERIC_LITERAL {
JavaIntLiteral* nl = new JavaIntLiteral;
if (!nl->ParseString(hex_numeric_literal_node->getText(), 16)) {
reportError("Hex integer literal could not be parsed");
SetErrorMessage({
BadNumericLiteral,
{ hex_numeric_literal_node->getText() }
});
delete nl;
je = nullptr;
} else {
je = nl;
}
}
| oct_numeric_literal_node:OCT_NUMERIC_LITERAL {
JavaIntLiteral* nl = new JavaIntLiteral;
if (!nl->ParseString(oct_numeric_literal_node->getText(), 8)) {
reportError("Octal integer literal could not be parsed");
SetErrorMessage({
BadNumericLiteral,
{ oct_numeric_literal_node->getText() }
});
delete nl;
je = nullptr;
} else {
je = nl;
}
}
| fp_numeric_literal_node:FP_NUMERIC_LITERAL {
JavaFloatLiteral* nl = new JavaFloatLiteral;
if (!nl->ParseString(fp_numeric_literal_node->getText())) {
reportError("Floating point literal could not be parsed");
SetErrorMessage({
BadNumericLiteral,
{ fp_numeric_literal_node->getText() }
});
delete nl;
je = nullptr;
} else {
je = nl;
}
}
| dec_numeric_literal_node:DEC_NUMERIC_LITERAL {
JavaIntLiteral* nl = new JavaIntLiteral;
if (!nl->ParseString(dec_numeric_literal_node->getText(), 10)) {
reportError("Decimal integer literal could not be parsed");
SetErrorMessage({
BadNumericLiteral,
{ dec_numeric_literal_node->getText() }
});
delete nl;
je = nullptr;
} else {
je = nl;
}
}
| character_literal_node:CharacterLiteral {
JavaCharLiteral* cl = new JavaCharLiteral;
if (!cl->ParseString(character_literal_node->getText())) {
reportError("Invalid character");
delete cl;
je = nullptr;
} else {
je = cl;
}
}
| string_literal_node:StringLiteral {
JavaStringLiteral* sl = new JavaStringLiteral;
if (!sl->ParseString(string_literal_node->getText())) {
reportError("Invalid string");
delete sl;
je = nullptr;
} else {
je = sl;
}
}
| TRUE {
je = new JavaBooleanLiteral(JNI_TRUE);
}
| FALSE {
je = new JavaBooleanLiteral(JNI_FALSE);
}
| JNULL {
je = new JavaNullLiteral;
}
| #(PRIMARY_SELECTOR a=expression s=selector) {
if ((a == nullptr) || (s == nullptr)) {
reportError("PRIMARY_SELECTED inner expressions failed to compile");
delete a;
delete s;
je = nullptr;
} else {
s->set_source(a);
je = s;
}
}
| #(TYPE_CAST type=type_name a=expression) {
if (a == nullptr) {
reportError("NULL source in type cast expression");
je = nullptr;
} else {
je = new TypeCastJavaExpression(type, a);
}
}
| #(METHOD_CALL method_node:Identifier r=arguments) {
if (r == nullptr) {
reportError("NULL method arguments in expression METHOD_CALL");
je = nullptr;
} else {
je = new MethodCallExpression(method_node->getText(), r);
}
}
;
binary_expression_token returns [BinaryJavaExpression::Type type] {
type = static_cast<BinaryJavaExpression::Type>(-1);
}
: ADD { type = BinaryJavaExpression::Type::add; }
| SUB { type = BinaryJavaExpression::Type::sub; }
| MUL { type = BinaryJavaExpression::Type::mul; }
| DIV { type = BinaryJavaExpression::Type::div; }
| MOD { type = BinaryJavaExpression::Type::mod; }
| AND { type = BinaryJavaExpression::Type::conditional_and; }
| OR { type = BinaryJavaExpression::Type::conditional_or; }
| EQUAL { type = BinaryJavaExpression::Type::eq; }
| NOTEQUAL { type = BinaryJavaExpression::Type::ne; }
| CMP_LE { type = BinaryJavaExpression::Type::le; }
| CMP_GE { type = BinaryJavaExpression::Type::ge; }
| CMP_LT { type = BinaryJavaExpression::Type::lt; }
| CMP_GT { type = BinaryJavaExpression::Type::gt; }
| BITAND { type = BinaryJavaExpression::Type::bitwise_and; }
| BITOR { type = BinaryJavaExpression::Type::bitwise_or; }
| CARET { type = BinaryJavaExpression::Type::bitwise_xor; }
| SHIFT_LEFT { type = BinaryJavaExpression::Type::shl; }
| SHIFT_RIGHT_S { type = BinaryJavaExpression::Type::shr_s; }
| SHIFT_RIGHT_U { type = BinaryJavaExpression::Type::shr_u; }
;
unary_expression_token returns [UnaryJavaExpression::Type type] {
type = static_cast<UnaryJavaExpression::Type>(-1);
}
: ADD { type = UnaryJavaExpression::Type::plus; }
| SUB { type = UnaryJavaExpression::Type::minus; }
| TILDE { type = UnaryJavaExpression::Type::bitwise_complement; }
| BANG { type = UnaryJavaExpression::Type::logical_complement; }
;
selector returns [JavaExpressionSelector* js] {
JavaExpression* a = nullptr;
JavaExpressionSelector* ds = nullptr;
js = nullptr;
}
: #(DOT_SELECTOR ds=dotSelector) {
if (ds == nullptr) {
reportError("Failed to parse dot expression");
js = nullptr;
} else {
js = ds;
}
}
| #(LBRACK a=expression RBRACK) {
if (a == nullptr) {
reportError("Failed to parse index expression");
js = nullptr;
} else {
js = new JavaExpressionIndexSelector(a);
}
}
;
dotSelector returns [JavaExpressionSelector* js] {
MethodArguments* r = nullptr;
js = nullptr;
}
: identifier_node:Identifier {
js = new JavaExpressionMemberSelector(identifier_node->getText());
}
| #(METHOD_CALL method_node:Identifier r=arguments) {
if (r == nullptr) {
reportError("NULL method arguments in dotSelector METHOD_CALL");
js = nullptr;
} else {
js = new MethodCallExpression(method_node->getText(), r);
}
}
;
arguments returns [MethodArguments* args] {
MethodArguments* tail = nullptr;
JavaExpression* arg = nullptr;
args = nullptr;
}
: #(EXPRESSION_LIST arg=expression tail=arguments) {
if ((arg == nullptr) || (tail == nullptr)) {
reportError("NULL method argument");
delete arg;
delete tail;
args = nullptr;
} else {
args = new MethodArguments(arg, tail);
}
}
| {
args = new MethodArguments();
}
;
type_name returns [string t] {
string tail;
}
: #(TYPE_NAME n1:Identifier tail=type_name) {
t = n1->getText();
if (!tail.empty()) {
t += '.';
t += tail;
}
}
| { }
;