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