1/* 2 * Copyright (C) 2007-2010 Júlio Vilmar Gesser. 3 * Copyright (C) 2011, 2013-2016 The JavaParser Team. 4 * 5 * This file is part of JavaParser. 6 * 7 * JavaParser can be used either under the terms of 8 * a) the GNU Lesser General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * b) the terms of the Apache License 12 * 13 * You should have received a copy of both licenses in LICENCE.LGPL and 14 * LICENCE.APACHE. Please refer to those files for details. 15 * 16 * JavaParser is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU Lesser General Public License for more details. 20 */ 21 22options { 23 STATIC=false; 24 COMMON_TOKEN_ACTION=true; 25 JDK_VERSION = "1.8"; 26 TOKEN_EXTENDS ="TokenBase"; 27 JAVA_TEMPLATE_TYPE = "modern"; 28} 29 30PARSER_BEGIN(GeneratedJavaParser) 31/* 32 * Copyright (C) 2007-2010 Júlio Vilmar Gesser. 33 * Copyright (C) 2011, 2013-2016 The JavaParser Team. 34 * 35 * This file is part of JavaParser. 36 * 37 * JavaParser can be used either under the terms of 38 * a) the GNU Lesser General Public License as published by 39 * the Free Software Foundation, either version 3 of the License, or 40 * (at your option) any later version. 41 * b) the terms of the Apache License 42 * 43 * You should have received a copy of both licenses in LICENCE.LGPL and 44 * LICENCE.APACHE. Please refer to those files for details. 45 * 46 * JavaParser is distributed in the hope that it will be useful, 47 * but WITHOUT ANY WARRANTY; without even the implied warranty of 48 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 49 * GNU Lesser General Public License for more details. 50 */ 51package com.github.javaparser; 52import java.io.*; 53import java.util.*; 54import com.github.javaparser.ast.*; 55import com.github.javaparser.ast.body.*; 56import com.github.javaparser.ast.comments.*; 57import com.github.javaparser.ast.modules.*; 58import com.github.javaparser.ast.expr.*; 59import com.github.javaparser.ast.stmt.*; 60import com.github.javaparser.ast.type.*; 61import com.github.javaparser.utils.*; 62import javax.annotation.Generated; 63import static com.github.javaparser.JavaToken.INVALID; 64import static com.github.javaparser.ast.Node.Parsedness.UNPARSABLE; 65import static com.github.javaparser.utils.Utils.*; 66import static com.github.javaparser.ast.NodeList.*; 67import static com.github.javaparser.GeneratedJavaParser.*; 68import static com.github.javaparser.Range.*; 69import static com.github.javaparser.Position.*; 70import static com.github.javaparser.ast.type.ArrayType.*; 71import static com.github.javaparser.GeneratedJavaParserTokenManagerBase.*; 72 73@Generated("JavaCC") 74final class GeneratedJavaParser extends GeneratedJavaParserBase { 75 /* Returns the JavaParser specific token type of the last matched token */ 76 JavaToken token() { 77 return token.javaToken; 78 } 79 80 /* Changes the amount by which the horizontal position is increased when a tab character is encountered. 81 One by default.*/ 82 void setTabSize(int size) { 83 jj_input_stream.setTabSize(size); 84 } 85 86 @Override 87 GeneratedJavaParserTokenManager getTokenSource() { 88 return token_source; 89 } 90} 91 92PARSER_END(GeneratedJavaParser) 93 94/* WHITE SPACE */ 95 96SPECIAL_TOKEN : 97{ 98 <SPACE: [" ", "\t", "\f", "\u0085", "\u00A0", "\u1680", "\u180e", "\u2000", "\u2001", "\u2002", "\u2003", "\u2004", "\u2005", 99 "\u2006", "\u2007", "\u2008", "\u2009", "\u200a", "\u200b", "\u200c", "\u200d", "\u2028", "\u2029", "\u202f", "\u205f", "\u2060", "\u3000", "\ufeff"]> 100| <WINDOWS_EOL : "\r\n"> 101| <UNIX_EOL: "\n"> 102| <OLD_MAC_EOL: "\r"> 103} 104 105TOKEN_MGR_DECLS : 106{ 107 private List<JavaToken> tokens = new ArrayList<JavaToken>(); 108 private CommentsCollection commentsCollection = new CommentsCollection(); 109 private JavaToken homeToken; 110 private Stack<Token> tokenWorkStack = new Stack<Token>(); 111 private boolean storeTokens; 112 113 void reset() { 114 tokens = new ArrayList<JavaToken>(); 115 commentsCollection = new CommentsCollection(); 116 homeToken = null; 117 } 118 119 List<JavaToken> getTokens() { 120 if(storeTokens) { 121 return tokens; 122 } 123 return null; 124 } 125 126 CommentsCollection getCommentsCollection() { 127 return commentsCollection; 128 } 129 130 /* Get the very first token in the file */ 131 JavaToken getHomeToken() { 132 return homeToken; 133 } 134 135 /* Makes the parser keep a list of tokens */ 136 public void setStoreTokens(boolean storeTokens) { 137 this.storeTokens = storeTokens; 138 } 139 140 private void CommonTokenAction(Token token) { 141 // Use an intermediary stack to avoid recursion, see issue 1003 142 do { 143 tokenWorkStack.push(token); 144 token = token.specialToken; 145 } while (token != null); 146 147 // The stack is now filled with tokens in left-to-right order. Process them. 148 while(!tokenWorkStack.empty()) { 149 token = tokenWorkStack.pop(); 150 token.javaToken = new JavaToken(token, tokens); 151 152 if(storeTokens) { 153 tokens.add(token.javaToken); 154 } 155 156 if (homeToken == null) { 157 homeToken = token.javaToken; 158 } 159 160 if(TokenTypes.isComment(token.kind)) { 161 Comment comment = createCommentFromToken(token); 162 commentsCollection.addComment(comment); 163 } 164 } 165 } 166} 167 168/* COMMENTS */ 169 170SPECIAL_TOKEN : 171{ 172 <SINGLE_LINE_COMMENT: "//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")? > 173} 174 175MORE : 176{ 177 <ENTER_JAVADOC_COMMENT: "/**" ~["/"]> { input_stream.backup(1); } : IN_JAVADOC_COMMENT 178| 179 <ENTER_MULTILINE_COMMENT: "/*"> : IN_MULTI_LINE_COMMENT 180} 181 182<IN_JAVADOC_COMMENT> 183SPECIAL_TOKEN : 184{ 185 <JAVADOC_COMMENT: "*/" > : DEFAULT 186} 187 188<IN_MULTI_LINE_COMMENT> 189SPECIAL_TOKEN : 190{ 191 <MULTI_LINE_COMMENT: "*/" > : DEFAULT 192} 193 194<IN_JAVADOC_COMMENT, IN_MULTI_LINE_COMMENT> 195MORE : 196{ 197 <COMMENT_CONTENT: ~[] > 198} 199 200/* RESERVED WORDS AND LITERALS */ 201 202TOKEN : 203{ 204 < ABSTRACT: "abstract" > 205| < ASSERT: "assert" > 206| < BOOLEAN: "boolean" > 207| < BREAK: "break" > 208| < BYTE: "byte" > 209| < CASE: "case" > 210| < CATCH: "catch" > 211| < CHAR: "char" > 212| < CLASS: "class" > 213| < CONST: "const" > 214| < CONTINUE: "continue" > 215| < _DEFAULT: "default" > 216| < DO: "do" > 217| < DOUBLE: "double" > 218| < ELSE: "else" > 219| < ENUM: "enum" > 220| < EXTENDS: "extends" > 221| < FALSE: "false" > 222| < FINAL: "final" > 223| < FINALLY: "finally" > 224| < FLOAT: "float" > 225| < FOR: "for" > 226| < GOTO: "goto" > 227| < IF: "if" > 228| < IMPLEMENTS: "implements" > 229| < IMPORT: "import" > 230| < INSTANCEOF: "instanceof" > 231| < INT: "int" > 232| < INTERFACE: "interface" > 233| < LONG: "long" > 234| < NATIVE: "native" > 235| < NEW: "new" > 236| < NULL: "null" > 237| < PACKAGE: "package"> 238| < PRIVATE: "private" > 239| < PROTECTED: "protected" > 240| < PUBLIC: "public" > 241| < RETURN: "return" > 242| < SHORT: "short" > 243| < STATIC: "static" > 244| < STRICTFP: "strictfp" > 245| < SUPER: "super" > 246| < SWITCH: "switch" > 247| < SYNCHRONIZED: "synchronized" > 248| < THIS: "this" > 249| < THROW: "throw" > 250| < THROWS: "throws" > 251| < TRANSIENT: "transient" > 252| < TRUE: "true" > 253| < TRY: "try" > 254| < VOID: "void" > 255| < VOLATILE: "volatile" > 256| < WHILE: "while" > 257| < REQUIRES: "requires" > 258| < TO: "to" > 259| < WITH: "with" > 260| < OPEN: "open" > 261| < OPENS: "opens" > 262| < USES: "uses" > 263| < MODULE: "module" > 264| < EXPORTS: "exports" > 265| < PROVIDES: "provides" > 266| < TRANSITIVE: "transitive" > 267} 268 269/* LITERALS */ 270 271TOKEN : 272{ 273 < LONG_LITERAL: 274 <DECIMAL_LITERAL> (["l","L"]) 275 | <HEX_LITERAL> (["l","L"]) 276 | <OCTAL_LITERAL> (["l","L"]) 277 | <BINARY_LITERAL> (["l","L"]) 278 > 279| 280 < INTEGER_LITERAL: 281 <DECIMAL_LITERAL> 282 | <HEX_LITERAL> 283 | <OCTAL_LITERAL> 284 | <BINARY_LITERAL> 285 > 286| 287 < #DECIMAL_LITERAL: ["0"-"9"]((["0"-"9","_"])*["0"-"9"])? > 288| 289 < #HEX_LITERAL: "0" ["x","X"] <HEX_DIGITS> > 290| 291 < #OCTAL_LITERAL: "0" ["0"-"7"]((["0"-"7","_"])*["0"-"7"])? > 292| 293 < #BINARY_LITERAL: "0" ["b","B"] ["0","1"]((["0","1","_"])*["0","1"])? > 294| 295 < FLOATING_POINT_LITERAL: 296 <DECIMAL_FLOATING_POINT_LITERAL> 297 | <HEXADECIMAL_FLOATING_POINT_LITERAL> 298 > 299| 300 < #DECIMAL_FLOATING_POINT_LITERAL: 301 <DECIMAL_LITERAL> "." (<DECIMAL_LITERAL>)? (<DECIMAL_EXPONENT>)? (["f","F","d","D"])? 302 | "." <DECIMAL_LITERAL> (<DECIMAL_EXPONENT>)? (["f","F","d","D"])? 303 | <DECIMAL_LITERAL> <DECIMAL_EXPONENT> (["f","F","d","D"])? 304 | <DECIMAL_LITERAL> (<DECIMAL_EXPONENT>)? ["f","F","d","D"] 305 > 306| 307 < #DECIMAL_EXPONENT: ["e","E"] (["+","-"])? (<DECIMAL_LITERAL>)+ > 308| 309 < #HEXADECIMAL_FLOATING_POINT_LITERAL: 310 <HEX_LITERAL> (".")? <HEXADECIMAL_EXPONENT> (["f","F","d","D"])? 311 | "0" ["x","X"] (<HEX_DIGITS>)? "." <HEX_DIGITS> <HEXADECIMAL_EXPONENT> (["f","F","d","D"])? 312 > 313| 314 < #HEXADECIMAL_EXPONENT: ["p","P"] (["+","-"])? <DECIMAL_LITERAL> > 315| 316 < #HEX_DIGITS: ["0"-"9","a"-"f","A"-"F"]((["0"-"9","a"-"f","A"-"F","_"])*["0"-"9","a"-"f","A"-"F"])? > 317| 318 < #UNICODE_ESCAPE: 319 "\\u" 320 ["0"-"9","A"-"F","a"-"f"] 321 ["0"-"9","A"-"F","a"-"f"] 322 ["0"-"9","A"-"F","a"-"f"] 323 ["0"-"9","A"-"F","a"-"f"] > 324| 325 < CHARACTER_LITERAL: 326 "'" 327 ( (~["'","\\","\n","\r"]) 328 | ("\\" 329 ( ["n","t","b","r","f","\\","'","\""] 330 | ["0"-"7"] ( ["0"-"7"] )? 331 | ["0"-"3"] ["0"-"7"] ["0"-"7"] 332 ) 333 ) 334 | <UNICODE_ESCAPE> 335 ) 336 "'" 337 > 338| 339 < STRING_LITERAL: 340 "\"" 341 ( (~["\"","\\","\n","\r"]) 342 | ("\\" 343 ( ["n","t","b","r","f","\\","'","\""] 344 | ["0"-"7"] ( ["0"-"7"] )? 345 | ["0"-"3"] ["0"-"7"] ["0"-"7"] 346 ) 347 ) 348 | ("\\u" 349 ["0"-"9","A"-"F","a"-"f"] 350 ["0"-"9","A"-"F","a"-"f"] 351 ["0"-"9","A"-"F","a"-"f"] 352 ["0"-"9","A"-"F","a"-"f"] 353 ) 354 )* 355 "\"" 356 > 357} 358 359/* IDENTIFIERS */ 360 361TOKEN : 362{ 363 < IDENTIFIER: <LETTER> (<PART_LETTER>)* > 364| 365 < #LETTER: [ 366 "\u0024", "\u0041"-"\u005a", "\u005f", "\u0061"-"\u007a", "\u00a2"-"\u00a5", "\u00aa", "\u00b5", 367 "\u00ba", "\u00c0"-"\u00d6", "\u00d8"-"\u00f6", "\u00f8"-"\u02c1", "\u02c6"-"\u02d1", "\u02e0"-"\u02e4", 368 "\u02ec", "\u02ee", "\u0370"-"\u0374", "\u0376"-"\u0377", "\u037a"-"\u037d", "\u0386", "\u0388"-"\u038a", 369 "\u038c", "\u038e"-"\u03a1", "\u03a3"-"\u03f5", "\u03f7"-"\u0481", "\u048a"-"\u0527", "\u0531"-"\u0556", 370 "\u0559", "\u0561"-"\u0587", "\u058f", "\u05d0"-"\u05ea", "\u05f0"-"\u05f2", "\u060b", "\u0620"-"\u064a", 371 "\u066e"-"\u066f", "\u0671"-"\u06d3", "\u06d5", "\u06e5"-"\u06e6", "\u06ee"-"\u06ef", "\u06fa"-"\u06fc", 372 "\u06ff", "\u0710", "\u0712"-"\u072f", "\u074d"-"\u07a5", "\u07b1", "\u07ca"-"\u07ea", "\u07f4"-"\u07f5", 373 "\u07fa", "\u0800"-"\u0815", "\u081a", "\u0824", "\u0828", "\u0840"-"\u0858", "\u08a0", "\u08a2"-"\u08ac", 374 "\u0904"-"\u0939", "\u093d", "\u0950", "\u0958"-"\u0961", "\u0971"-"\u0977", "\u0979"-"\u097f", 375 "\u0985"-"\u098c", "\u098f"-"\u0990", "\u0993"-"\u09a8", "\u09aa"-"\u09b0", "\u09b2", "\u09b6"-"\u09b9", 376 "\u09bd", "\u09ce", "\u09dc"-"\u09dd", "\u09df"-"\u09e1", "\u09f0"-"\u09f3", "\u09fb", "\u0a05"-"\u0a0a", 377 "\u0a0f"-"\u0a10", "\u0a13"-"\u0a28", "\u0a2a"-"\u0a30", "\u0a32"-"\u0a33", "\u0a35"-"\u0a36", 378 "\u0a38"-"\u0a39", "\u0a59"-"\u0a5c", "\u0a5e", "\u0a72"-"\u0a74", "\u0a85"-"\u0a8d", "\u0a8f"-"\u0a91", 379 "\u0a93"-"\u0aa8", "\u0aaa"-"\u0ab0", "\u0ab2"-"\u0ab3", "\u0ab5"-"\u0ab9", "\u0abd", "\u0ad0", 380 "\u0ae0"-"\u0ae1", "\u0af1", "\u0b05"-"\u0b0c", "\u0b0f"-"\u0b10", "\u0b13"-"\u0b28", "\u0b2a"-"\u0b30", 381 "\u0b32"-"\u0b33", "\u0b35"-"\u0b39", "\u0b3d", "\u0b5c"-"\u0b5d", "\u0b5f"-"\u0b61", "\u0b71", 382 "\u0b83", "\u0b85"-"\u0b8a", "\u0b8e"-"\u0b90", "\u0b92"-"\u0b95", "\u0b99"-"\u0b9a", "\u0b9c", 383 "\u0b9e"-"\u0b9f", "\u0ba3"-"\u0ba4", "\u0ba8"-"\u0baa", "\u0bae"-"\u0bb9", "\u0bd0", "\u0bf9", 384 "\u0c05"-"\u0c0c", "\u0c0e"-"\u0c10", "\u0c12"-"\u0c28", "\u0c2a"-"\u0c33", "\u0c35"-"\u0c39", 385 "\u0c3d", "\u0c58"-"\u0c59", "\u0c60"-"\u0c61", "\u0c85"-"\u0c8c", "\u0c8e"-"\u0c90", "\u0c92"-"\u0ca8", 386 "\u0caa"-"\u0cb3", "\u0cb5"-"\u0cb9", "\u0cbd", "\u0cde", "\u0ce0"-"\u0ce1", "\u0cf1"-"\u0cf2", 387 "\u0d05"-"\u0d0c", "\u0d0e"-"\u0d10", "\u0d12"-"\u0d3a", "\u0d3d", "\u0d4e", "\u0d60"-"\u0d61", 388 "\u0d7a"-"\u0d7f", "\u0d85"-"\u0d96", "\u0d9a"-"\u0db1", "\u0db3"-"\u0dbb", "\u0dbd", "\u0dc0"-"\u0dc6", 389 "\u0e01"-"\u0e30", "\u0e32"-"\u0e33", "\u0e3f"-"\u0e46", "\u0e81"-"\u0e82", "\u0e84", "\u0e87"-"\u0e88", 390 "\u0e8a", "\u0e8d", "\u0e94"-"\u0e97", "\u0e99"-"\u0e9f", "\u0ea1"-"\u0ea3", "\u0ea5", "\u0ea7", 391 "\u0eaa"-"\u0eab", "\u0ead"-"\u0eb0", "\u0eb2"-"\u0eb3", "\u0ebd", "\u0ec0"-"\u0ec4", "\u0ec6", 392 "\u0edc"-"\u0edf", "\u0f00", "\u0f40"-"\u0f47", "\u0f49"-"\u0f6c", "\u0f88"-"\u0f8c", "\u1000"-"\u102a", 393 "\u103f", "\u1050"-"\u1055", "\u105a"-"\u105d", "\u1061", "\u1065"-"\u1066", "\u106e"-"\u1070", 394 "\u1075"-"\u1081", "\u108e", "\u10a0"-"\u10c5", "\u10c7", "\u10cd", "\u10d0"-"\u10fa", "\u10fc"-"\u1248", 395 "\u124a"-"\u124d", "\u1250"-"\u1256", "\u1258", "\u125a"-"\u125d", "\u1260"-"\u1288", "\u128a"-"\u128d", 396 "\u1290"-"\u12b0", "\u12b2"-"\u12b5", "\u12b8"-"\u12be", "\u12c0", "\u12c2"-"\u12c5", "\u12c8"-"\u12d6", 397 "\u12d8"-"\u1310", "\u1312"-"\u1315", "\u1318"-"\u135a", "\u1380"-"\u138f", "\u13a0"-"\u13f4", 398 "\u1401"-"\u166c", "\u166f"-"\u167f", "\u1681"-"\u169a", "\u16a0"-"\u16ea", "\u16ee"-"\u16f0", 399 "\u1700"-"\u170c", "\u170e"-"\u1711", "\u1720"-"\u1731", "\u1740"-"\u1751", "\u1760"-"\u176c", 400 "\u176e"-"\u1770", "\u1780"-"\u17b3", "\u17d7", "\u17db"-"\u17dc", "\u1820"-"\u1877", "\u1880"-"\u18a8", 401 "\u18aa", "\u18b0"-"\u18f5", "\u1900"-"\u191c", "\u1950"-"\u196d", "\u1970"-"\u1974", "\u1980"-"\u19ab", 402 "\u19c1"-"\u19c7", "\u1a00"-"\u1a16", "\u1a20"-"\u1a54", "\u1aa7", "\u1b05"-"\u1b33", "\u1b45"-"\u1b4b", 403 "\u1b83"-"\u1ba0", "\u1bae"-"\u1baf", "\u1bba"-"\u1be5", "\u1c00"-"\u1c23", "\u1c4d"-"\u1c4f", 404 "\u1c5a"-"\u1c7d", "\u1ce9"-"\u1cec", "\u1cee"-"\u1cf1", "\u1cf5"-"\u1cf6", "\u1d00"-"\u1dbf", 405 "\u1e00"-"\u1f15", "\u1f18"-"\u1f1d", "\u1f20"-"\u1f45", "\u1f48"-"\u1f4d", "\u1f50"-"\u1f57", 406 "\u1f59", "\u1f5b", "\u1f5d", "\u1f5f"-"\u1f7d", "\u1f80"-"\u1fb4", "\u1fb6"-"\u1fbc", "\u1fbe", 407 "\u1fc2"-"\u1fc4", "\u1fc6"-"\u1fcc", "\u1fd0"-"\u1fd3", "\u1fd6"-"\u1fdb", "\u1fe0"-"\u1fec", 408 "\u1ff2"-"\u1ff4", "\u1ff6"-"\u1ffc", "\u203f"-"\u2040", "\u2054", "\u2071", "\u207f", "\u2090"-"\u209c", 409 "\u20a0"-"\u20ba", "\u2102", "\u2107", "\u210a"-"\u2113", "\u2115", "\u2119"-"\u211d", "\u2124", 410 "\u2126", "\u2128", "\u212a"-"\u212d", "\u212f"-"\u2139", "\u213c"-"\u213f", "\u2145"-"\u2149", 411 "\u214e", "\u2160"-"\u2188", "\u2c00"-"\u2c2e", "\u2c30"-"\u2c5e", "\u2c60"-"\u2ce4", "\u2ceb"-"\u2cee", 412 "\u2cf2"-"\u2cf3", "\u2d00"-"\u2d25", "\u2d27", "\u2d2d", "\u2d30"-"\u2d67", "\u2d6f", "\u2d80"-"\u2d96", 413 "\u2da0"-"\u2da6", "\u2da8"-"\u2dae", "\u2db0"-"\u2db6", "\u2db8"-"\u2dbe", "\u2dc0"-"\u2dc6", 414 "\u2dc8"-"\u2dce", "\u2dd0"-"\u2dd6", "\u2dd8"-"\u2dde", "\u2e2f", "\u3005"-"\u3007", "\u3021"-"\u3029", 415 "\u3031"-"\u3035", "\u3038"-"\u303c", "\u3041"-"\u3096", "\u309d"-"\u309f", "\u30a1"-"\u30fa", 416 "\u30fc"-"\u30ff", "\u3105"-"\u312d", "\u3131"-"\u318e", "\u31a0"-"\u31ba", "\u31f0"-"\u31ff", 417 "\u3400"-"\u4db5", "\u4e00"-"\u9fcc", "\ua000"-"\ua48c", "\ua4d0"-"\ua4fd", "\ua500"-"\ua60c", 418 "\ua610"-"\ua61f", "\ua62a"-"\ua62b", "\ua640"-"\ua66e", "\ua67f"-"\ua697", "\ua6a0"-"\ua6ef", 419 "\ua717"-"\ua71f", "\ua722"-"\ua788", "\ua78b"-"\ua78e", "\ua790"-"\ua793", "\ua7a0"-"\ua7aa", 420 "\ua7f8"-"\ua801", "\ua803"-"\ua805", "\ua807"-"\ua80a", "\ua80c"-"\ua822", "\ua838", "\ua840"-"\ua873", 421 "\ua882"-"\ua8b3", "\ua8f2"-"\ua8f7", "\ua8fb", "\ua90a"-"\ua925", "\ua930"-"\ua946", "\ua960"-"\ua97c", 422 "\ua984"-"\ua9b2", "\ua9cf", "\uaa00"-"\uaa28", "\uaa40"-"\uaa42", "\uaa44"-"\uaa4b", "\uaa60"-"\uaa76", 423 "\uaa7a", "\uaa80"-"\uaaaf", "\uaab1", "\uaab5"-"\uaab6", "\uaab9"-"\uaabd", "\uaac0", "\uaac2", 424 "\uaadb"-"\uaadd", "\uaae0"-"\uaaea", "\uaaf2"-"\uaaf4", "\uab01"-"\uab06", "\uab09"-"\uab0e", 425 "\uab11"-"\uab16", "\uab20"-"\uab26", "\uab28"-"\uab2e", "\uabc0"-"\uabe2", "\uac00"-"\ud7a3", 426 "\ud7b0"-"\ud7c6", "\ud7cb"-"\ud7fb", "\ud800"-"\udfff", "\uf900"-"\ufa6d", "\ufa70"-"\ufad9", 427 "\ufb00"-"\ufb06", "\ufb13"-"\ufb17", "\ufb1d", "\ufb1f"-"\ufb28", "\ufb2a"-"\ufb36", "\ufb38"-"\ufb3c", 428 "\ufb3e", "\ufb40"-"\ufb41", "\ufb43"-"\ufb44", "\ufb46"-"\ufbb1", "\ufbd3"-"\ufd3d", "\ufd50"-"\ufd8f", 429 "\ufd92"-"\ufdc7", "\ufdf0"-"\ufdfc", "\ufe33"-"\ufe34", "\ufe4d"-"\ufe4f", "\ufe69", "\ufe70"-"\ufe74", 430 "\ufe76"-"\ufefc", "\uff04", "\uff21"-"\uff3a", "\uff3f", "\uff41"-"\uff5a", "\uff66"-"\uffbe", 431 "\uffc2"-"\uffc7", "\uffca"-"\uffcf", "\uffd2"-"\uffd7", "\uffda"-"\uffdc", "\uffe0"-"\uffe1", 432 "\uffe5"-"\uffe6" ] 433 | <UNICODE_ESCAPE> 434 > 435| 436 < #PART_LETTER: [ 437 "\u0000"-"\u0008", "\u000e"-"\u001b", "\u0024", "\u0030"-"\u0039", "\u0041"-"\u005a", "\u005f", 438 "\u0061"-"\u007a", "\u007f"-"\u009f", "\u00a2"-"\u00a5", "\u00aa", "\u00ad", "\u00b5", "\u00ba", 439 "\u00c0"-"\u00d6", "\u00d8"-"\u00f6", "\u00f8"-"\u02c1", "\u02c6"-"\u02d1", "\u02e0"-"\u02e4", 440 "\u02ec", "\u02ee", "\u0300"-"\u0374", "\u0376"-"\u0377", "\u037a"-"\u037d", "\u0386", "\u0388"-"\u038a", 441 "\u038c", "\u038e"-"\u03a1", "\u03a3"-"\u03f5", "\u03f7"-"\u0481", "\u0483"-"\u0487", "\u048a"-"\u0527", 442 "\u0531"-"\u0556", "\u0559", "\u0561"-"\u0587", "\u058f", "\u0591"-"\u05bd", "\u05bf", "\u05c1"-"\u05c2", 443 "\u05c4"-"\u05c5", "\u05c7", "\u05d0"-"\u05ea", "\u05f0"-"\u05f2", "\u0600"-"\u0604", "\u060b", 444 "\u0610"-"\u061a", "\u0620"-"\u0669", "\u066e"-"\u06d3", "\u06d5"-"\u06dd", "\u06df"-"\u06e8", 445 "\u06ea"-"\u06fc", "\u06ff", "\u070f"-"\u074a", "\u074d"-"\u07b1", "\u07c0"-"\u07f5", "\u07fa", 446 "\u0800"-"\u082d", "\u0840"-"\u085b", "\u08a0", "\u08a2"-"\u08ac", "\u08e4"-"\u08fe", "\u0900"-"\u0963", 447 "\u0966"-"\u096f", "\u0971"-"\u0977", "\u0979"-"\u097f", "\u0981"-"\u0983", "\u0985"-"\u098c", 448 "\u098f"-"\u0990", "\u0993"-"\u09a8", "\u09aa"-"\u09b0", "\u09b2", "\u09b6"-"\u09b9", "\u09bc"-"\u09c4", 449 "\u09c7"-"\u09c8", "\u09cb"-"\u09ce", "\u09d7", "\u09dc"-"\u09dd", "\u09df"-"\u09e3", "\u09e6"-"\u09f3", 450 "\u09fb", "\u0a01"-"\u0a03", "\u0a05"-"\u0a0a", "\u0a0f"-"\u0a10", "\u0a13"-"\u0a28", "\u0a2a"-"\u0a30", 451 "\u0a32"-"\u0a33", "\u0a35"-"\u0a36", "\u0a38"-"\u0a39", "\u0a3c", "\u0a3e"-"\u0a42", "\u0a47"-"\u0a48", 452 "\u0a4b"-"\u0a4d", "\u0a51", "\u0a59"-"\u0a5c", "\u0a5e", "\u0a66"-"\u0a75", "\u0a81"-"\u0a83", 453 "\u0a85"-"\u0a8d", "\u0a8f"-"\u0a91", "\u0a93"-"\u0aa8", "\u0aaa"-"\u0ab0", "\u0ab2"-"\u0ab3", 454 "\u0ab5"-"\u0ab9", "\u0abc"-"\u0ac5", "\u0ac7"-"\u0ac9", "\u0acb"-"\u0acd", "\u0ad0", "\u0ae0"-"\u0ae3", 455 "\u0ae6"-"\u0aef", "\u0af1", "\u0b01"-"\u0b03", "\u0b05"-"\u0b0c", "\u0b0f"-"\u0b10", "\u0b13"-"\u0b28", 456 "\u0b2a"-"\u0b30", "\u0b32"-"\u0b33", "\u0b35"-"\u0b39", "\u0b3c"-"\u0b44", "\u0b47"-"\u0b48", 457 "\u0b4b"-"\u0b4d", "\u0b56"-"\u0b57", "\u0b5c"-"\u0b5d", "\u0b5f"-"\u0b63", "\u0b66"-"\u0b6f", 458 "\u0b71", "\u0b82"-"\u0b83", "\u0b85"-"\u0b8a", "\u0b8e"-"\u0b90", "\u0b92"-"\u0b95", "\u0b99"-"\u0b9a", 459 "\u0b9c", "\u0b9e"-"\u0b9f", "\u0ba3"-"\u0ba4", "\u0ba8"-"\u0baa", "\u0bae"-"\u0bb9", "\u0bbe"-"\u0bc2", 460 "\u0bc6"-"\u0bc8", "\u0bca"-"\u0bcd", "\u0bd0", "\u0bd7", "\u0be6"-"\u0bef", "\u0bf9", "\u0c01"-"\u0c03", 461 "\u0c05"-"\u0c0c", "\u0c0e"-"\u0c10", "\u0c12"-"\u0c28", "\u0c2a"-"\u0c33", "\u0c35"-"\u0c39", 462 "\u0c3d"-"\u0c44", "\u0c46"-"\u0c48", "\u0c4a"-"\u0c4d", "\u0c55"-"\u0c56", "\u0c58"-"\u0c59", 463 "\u0c60"-"\u0c63", "\u0c66"-"\u0c6f", "\u0c82"-"\u0c83", "\u0c85"-"\u0c8c", "\u0c8e"-"\u0c90", 464 "\u0c92"-"\u0ca8", "\u0caa"-"\u0cb3", "\u0cb5"-"\u0cb9", "\u0cbc"-"\u0cc4", "\u0cc6"-"\u0cc8", 465 "\u0cca"-"\u0ccd", "\u0cd5"-"\u0cd6", "\u0cde", "\u0ce0"-"\u0ce3", "\u0ce6"-"\u0cef", "\u0cf1"-"\u0cf2", 466 "\u0d02"-"\u0d03", "\u0d05"-"\u0d0c", "\u0d0e"-"\u0d10", "\u0d12"-"\u0d3a", "\u0d3d"-"\u0d44", 467 "\u0d46"-"\u0d48", "\u0d4a"-"\u0d4e", "\u0d57", "\u0d60"-"\u0d63", "\u0d66"-"\u0d6f", "\u0d7a"-"\u0d7f", 468 "\u0d82"-"\u0d83", "\u0d85"-"\u0d96", "\u0d9a"-"\u0db1", "\u0db3"-"\u0dbb", "\u0dbd", "\u0dc0"-"\u0dc6", 469 "\u0dca", "\u0dcf"-"\u0dd4", "\u0dd6", "\u0dd8"-"\u0ddf", "\u0df2"-"\u0df3", "\u0e01"-"\u0e3a", 470 "\u0e3f"-"\u0e4e", "\u0e50"-"\u0e59", "\u0e81"-"\u0e82", "\u0e84", "\u0e87"-"\u0e88", "\u0e8a", 471 "\u0e8d", "\u0e94"-"\u0e97", "\u0e99"-"\u0e9f", "\u0ea1"-"\u0ea3", "\u0ea5", "\u0ea7", "\u0eaa"-"\u0eab", 472 "\u0ead"-"\u0eb9", "\u0ebb"-"\u0ebd", "\u0ec0"-"\u0ec4", "\u0ec6", "\u0ec8"-"\u0ecd", "\u0ed0"-"\u0ed9", 473 "\u0edc"-"\u0edf", "\u0f00", "\u0f18"-"\u0f19", "\u0f20"-"\u0f29", "\u0f35", "\u0f37", "\u0f39", 474 "\u0f3e"-"\u0f47", "\u0f49"-"\u0f6c", "\u0f71"-"\u0f84", "\u0f86"-"\u0f97", "\u0f99"-"\u0fbc", 475 "\u0fc6", "\u1000"-"\u1049", "\u1050"-"\u109d", "\u10a0"-"\u10c5", "\u10c7", "\u10cd", "\u10d0"-"\u10fa", 476 "\u10fc"-"\u1248", "\u124a"-"\u124d", "\u1250"-"\u1256", "\u1258", "\u125a"-"\u125d", "\u1260"-"\u1288", 477 "\u128a"-"\u128d", "\u1290"-"\u12b0", "\u12b2"-"\u12b5", "\u12b8"-"\u12be", "\u12c0", "\u12c2"-"\u12c5", 478 "\u12c8"-"\u12d6", "\u12d8"-"\u1310", "\u1312"-"\u1315", "\u1318"-"\u135a", "\u135d"-"\u135f", 479 "\u1380"-"\u138f", "\u13a0"-"\u13f4", "\u1401"-"\u166c", "\u166f"-"\u167f", "\u1681"-"\u169a", 480 "\u16a0"-"\u16ea", "\u16ee"-"\u16f0", "\u1700"-"\u170c", "\u170e"-"\u1714", "\u1720"-"\u1734", 481 "\u1740"-"\u1753", "\u1760"-"\u176c", "\u176e"-"\u1770", "\u1772"-"\u1773", "\u1780"-"\u17d3", 482 "\u17d7", "\u17db"-"\u17dd", "\u17e0"-"\u17e9", "\u180b"-"\u180d", "\u1810"-"\u1819", "\u1820"-"\u1877", 483 "\u1880"-"\u18aa", "\u18b0"-"\u18f5", "\u1900"-"\u191c", "\u1920"-"\u192b", "\u1930"-"\u193b", 484 "\u1946"-"\u196d", "\u1970"-"\u1974", "\u1980"-"\u19ab", "\u19b0"-"\u19c9", "\u19d0"-"\u19d9", 485 "\u1a00"-"\u1a1b", "\u1a20"-"\u1a5e", "\u1a60"-"\u1a7c", "\u1a7f"-"\u1a89", "\u1a90"-"\u1a99", 486 "\u1aa7", "\u1b00"-"\u1b4b", "\u1b50"-"\u1b59", "\u1b6b"-"\u1b73", "\u1b80"-"\u1bf3", "\u1c00"-"\u1c37", 487 "\u1c40"-"\u1c49", "\u1c4d"-"\u1c7d", "\u1cd0"-"\u1cd2", "\u1cd4"-"\u1cf6", "\u1d00"-"\u1de6", 488 "\u1dfc"-"\u1f15", "\u1f18"-"\u1f1d", "\u1f20"-"\u1f45", "\u1f48"-"\u1f4d", "\u1f50"-"\u1f57", 489 "\u1f59", "\u1f5b", "\u1f5d", "\u1f5f"-"\u1f7d", "\u1f80"-"\u1fb4", "\u1fb6"-"\u1fbc", "\u1fbe", 490 "\u1fc2"-"\u1fc4", "\u1fc6"-"\u1fcc", "\u1fd0"-"\u1fd3", "\u1fd6"-"\u1fdb", "\u1fe0"-"\u1fec", 491 "\u1ff2"-"\u1ff4", "\u1ff6"-"\u1ffc", "\u200b"-"\u200f", "\u202a"-"\u202e", "\u203f"-"\u2040", 492 "\u2054", "\u2060"-"\u2064", "\u206a"-"\u206f", "\u2071", "\u207f", "\u2090"-"\u209c", "\u20a0"-"\u20ba", 493 "\u20d0"-"\u20dc", "\u20e1", "\u20e5"-"\u20f0", "\u2102", "\u2107", "\u210a"-"\u2113", "\u2115", 494 "\u2119"-"\u211d", "\u2124", "\u2126", "\u2128", "\u212a"-"\u212d", "\u212f"-"\u2139", "\u213c"-"\u213f", 495 "\u2145"-"\u2149", "\u214e", "\u2160"-"\u2188", "\u2c00"-"\u2c2e", "\u2c30"-"\u2c5e", "\u2c60"-"\u2ce4", 496 "\u2ceb"-"\u2cf3", "\u2d00"-"\u2d25", "\u2d27", "\u2d2d", "\u2d30"-"\u2d67", "\u2d6f", "\u2d7f"-"\u2d96", 497 "\u2da0"-"\u2da6", "\u2da8"-"\u2dae", "\u2db0"-"\u2db6", "\u2db8"-"\u2dbe", "\u2dc0"-"\u2dc6", 498 "\u2dc8"-"\u2dce", "\u2dd0"-"\u2dd6", "\u2dd8"-"\u2dde", "\u2de0"-"\u2dff", "\u2e2f", "\u3005"-"\u3007", 499 "\u3021"-"\u302f", "\u3031"-"\u3035", "\u3038"-"\u303c", "\u3041"-"\u3096", "\u3099"-"\u309a", 500 "\u309d"-"\u309f", "\u30a1"-"\u30fa", "\u30fc"-"\u30ff", "\u3105"-"\u312d", "\u3131"-"\u318e", 501 "\u31a0"-"\u31ba", "\u31f0"-"\u31ff", "\u3400"-"\u4db5", "\u4e00"-"\u9fcc", "\ua000"-"\ua48c", 502 "\ua4d0"-"\ua4fd", "\ua500"-"\ua60c", "\ua610"-"\ua62b", "\ua640"-"\ua66f", "\ua674"-"\ua67d", 503 "\ua67f"-"\ua697", "\ua69f"-"\ua6f1", "\ua717"-"\ua71f", "\ua722"-"\ua788", "\ua78b"-"\ua78e", 504 "\ua790"-"\ua793", "\ua7a0"-"\ua7aa", "\ua7f8"-"\ua827", "\ua838", "\ua840"-"\ua873", "\ua880"-"\ua8c4", 505 "\ua8d0"-"\ua8d9", "\ua8e0"-"\ua8f7", "\ua8fb", "\ua900"-"\ua92d", "\ua930"-"\ua953", "\ua960"-"\ua97c", 506 "\ua980"-"\ua9c0", "\ua9cf"-"\ua9d9", "\uaa00"-"\uaa36", "\uaa40"-"\uaa4d", "\uaa50"-"\uaa59", 507 "\uaa60"-"\uaa76", "\uaa7a"-"\uaa7b", "\uaa80"-"\uaac2", "\uaadb"-"\uaadd", "\uaae0"-"\uaaef", 508 "\uaaf2"-"\uaaf6", "\uab01"-"\uab06", "\uab09"-"\uab0e", "\uab11"-"\uab16", "\uab20"-"\uab26", 509 "\uab28"-"\uab2e", "\uabc0"-"\uabea", "\uabec"-"\uabed", "\uabf0"-"\uabf9", "\uac00"-"\ud7a3", 510 "\ud7b0"-"\ud7c6", "\ud7cb"-"\ud7fb", "\ud800"-"\udfff", "\uf900"-"\ufa6d", "\ufa70"-"\ufad9", 511 "\ufb00"-"\ufb06", "\ufb13"-"\ufb17", "\ufb1d"-"\ufb28", "\ufb2a"-"\ufb36", "\ufb38"-"\ufb3c", 512 "\ufb3e", "\ufb40"-"\ufb41", "\ufb43"-"\ufb44", "\ufb46"-"\ufbb1", "\ufbd3"-"\ufd3d", "\ufd50"-"\ufd8f", 513 "\ufd92"-"\ufdc7", "\ufdf0"-"\ufdfc", "\ufe00"-"\ufe0f", "\ufe20"-"\ufe26", "\ufe33"-"\ufe34", 514 "\ufe4d"-"\ufe4f", "\ufe69", "\ufe70"-"\ufe74", "\ufe76"-"\ufefc", "\ufeff", "\uff04", "\uff10"-"\uff19", 515 "\uff21"-"\uff3a", "\uff3f", "\uff41"-"\uff5a", "\uff66"-"\uffbe", "\uffc2"-"\uffc7", "\uffca"-"\uffcf", 516 "\uffd2"-"\uffd7", "\uffda"-"\uffdc", "\uffe0"-"\uffe1", "\uffe5"-"\uffe6", "\ufff9"-"\ufffb" ] 517 | <UNICODE_ESCAPE> 518 > 519} 520 521/* SEPARATORS */ 522 523TOKEN : 524{ 525 < LPAREN: "(" > 526| < RPAREN: ")" > 527| < LBRACE: "{" > 528| < RBRACE: "}" > 529| < LBRACKET: "[" > 530| < RBRACKET: "]" > 531| < SEMICOLON: ";" > 532| < COMMA: "," > 533| < DOT: "." > 534| < AT: "@" > 535} 536 537/* OPERATORS */ 538 539TOKEN : 540{ 541 < ASSIGN: "=" > 542| < LT: "<" > 543| < BANG: "!" > 544| < TILDE: "~" > 545| < HOOK: "?" > 546| < COLON: ":" > 547| < EQ: "==" > 548| < LE: "<=" > 549| < GE: ">=" > 550| < NE: "!=" > 551| < SC_OR: "||" > 552| < SC_AND: "&&" > 553| < INCR: "++" > 554| < DECR: "--" > 555| < PLUS: "+" > 556| < MINUS: "-" > 557| < STAR: "*" > 558| < SLASH: "/" > 559| < BIT_AND: "&" > 560| < BIT_OR: "|" > 561| < XOR: "^" > 562| < REM: "%" > 563| < LSHIFT: "<<" > 564| < PLUSASSIGN: "+=" > 565| < MINUSASSIGN: "-=" > 566| < STARASSIGN: "*=" > 567| < SLASHASSIGN: "/=" > 568| < ANDASSIGN: "&=" > 569| < ORASSIGN: "|=" > 570| < XORASSIGN: "^=" > 571| < REMASSIGN: "%=" > 572| < LSHIFTASSIGN: "<<=" > 573| < RSIGNEDSHIFTASSIGN: ">>=" > 574| < RUNSIGNEDSHIFTASSIGN: ">>>=" > 575| < ELLIPSIS: "..." > 576| < ARROW: "->" > 577| < DOUBLECOLON: "::" > 578} 579 580/* >'s need special attention due to generics syntax. */ 581TOKEN : 582{ 583 < RUNSIGNEDSHIFT: ">>>" > 584 { 585 matchedToken.kind = GT; 586 matchedToken.realKind = RUNSIGNEDSHIFT; 587 input_stream.backup(2); 588 } 589| < RSIGNEDSHIFT: ">>" > 590 { 591 matchedToken.kind = GT; 592 matchedToken.realKind = RSIGNEDSHIFT; 593 input_stream.backup(1); 594 } 595| < GT: ">" > 596} 597 598TOKEN: { <CTRL_Z: "\u001A" /** ctrl+z char **/> } 599 600/***************************************** 601 * THE JAVA LANGUAGE GRAMMAR STARTS HERE * 602 *****************************************/ 603 604/* 605 * Program structuring syntax follows. 606 */ 607 608CompilationUnit CompilationUnit(): 609{ 610 PackageDeclaration pakage = null; 611 NodeList<ImportDeclaration> imports = emptyList(); 612 ImportDeclaration in = null; 613 NodeList<TypeDeclaration<?>> types = emptyList(); 614 ModifierHolder modifier; 615 TypeDeclaration tn = null; 616 ModuleDeclaration module = null; 617} 618{ 619 try { 620 ( LOOKAHEAD(2)";" )* 621 [ LOOKAHEAD(PackageDeclaration()) pakage = PackageDeclaration() ] 622 ( 623 in = ImportDeclaration() { imports = add(imports, in); } 624 | 625 ( 626 modifier = Modifiers() 627 ( 628 tn = ClassOrInterfaceDeclaration(modifier) { types = add(types, tn); } 629 | 630 tn = EnumDeclaration(modifier) { types = add(types, tn); } 631 | 632 tn = AnnotationTypeDeclaration(modifier) { types = add(types, tn); } 633 | 634 module = ModuleDeclaration(modifier) 635 | 636 ";" 637 ) 638 ) 639 )* 640 (<EOF> | <CTRL_Z>) 641 { return new CompilationUnit(range(token_source.getHomeToken(), token()), pakage, imports, types, module); } 642 } catch (ParseException e) { 643 recover(EOF, e); 644 final CompilationUnit compilationUnit = new CompilationUnit(range(token_source.getHomeToken(), token()), null, new NodeList<ImportDeclaration>(), new NodeList<TypeDeclaration<?>>(), null); 645 compilationUnit.setParsed(UNPARSABLE); 646 return compilationUnit; 647 } 648} 649 650PackageDeclaration PackageDeclaration(): 651{ 652 NodeList<AnnotationExpr> annotations = new NodeList<AnnotationExpr>(); 653 Name name; 654 JavaToken begin; 655} 656{ 657 annotations = Annotations() 658 "package" {begin = token();} name = Name() ";" 659 { return new PackageDeclaration(range(begin, token()), annotations, name); } 660} 661 662 663ImportDeclaration ImportDeclaration(): 664{ 665 Name name; 666 boolean isStatic = false; 667 boolean isAsterisk = false; 668 JavaToken begin; 669} 670{ 671 "import" {begin = token();} 672 [ "static" { isStatic = true; } ] 673 name = Name() 674 [ "." "*" { isAsterisk = true; } ] ";" 675 { return new ImportDeclaration(range(begin, token()), name, isStatic, isAsterisk); } 676} 677 678/* 679 * Modifiers. We match all modifiers in a single rule to reduce the chances of 680 * syntax errors for simple modifier mistakes. It will also enable us to give 681 * better error messages. 682 */ 683 684ModifierHolder Modifiers(): 685{ 686 JavaToken begin = INVALID; 687 EnumSet<Modifier> modifiers = EnumSet.noneOf(Modifier.class); 688 NodeList<AnnotationExpr> annotations = new NodeList<AnnotationExpr>(); 689 AnnotationExpr ann; 690} 691{ 692 ( 693 LOOKAHEAD(2) 694 ( 695 "public" { addModifier(modifiers, Modifier.PUBLIC); begin = orIfInvalid(begin, token()); } 696 | 697 "static" { addModifier(modifiers, Modifier.STATIC); begin = orIfInvalid(begin, token()); } 698 | 699 "protected" { addModifier(modifiers, Modifier.PROTECTED); begin = orIfInvalid(begin, token()); } 700 | 701 "private" { addModifier(modifiers, Modifier.PRIVATE); begin = orIfInvalid(begin, token()); } 702 | 703 "final" { addModifier(modifiers, Modifier.FINAL); begin = orIfInvalid(begin, token()); } 704 | 705 "abstract" { addModifier(modifiers, Modifier.ABSTRACT); begin = orIfInvalid(begin, token()); } 706 | 707 "synchronized" { addModifier(modifiers, Modifier.SYNCHRONIZED); begin = orIfInvalid(begin, token()); } 708 | 709 "native" { addModifier(modifiers, Modifier.NATIVE); begin = orIfInvalid(begin, token()); } 710 | 711 "transient" { addModifier(modifiers, Modifier.TRANSIENT); begin = orIfInvalid(begin, token()); } 712 | 713 "volatile" { addModifier(modifiers, Modifier.VOLATILE); begin = orIfInvalid(begin, token()); } 714 | 715 "strictfp" { addModifier(modifiers, Modifier.STRICTFP); begin = orIfInvalid(begin, token()); } 716 | 717 "transitive" { addModifier(modifiers, Modifier.TRANSITIVE); begin = orIfInvalid(begin, token()); } 718 | 719 "default" { addModifier(modifiers, Modifier.DEFAULT); begin = orIfInvalid(begin, token()); } 720 | 721 ann = Annotation() { annotations = add(annotations, ann); begin = orIfInvalid(begin, ann); } 722 ) 723 )* 724 725 { 726 return new ModifierHolder(begin, modifiers, annotations); 727 } 728} 729 730/* 731 * Declaration syntax follows. 732 */ 733 734ClassOrInterfaceDeclaration ClassOrInterfaceDeclaration(ModifierHolder modifier): 735{ 736 boolean isInterface = false; 737 SimpleName name; 738 RangedList<TypeParameter> typePar = new RangedList<TypeParameter>(emptyList()); 739 NodeList<ClassOrInterfaceType> extList = emptyList(); 740 NodeList<ClassOrInterfaceType> impList = emptyList(); 741 NodeList<BodyDeclaration<?>> members = emptyList(); 742 JavaToken begin = modifier.begin; 743} 744{ 745 ( "class" | "interface" { isInterface = true; } ) { begin = orIfInvalid(begin, token()); } 746 name = SimpleName() 747 [ typePar = TypeParameters() ] 748 [ extList = ExtendsList() ] 749 [ impList = ImplementsList() ] 750 members = ClassOrInterfaceBody() 751 752 { return new ClassOrInterfaceDeclaration(range(begin, token()), modifier.modifiers, modifier.annotations, isInterface, name, typePar.list, extList, impList, members); } 753} 754 755NodeList<ClassOrInterfaceType> ExtendsList(): 756{ 757 boolean extendsMoreThanOne = false; 758 NodeList<ClassOrInterfaceType> ret = new NodeList<ClassOrInterfaceType>(); 759 ClassOrInterfaceType cit; 760} 761{ 762 "extends" cit = AnnotatedClassOrInterfaceType() { ret.add(cit); } 763 ( "," cit = AnnotatedClassOrInterfaceType() { ret.add(cit); extendsMoreThanOne = true; } )* 764 { return ret; } 765} 766 767NodeList<ClassOrInterfaceType> ImplementsList(): 768{ 769 NodeList<ClassOrInterfaceType> ret = new NodeList<ClassOrInterfaceType>(); 770 ClassOrInterfaceType cit; 771} 772{ 773 "implements" cit = AnnotatedClassOrInterfaceType() { ret.add(cit); } 774 ( "," cit = AnnotatedClassOrInterfaceType() { ret.add(cit); } )* 775 { return ret; } 776} 777 778EnumDeclaration EnumDeclaration(ModifierHolder modifier): 779{ 780 SimpleName name; 781 NodeList<ClassOrInterfaceType> impList = emptyList(); 782 EnumConstantDeclaration entry; 783 NodeList<EnumConstantDeclaration> entries = emptyList(); 784 BodyDeclaration<?> member; 785 NodeList<BodyDeclaration<?>> members = emptyList(); 786 JavaToken begin = modifier.begin; 787} 788{ 789 "enum" { begin = orIfInvalid(begin, token()); } 790 name = SimpleName() 791 [ impList = ImplementsList() ] 792 "{" 793 [ 794 entry = EnumConstantDeclaration() { entries.add(entry); } ( LOOKAHEAD(2) "," entry = EnumConstantDeclaration() { entries.add(entry); } )* 795 ] 796 [ "," ] 797 [ 798 ";" ( 799 member = ClassOrInterfaceBodyDeclaration() { members = add(members, member); } 800 | 801 ";" 802 )* 803 ] 804 "}" 805 806 { return new EnumDeclaration(range(begin, token()), modifier.modifiers, modifier.annotations, name, impList, entries, members); } 807} 808 809 810EnumConstantDeclaration EnumConstantDeclaration(): 811{ 812 NodeList<AnnotationExpr> annotations = new NodeList<AnnotationExpr>(); 813 AnnotationExpr ann; 814 SimpleName name; 815 NodeList<Expression> args = emptyList(); 816 NodeList<BodyDeclaration<?>> classBody = emptyList(); 817 JavaToken begin = INVALID; 818} 819{ 820 { } 821 ( ann = Annotation() { annotations = add(annotations, ann); begin = orIfInvalid(begin, ann); } )* 822 name = SimpleName() { begin = orIfInvalid(begin, token()); } 823 [ args = Arguments() ] [ classBody = ClassOrInterfaceBody() ] 824 { 825 return new EnumConstantDeclaration(range(begin, token()), annotations, name, args, classBody); 826 } 827} 828 829/** 830 * If the list inside the returned RangedList is null, there are no brackets. 831 * If it is empty, there are brackets, but nothing is in them <>. 832 * The normal case is that it contains TypeParameters, like <A, B, C>. 833 */ 834RangedList<TypeParameter> TypeParameters(): 835{ 836 RangedList<TypeParameter> ret = new RangedList<TypeParameter>(new NodeList<TypeParameter>()); 837 TypeParameter tp; 838 NodeList<AnnotationExpr> annotations; 839} 840{ 841 "<" { ret.beginAt(token()); } 842 annotations = Annotations() 843 tp = TypeParameter(annotations) { ret.add(tp); annotations = null; } 844 ( "," 845 annotations = Annotations() tp = TypeParameter(annotations) { ret.add(tp); annotations = null; } )* 846 ">" { ret.endAt(token()); } 847 { return ret; } 848} 849 850TypeParameter TypeParameter(NodeList<AnnotationExpr> annotations): 851{ 852 SimpleName name; 853 NodeList<ClassOrInterfaceType> typeBound = emptyList(); 854 JavaToken begin; 855} 856{ 857 name = SimpleName() { begin=token(); } [ typeBound = TypeBound() ] 858 { return new TypeParameter(range(begin, token()), name, typeBound, annotations); } 859} 860 861NodeList<ClassOrInterfaceType> TypeBound(): 862{ 863 NodeList<ClassOrInterfaceType> ret = emptyList(); 864 ClassOrInterfaceType cit; 865} 866{ 867 "extends" cit = AnnotatedClassOrInterfaceType() { ret.add(cit); } 868 ( "&" cit = AnnotatedClassOrInterfaceType() { ret.add(cit); } )* 869 { return ret; } 870} 871 872NodeList<BodyDeclaration<?>> ClassOrInterfaceBody(): 873{ 874 NodeList<BodyDeclaration<?>> ret = emptyList(); 875 BodyDeclaration member; 876} 877{ 878 "{" ( 879 member = ClassOrInterfaceBodyDeclaration() { ret.add(member); } 880 | 881 ";" 882 )* "}" 883 { return ret; } 884} 885 886BodyDeclaration<?> ClassOrInterfaceBodyDeclaration(): 887{ 888 ModifierHolder modifier; 889 BodyDeclaration<?> ret; 890} 891{ 892 ( 893 LOOKAHEAD(2) 894 ret = InitializerDeclaration() 895 | 896 // Just get all the modifiers out of the way. If you want to do 897 // more checks, pass the modifiers down to the member 898 modifier = Modifiers() 899 ( 900 ret = ClassOrInterfaceDeclaration(modifier) 901 | LOOKAHEAD("enum") 902 ret = EnumDeclaration(modifier) 903 | LOOKAHEAD("@" "interface") 904 ret = AnnotationTypeDeclaration(modifier) 905 | LOOKAHEAD( [ TypeParameters() ] Identifier() "(" ) 906 ret = ConstructorDeclaration(modifier) 907 | LOOKAHEAD( Type() Identifier() ( ArrayBracketPair() )* ( "," | "=" | ";" ) ) 908 ret = FieldDeclaration(modifier) 909 | 910 ret = MethodDeclaration(modifier) 911 ) 912 ) 913 { return ret; } 914} 915 916FieldDeclaration FieldDeclaration(ModifierHolder modifier): 917{ 918 Type partialType; 919 NodeList<VariableDeclarator> variables = new NodeList<VariableDeclarator>(); 920 VariableDeclarator val; 921} 922{ 923 // Modifiers are already matched in the caller 924 partialType = Type(emptyList()) val = VariableDeclarator(partialType) { variables.add(val); } 925 ( "," val = VariableDeclarator(partialType) { variables.add(val); } )* ";" 926 { 927 JavaToken begin = orIfInvalid(modifier.begin, partialType); 928 return new FieldDeclaration(range(begin, token()), modifier.modifiers, modifier.annotations, variables); 929 } 930} 931 932VariableDeclarator VariableDeclarator(Type partialType): 933{ 934 Pair<SimpleName, List<ArrayBracketPair>> id; 935 Expression init = null; 936} 937{ 938 id = VariableDeclaratorId() [ "=" init = VariableInitializer() ] 939 { return new VariableDeclarator(range(id.a, token()), juggleArrayType(partialType, id.b), id.a, init); } 940} 941 942Pair<SimpleName, List<ArrayBracketPair>> VariableDeclaratorId(): 943{ 944 SimpleName name; 945 JavaToken begin; 946 ArrayBracketPair arrayBracketPair; 947 List<ArrayBracketPair> arrayBracketPairs = new ArrayList(0); 948} 949{ 950 name = SimpleName() { begin=token();} ( arrayBracketPair = ArrayBracketPair(Origin.NAME) { arrayBracketPairs=add(arrayBracketPairs, arrayBracketPair); } )* 951 { 952 if(storeTokens) { 953 name.setTokenRange(name.getTokenRange().get().withEnd(token())); 954 } 955 return new Pair(name, arrayBracketPairs); 956 } 957} 958 959Expression VariableInitializer(): 960{ 961 Expression ret; 962} 963{ 964 ( 965 ret = ArrayInitializer() 966 | 967 ret = Expression() 968 ) 969 { return ret;} 970} 971 972ArrayInitializerExpr ArrayInitializer(): 973{ 974 NodeList<Expression> values = emptyList(); 975 Expression val; 976 JavaToken begin; 977} 978{ 979 "{" {begin=token();} [ val = VariableInitializer() { values = add(values, val); } ( LOOKAHEAD(2) "," val = VariableInitializer() { values = add(values, val); } )* ] [ "," ] "}" 980 { return new ArrayInitializerExpr(range(begin, token()), values); } 981} 982 983MethodDeclaration MethodDeclaration(ModifierHolder modifier): 984{ 985 RangedList<TypeParameter> typeParameters = new RangedList<TypeParameter>(emptyList()); 986 Type type; 987 SimpleName name; 988 Pair<NodeList<Parameter>, ReceiverParameter> parameters = new Pair<NodeList<Parameter>, ReceiverParameter>(emptyList(), null); 989 ArrayBracketPair arrayBracketPair; 990 List<ArrayBracketPair> arrayBracketPairs = new ArrayList(0); 991 NodeList<ReferenceType> throws_ = emptyList(); 992 BlockStmt body = null; 993 NodeList<AnnotationExpr> annotations; 994 JavaToken begin = modifier.begin; 995 ReferenceType throwType; 996} 997{ 998 // Modifiers already matched in the caller! 999 [ typeParameters = TypeParameters() { begin = orIfInvalid(begin, typeParameters.range.getBegin()); } ] 1000 annotations = Annotations() { modifier.annotations.addAll(annotations); begin = orIfInvalid(begin, nodeListBegin(annotations)); } 1001 type = ResultType(emptyList()) { begin = orIfInvalid(begin, type); } 1002 name = SimpleName() parameters = Parameters() ( arrayBracketPair = ArrayBracketPair(Origin.NAME) { arrayBracketPairs=add(arrayBracketPairs, arrayBracketPair); } )* 1003 [ "throws" throwType = AnnotatedReferenceType() { throws_ = add(throws_, throwType); } 1004 ("," throwType = AnnotatedReferenceType() { throws_ = add(throws_, throwType); } )* ] 1005 ( body = Block() | ";" ) 1006 { 1007 type = juggleArrayType(type, arrayBracketPairs); 1008 return new MethodDeclaration(range(begin, token()), modifier.modifiers, modifier.annotations, typeParameters.list, type, name, parameters.a, throws_, body, parameters.b); 1009 } 1010} 1011 1012ReferenceType AnnotatedReferenceType(): 1013{ 1014 NodeList<AnnotationExpr> annotations; 1015 ReferenceType type; 1016} 1017{ 1018 annotations = Annotations() 1019 type = ReferenceType(annotations) 1020 { return type; } 1021} 1022 1023Type AnnotatedType(): 1024{ 1025 NodeList<AnnotationExpr> annotations; 1026 Type type; 1027} 1028{ 1029 annotations = Annotations() 1030 type = Type(annotations) 1031 { return type; } 1032} 1033 1034Pair<NodeList<Parameter>, ReceiverParameter> Parameters(): 1035{ 1036 NodeList<Parameter> ret = emptyList(); 1037 Parameter par; 1038 ReceiverParameter rp = null; 1039} 1040{ 1041 "(" 1042 [ 1043 ( LOOKAHEAD(ReceiverParameter()) 1044 rp = ReceiverParameter() 1045 | 1046 par = Parameter() { ret = add(ret, par); } 1047 ) 1048 ( "," par = Parameter() { ret = add(ret, par); } )* 1049 ] 1050 ")" 1051 { return new Pair(ret, rp); } 1052} 1053 1054NodeList<Parameter> LambdaParameters(): 1055{ 1056 NodeList<Parameter> ret = null; 1057 Parameter par; 1058} 1059{ 1060 par = Parameter() { ret = add(ret, par); } ( "," par = Parameter() { ret = add(ret, par); } )* 1061 { return ret; } 1062} 1063 1064NodeList<Parameter> InferredLambdaParameters(): 1065{ 1066 NodeList<Parameter> ret = null; 1067 Pair<SimpleName, List<ArrayBracketPair>> id; 1068} 1069{ 1070 id = VariableDeclaratorId() { ret = add(ret, new Parameter(range(id.a, id.a), EnumSet.noneOf(Modifier.class), emptyList(), new UnknownType(), false, emptyList(), id.a));} 1071 ( 1072 "," id = VariableDeclaratorId() { ret = add(ret, new Parameter(range(id.a, id.a), EnumSet.noneOf(Modifier.class), emptyList(), new UnknownType(), false, emptyList(), id.a)); } 1073 )* 1074 { return ret; } 1075} 1076 1077Parameter Parameter(): 1078{ 1079 ModifierHolder modifier; 1080 Type partialType; 1081 boolean isVarArg = false; 1082 Pair<SimpleName, List<ArrayBracketPair>> id; 1083 NodeList<AnnotationExpr> varArgAnnotations = emptyList(); 1084} 1085{ 1086 modifier = Modifiers() partialType = Type(emptyList()) [ varArgAnnotations = Annotations() "..." { isVarArg = true;} ] 1087 id = VariableDeclaratorId() 1088 { 1089 JavaToken begin = orIfInvalid(modifier.begin, partialType); 1090 return new Parameter(range(begin, token()), modifier.modifiers, modifier.annotations, juggleArrayType(partialType, id.b), isVarArg, varArgAnnotations, id.a); 1091 } 1092} 1093 1094ReceiverParameter ReceiverParameter(): 1095{ 1096 Type partialType; 1097 Name id; 1098 NodeList<AnnotationExpr> annotations = emptyList(); 1099} 1100{ 1101 annotations = Annotations() 1102 partialType = Type(emptyList()) 1103 id = ReceiverParameterId() 1104 { 1105 return new ReceiverParameter(range(partialType, token()), annotations, partialType, id); 1106 } 1107} 1108 1109Name ReceiverParameterId(): 1110{ 1111 Name ret = null; 1112 NodeList<AnnotationExpr> annotations; 1113} 1114{ 1115 [ LOOKAHEAD(Name()) ret = Name() "."] annotations=Annotations() "this" 1116 { return new Name(tokenRange(), ret, token.image, annotations); } 1117} 1118 1119ConstructorDeclaration ConstructorDeclaration(ModifierHolder modifier): 1120{ 1121 RangedList<TypeParameter> typeParameters = new RangedList<TypeParameter>(emptyList()); 1122 SimpleName name; 1123 Pair<NodeList<Parameter>, ReceiverParameter> parameters = new Pair<NodeList<Parameter>, ReceiverParameter>(emptyList(), null); 1124 NodeList<ReferenceType> throws_ = emptyList(); 1125 ExplicitConstructorInvocationStmt exConsInv = null; 1126 NodeList<Statement> stmts = emptyList(); 1127 JavaToken begin = modifier.begin; 1128 JavaToken blockBegin = INVALID; 1129 ReferenceType throwType; 1130} 1131{ 1132 [ typeParameters = TypeParameters() { begin = orIfInvalid(begin, typeParameters.range.getBegin()); } ] 1133 // Modifiers matched in the caller 1134 name = SimpleName() { begin = orIfInvalid(begin, typeParameters.range.getBegin()); begin = orIfInvalid(begin, token()); } parameters = Parameters() [ "throws" throwType = AnnotatedReferenceType() { throws_ = add(throws_, throwType); } 1135 ("," throwType = AnnotatedReferenceType() { throws_ = add(throws_, throwType); })* ] 1136 "{" { blockBegin=token(); } 1137 [ LOOKAHEAD(ExplicitConstructorInvocation()) exConsInv = ExplicitConstructorInvocation() ] 1138 stmts = Statements() 1139 "}" 1140 1141 { 1142 if (exConsInv != null) { 1143 stmts = prepend(stmts, exConsInv); 1144 } 1145 return new ConstructorDeclaration(range(begin, token()), modifier.modifiers, modifier.annotations, typeParameters.list, name, parameters.a, throws_, new BlockStmt(range(blockBegin, token()), stmts), parameters.b); 1146 } 1147} 1148 1149ExplicitConstructorInvocationStmt ExplicitConstructorInvocation(): 1150{ 1151 boolean isThis = false; 1152 NodeList<Expression> args; 1153 Expression expr = null; 1154 RangedList<Type> typeArgs = new RangedList<Type>(null); 1155 JavaToken begin = INVALID; 1156} 1157{ 1158 ( 1159 LOOKAHEAD([ TypeArguments() ] <THIS> "(") 1160 [ typeArgs = TypeArguments() { begin=typeArgs.range.getBegin(); } ] 1161 <THIS> { begin = orIfInvalid(begin, token()); isThis = true; } 1162 args = Arguments() ";" 1163 | 1164 [ 1165 LOOKAHEAD( PrimaryExpressionWithoutSuperSuffix() "." ) 1166 expr = PrimaryExpressionWithoutSuperSuffix() "." 1167 { begin = orIfInvalid(begin, expr); } 1168 ] 1169 [ typeArgs = TypeArguments() { begin = orIfInvalid(begin, typeArgs.range.getBegin()); } ] 1170 <SUPER> {begin = orIfInvalid(begin, token());} 1171 args = Arguments() ";" 1172 ) 1173 { return new ExplicitConstructorInvocationStmt(range(begin, token()),typeArgs.list, isThis, expr, args); } 1174} 1175 1176NodeList<Statement> Statements(): 1177{ 1178 NodeList<Statement> ret = emptyList(); 1179 Statement stmt; 1180} 1181{ 1182 ( LOOKAHEAD(2) stmt = BlockStatement() { ret = add(ret, stmt); } )* 1183 { return ret; } 1184} 1185 1186InitializerDeclaration InitializerDeclaration(): 1187{ 1188 BlockStmt body; 1189 JavaToken begin = INVALID; 1190 boolean isStatic = false; 1191} 1192{ 1193 [ "static" { isStatic = true; begin=token();} ] 1194 body = Block() {begin = orIfInvalid(begin, body);} 1195 { return new InitializerDeclaration(range(begin, token()), isStatic, body); } 1196} 1197 1198 1199/* 1200 * Type, name and expression syntax follows. 1201 */ 1202 1203Type Type(NodeList<AnnotationExpr> annotations): 1204{ 1205 Type ret; 1206} 1207{ 1208 ( 1209 LOOKAHEAD(2) ret = ReferenceType(annotations) 1210 | 1211 ret = PrimitiveType(annotations ) 1212 ) 1213 { return ret; } 1214} 1215 1216ReferenceType ReferenceType(NodeList<AnnotationExpr> annotations): 1217{ 1218 Type type; 1219 ArrayBracketPair arrayBracketPair; 1220 List<ArrayBracketPair> arrayBracketPairs = new ArrayList(0); 1221} 1222{ 1223 ( 1224 type = PrimitiveType(annotations) ( LOOKAHEAD(Annotations() "[") arrayBracketPair = ArrayBracketPair(Origin.TYPE) { arrayBracketPairs=add(arrayBracketPairs, arrayBracketPair); } )+ 1225 | 1226 type = ClassOrInterfaceType(annotations) ( LOOKAHEAD(Annotations() "[") arrayBracketPair = ArrayBracketPair(Origin.TYPE) { arrayBracketPairs=add(arrayBracketPairs, arrayBracketPair); } )* 1227 ) 1228 { return (ReferenceType)wrapInArrayTypes(type, arrayBracketPairs); } 1229} 1230 1231ArrayBracketPair ArrayBracketPair(Origin origin): 1232{ 1233 NodeList<AnnotationExpr> annotations; 1234 JavaToken begin = INVALID; 1235} 1236{ 1237 annotations = Annotations() 1238 "[" { begin = orIfInvalid(begin, token()); } "]" 1239 { return new ArrayBracketPair(range(begin, token()), origin, annotations); } 1240} 1241 1242IntersectionType IntersectionType(NodeList<AnnotationExpr> annotations): 1243{ 1244 JavaToken begin = INVALID; 1245 ReferenceType elementType; 1246 NodeList<ReferenceType> elements = emptyList(); 1247} 1248{ 1249 elementType = ReferenceType(annotations) { begin = orIfInvalid(begin, elementType); elements = add(elements, elementType); } 1250 "&" (elementType = AnnotatedReferenceType() { elements = add(elements, elementType); } )+ 1251 { return new IntersectionType(range(begin, token()), elements); } 1252} 1253 1254ClassOrInterfaceType AnnotatedClassOrInterfaceType(): 1255{ 1256 NodeList<AnnotationExpr> annotations = new NodeList<AnnotationExpr>(); 1257 ClassOrInterfaceType cit; 1258} 1259{ 1260 annotations = Annotations() 1261 cit = ClassOrInterfaceType(annotations) 1262 { return cit; } 1263} 1264 1265ClassOrInterfaceType ClassOrInterfaceType(NodeList<AnnotationExpr> firstAnnotations): 1266{ 1267 ClassOrInterfaceType ret; 1268 SimpleName name; 1269 RangedList<Type> typeArgs = new RangedList<Type>(null); 1270 JavaToken begin; 1271 NodeList<AnnotationExpr> annotations = new NodeList<AnnotationExpr>(); 1272} 1273{ 1274 name = SimpleName() {begin=token();} 1275 [ LOOKAHEAD(2) typeArgs = TypeArguments() ] 1276 { 1277 ret = new ClassOrInterfaceType(range(begin, token()), null, name, typeArgs.list, firstAnnotations); 1278 typeArgs = new RangedList<Type>(null); 1279 } 1280 ( 1281 LOOKAHEAD(2) "." annotations = Annotations() name = SimpleName() 1282 [ LOOKAHEAD(2) typeArgs = TypeArguments() ] 1283 { 1284 ret = new ClassOrInterfaceType(range(begin, token()), ret, name, typeArgs.list, annotations); 1285 typeArgs = new RangedList<Type>(null); 1286 } 1287 )* 1288 { return ret; } 1289} 1290 1291RangedList<Type> TypeArguments(): 1292{ 1293 RangedList<Type> ret = new RangedList<Type>(new NodeList<Type>()); 1294 Type type; 1295} 1296{ 1297 ( 1298 "<" { ret.beginAt(token()); } 1299 (type = TypeArgument() { ret.add(type); } ( "," type = TypeArgument() { ret.add(type); } )*)? 1300 ">" { ret.endAt(token()); } 1301 ) 1302 { return ret; } 1303} 1304 1305Type TypeArgument(): 1306{ 1307 Type ret; 1308 NodeList<AnnotationExpr> annotations; 1309} 1310{ 1311 annotations = Annotations() 1312 ( 1313 ret = Type(annotations) 1314 | 1315 ret = Wildcard(annotations) 1316 ) 1317 { return ret; } 1318} 1319 1320WildcardType Wildcard(NodeList<AnnotationExpr> firstAnnotations): 1321{ 1322 ReferenceType ext = null; 1323 ReferenceType sup = null; 1324 JavaToken begin; 1325 NodeList<AnnotationExpr> annotations = new NodeList<AnnotationExpr>(); 1326} 1327{ 1328 "?" {begin=token();} 1329 [ 1330 "extends" annotations = Annotations() ext = ReferenceType(annotations) 1331 | 1332 "super" annotations = Annotations() sup = ReferenceType(annotations) 1333 ] 1334 { 1335 return new WildcardType(range(begin, token()), ext, sup, firstAnnotations); 1336 } 1337} 1338 1339PrimitiveType PrimitiveType(NodeList<AnnotationExpr> annotations): 1340{ 1341 PrimitiveType ret; 1342} 1343{ 1344( 1345 "boolean" { ret = new PrimitiveType(tokenRange(), PrimitiveType.Primitive.BOOLEAN, annotations); } 1346| 1347 "char" { ret = new PrimitiveType(tokenRange(), PrimitiveType.Primitive.CHAR, annotations); } 1348| 1349 "byte" { ret = new PrimitiveType(tokenRange(), PrimitiveType.Primitive.BYTE, annotations); } 1350| 1351 "short" { ret = new PrimitiveType(tokenRange(), PrimitiveType.Primitive.SHORT, annotations); } 1352| 1353 "int" { ret = new PrimitiveType(tokenRange(), PrimitiveType.Primitive.INT, annotations); } 1354| 1355 "long" { ret = new PrimitiveType(tokenRange(), PrimitiveType.Primitive.LONG, annotations); } 1356| 1357 "float" { ret = new PrimitiveType(tokenRange(), PrimitiveType.Primitive.FLOAT, annotations); } 1358| 1359 "double" { ret = new PrimitiveType(tokenRange(), PrimitiveType.Primitive.DOUBLE, annotations); } 1360) 1361{ return ret; } 1362} 1363 1364Type ResultType(NodeList<AnnotationExpr> annotations): 1365{ 1366 Type ret; 1367} 1368{ 1369 ( 1370 "void" { ret = new VoidType(tokenRange()); } 1371 | 1372 ret = Type(annotations) 1373 ) 1374 { return ret; } 1375} 1376 1377Name Name(): 1378/* 1379 * A lookahead is required below since "Name" can be followed 1380 * by a ".*" when used in the context of an "ImportDeclaration". 1381 */ 1382{ 1383 Name ret; 1384 NodeList<AnnotationExpr> annotations = new NodeList<AnnotationExpr>(); 1385} 1386{ 1387 annotations=Annotations() Identifier() { ret = new Name(tokenRange(), null, token.image, annotations); } 1388 ( LOOKAHEAD("." Annotations() Identifier()) 1389 "." annotations=Annotations() Identifier() { ret = new Name(range(ret, token()), ret, token.image, annotations); } )* 1390 { return ret; } 1391} 1392 1393SimpleName SimpleName(): 1394{ 1395 SimpleName ret; 1396} 1397{ 1398 Identifier() { ret = new SimpleName(tokenRange(), token.image); } 1399 { return ret; } 1400} 1401 1402 1403String Identifier(): 1404{ 1405 String ret; 1406} 1407{ 1408 // Make sure the module info keywords don't interfere with normal Java parsing by matching them as normal identifiers. 1409 (<MODULE> | <REQUIRES> | <TO> | <WITH> | <OPEN> | <OPENS> | <USES> | <EXPORTS> | <PROVIDES> | <TRANSITIVE> | 1410 // Make sure older Java versions parse 1411 <ENUM> | <STRICTFP> | 1412 // An actual plain old identifier 1413 <IDENTIFIER>) { ret = token.image; setTokenKind(IDENTIFIER);} 1414 { return ret; } 1415} 1416 1417/* 1418 * Expression syntax follows. 1419 */ 1420 1421Expression Expression(): 1422/* 1423 * This expansion has been written this way instead of: 1424 * Assignment() | ConditionalExpression() 1425 * for performance reasons. 1426 * However, it is a weakening of the grammar for it allows the LHS of 1427 * assignments to be any conditional expression whereas it can only be 1428 * a primary expression. This is caught by a validation after parsing. 1429 */ 1430{ 1431 Expression ret; 1432 AssignExpr.Operator op; 1433 Expression value; 1434 Statement lambdaBody = null; 1435 RangedList<Type> typeArgs = new RangedList<Type>(null); 1436} 1437{ 1438 ret = ConditionalExpression() 1439 [ 1440 ( LOOKAHEAD(2) 1441 op = AssignmentOperator() value = Expression() { ret = new AssignExpr(range(ret, token()), ret, value, op); } 1442 | 1443 "->" lambdaBody = LambdaBody() 1444 { 1445 if (ret instanceof CastExpr) { 1446 ret = generateLambda(ret, lambdaBody); 1447 } else if (ret instanceof ConditionalExpr) { 1448 ConditionalExpr ce = (ConditionalExpr) ret; 1449 if(ce.getElseExpr() != null) { 1450 ce.setElseExpr(generateLambda(ce.getElseExpr(), lambdaBody)); 1451 } 1452 } else { 1453 ret = generateLambda(ret, lambdaBody); 1454 } 1455 } 1456 | 1457 "::" [typeArgs = TypeArguments() ] (Identifier() | "new") { ret = new MethodReferenceExpr(range(ret, token()), ret, typeArgs.list, token.image); } 1458 ) 1459 ] 1460 1461 { return ret; } 1462} 1463 1464AssignExpr.Operator AssignmentOperator(): 1465{ 1466 AssignExpr.Operator ret; 1467} 1468{ 1469 ( 1470 "=" { ret = AssignExpr.Operator.ASSIGN; } 1471 | "*=" { ret = AssignExpr.Operator.MULTIPLY; } 1472 | "/=" { ret = AssignExpr.Operator.DIVIDE; } 1473 | "%=" { ret = AssignExpr.Operator.REMAINDER; } 1474 | "+=" { ret = AssignExpr.Operator.PLUS; } 1475 | "-=" { ret = AssignExpr.Operator.MINUS; } 1476 | "<<=" { ret = AssignExpr.Operator.LEFT_SHIFT; } 1477 | ">>=" { ret = AssignExpr.Operator.SIGNED_RIGHT_SHIFT; } 1478 | ">>>=" { ret = AssignExpr.Operator.UNSIGNED_RIGHT_SHIFT; } 1479 | "&=" { ret = AssignExpr.Operator.BINARY_AND; } 1480 | "^=" { ret = AssignExpr.Operator.XOR; } 1481 | "|=" { ret = AssignExpr.Operator.BINARY_OR; } 1482 ) 1483 { return ret; } 1484} 1485 1486Expression ConditionalExpression(): 1487{ 1488 Expression ret; 1489 Expression left; 1490 Expression right; 1491} 1492{ 1493 ret = ConditionalOrExpression() 1494 [ "?" left = Expression() ":" right = ConditionalExpression() { ret = new ConditionalExpr(range(ret, token()), ret, left, right); } ] 1495 { return ret; } 1496} 1497 1498Expression ConditionalOrExpression(): 1499{ 1500 Expression ret; 1501 Expression right; 1502} 1503{ 1504 ret = ConditionalAndExpression() ( "||" right = ConditionalAndExpression() { ret = new BinaryExpr(range(ret, token()), ret, right, BinaryExpr.Operator.OR); } )* 1505 { return ret; } 1506} 1507 1508Expression ConditionalAndExpression(): 1509{ 1510 Expression ret; 1511 Expression right; 1512} 1513{ 1514 ret = InclusiveOrExpression() ( "&&" right = InclusiveOrExpression() { ret = new BinaryExpr(range(ret, token()), ret, right, BinaryExpr.Operator.AND); } )* 1515 { return ret; } 1516} 1517 1518Expression InclusiveOrExpression(): 1519{ 1520 Expression ret; 1521 Expression right; 1522} 1523{ 1524 ret = ExclusiveOrExpression() ( "|" right = ExclusiveOrExpression() { ret = new BinaryExpr(range(ret, token()), ret, right, BinaryExpr.Operator.BINARY_OR); } )* 1525 { return ret; } 1526} 1527 1528Expression ExclusiveOrExpression(): 1529{ 1530 Expression ret; 1531 Expression right; 1532} 1533{ 1534 ret = AndExpression() ( "^" right = AndExpression() { ret = new BinaryExpr(range(ret, token()), ret, right, BinaryExpr.Operator.XOR); } )* 1535 { return ret; } 1536} 1537 1538Expression AndExpression(): 1539{ 1540 Expression ret; 1541 Expression right; 1542} 1543{ 1544 ret = EqualityExpression() ( "&" right = EqualityExpression() { ret = new BinaryExpr(range(ret, token()), ret, right, BinaryExpr.Operator.BINARY_AND); } )* 1545 { return ret; } 1546} 1547 1548Expression EqualityExpression(): 1549{ 1550 Expression ret; 1551 Expression right; 1552 BinaryExpr.Operator op; 1553} 1554{ 1555 ret = InstanceOfExpression() 1556 ( 1557 ( "==" { op = BinaryExpr.Operator.EQUALS; } | 1558 "!=" { op = BinaryExpr.Operator.NOT_EQUALS; } 1559 ) right = InstanceOfExpression() { ret = new BinaryExpr(range(ret, token()), ret, right, op); } 1560 )* 1561 { return ret; } 1562} 1563 1564Expression InstanceOfExpression(): 1565{ 1566 Expression ret; 1567 ReferenceType type; 1568 NodeList<AnnotationExpr> annotations; 1569} 1570{ 1571 ret = RelationalExpression() [ "instanceof" type = AnnotatedReferenceType() { 1572 ret = new InstanceOfExpr(range(ret, token()), ret, type); 1573 } ] 1574 { return ret; } 1575} 1576 1577Expression RelationalExpression(): 1578{ 1579 Expression ret; 1580 Expression right; 1581 BinaryExpr.Operator op; 1582} 1583{ 1584 ret = ShiftExpression() 1585 ( 1586 ( "<" { op = BinaryExpr.Operator.LESS; } | 1587 ">" { op = BinaryExpr.Operator.GREATER; } | 1588 "<=" { op = BinaryExpr.Operator.LESS_EQUALS; } | 1589 ">=" { op = BinaryExpr.Operator.GREATER_EQUALS; } 1590 ) right = ShiftExpression() { ret = new BinaryExpr(range(ret, token()), ret, right, op); } 1591 )* 1592 { return ret; } 1593} 1594 1595Expression ShiftExpression(): 1596{ 1597 Expression ret; 1598 Expression right; 1599 BinaryExpr.Operator op; 1600} 1601{ 1602 ret = AdditiveExpression() 1603 ( 1604 ( "<<" { op = BinaryExpr.Operator.LEFT_SHIFT; } | 1605 RSIGNEDSHIFT() { op = BinaryExpr.Operator.SIGNED_RIGHT_SHIFT; } | 1606 RUNSIGNEDSHIFT() { op = BinaryExpr.Operator.UNSIGNED_RIGHT_SHIFT; } 1607 ) right = AdditiveExpression() { ret = new BinaryExpr(range(ret, token()), ret, right, op); } 1608 )* 1609 { return ret; } 1610} 1611 1612Expression AdditiveExpression(): 1613{ 1614 Expression ret; 1615 Expression right; 1616 BinaryExpr.Operator op; 1617} 1618{ 1619 ret = MultiplicativeExpression() 1620 ( 1621 ( "+" { op = BinaryExpr.Operator.PLUS; } | 1622 "-" { op = BinaryExpr.Operator.MINUS; } 1623 ) right = MultiplicativeExpression() { ret = new BinaryExpr(range(ret, token()), ret, right, op); } 1624 )* 1625 { return ret; } 1626} 1627 1628Expression MultiplicativeExpression(): 1629{ 1630 Expression ret; 1631 Expression right; 1632 BinaryExpr.Operator op; 1633} 1634{ 1635 ret = UnaryExpression() 1636 ( 1637 ( "*" { op = BinaryExpr.Operator.MULTIPLY; } | 1638 "/" { op = BinaryExpr.Operator.DIVIDE; } | 1639 "%" { op = BinaryExpr.Operator.REMAINDER; } 1640 ) right = UnaryExpression() { ret = new BinaryExpr(range(ret, token()), ret, right, op); } 1641 )* 1642 { return ret; } 1643} 1644 1645Expression UnaryExpression(): 1646{ 1647 Expression ret; 1648 UnaryExpr.Operator op; 1649 JavaToken begin = INVALID; 1650} 1651{ 1652 ( 1653 ret = PreIncrementExpression() 1654 | 1655 ret = PreDecrementExpression() 1656 | 1657 ( "+" { op = UnaryExpr.Operator.PLUS; begin=token();} | 1658 "-" { op = UnaryExpr.Operator.MINUS; begin=token();} 1659 ) ret = UnaryExpression() 1660 { 1661 ret = new UnaryExpr(range(begin, token()), ret, op); 1662 } 1663 | 1664 ret = UnaryExpressionNotPlusMinus() 1665 ) 1666 { return ret; } 1667} 1668 1669Expression PreIncrementExpression(): 1670{ 1671 Expression ret; 1672 JavaToken begin = INVALID; 1673} 1674{ 1675 "++" {begin=token();} ret = UnaryExpression() { ret = new UnaryExpr(range(begin, token()), ret, UnaryExpr.Operator.PREFIX_INCREMENT); } 1676 { return ret; } 1677} 1678 1679Expression PreDecrementExpression(): 1680{ 1681 Expression ret; 1682 JavaToken begin; 1683} 1684{ 1685 "--" {begin=token();} ret = UnaryExpression() { ret = new UnaryExpr(range(begin, token()), ret, UnaryExpr.Operator.PREFIX_DECREMENT); } 1686 { return ret; } 1687} 1688 1689Expression UnaryExpressionNotPlusMinus(): 1690{ 1691 Expression ret; 1692 UnaryExpr.Operator op; 1693 JavaToken begin = INVALID; 1694} 1695{ 1696 ( 1697 ( "~" { op = UnaryExpr.Operator.BITWISE_COMPLEMENT; begin=token(); } | 1698 "!" { op = UnaryExpr.Operator.LOGICAL_COMPLEMENT; begin=token(); } 1699 ) ret = UnaryExpression() { ret = new UnaryExpr(range(begin, token()), ret, op); } 1700 | 1701 LOOKAHEAD( CastExpression() ) 1702 ret = CastExpression() 1703 | 1704 ret = PostfixExpression() 1705 ) 1706 { return ret; } 1707} 1708 1709Expression PostfixExpression(): 1710{ 1711 Expression ret; 1712 UnaryExpr.Operator op; 1713} 1714{ 1715 ret = PrimaryExpression() 1716 [ 1717 LOOKAHEAD(2) 1718 ( "++" { op = UnaryExpr.Operator.POSTFIX_INCREMENT; } | 1719 "--" { op = UnaryExpr.Operator.POSTFIX_DECREMENT; } 1720 ) { ret = new UnaryExpr(range(ret, token()), ret, op); } 1721 ] 1722 { return ret; } 1723} 1724 1725Expression CastExpression(): 1726{ 1727 Expression ret; 1728 ReferenceType referenceType; 1729 PrimitiveType primitiveType; 1730 JavaToken begin = INVALID; 1731 NodeList<AnnotationExpr> annotations; 1732 NodeList<ReferenceType> typesOfMultiCast = emptyList(); 1733} 1734{ 1735 "(" {begin=token();} 1736 annotations = Annotations() 1737 ( 1738 LOOKAHEAD(2) 1739 primitiveType = PrimitiveType(annotations) ")" ret = UnaryExpression() { ret = new CastExpr(range(begin, token()), primitiveType, ret); } 1740 | 1741 referenceType = ReferenceType(annotations) { typesOfMultiCast = add(typesOfMultiCast, referenceType); } 1742 ( "&" referenceType = AnnotatedReferenceType() { 1743 typesOfMultiCast = add(typesOfMultiCast, referenceType); 1744 } 1745 )* 1746 ")" ret = UnaryExpressionNotPlusMinus() { 1747 if (typesOfMultiCast.size() > 1) { 1748 ret = new CastExpr(range(begin, token()), new IntersectionType(range(typesOfMultiCast.get(0), typesOfMultiCast.get(typesOfMultiCast.size() -1)), typesOfMultiCast), ret); 1749 } else { 1750 ret = new CastExpr(range(begin, token()), referenceType, ret); 1751 } 1752 } 1753 ) 1754 { return ret; } 1755} 1756 1757 1758 1759Expression PrimaryExpression(): 1760{ 1761 Expression ret; 1762} 1763{ 1764 ret = PrimaryPrefix() ( LOOKAHEAD(2) ret = PrimarySuffix(ret) )* 1765 { return ret; } 1766} 1767 1768Expression PrimaryExpressionWithoutSuperSuffix(): 1769{ 1770 Expression ret; 1771} 1772{ 1773 ret = PrimaryPrefix() ( LOOKAHEAD( PrimarySuffixWithoutSuper(null) ) ret = PrimarySuffixWithoutSuper(ret) )* 1774 { return ret; } 1775} 1776 1777Expression PrimaryPrefix(): 1778{ 1779 Expression ret = null; 1780 SimpleName name; 1781 RangedList<Type> typeArgs = new RangedList<Type>(null); 1782 NodeList<Expression> args = emptyList(); 1783 NodeList<Parameter> params = emptyList(); 1784 boolean hasArgs = false; 1785 boolean isLambda = false; 1786 Type type; 1787 JavaToken begin; 1788 Parameter p = null; 1789 SimpleName id = null; 1790} 1791{ 1792 ( 1793 ret = Literal() 1794 | 1795 <THIS> { ret = new ThisExpr(tokenRange(), null); } 1796 | 1797 <SUPER> { ret = new SuperExpr(tokenRange(), null); } 1798 ( 1799 "." 1800 [ typeArgs = TypeArguments() ] 1801 name = SimpleName() 1802 [ args = Arguments() {hasArgs=true;} ] 1803 { 1804 if (hasArgs) { 1805 ret = new MethodCallExpr(range(ret, token()), ret, typeArgs.list, name, args); 1806 } else { 1807 ret = new FieldAccessExpr(range(ret, token()), ret, emptyList(), name); 1808 } 1809 } 1810 | 1811 "::" [typeArgs = TypeArguments() ] (Identifier() | "new") 1812 { 1813 ret = new MethodReferenceExpr(range(ret, token()), ret, typeArgs.list, token.image); 1814 } 1815 ) 1816 | 1817 "(" {begin=token();} 1818 ( 1819 ")" { ret = new LambdaExpr(range(begin, token()), params, new BlockStmt(), true); } 1820 | LOOKAHEAD(Parameter()) 1821 params = LambdaParameters() ")" { ret = new LambdaExpr(range(begin, token()), params, new BlockStmt(), true); } 1822 | LOOKAHEAD(VariableDeclaratorId() ",") 1823 params = InferredLambdaParameters() ")" { ret = new LambdaExpr(range(begin, token()), params, new BlockStmt(), true); } 1824 | 1825 // This could still be a lambda expression, but this is handled after matching -> elsewhere 1826 ret = Expression() ")" { ret = new EnclosedExpr(range(begin, token()), ret); } 1827 ) 1828 | 1829 ret = AllocationExpression(null) 1830 | 1831 LOOKAHEAD( ResultType() "." "class" ) 1832 type = ResultType(emptyList()) "." "class" { ret = new ClassExpr(range(type, token()), type); } 1833 1834 | LOOKAHEAD (AnnotatedType() "::" ) 1835 type = AnnotatedType() "::" [typeArgs = TypeArguments() ] (Identifier() | "new") 1836 { 1837 ret = new TypeExpr(range(type, type), type); 1838 ret = new MethodReferenceExpr(range(ret, token()), ret, typeArgs.list, token.image); 1839 } 1840 1841 | 1842 name = SimpleName() { begin=token(); } 1843 [ args = Arguments() { hasArgs=true; } ] 1844 { 1845 if (hasArgs) { 1846 ret = new MethodCallExpr(range(begin, token()), null, null, name, args); 1847 } else { 1848 ret = new NameExpr(name); 1849 } 1850 } 1851 ) 1852 { return ret; } 1853} 1854 1855Expression PrimarySuffix(Expression scope): 1856{ 1857 Expression ret; 1858} 1859{ 1860 ( 1861 LOOKAHEAD(2) 1862 ret = PrimarySuffixWithoutSuper(scope) 1863 | 1864 "." "super" { ret = new SuperExpr(range(scope, token()), scope); } 1865 ) 1866 { return ret; } 1867} 1868 1869Expression PrimarySuffixWithoutSuper(Expression scope): 1870{ 1871 Expression ret; 1872 RangedList<Type> typeArgs = new RangedList<Type>(null); 1873 NodeList<Expression> args = emptyList(); 1874 boolean hasArgs = false; 1875 SimpleName name; 1876} 1877{ 1878 ( 1879 "." 1880 ( 1881 "this" { ret = new ThisExpr(range(scope, token()), scope); } 1882 | 1883 ret = AllocationExpression(scope) 1884 | 1885 LOOKAHEAD( [ TypeArguments() ] Identifier() ) 1886 [ typeArgs = TypeArguments() ] 1887 name = SimpleName() 1888 [ args = Arguments() {hasArgs=true;} ] 1889 { 1890 if (hasArgs) { 1891 ret = new MethodCallExpr(range(scope, token()), scope, typeArgs.list, name, args); 1892 } else { 1893 ret = new FieldAccessExpr(range(scope, token()), scope, typeArgs.list, name); 1894 } 1895 } 1896 ) 1897 | 1898 "["ret = Expression() "]" { ret = new ArrayAccessExpr(range(scope, token()), scope, ret); } 1899 ) 1900 { return ret; } 1901} 1902 1903Expression Literal(): 1904{ 1905 Expression ret; 1906} 1907{ 1908 ( 1909 <INTEGER_LITERAL> { 1910 ret = new IntegerLiteralExpr(tokenRange(), token.image); 1911 } 1912 | 1913 <LONG_LITERAL> { 1914 ret = new LongLiteralExpr(tokenRange(), token.image); 1915 } 1916 | 1917 <FLOATING_POINT_LITERAL> { 1918 ret = new DoubleLiteralExpr(tokenRange(), token.image); 1919 } 1920 | 1921 <CHARACTER_LITERAL> { 1922 ret = new CharLiteralExpr(tokenRange(), token.image.substring(1, token.image.length()-1)); 1923 } 1924 | 1925 <STRING_LITERAL> { 1926 ret = new StringLiteralExpr(tokenRange(), token.image.substring(1, token.image.length()-1)); 1927 } 1928 | 1929 ret = BooleanLiteral() 1930 | 1931 ret = NullLiteral() 1932 ) 1933 { return ret; } 1934} 1935 1936Expression BooleanLiteral(): 1937{ 1938 Expression ret; 1939} 1940{ 1941 ( 1942 "true" { ret = new BooleanLiteralExpr(tokenRange(), true); } 1943 | 1944 "false" { ret = new BooleanLiteralExpr(tokenRange(), false); } 1945 ) 1946 { return ret; } 1947} 1948 1949Expression NullLiteral(): 1950{} 1951{ 1952 "null" 1953 { return new NullLiteralExpr(tokenRange()); } 1954} 1955 1956NodeList<Expression> Arguments(): 1957{ 1958 NodeList<Expression> ret = emptyList(); 1959} 1960{ 1961 "(" [ ret = ArgumentList() ] ")" 1962 { return ret; } 1963} 1964 1965NodeList<Expression> ArgumentList(): 1966{ 1967 NodeList<Expression> ret = emptyList(); 1968 Expression expr; 1969} 1970{ 1971 expr = Expression() { ret.add(expr); } ( "," expr = Expression() { ret.add(expr); } )* 1972 { return ret; } 1973} 1974 1975Expression AllocationExpression(Expression scope): 1976{ 1977 Expression ret; 1978 Type type; 1979 RangedList<Type> typeArgs = new RangedList<Type>(null); 1980 NodeList<BodyDeclaration<?>> anonymousBody = null; 1981 NodeList<Expression> args; 1982 JavaToken begin = INVALID; 1983 NodeList<AnnotationExpr> annotations = new NodeList<AnnotationExpr>(); 1984} 1985{ 1986 "new" { if(scope==null) {begin=token();} else {begin = orIfInvalid(begin, scope);} } 1987 1988 annotations = Annotations() 1989 ( 1990 type = PrimitiveType(annotations) 1991 ret = ArrayCreation(begin, type) 1992 | 1993 [ typeArgs = TypeArguments() ] 1994 type = AnnotatedClassOrInterfaceType() 1995 ( 1996 ret = ArrayCreation(begin, type) 1997 | 1998 args = Arguments() [ LOOKAHEAD(2) anonymousBody = ClassOrInterfaceBody() ] 1999 { ret = new ObjectCreationExpr(range(begin, token()), scope, (ClassOrInterfaceType) type, typeArgs.list, args, anonymousBody); } 2000 ) 2001 ) 2002 { return ret; } 2003} 2004 2005ArrayCreationExpr ArrayCreation(JavaToken begin, Type type): 2006{ 2007 Expression expr = null; 2008 ArrayInitializerExpr arrayInitializerExpr = null; 2009 NodeList<Expression> inits = emptyList(); 2010 List<NodeList<AnnotationExpr>> accum = new ArrayList<NodeList<AnnotationExpr>>(); 2011 NodeList<AnnotationExpr> annotations = new NodeList<AnnotationExpr>(); 2012 JavaToken arrayCreationLevelStart = INVALID; 2013 List<TokenRange> levelRanges = new ArrayList<TokenRange>(); 2014} 2015{ 2016 ( LOOKAHEAD(2) 2017 annotations = Annotations() 2018 "[" { arrayCreationLevelStart = annotations.isEmpty() ? token() : orIfInvalid(arrayCreationLevelStart, annotations.get(0)); } 2019 (expr = Expression())? { accum = add(accum, annotations); inits = add(inits, expr); annotations=null; expr=null; } 2020 "]" { levelRanges.add(range(arrayCreationLevelStart, token())); } 2021 )+ 2022 (arrayInitializerExpr = ArrayInitializer())? 2023 { 2024 return juggleArrayCreation(range(begin, token()), levelRanges, type, inits, accum, arrayInitializerExpr); 2025 } 2026} 2027 2028/* 2029 * Statement syntax follows. 2030 */ 2031 2032Statement Statement(): 2033{ 2034 Statement ret; 2035} 2036{ 2037 try { 2038 ( LOOKAHEAD(2) 2039 ret = LabeledStatement() 2040 | 2041 ret = AssertStatement() 2042 | 2043 ret = Block() 2044 | 2045 ret = EmptyStatement() 2046 | 2047 ret = StatementExpression() 2048 | 2049 ret = SwitchStatement() 2050 | 2051 ret = IfStatement() 2052 | 2053 ret = WhileStatement() 2054 | 2055 ret = DoStatement() 2056 | 2057 ret = ForStatement() 2058 | 2059 ret = BreakStatement() 2060 | 2061 ret = ContinueStatement() 2062 | 2063 ret = ReturnStatement() 2064 | 2065 ret = ThrowStatement() 2066 | 2067 ret = SynchronizedStatement() 2068 | 2069 ret = TryStatement() 2070 ) 2071 { return ret; } 2072 } catch (ParseException e) { 2073 TokenRange errorRange = recover(SEMICOLON, e); 2074 return new UnparsableStmt(errorRange); 2075 } 2076} 2077 2078AssertStmt AssertStatement(): 2079{ 2080 Expression check; 2081 Expression msg = null; 2082 JavaToken begin; 2083} 2084{ 2085 "assert" {begin=token();} check = Expression() [ ":" msg = Expression() ] ";" 2086 { return new AssertStmt(range(begin, token()), check, msg); } 2087} 2088 2089LabeledStmt LabeledStatement(): 2090{ 2091 SimpleName label; 2092 Statement stmt; 2093 JavaToken begin; 2094} 2095{ 2096 label = SimpleName() {begin=token();} ":" stmt = Statement() 2097 { return new LabeledStmt(range(begin, token()), label, stmt); } 2098} 2099 2100BlockStmt Block(): 2101{ 2102 NodeList<Statement> stmts = emptyList(); 2103 JavaToken begin; 2104} 2105{ 2106 "{" {begin=token();} 2107 try { 2108 stmts = Statements() 2109 "}" 2110 { return new BlockStmt(range(begin, token()), stmts); } 2111 } catch (ParseException e) { 2112 recover(RBRACE, e); 2113 BlockStmt block = new BlockStmt(range(begin, token()), new NodeList<Statement>()); 2114 block.setParsed(UNPARSABLE); 2115 return block; 2116 } 2117} 2118 2119/* 2120 * Classes inside body statements can only be abstract or final. The semantic must check it. 2121 */ 2122Statement BlockStatement(): 2123{ 2124 Statement ret; 2125 Expression expr; 2126 ClassOrInterfaceDeclaration typeDecl; 2127 ModifierHolder modifier; 2128} 2129{ 2130 try { 2131 ( LOOKAHEAD( Modifiers() ("class" | "interface") ) 2132 modifier = Modifiers() 2133 typeDecl = ClassOrInterfaceDeclaration(modifier) { ret = new LocalClassDeclarationStmt(range(typeDecl, token()), typeDecl); } 2134 | LOOKAHEAD(VariableDeclarationExpression() ) 2135 expr = VariableDeclarationExpression() ";" 2136 { ret = new ExpressionStmt(range(expr, token()), expr); } 2137 | 2138 ret = Statement() 2139 ) 2140 { return ret; } 2141 } catch (ParseException e) { 2142 TokenRange errorRange = recover(SEMICOLON, e); 2143 return new UnparsableStmt(errorRange); 2144 } 2145} 2146 2147VariableDeclarationExpr VariableDeclarationExpression(): 2148{ 2149 ModifierHolder modifier; 2150 Type partialType; 2151 NodeList<VariableDeclarator> variables = new NodeList<VariableDeclarator>(); 2152 VariableDeclarator var; 2153} 2154{ 2155 modifier = Modifiers() partialType = Type(emptyList()) var = VariableDeclarator(partialType) { variables.add(var); } ( "," var = VariableDeclarator(partialType) { variables.add(var); } )* 2156 { 2157 JavaToken begin=orIfInvalid(modifier.begin, partialType); 2158 return new VariableDeclarationExpr(range(begin, token()), modifier.modifiers, modifier.annotations, variables); 2159 } 2160} 2161 2162EmptyStmt EmptyStatement(): 2163{} 2164{ 2165 ";" 2166 { return new EmptyStmt(tokenRange()); } 2167} 2168 2169Statement LambdaBody(): 2170{ 2171 Expression expr; 2172 Statement n = null; 2173} 2174{ 2175 ( 2176 expr = Expression() { n = new ExpressionStmt(range(expr, token()), expr); } 2177 | 2178 n = Block() 2179 ) 2180 { return n; } 2181} 2182 2183ExpressionStmt StatementExpression(): 2184/* 2185 * The last expansion of this production accepts more than the legal 2186 * Java expansions for StatementExpression. This expansion does not 2187 * use PostfixExpression for performance reasons. 2188 */ 2189{ 2190 Expression expr; 2191 AssignExpr.Operator op; 2192 Expression value; 2193 RangedList<Type> typeArgs = new RangedList<Type>(null); 2194 Statement lambdaBody; 2195} 2196{ 2197 ( LOOKAHEAD(2) 2198 expr = PreIncrementExpression() 2199 | 2200 expr = PreDecrementExpression() 2201 | 2202 expr = PrimaryExpression() 2203 [ 2204 "++" { expr = new UnaryExpr(range(expr, token()), expr, UnaryExpr.Operator.POSTFIX_INCREMENT); } 2205 | 2206 "--" { expr = new UnaryExpr(range(expr, token()), expr, UnaryExpr.Operator.POSTFIX_DECREMENT); } 2207 | 2208 op = AssignmentOperator() value = Expression() { expr = new AssignExpr(range(expr, token()), expr, value, op); } 2209 ] 2210 ) 2211 ";" 2212 { return new ExpressionStmt(range(expr, token()), expr); } 2213} 2214 2215SwitchStmt SwitchStatement(): 2216{ 2217 Expression selector; 2218 SwitchEntryStmt entry; 2219 NodeList<SwitchEntryStmt> entries = emptyList(); 2220 JavaToken begin; 2221} 2222{ 2223 "switch" {begin=token();} "(" selector = Expression() ")" "{" 2224 ( entry = SwitchEntry() { entries = add(entries, entry); } )* 2225 "}" 2226 2227 { return new SwitchStmt(range(begin, token()), selector, entries); } 2228} 2229 2230SwitchEntryStmt SwitchEntry(): 2231{ 2232 Expression label = null; 2233 NodeList<Statement> stmts; 2234 JavaToken begin; 2235} 2236{ 2237 ( 2238 "case" {begin=token();} label = Expression() 2239 | 2240 "default" {begin=token();} 2241 ) 2242 ":" stmts = Statements() 2243 2244 { return new SwitchEntryStmt(range(begin, token()),label, stmts); } 2245} 2246 2247IfStmt IfStatement(): 2248/* 2249 * The disambiguating algorithm of JavaCC automatically binds dangling 2250 * else's to the innermost if statement. The LOOKAHEAD specification 2251 * is to tell JavaCC that we know what we are doing. 2252 */ 2253{ 2254 Expression condition; 2255 Statement thenStmt; 2256 Statement elseStmt = null; 2257 JavaToken begin; 2258} 2259{ 2260 "if" {begin=token();} "(" condition = Expression() ")" {} thenStmt = Statement() [ LOOKAHEAD(1) "else" {} elseStmt = Statement() ] 2261 { 2262 return new IfStmt(range(begin, token()), condition, thenStmt, elseStmt); 2263 } 2264} 2265 2266WhileStmt WhileStatement(): 2267{ 2268 Expression condition; 2269 Statement body; 2270 JavaToken begin; 2271} 2272{ 2273 "while" {begin=token();} "(" condition = Expression() ")" body = Statement() 2274 { return new WhileStmt(range(begin, token()),condition, body); } 2275} 2276 2277DoStmt DoStatement(): 2278{ 2279 Expression condition; 2280 Statement body; 2281 JavaToken begin; 2282} 2283{ 2284 "do" {begin=token();} body = Statement() "while" "(" condition = Expression() ")" ";" 2285 { return new DoStmt(range(begin, token()),body, condition); } 2286} 2287 2288Statement ForStatement(): 2289{ 2290 VariableDeclarationExpr varExpr = null; 2291 Expression expr = null; 2292 NodeList<Expression> init = emptyList(); 2293 NodeList<Expression> update = emptyList(); 2294 Statement body; 2295 JavaToken begin; 2296} 2297{ 2298 "for" {begin=token();} "(" 2299 2300 ( 2301 LOOKAHEAD(VariableDeclarationExpression() ":") 2302 varExpr = VariableDeclarationExpression() ":" expr = Expression() 2303 | 2304 [ init = ForInit() ] ";" [ expr = Expression() ] ";" [ update = ForUpdate() ] 2305 ) 2306 2307 ")" body = Statement() 2308 2309 { 2310 if (varExpr != null) { 2311 return new ForeachStmt(range(begin, token()),varExpr, expr, body); 2312 } 2313 return new ForStmt(range(begin, token()),init, expr, update, body); 2314 } 2315} 2316 2317NodeList<Expression> ForInit(): 2318{ 2319 NodeList<Expression> ret; 2320 Expression expr; 2321} 2322{ 2323 ( 2324 LOOKAHEAD( Modifiers() Type() Identifier() ) 2325 expr = VariableDeclarationExpression() { ret = new NodeList<Expression>(); ret.add(expr); } 2326 | 2327 ret = ExpressionList() 2328 ) 2329 { return ret; } 2330} 2331 2332NodeList<Expression> ExpressionList(): 2333{ 2334 NodeList<Expression> ret = new NodeList<Expression>(); 2335 Expression expr; 2336} 2337{ 2338 expr = Expression() { ret.add(expr); } ( "," expr = Expression() { ret.add(expr); } )* 2339 2340 { return ret; } 2341} 2342 2343NodeList<Expression> ForUpdate(): 2344{ 2345 NodeList<Expression> ret; 2346} 2347{ 2348 ret = ExpressionList() 2349 2350 { return ret; } 2351} 2352 2353BreakStmt BreakStatement(): 2354{ 2355 SimpleName label = null; 2356 JavaToken begin; 2357} 2358{ 2359 "break" {begin=token();} [ label = SimpleName() ] ";" 2360 { return new BreakStmt(range(begin, token()), label); } 2361} 2362 2363ContinueStmt ContinueStatement(): 2364{ 2365 SimpleName label = null; 2366 JavaToken begin; 2367} 2368{ 2369 "continue" {begin=token();} [ label = SimpleName() ] ";" 2370 { return new ContinueStmt(range(begin, token()), label); } 2371} 2372 2373ReturnStmt ReturnStatement(): 2374{ 2375 Expression expr = null; 2376 JavaToken begin; 2377} 2378{ 2379 "return" {begin=token();} [ expr = Expression() ] ";" 2380 { return new ReturnStmt(range(begin, token()),expr); } 2381} 2382 2383ThrowStmt ThrowStatement(): 2384{ 2385 Expression expr; 2386 JavaToken begin; 2387} 2388{ 2389 "throw" {begin=token();} expr = Expression() ";" 2390 { return new ThrowStmt(range(begin, token()),expr); } 2391} 2392 2393SynchronizedStmt SynchronizedStatement(): 2394{ 2395 Expression expr; 2396 BlockStmt body; 2397 JavaToken begin; 2398} 2399{ 2400 "synchronized" {begin=token();} "(" expr = Expression() ")" body = Block() 2401 { return new SynchronizedStmt(range(begin, token()),expr, body); } 2402} 2403 2404TryStmt TryStatement(): 2405{ 2406 NodeList<Expression> resources = emptyList(); 2407 BlockStmt tryBlock; 2408 BlockStmt finallyBlock = null; 2409 NodeList<CatchClause> catchs = emptyList(); 2410 BlockStmt catchBlock; 2411 ModifierHolder exceptModifier; 2412 ReferenceType exceptionType; 2413 NodeList<ReferenceType> exceptionTypes = emptyList(); 2414 Pair<SimpleName, List<ArrayBracketPair>> exceptId; 2415 JavaToken begin; 2416 JavaToken catchBegin; 2417 JavaToken typesBegin; 2418 JavaToken paramEnd; 2419 Type type; 2420} 2421{ 2422 "try" {begin=token();} 2423 (resources = ResourceSpecification())? 2424 tryBlock = Block() 2425 ( 2426 LOOKAHEAD(2) 2427 ( 2428 "catch" {catchBegin=token();} 2429 "(" { typesBegin=token(); } 2430 exceptModifier = Modifiers() exceptionType = ReferenceType(emptyList()) { exceptionTypes.add(exceptionType); } 2431 ( "|" exceptionType = AnnotatedReferenceType() { exceptionTypes.add(exceptionType); } )* 2432 exceptId = VariableDeclaratorId() { paramEnd = token(); } 2433 ")" 2434 2435 catchBlock = Block() 2436 { 2437 if (exceptionTypes.size() > 1) { 2438 type = new UnionType(range(exceptionTypes.get(0), exceptionTypes.get(exceptionTypes.size() - 1)), exceptionTypes); 2439 } else { 2440 type = (Type)exceptionTypes.get(0); 2441 } 2442 Parameter catchType = new Parameter(range(type, paramEnd), exceptModifier.modifiers, exceptModifier.annotations, type, false, emptyList(), exceptId.a); 2443 catchs = add(catchs, new CatchClause(range(catchBegin, token()), catchType, catchBlock)); 2444 exceptionTypes = emptyList(); } 2445 )* 2446 [ "finally" finallyBlock = Block() ] 2447 | 2448 "finally" finallyBlock = Block() 2449 ) 2450 { return new TryStmt(range(begin, token()), resources, tryBlock, catchs, finallyBlock); } 2451} 2452 2453 2454NodeList<Expression> ResourceSpecification() : 2455{ 2456 NodeList<Expression> variables; 2457} 2458{ 2459 "(" 2460 variables = Resources() 2461 (LOOKAHEAD(2) ";")? 2462 ")" 2463 { return variables; } 2464} 2465 2466 2467NodeList<Expression> Resources() : 2468{ 2469 NodeList<Expression> expressions = new NodeList<Expression>(); 2470 Expression expr; 2471} 2472{ 2473 expr = Resource() {expressions.add(expr);} (LOOKAHEAD(2) ";" expr = Resource() {expressions.add(expr);})* 2474 { return expressions; } 2475} 2476 2477Expression Resource() : 2478{ 2479 Expression expr; 2480} 2481{ 2482 ( LOOKAHEAD( Modifiers() partialType = Type() VariableDeclarator(partialType)) 2483 /*this is a bit more lenient than we need to be, eg allowing access modifiers like private*/ 2484 expr = VariableDeclarationExpression() 2485 | 2486 expr = PrimaryExpression() 2487 ) 2488 { return expr; } 2489} 2490 2491 2492/* We use productions to match >>>, >> and > so that we can keep the 2493 * type declaration syntax with generics clean 2494 */ 2495 2496void RUNSIGNEDSHIFT(): 2497{} 2498{ 2499 ( LOOKAHEAD({ getToken(1).kind == GT && 2500 getToken(1).realKind == RUNSIGNEDSHIFT} ) 2501 ">" ">" ">" 2502 ) 2503} 2504 2505void RSIGNEDSHIFT(): 2506{} 2507{ 2508 ( LOOKAHEAD({ getToken(1).kind == GT && 2509 getToken(1).realKind == RSIGNEDSHIFT} ) 2510 ">" ">" 2511 ) 2512} 2513 2514/* Annotation syntax follows. */ 2515 2516NodeList<AnnotationExpr> Annotations(): 2517{ 2518 NodeList<AnnotationExpr> annotations = new NodeList<AnnotationExpr>(); 2519 AnnotationExpr annotation; 2520} 2521{ 2522 (LOOKAHEAD("@") annotation = Annotation() {annotations = add(annotations, annotation);} )* 2523 { return annotations; } 2524} 2525 2526AnnotationExpr Annotation(): 2527{ 2528 AnnotationExpr ret; 2529 Name name; 2530 NodeList<MemberValuePair> pairs = emptyList(); 2531 JavaToken begin; 2532 Expression memberVal; 2533} 2534{ 2535 "@" { begin=token(); } name = Name() 2536 ( 2537 LOOKAHEAD( "(" ( Identifier() "=" | ")" )) 2538 "(" [ pairs = MemberValuePairs() ] ")" 2539 { ret = new NormalAnnotationExpr(range(begin, token()), name, pairs); } 2540 | 2541 LOOKAHEAD( "(" ) 2542 "(" memberVal = MemberValue() ")" 2543 { ret = new SingleMemberAnnotationExpr(range(begin, token()), name, memberVal); } 2544 | 2545 { ret = new MarkerAnnotationExpr(range(begin, token()), name); } 2546 ) 2547 { return ret; } 2548} 2549 2550NodeList<MemberValuePair> MemberValuePairs(): 2551{ 2552 NodeList<MemberValuePair> ret = new NodeList<MemberValuePair>(); 2553 MemberValuePair pair; 2554} 2555{ 2556 pair = MemberValuePair() { ret.add(pair); } ( "," pair = MemberValuePair() { ret.add(pair); } )* 2557 { return ret; } 2558} 2559 2560MemberValuePair MemberValuePair(): 2561{ 2562 SimpleName name; 2563 Expression value; 2564 JavaToken begin; 2565} 2566{ 2567 name = SimpleName() { begin=token();} "=" value = MemberValue() 2568 { return new MemberValuePair(range(begin, token()),name, value); } 2569} 2570 2571Expression MemberValue(): 2572{ 2573 Expression ret; 2574} 2575{ 2576 ( LOOKAHEAD("@") 2577 ret = Annotation() 2578 | 2579 ret = MemberValueArrayInitializer() 2580 | 2581 ret = ConditionalExpression() 2582 ) 2583 { return ret; } 2584} 2585 2586Expression MemberValueArrayInitializer(): 2587{ 2588 NodeList<Expression> ret = emptyList(); 2589 Expression member; 2590 JavaToken begin; 2591} 2592{ 2593 "{" {begin=token();} 2594 ( member = MemberValue() { ret.add(member); } ( LOOKAHEAD(2) "," member = MemberValue() { ret.add(member); } )* )? [ "," ] 2595 "}" 2596 { return new ArrayInitializerExpr(range(begin, token()),ret); } 2597} 2598 2599 2600/* Annotation Types. */ 2601 2602AnnotationDeclaration AnnotationTypeDeclaration(ModifierHolder modifier): 2603{ 2604 SimpleName name; 2605 NodeList<BodyDeclaration<?>> members = emptyList(); 2606 JavaToken begin = modifier.begin; 2607} 2608{ 2609 "@" { begin=orIfInvalid(begin, token()); } 2610 "interface" name = SimpleName() members = AnnotationTypeBody() 2611 { 2612 return new AnnotationDeclaration(range(begin, token()), modifier.modifiers, modifier.annotations, name, members); 2613 } 2614} 2615 2616NodeList<BodyDeclaration<?>> AnnotationTypeBody(): 2617{ 2618 NodeList<BodyDeclaration<?>> ret = emptyList(); 2619 BodyDeclaration member; 2620} 2621{ 2622 "{" ( 2623 member = AnnotationBodyDeclaration() { ret = addWhenNotNull(ret, member); } 2624 | 2625 ";" 2626 )* "}" 2627 { return ret; } 2628} 2629 2630BodyDeclaration<?> AnnotationBodyDeclaration(): 2631{ 2632 ModifierHolder modifier; 2633 BodyDeclaration ret; 2634} 2635{ 2636 ( 2637 modifier = Modifiers() 2638 ( 2639 LOOKAHEAD(Type() Identifier() "(") 2640 ret = AnnotationTypeMemberDeclaration(modifier) 2641 | 2642 ret = ClassOrInterfaceDeclaration(modifier) 2643 | LOOKAHEAD("enum") 2644 ret = EnumDeclaration(modifier) 2645 | 2646 ret = AnnotationTypeDeclaration(modifier) 2647 | 2648 ret = FieldDeclaration(modifier) 2649 ) 2650 ) 2651 { return ret; } 2652} 2653 2654AnnotationMemberDeclaration AnnotationTypeMemberDeclaration(ModifierHolder modifier): 2655{ 2656 Type type; 2657 SimpleName name; 2658 Expression defaultVal = null; 2659} 2660{ 2661 type = Type(emptyList()) name = SimpleName() "(" ")" [ defaultVal = DefaultValue() ] ";" 2662 2663 { 2664 JavaToken begin = orIfInvalid(modifier.begin, type); 2665 return new AnnotationMemberDeclaration(range(begin, token()), modifier.modifiers, modifier.annotations, type, name, defaultVal); 2666 } 2667} 2668 2669Expression DefaultValue(): 2670{ 2671 Expression ret; 2672} 2673{ 2674 "default" ret = MemberValue() 2675 { return ret; } 2676} 2677 2678/* Module syntax follows */ 2679 2680 2681ModuleStmt ModuleStmt(): 2682{ 2683 ModifierHolder modifiers; 2684 Name name; 2685 Name tmpName; 2686 NodeList<Name> names=emptyList(); 2687 Type type; 2688 Type tmpType; 2689 NodeList<Type> types=emptyList(); 2690 JavaToken begin; 2691 ModuleStmt stmt=new ModuleRequiresStmt(); 2692 JavaToken transitiveExceptionalToken; 2693} 2694{ 2695 ( 2696 // This is a hack for the edge case "requires transitive;" which is supposed to mean "require the module named 'transitive'" 2697 LOOKAHEAD(<REQUIRES> <TRANSITIVE> ";") 2698 <REQUIRES> {begin=token();} <TRANSITIVE> {transitiveExceptionalToken=token(); setTokenKind(IDENTIFIER);} ";" {stmt=new ModuleRequiresStmt(range(begin, token()), EnumSet.noneOf(Modifier.class), new Name(range(transitiveExceptionalToken, transitiveExceptionalToken), null, transitiveExceptionalToken.getText(), new NodeList<AnnotationExpr>()));} 2699 | 2700 <REQUIRES> {begin=token();} modifiers=Modifiers() name=Name() ";" {stmt=new ModuleRequiresStmt(range(begin, token()), modifiers.modifiers, name);} 2701 | 2702 <EXPORTS> {begin=token();} name=Name() [<TO> tmpName=Name() {names.add(tmpName);} ("," tmpName=Name(){names.add(tmpName);} )* ] ";" {stmt=new ModuleExportsStmt(range(begin, token()), name, names);} 2703 | 2704 <OPENS> {begin=token();} name=Name() [<TO> tmpName=Name() {names.add(tmpName);} ("," tmpName=Name(){names.add(tmpName);} )* ] ";" {stmt=new ModuleOpensStmt(range(begin, token()), name, names);} 2705 | 2706 <USES> { begin=token();} type=Type(emptyList()) ";" {stmt=new ModuleUsesStmt(range(begin, token()), type);} 2707 | 2708 <PROVIDES> { begin=token();} type=Type(emptyList()) <WITH> tmpType=Type(emptyList()) {types.add(tmpType);} ("," tmpType=Type(emptyList()) {types.add(tmpType);} )* ";" {stmt=new ModuleProvidesStmt(range(begin, token()), type, types);} 2709 ) 2710 { return stmt; } 2711} 2712 2713ModuleDeclaration ModuleDeclaration(ModifierHolder modifier): 2714{ 2715 NodeList<ModuleStmt> statements = new NodeList<ModuleStmt>(); 2716 boolean open=false; 2717 ModuleStmt st; 2718 Name name; 2719 JavaToken begin = modifier.begin; 2720} 2721{ 2722 [ <OPEN> {open=true; begin = orIfInvalid(begin, token());} ] 2723 <MODULE> { begin = orIfInvalid(begin, token()); } 2724 name = Name() "{" 2725 ( st = ModuleStmt() { statements = add(statements, st); } )* 2726 "}" 2727 { return new ModuleDeclaration(range(begin, token()), modifier.annotations, name, open, statements); } 2728} 2729 2730/* Rules for matching partial inputs. 2731These rules are needed to properly terminate them - 2732if we simply use the usual rules, they will ignore everything in the provider 2733after they matched their desired input, which will lead to unexpected behaviour 2734*/ 2735 2736 2737BlockStmt BlockParseStart(): 2738{ BlockStmt ret; } 2739{ ret = Block() <EOF> { return ret; } } 2740 2741Statement BlockStatementParseStart(): 2742{ Statement ret; } 2743{ (LOOKAHEAD(3) ret = BlockStatement()|ret = ExplicitConstructorInvocation()) <EOF> { return ret; } } 2744 2745ImportDeclaration ImportDeclarationParseStart(): 2746{ ImportDeclaration ret; } 2747{ ret = ImportDeclaration() <EOF> { return ret; } } 2748 2749Expression ExpressionParseStart(): 2750{ Expression ret; } 2751{ ret = Expression() <EOF> { return ret; } } 2752 2753AnnotationExpr AnnotationParseStart(): 2754{ AnnotationExpr ret; } 2755{ ret = Annotation() <EOF> { return ret; } } 2756 2757BodyDeclaration<?> AnnotationBodyDeclarationParseStart(): 2758{ BodyDeclaration<?> ret; } 2759{ ret = AnnotationBodyDeclaration() <EOF> { return ret; } } 2760 2761BodyDeclaration<?> ClassOrInterfaceBodyDeclarationParseStart(): 2762{ BodyDeclaration<?> ret; } 2763{ ret = ClassOrInterfaceBodyDeclaration() <EOF> { return ret; } } 2764 2765ClassOrInterfaceType ClassOrInterfaceTypeParseStart(): 2766{ ClassOrInterfaceType ret; } 2767{ ret = AnnotatedClassOrInterfaceType() <EOF> { return ret; } } 2768 2769Type ResultTypeParseStart(): 2770{ NodeList<AnnotationExpr> annotations; Type ret; } 2771{ annotations = Annotations() ret = ResultType(annotations) <EOF> { return ret; } } 2772 2773VariableDeclarationExpr VariableDeclarationExpressionParseStart(): 2774{ VariableDeclarationExpr ret; } 2775{ ret = VariableDeclarationExpression() <EOF> { return ret; } } 2776 2777ExplicitConstructorInvocationStmt ExplicitConstructorInvocationParseStart(): 2778{ ExplicitConstructorInvocationStmt ret; } 2779{ ret = ExplicitConstructorInvocation() <EOF> { return ret; } } 2780 2781Name NameParseStart(): 2782{ Name ret; } 2783{ ret = Name() <EOF> { return ret; } } 2784 2785SimpleName SimpleNameParseStart(): 2786{ SimpleName ret; } 2787{ ret = SimpleName() <EOF> { return ret; } } 2788 2789Parameter ParameterParseStart(): 2790{ Parameter ret; } 2791{ ret = Parameter() <EOF> { return ret; } } 2792 2793PackageDeclaration PackageDeclarationParseStart(): 2794{ PackageDeclaration ret; } 2795{ ret = PackageDeclaration() <EOF> { return ret; } } 2796