PageRenderTime 52ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/groovy-eclipse/org.codehaus.groovy.eclipse.core/src/org/codehaus/groovy/eclipse/core/compiler/internal/antlr/GroovyRecognizer.java

http://groovy-eclipse.googlecode.com/
Java | 2198 lines | 1819 code | 112 blank | 267 comment | 187 complexity | 5dded98d63fc678d24fd6a36a806da02 MD5 | raw file
Possible License(s): Apache-2.0

Large files files are truncated, but you can click here to view the full file

  1. // $ANTLR 2.7.7 (20060930): "groovy.g" -> "GroovyRecognizer.java"$
  2. package org.codehaus.groovy.eclipse.core.compiler.internal.antlr;
  3. import org.codehaus.groovy.antlr.*;
  4. import java.util.*;
  5. import java.io.InputStream;
  6. import java.io.Reader;
  7. import antlr.InputBuffer;
  8. import antlr.LexerSharedInputState;
  9. import antlr.CommonToken;
  10. import org.codehaus.groovy.GroovyBugError;
  11. import antlr.TokenStreamRecognitionException;
  12. import antlr.TokenBuffer;
  13. import antlr.TokenStreamException;
  14. import antlr.TokenStreamIOException;
  15. import antlr.ANTLRException;
  16. import antlr.LLkParser;
  17. import antlr.Token;
  18. import antlr.TokenStream;
  19. import antlr.RecognitionException;
  20. import antlr.NoViableAltException;
  21. import antlr.MismatchedTokenException;
  22. import antlr.SemanticException;
  23. import antlr.ParserSharedInputState;
  24. import antlr.collections.impl.BitSet;
  25. import antlr.collections.AST;
  26. import java.util.Hashtable;
  27. import antlr.ASTFactory;
  28. import antlr.ASTPair;
  29. import antlr.collections.impl.ASTArray;
  30. /** JSR-241 Groovy Recognizer
  31. *
  32. * Run 'java Main [-showtree] directory-full-of-groovy-files'
  33. *
  34. * [The -showtree option pops up a Swing frame that shows
  35. * the AST constructed from the parser.]
  36. *
  37. * Contributing authors:
  38. * John Mitchell johnm@non.net
  39. * Terence Parr parrt@magelang.com
  40. * John Lilley jlilley@empathy.com
  41. * Scott Stanchfield thetick@magelang.com
  42. * Markus Mohnen mohnen@informatik.rwth-aachen.de
  43. * Peter Williams pete.williams@sun.com
  44. * Allan Jacobs Allan.Jacobs@eng.sun.com
  45. * Steve Messick messick@redhills.com
  46. * James Strachan jstrachan@protique.com
  47. * John Pybus john@pybus.org
  48. * John Rose rose00@mac.com
  49. * Jeremy Rayner groovy@ross-rayner.com
  50. * Alex Popescu the.mindstorm@gmail.com
  51. * Martin Kempf mkempf@hsr.ch
  52. * Reto Kleeb rkleeb@hsr.ch
  53. *
  54. * Version 1.00 December 9, 1997 -- initial release
  55. * Version 1.01 December 10, 1997
  56. * fixed bug in octal def (0..7 not 0..8)
  57. * Version 1.10 August 1998 (parrt)
  58. * added tree construction
  59. * fixed definition of WS,comments for mac,pc,unix newlines
  60. * added unary plus
  61. * Version 1.11 (Nov 20, 1998)
  62. * Added "shutup" option to turn off last ambig warning.
  63. * Fixed inner class def to allow named class defs as statements
  64. * synchronized requires compound not simple statement
  65. * add [] after builtInType DOT class in primaryExpression
  66. * "const" is reserved but not valid..removed from modifiers
  67. * Version 1.12 (Feb 2, 1999)
  68. * Changed LITERAL_xxx to xxx in tree grammar.
  69. * Updated java.g to use tokens {...} now for 2.6.0 (new feature).
  70. *
  71. * Version 1.13 (Apr 23, 1999)
  72. * Didn't have (stat)? for else clause in tree parser.
  73. * Didn't gen ASTs for interface extends. Updated tree parser too.
  74. * Updated to 2.6.0.
  75. * Version 1.14 (Jun 20, 1999)
  76. * Allowed final/abstract on local classes.
  77. * Removed local interfaces from methods
  78. * Put instanceof precedence where it belongs...in relationalExpr
  79. * It also had expr not type as arg; fixed it.
  80. * Missing ! on SEMI in classBlock
  81. * fixed: (expr) + "string" was parsed incorrectly (+ as unary plus).
  82. * fixed: didn't like Object[].class in parser or tree parser
  83. * Version 1.15 (Jun 26, 1999)
  84. * Screwed up rule with instanceof in it. :( Fixed.
  85. * Tree parser didn't like (expr).something; fixed.
  86. * Allowed multiple inheritance in tree grammar. oops.
  87. * Version 1.16 (August 22, 1999)
  88. * Extending an interface built a wacky tree: had extra EXTENDS.
  89. * Tree grammar didn't allow multiple superinterfaces.
  90. * Tree grammar didn't allow empty var initializer: {}
  91. * Version 1.17 (October 12, 1999)
  92. * ESC lexer rule allowed 399 max not 377 max.
  93. * java.tree.g didn't handle the expression of synchronized
  94. * statements.
  95. * Version 1.18 (August 12, 2001)
  96. * Terence updated to Java 2 Version 1.3 by
  97. * observing/combining work of Allan Jacobs and Steve
  98. * Messick. Handles 1.3 src. Summary:
  99. * o primary didn't include boolean.class kind of thing
  100. * o constructor calls parsed explicitly now:
  101. * see explicitConstructorInvocation
  102. * o add strictfp modifier
  103. * o missing objBlock after new expression in tree grammar
  104. * o merged local class definition alternatives, moved after declaration
  105. * o fixed problem with ClassName.super.field
  106. * o reordered some alternatives to make things more efficient
  107. * o long and double constants were not differentiated from int/float
  108. * o whitespace rule was inefficient: matched only one char
  109. * o add an examples directory with some nasty 1.3 cases
  110. * o made Main.java use buffered IO and a Reader for Unicode support
  111. * o supports UNICODE?
  112. * Using Unicode charVocabulay makes code file big, but only
  113. * in the bitsets at the end. I need to make ANTLR generate
  114. * unicode bitsets more efficiently.
  115. * Version 1.19 (April 25, 2002)
  116. * Terence added in nice fixes by John Pybus concerning floating
  117. * constants and problems with super() calls. John did a nice
  118. * reorg of the primary/postfix expression stuff to read better
  119. * and makes f.g.super() parse properly (it was METHOD_CALL not
  120. * a SUPER_CTOR_CALL). Also:
  121. *
  122. * o "finally" clause was a root...made it a child of "try"
  123. * o Added stuff for asserts too for Java 1.4, but *commented out*
  124. * as it is not backward compatible.
  125. *
  126. * Version 1.20 (October 27, 2002)
  127. *
  128. * Terence ended up reorging John Pybus' stuff to
  129. * remove some nondeterminisms and some syntactic predicates.
  130. * Note that the grammar is stricter now; e.g., this(...) must
  131. * be the first statement.
  132. *
  133. * Trinary ?: operator wasn't working as array name:
  134. * (isBig ? bigDigits : digits)[i];
  135. *
  136. * Checked parser/tree parser on source for
  137. * Resin-2.0.5, jive-2.1.1, jdk 1.3.1, Lucene, antlr 2.7.2a4,
  138. * and the 110k-line jGuru server source.
  139. *
  140. * Version 1.21 (October 17, 2003)
  141. * Fixed lots of problems including:
  142. * Ray Waldin: add typeDefinition to interfaceBlock in java.tree.g
  143. * He found a problem/fix with floating point that start with 0
  144. * Ray also fixed problem that (int.class) was not recognized.
  145. * Thorsten van Ellen noticed that \n are allowed incorrectly in strings.
  146. * TJP fixed CHAR_LITERAL analogously.
  147. *
  148. * Version 1.21.2 (March, 2003)
  149. * Changes by Matt Quail to support generics (as per JDK1.5/JSR14)
  150. * Notes:
  151. * o We only allow the "extends" keyword and not the "implements"
  152. * keyword, since thats what JSR14 seems to imply.
  153. * o Thanks to Monty Zukowski for his help on the antlr-interest
  154. * mail list.
  155. * o Thanks to Alan Eliasen for testing the grammar over his
  156. * Fink source base
  157. *
  158. * Version 1.22 (July, 2004)
  159. * Changes by Michael Studman to support Java 1.5 language extensions
  160. * Notes:
  161. * o Added support for annotations types
  162. * o Finished off Matt Quail's generics enhancements to support bound type arguments
  163. * o Added support for new for statement syntax
  164. * o Added support for static import syntax
  165. * o Added support for enum types
  166. * o Tested against JDK 1.5 source base and source base of jdigraph project
  167. * o Thanks to Matt Quail for doing the hard part by doing most of the generics work
  168. *
  169. * Version 1.22.1 (July 28, 2004)
  170. * Bug/omission fixes for Java 1.5 language support
  171. * o Fixed tree structure bug with classOrInterface - thanks to Pieter Vangorpto for
  172. * spotting this
  173. * o Fixed bug where incorrect handling of SR and BSR tokens would cause type
  174. * parameters to be recognised as type arguments.
  175. * o Enabled type parameters on constructors, annotations on enum constants
  176. * and package definitions
  177. * o Fixed problems when parsing if ((char.class.equals(c))) {} - solution by Matt Quail at Cenqua
  178. *
  179. * Version 1.22.2 (July 28, 2004)
  180. * Slight refactoring of Java 1.5 language support
  181. * o Refactored for/"foreach" productions so that original literal "for" literal
  182. * is still used but the for sub-clauses vary by token type
  183. * o Fixed bug where type parameter was not included in generic constructor's branch of AST
  184. *
  185. * Version 1.22.3 (August 26, 2004)
  186. * Bug fixes as identified by Michael Stahl; clean up of tabs/spaces
  187. * and other refactorings
  188. * o Fixed typeParameters omission in identPrimary and newStatement
  189. * o Replaced GT reconcilliation code with simple semantic predicate
  190. * o Adapted enum/assert keyword checking support from Michael Stahl's java15 grammar
  191. * o Refactored typeDefinition production and field productions to reduce duplication
  192. *
  193. * Version 1.22.4 (October 21, 2004)
  194. * Small bux fixes
  195. * o Added typeArguments to explicitConstructorInvocation, e.g. new <String>MyParameterised()
  196. * o Added typeArguments to postfixExpression productions for anonymous inner class super
  197. * constructor invocation, e.g. new Outer().<String>super()
  198. * o Fixed bug in array declarations identified by Geoff Roy
  199. *
  200. * Version 1.22.4.g.1
  201. * o I have taken java.g for Java1.5 from Michael Studman (1.22.4)
  202. * and have applied the groovy.diff from java.g (1.22) by John Rose
  203. * back onto the new root (1.22.4) - Jeremy Rayner (Jan 2005)
  204. * o for a map of the task see...
  205. * http://groovy.javanicus.com/java-g.png
  206. *
  207. * Version 1.22.4.g.2
  208. * o mkempf, rkleeb, Dec 2007
  209. * o fixed various rules so that they call the correct Create Method
  210. * to make sure that the line information are correct
  211. *
  212. * This grammar is in the PUBLIC DOMAIN
  213. */
  214. public class GroovyRecognizer extends antlr.LLkParser implements GroovyTokenTypes
  215. {
  216. /** This factory is the correct way to wire together a Groovy parser and lexer. */
  217. public static GroovyRecognizer make(GroovyLexer lexer) {
  218. GroovyRecognizer parser = new GroovyRecognizer(lexer.plumb());
  219. // TODO: set up a common error-handling control block, to avoid excessive tangle between these guys
  220. parser.lexer = lexer;
  221. lexer.parser = parser;
  222. parser.getASTFactory().setASTNodeClass(GroovySourceAST.class);
  223. parser.warningList = new ArrayList();
  224. parser.errorList = new ArrayList();
  225. return parser;
  226. }
  227. // Create a scanner that reads from the input stream passed to us...
  228. public static GroovyRecognizer make(InputStream in) { return make(new GroovyLexer(in)); }
  229. public static GroovyRecognizer make(Reader in) { return make(new GroovyLexer(in)); }
  230. public static GroovyRecognizer make(InputBuffer in) { return make(new GroovyLexer(in)); }
  231. public static GroovyRecognizer make(LexerSharedInputState in) { return make(new GroovyLexer(in)); }
  232. private static GroovySourceAST dummyVariableToforceClassLoaderToFindASTClass = new GroovySourceAST();
  233. List warningList;
  234. public List getWarningList() { return warningList; }
  235. List errorList;
  236. public List getErrorList() { return errorList; }
  237. GroovyLexer lexer;
  238. public GroovyLexer getLexer() { return lexer; }
  239. public void setFilename(String f) { super.setFilename(f); lexer.setFilename(f); }
  240. private SourceBuffer sourceBuffer;
  241. public void setSourceBuffer(SourceBuffer sourceBuffer) {
  242. this.sourceBuffer = sourceBuffer;
  243. }
  244. /** Create an AST node with the token type and text passed in, but
  245. * with the same background information as another supplied Token (e.g.&nbsp;line numbers).
  246. * To be used in place of antlr tree construction syntax,
  247. * i.e. #[TOKEN,"text"] becomes create(TOKEN,"text",anotherToken)
  248. *
  249. * todo - change antlr.ASTFactory to do this instead...
  250. */
  251. public AST create(int type, String txt, AST first) {
  252. AST t = astFactory.create(type,txt);
  253. if ( t != null && first != null) {
  254. // first copy details from first token
  255. t.initialize(first);
  256. // then ensure that type and txt are specific to this new node
  257. t.initialize(type,txt);
  258. }
  259. return t;
  260. }
  261. private AST attachLast(AST t, Object last) {
  262. if ((t instanceof GroovySourceAST) && (last instanceof SourceInfo)) {
  263. SourceInfo lastInfo = (SourceInfo) last;
  264. GroovySourceAST node = (GroovySourceAST)t;
  265. node.setColumnLast(lastInfo.getColumn());
  266. node.setLineLast(lastInfo.getLine());
  267. // This is a good point to call node.setSnippet(),
  268. // but it bulks up the AST too much for production code.
  269. }
  270. return t;
  271. }
  272. public AST create(int type, String txt, Token first, Token last) {
  273. return attachLast(create(type, txt, astFactory.create(first)), last);
  274. }
  275. public AST create(int type, String txt, AST first, Token last) {
  276. return attachLast(create(type, txt, first), last);
  277. }
  278. public AST create(int type, String txt, AST first, AST last) {
  279. return attachLast(create(type, txt, first), last);
  280. }
  281. /**
  282. * Clones the token
  283. */
  284. public Token cloneToken(Token t) {
  285. CommonToken clone = new CommonToken(t.getType(),t.getText());
  286. clone.setLine(t.getLine());
  287. clone.setColumn(t.getColumn());
  288. return clone;
  289. }
  290. // stuff to adjust ANTLR's tracing machinery
  291. public static boolean tracing = false; // only effective if antlr.Tool is run with -traceParser
  292. public void traceIn(String rname) throws TokenStreamException {
  293. if (!GroovyRecognizer.tracing) return;
  294. super.traceIn(rname);
  295. }
  296. public void traceOut(String rname) throws TokenStreamException {
  297. if (!GroovyRecognizer.tracing) return;
  298. if (returnAST != null) rname += returnAST.toStringList();
  299. super.traceOut(rname);
  300. }
  301. // Error handling. This is a funnel through which parser errors go, when the parser can suggest a solution.
  302. public void requireFailed(String problem, String solution) throws SemanticException {
  303. // TODO: Needs more work.
  304. Token lt = null;
  305. int lineNum = Token.badToken.getLine(), colNum = Token.badToken.getColumn();
  306. try {
  307. lt = LT(1);
  308. if(lt != null) {
  309. lineNum = lt.getLine();
  310. colNum = lt.getColumn();
  311. }
  312. }
  313. catch (TokenStreamException ee) {
  314. if(ee instanceof TokenStreamRecognitionException) {
  315. lineNum = ((TokenStreamRecognitionException) ee).recog.getLine();
  316. colNum = ((TokenStreamRecognitionException) ee).recog.getColumn();
  317. }
  318. }
  319. throw new SemanticException(problem + ";\n solution: " + solution,
  320. getFilename(), lineNum, colNum);
  321. }
  322. public void addWarning(String warning, String solution) {
  323. Token lt = null;
  324. try { lt = LT(1); }
  325. catch (TokenStreamException ee) { }
  326. if (lt == null) lt = Token.badToken;
  327. Map row = new HashMap();
  328. row.put("warning", warning);
  329. row.put("solution", solution);
  330. row.put("filename", getFilename());
  331. row.put("line", Integer.valueOf(lt.getLine()));
  332. row.put("column", Integer.valueOf(lt.getColumn()));
  333. // System.out.println(row);
  334. warningList.add(row);
  335. }
  336. /**
  337. * Report a recovered error.
  338. */
  339. public void reportError(String message) {
  340. Token lt = null;
  341. try { lt = LT(1); }
  342. catch (TokenStreamException ee) { }
  343. if (lt == null) lt = Token.badToken;
  344. Map row = new HashMap();
  345. row.put("error" ,message);
  346. row.put("filename", getFilename());
  347. row.put("line", new Integer(lt.getLine()));
  348. row.put("column", new Integer(lt.getColumn()));
  349. errorList.add(row);
  350. }
  351. /**
  352. * Report a recovered exception.
  353. */
  354. public void reportError(RecognitionException e) {
  355. Token lt = null;
  356. try { lt = LT(1); }
  357. catch (TokenStreamException ee) { }
  358. if (lt == null) lt = Token.badToken;
  359. Map row = new HashMap();
  360. row.put("error", e.getMessage());
  361. row.put("filename", getFilename());
  362. row.put("line",new Integer(lt.getLine()));
  363. row.put("column", new Integer(lt.getColumn()));
  364. errorList.add(row);
  365. }
  366. // Convenience method for checking of expected error syndromes.
  367. private void require(boolean z, String problem, String solution) throws SemanticException {
  368. if (!z) requireFailed(problem, solution);
  369. }
  370. private boolean matchGenericTypeBrackets(boolean z, String problem, String solution) throws SemanticException {
  371. if (!z) matchGenericTypeBracketsFailed(problem, solution);
  372. return z;
  373. }
  374. public void matchGenericTypeBracketsFailed(String problem, String solution) throws SemanticException {
  375. Token lt = null;
  376. int lineNum = Token.badToken.getLine(), colNum = Token.badToken.getColumn();
  377. try {
  378. lt = LT(1);
  379. if(lt != null) {
  380. lineNum = lt.getLine();
  381. colNum = lt.getColumn();
  382. }
  383. }
  384. catch (TokenStreamException ee) {
  385. if(ee instanceof TokenStreamRecognitionException) {
  386. lineNum = ((TokenStreamRecognitionException) ee).recog.getLine();
  387. colNum = ((TokenStreamRecognitionException) ee).recog.getColumn();
  388. }
  389. }
  390. throw new SemanticException(problem + ";\n solution: " + solution,
  391. getFilename(), lineNum, colNum);
  392. }
  393. // Query a name token to see if it begins with a capital letter.
  394. // This is used to tell the difference (w/o symbol table access) between {String x} and {println x}.
  395. private boolean isUpperCase(Token x) {
  396. if (x == null || x.getType() != IDENT) return false; // cannot happen?
  397. String xtext = x.getText();
  398. return (xtext.length() > 0 && Character.isUpperCase(xtext.charAt(0)));
  399. }
  400. private AST currentClass = null; // current enclosing class (for constructor recognition)
  401. // Query a name token to see if it is identical with the current class name.
  402. // This is used to distinguish constructors from other methods.
  403. private boolean isConstructorIdent(Token x) {
  404. if (currentClass == null) return false;
  405. if (currentClass.getType() != IDENT) return false; // cannot happen?
  406. String cname = currentClass.getText();
  407. if (x == null || x.getType() != IDENT) return false; // cannot happen?
  408. return cname.equals(x.getText());
  409. }
  410. // Scratch variable for last 'sep' token.
  411. // Written by the 'sep' rule, read only by immediate callers of 'sep'.
  412. // (Not entirely clean, but better than a million xx=sep occurrences.)
  413. private int sepToken = EOF;
  414. // Scratch variable for last argument list; tells whether there was a label.
  415. // Written by 'argList' rule, read only by immediate callers of 'argList'.
  416. private boolean argListHasLabels = false;
  417. // Scratch variable, holds most recently completed pathExpression.
  418. // Read only by immediate callers of 'pathExpression' and 'expression'.
  419. private AST lastPathExpression = null;
  420. // Inherited attribute pushed into most expression rules.
  421. // If not zero, it means that the left context of the expression
  422. // being parsed is a statement boundary or an initializer sign '='.
  423. // Only such expressions are allowed to reach across newlines
  424. // to pull in an LCURLY and appended block.
  425. private final int LC_STMT = 1, LC_INIT = 2;
  426. /**
  427. * Counts the number of LT seen in the typeArguments production.
  428. * It is used in semantic predicates to ensure we have seen
  429. * enough closing '>' characters; which actually may have been
  430. * either GT, SR or BSR tokens.
  431. */
  432. private int ltCounter = 0;
  433. /* This symbol is used to work around a known ANTLR limitation.
  434. * In a loop with syntactic predicate, ANTLR needs help knowing
  435. * that the loop exit is a second alternative.
  436. * Example usage: ( (LCURLY)=> block | {ANTLR_LOOP_EXIT}? )*
  437. * Probably should be an ANTLR RFE.
  438. */
  439. ////// Original comment in Java grammar:
  440. // Unfortunately a syntactic predicate can only select one of
  441. // multiple alternatives on the same level, not break out of
  442. // an enclosing loop, which is why this ugly hack (a fake
  443. // empty alternative with always-false semantic predicate)
  444. // is necessary.
  445. private static final boolean ANTLR_LOOP_EXIT = false;
  446. protected GroovyRecognizer(TokenBuffer tokenBuf, int k) {
  447. super(tokenBuf,k);
  448. tokenNames = _tokenNames;
  449. buildTokenTypeASTClassMap();
  450. astFactory = new ASTFactory(getTokenTypeToASTClassMap());
  451. }
  452. public GroovyRecognizer(TokenBuffer tokenBuf) {
  453. this(tokenBuf,2);
  454. }
  455. protected GroovyRecognizer(TokenStream lexer, int k) {
  456. super(lexer,k);
  457. tokenNames = _tokenNames;
  458. buildTokenTypeASTClassMap();
  459. astFactory = new ASTFactory(getTokenTypeToASTClassMap());
  460. }
  461. public GroovyRecognizer(TokenStream lexer) {
  462. this(lexer,2);
  463. }
  464. public GroovyRecognizer(ParserSharedInputState state) {
  465. super(state,2);
  466. tokenNames = _tokenNames;
  467. buildTokenTypeASTClassMap();
  468. astFactory = new ASTFactory(getTokenTypeToASTClassMap());
  469. }
  470. public final void compilationUnit() throws RecognitionException, TokenStreamException {
  471. returnAST = null;
  472. ASTPair currentAST = new ASTPair();
  473. AST compilationUnit_AST = null;
  474. {
  475. switch ( LA(1)) {
  476. case SH_COMMENT:
  477. {
  478. match(SH_COMMENT);
  479. break;
  480. }
  481. case EOF:
  482. case FINAL:
  483. case ABSTRACT:
  484. case STRICTFP:
  485. case LITERAL_package:
  486. case LITERAL_import:
  487. case LITERAL_static:
  488. case LITERAL_def:
  489. case LBRACK:
  490. case IDENT:
  491. case STRING_LITERAL:
  492. case LPAREN:
  493. case LITERAL_class:
  494. case LITERAL_interface:
  495. case LITERAL_enum:
  496. case AT:
  497. case LITERAL_super:
  498. case LITERAL_void:
  499. case LITERAL_boolean:
  500. case LITERAL_byte:
  501. case LITERAL_char:
  502. case LITERAL_short:
  503. case LITERAL_int:
  504. case LITERAL_float:
  505. case LITERAL_long:
  506. case LITERAL_double:
  507. case LITERAL_private:
  508. case LITERAL_public:
  509. case LITERAL_protected:
  510. case LITERAL_transient:
  511. case LITERAL_native:
  512. case LITERAL_threadsafe:
  513. case LITERAL_synchronized:
  514. case LITERAL_volatile:
  515. case LCURLY:
  516. case SEMI:
  517. case NLS:
  518. case LITERAL_this:
  519. case LITERAL_if:
  520. case LITERAL_while:
  521. case LITERAL_switch:
  522. case LITERAL_for:
  523. case LITERAL_return:
  524. case LITERAL_break:
  525. case LITERAL_continue:
  526. case LITERAL_throw:
  527. case LITERAL_assert:
  528. case PLUS:
  529. case MINUS:
  530. case LITERAL_try:
  531. case LITERAL_false:
  532. case LITERAL_new:
  533. case LITERAL_null:
  534. case LITERAL_true:
  535. case INC:
  536. case DEC:
  537. case BNOT:
  538. case LNOT:
  539. case STRING_CTOR_START:
  540. case NUM_INT:
  541. case NUM_FLOAT:
  542. case NUM_LONG:
  543. case NUM_DOUBLE:
  544. case NUM_BIG_INT:
  545. case NUM_BIG_DECIMAL:
  546. {
  547. break;
  548. }
  549. default:
  550. {
  551. throw new NoViableAltException(LT(1), getFilename());
  552. }
  553. }
  554. }
  555. nls();
  556. {
  557. boolean synPredMatched5 = false;
  558. if (((LA(1)==LITERAL_package||LA(1)==AT) && (LA(2)==IDENT))) {
  559. int _m5 = mark();
  560. synPredMatched5 = true;
  561. inputState.guessing++;
  562. try {
  563. {
  564. annotationsOpt();
  565. match(LITERAL_package);
  566. }
  567. }
  568. catch (RecognitionException pe) {
  569. synPredMatched5 = false;
  570. }
  571. rewind(_m5);
  572. inputState.guessing--;
  573. }
  574. if ( synPredMatched5 ) {
  575. packageDefinition();
  576. astFactory.addASTChild(currentAST, returnAST);
  577. }
  578. else if ((_tokenSet_0.member(LA(1))) && (_tokenSet_1.member(LA(2)))) {
  579. {
  580. switch ( LA(1)) {
  581. case FINAL:
  582. case ABSTRACT:
  583. case STRICTFP:
  584. case LITERAL_import:
  585. case LITERAL_static:
  586. case LITERAL_def:
  587. case LBRACK:
  588. case IDENT:
  589. case STRING_LITERAL:
  590. case LPAREN:
  591. case LITERAL_class:
  592. case LITERAL_interface:
  593. case LITERAL_enum:
  594. case AT:
  595. case LITERAL_super:
  596. case LITERAL_void:
  597. case LITERAL_boolean:
  598. case LITERAL_byte:
  599. case LITERAL_char:
  600. case LITERAL_short:
  601. case LITERAL_int:
  602. case LITERAL_float:
  603. case LITERAL_long:
  604. case LITERAL_double:
  605. case LITERAL_private:
  606. case LITERAL_public:
  607. case LITERAL_protected:
  608. case LITERAL_transient:
  609. case LITERAL_native:
  610. case LITERAL_threadsafe:
  611. case LITERAL_synchronized:
  612. case LITERAL_volatile:
  613. case LCURLY:
  614. case LITERAL_this:
  615. case LITERAL_if:
  616. case LITERAL_while:
  617. case LITERAL_switch:
  618. case LITERAL_for:
  619. case LITERAL_return:
  620. case LITERAL_break:
  621. case LITERAL_continue:
  622. case LITERAL_throw:
  623. case LITERAL_assert:
  624. case PLUS:
  625. case MINUS:
  626. case LITERAL_try:
  627. case LITERAL_false:
  628. case LITERAL_new:
  629. case LITERAL_null:
  630. case LITERAL_true:
  631. case INC:
  632. case DEC:
  633. case BNOT:
  634. case LNOT:
  635. case STRING_CTOR_START:
  636. case NUM_INT:
  637. case NUM_FLOAT:
  638. case NUM_LONG:
  639. case NUM_DOUBLE:
  640. case NUM_BIG_INT:
  641. case NUM_BIG_DECIMAL:
  642. {
  643. statement(EOF);
  644. astFactory.addASTChild(currentAST, returnAST);
  645. break;
  646. }
  647. case EOF:
  648. case SEMI:
  649. case NLS:
  650. {
  651. break;
  652. }
  653. default:
  654. {
  655. throw new NoViableAltException(LT(1), getFilename());
  656. }
  657. }
  658. }
  659. }
  660. else {
  661. throw new NoViableAltException(LT(1), getFilename());
  662. }
  663. }
  664. {
  665. _loop9:
  666. do {
  667. if ((LA(1)==SEMI||LA(1)==NLS)) {
  668. sep();
  669. {
  670. switch ( LA(1)) {
  671. case FINAL:
  672. case ABSTRACT:
  673. case STRICTFP:
  674. case LITERAL_import:
  675. case LITERAL_static:
  676. case LITERAL_def:
  677. case LBRACK:
  678. case IDENT:
  679. case STRING_LITERAL:
  680. case LPAREN:
  681. case LITERAL_class:
  682. case LITERAL_interface:
  683. case LITERAL_enum:
  684. case AT:
  685. case LITERAL_super:
  686. case LITERAL_void:
  687. case LITERAL_boolean:
  688. case LITERAL_byte:
  689. case LITERAL_char:
  690. case LITERAL_short:
  691. case LITERAL_int:
  692. case LITERAL_float:
  693. case LITERAL_long:
  694. case LITERAL_double:
  695. case LITERAL_private:
  696. case LITERAL_public:
  697. case LITERAL_protected:
  698. case LITERAL_transient:
  699. case LITERAL_native:
  700. case LITERAL_threadsafe:
  701. case LITERAL_synchronized:
  702. case LITERAL_volatile:
  703. case LCURLY:
  704. case LITERAL_this:
  705. case LITERAL_if:
  706. case LITERAL_while:
  707. case LITERAL_switch:
  708. case LITERAL_for:
  709. case LITERAL_return:
  710. case LITERAL_break:
  711. case LITERAL_continue:
  712. case LITERAL_throw:
  713. case LITERAL_assert:
  714. case PLUS:
  715. case MINUS:
  716. case LITERAL_try:
  717. case LITERAL_false:
  718. case LITERAL_new:
  719. case LITERAL_null:
  720. case LITERAL_true:
  721. case INC:
  722. case DEC:
  723. case BNOT:
  724. case LNOT:
  725. case STRING_CTOR_START:
  726. case NUM_INT:
  727. case NUM_FLOAT:
  728. case NUM_LONG:
  729. case NUM_DOUBLE:
  730. case NUM_BIG_INT:
  731. case NUM_BIG_DECIMAL:
  732. {
  733. statement(sepToken);
  734. astFactory.addASTChild(currentAST, returnAST);
  735. break;
  736. }
  737. case EOF:
  738. case SEMI:
  739. case NLS:
  740. {
  741. break;
  742. }
  743. default:
  744. {
  745. throw new NoViableAltException(LT(1), getFilename());
  746. }
  747. }
  748. }
  749. }
  750. else {
  751. break _loop9;
  752. }
  753. } while (true);
  754. }
  755. match(Token.EOF_TYPE);
  756. compilationUnit_AST = (AST)currentAST.root;
  757. returnAST = compilationUnit_AST;
  758. }
  759. /** Zero or more insignificant newlines, all gobbled up and thrown away. */
  760. public final void nls() throws RecognitionException, TokenStreamException {
  761. returnAST = null;
  762. ASTPair currentAST = new ASTPair();
  763. AST nls_AST = null;
  764. {
  765. if ((LA(1)==NLS) && (_tokenSet_2.member(LA(2)))) {
  766. match(NLS);
  767. }
  768. else if ((_tokenSet_2.member(LA(1))) && (_tokenSet_3.member(LA(2)))) {
  769. }
  770. else {
  771. throw new NoViableAltException(LT(1), getFilename());
  772. }
  773. }
  774. returnAST = nls_AST;
  775. }
  776. public final void annotationsOpt() throws RecognitionException, TokenStreamException {
  777. returnAST = null;
  778. ASTPair currentAST = new ASTPair();
  779. AST annotationsOpt_AST = null;
  780. Token first = LT(1);
  781. {
  782. _loop88:
  783. do {
  784. if ((LA(1)==AT)) {
  785. annotation();
  786. astFactory.addASTChild(currentAST, returnAST);
  787. nls();
  788. }
  789. else {
  790. break _loop88;
  791. }
  792. } while (true);
  793. }
  794. if ( inputState.guessing==0 ) {
  795. annotationsOpt_AST = (AST)currentAST.root;
  796. annotationsOpt_AST = (AST)astFactory.make( (new ASTArray(2)).add(create(ANNOTATIONS,"ANNOTATIONS",first,LT(1))).add(annotationsOpt_AST));
  797. currentAST.root = annotationsOpt_AST;
  798. currentAST.child = annotationsOpt_AST!=null &&annotationsOpt_AST.getFirstChild()!=null ?
  799. annotationsOpt_AST.getFirstChild() : annotationsOpt_AST;
  800. currentAST.advanceChildToEnd();
  801. }
  802. annotationsOpt_AST = (AST)currentAST.root;
  803. returnAST = annotationsOpt_AST;
  804. }
  805. public final void packageDefinition() throws RecognitionException, TokenStreamException {
  806. returnAST = null;
  807. ASTPair currentAST = new ASTPair();
  808. AST packageDefinition_AST = null;
  809. Token p = null;
  810. AST p_AST = null;
  811. annotationsOpt();
  812. astFactory.addASTChild(currentAST, returnAST);
  813. p = LT(1);
  814. p_AST = astFactory.create(p);
  815. astFactory.makeASTRoot(currentAST, p_AST);
  816. match(LITERAL_package);
  817. if ( inputState.guessing==0 ) {
  818. p_AST.setType(PACKAGE_DEF);
  819. }
  820. identifier();
  821. astFactory.addASTChild(currentAST, returnAST);
  822. packageDefinition_AST = (AST)currentAST.root;
  823. returnAST = packageDefinition_AST;
  824. }
  825. /** A statement is an element of a block.
  826. * Typical statements are declarations (which are scoped to the block)
  827. * and expressions.
  828. */
  829. public final void statement(
  830. int prevToken
  831. ) throws RecognitionException, TokenStreamException {
  832. returnAST = null;
  833. ASTPair currentAST = new ASTPair();
  834. AST statement_AST = null;
  835. AST pfx_AST = null;
  836. AST es_AST = null;
  837. AST m_AST = null;
  838. AST ale_AST = null;
  839. AST ifCbs_AST = null;
  840. AST elseCbs_AST = null;
  841. AST while_sce_AST = null;
  842. Token s = null;
  843. AST s_AST = null;
  844. AST while_cbs_AST = null;
  845. AST switchSce_AST = null;
  846. AST cg_AST = null;
  847. AST synch_sce_AST = null;
  848. AST synch_cs_AST = null;
  849. boolean sce=false; Token first = LT(1); AST casesGroup_AST = null;
  850. switch ( LA(1)) {
  851. case LITERAL_if:
  852. {
  853. match(LITERAL_if);
  854. match(LPAREN);
  855. assignmentLessExpression();
  856. ale_AST = (AST)returnAST;
  857. match(RPAREN);
  858. nlsWarn();
  859. compatibleBodyStatement();
  860. ifCbs_AST = (AST)returnAST;
  861. {
  862. boolean synPredMatched280 = false;
  863. if (((_tokenSet_4.member(LA(1))) && (_tokenSet_5.member(LA(2))))) {
  864. int _m280 = mark();
  865. synPredMatched280 = true;
  866. inputState.guessing++;
  867. try {
  868. {
  869. {
  870. switch ( LA(1)) {
  871. case SEMI:
  872. case NLS:
  873. {
  874. sep();
  875. break;
  876. }
  877. case LITERAL_else:
  878. {
  879. break;
  880. }
  881. default:
  882. {
  883. throw new NoViableAltException(LT(1), getFilename());
  884. }
  885. }
  886. }
  887. match(LITERAL_else);
  888. }
  889. }
  890. catch (RecognitionException pe) {
  891. synPredMatched280 = false;
  892. }
  893. rewind(_m280);
  894. inputState.guessing--;
  895. }
  896. if ( synPredMatched280 ) {
  897. {
  898. switch ( LA(1)) {
  899. case SEMI:
  900. case NLS:
  901. {
  902. sep();
  903. break;
  904. }
  905. case LITERAL_else:
  906. {
  907. break;
  908. }
  909. default:
  910. {
  911. throw new NoViableAltException(LT(1), getFilename());
  912. }
  913. }
  914. }
  915. match(LITERAL_else);
  916. nlsWarn();
  917. compatibleBodyStatement();
  918. elseCbs_AST = (AST)returnAST;
  919. }
  920. else if ((_tokenSet_6.member(LA(1))) && (_tokenSet_7.member(LA(2)))) {
  921. }
  922. else {
  923. throw new NoViableAltException(LT(1), getFilename());
  924. }
  925. }
  926. if ( inputState.guessing==0 ) {
  927. statement_AST = (AST)currentAST.root;
  928. statement_AST = (AST)astFactory.make( (new ASTArray(4)).add(create(LITERAL_if,"if",first,LT(1))).add(ale_AST).add(ifCbs_AST).add(elseCbs_AST));
  929. currentAST.root = statement_AST;
  930. currentAST.child = statement_AST!=null &&statement_AST.getFirstChild()!=null ?
  931. statement_AST.getFirstChild() : statement_AST;
  932. currentAST.advanceChildToEnd();
  933. }
  934. statement_AST = (AST)currentAST.root;
  935. break;
  936. }
  937. case LITERAL_for:
  938. {
  939. forStatement();
  940. astFactory.addASTChild(currentAST, returnAST);
  941. statement_AST = (AST)currentAST.root;
  942. break;
  943. }
  944. case LITERAL_while:
  945. {
  946. match(LITERAL_while);
  947. match(LPAREN);
  948. sce=strictContextExpression(false);
  949. while_sce_AST = (AST)returnAST;
  950. match(RPAREN);
  951. nlsWarn();
  952. {
  953. switch ( LA(1)) {
  954. case SEMI:
  955. {
  956. s = LT(1);
  957. s_AST = astFactory.create(s);
  958. match(SEMI);
  959. break;
  960. }
  961. case FINAL:
  962. case ABSTRACT:
  963. case STRICTFP:
  964. case LITERAL_import:
  965. case LITERAL_static:
  966. case LITERAL_def:
  967. case LBRACK:
  968. case IDENT:
  969. case STRING_LITERAL:
  970. case LPAREN:
  971. case LITERAL_class:
  972. case LITERAL_interface:
  973. case LITERAL_enum:
  974. case AT:
  975. case LITERAL_super:
  976. case LITERAL_void:
  977. case LITERAL_boolean:
  978. case LITERAL_byte:
  979. case LITERAL_char:
  980. case LITERAL_short:
  981. case LITERAL_int:
  982. case LITERAL_float:
  983. case LITERAL_long:
  984. case LITERAL_double:
  985. case LITERAL_private:
  986. case LITERAL_public:
  987. case LITERAL_protected:
  988. case LITERAL_transient:
  989. case LITERAL_native:
  990. case LITERAL_threadsafe:
  991. case LITERAL_synchronized:
  992. case LITERAL_volatile:
  993. case LCURLY:
  994. case LITERAL_this:
  995. case LITERAL_if:
  996. case LITERAL_while:
  997. case LITERAL_switch:
  998. case LITERAL_for:
  999. case LITERAL_return:
  1000. case LITERAL_break:
  1001. case LITERAL_continue:
  1002. case LITERAL_throw:
  1003. case LITERAL_assert:
  1004. case PLUS:
  1005. case MINUS:
  1006. case LITERAL_try:
  1007. case LITERAL_false:
  1008. case LITERAL_new:
  1009. case LITERAL_null:
  1010. case LITERAL_true:
  1011. case INC:
  1012. case DEC:
  1013. case BNOT:
  1014. case LNOT:
  1015. case STRING_CTOR_START:
  1016. case NUM_INT:
  1017. case NUM_FLOAT:
  1018. case NUM_LONG:
  1019. case NUM_DOUBLE:
  1020. case NUM_BIG_INT:
  1021. case NUM_BIG_DECIMAL:
  1022. {
  1023. compatibleBodyStatement();
  1024. while_cbs_AST = (AST)returnAST;
  1025. break;
  1026. }
  1027. default:
  1028. {
  1029. throw new NoViableAltException(LT(1), getFilename());
  1030. }
  1031. }
  1032. }
  1033. if ( inputState.guessing==0 ) {
  1034. statement_AST = (AST)currentAST.root;
  1035. if (s_AST != null)
  1036. statement_AST = (AST)astFactory.make( (new ASTArray(3)).add(create(LITERAL_while,"Literal_while",first,LT(1))).add(while_sce_AST).add(s_AST));
  1037. else
  1038. statement_AST = (AST)astFactory.make( (new ASTArray(3)).add(create(LITERAL_while,"Literal_while",first,LT(1))).add(while_sce_AST).add(while_cbs_AST));
  1039. currentAST.root = statement_AST;
  1040. currentAST.child = statement_AST!=null &&statement_AST.getFirstChild()!=null ?
  1041. statement_AST.getFirstChild() : statement_AST;
  1042. currentAST.advanceChildToEnd();
  1043. }
  1044. statement_AST = (AST)currentAST.root;
  1045. break;
  1046. }
  1047. case LITERAL_import:
  1048. {
  1049. importStatement();
  1050. astFactory.addASTChild(currentAST, returnAST);
  1051. statement_AST = (AST)currentAST.root;
  1052. break;
  1053. }
  1054. case LITERAL_switch:
  1055. {
  1056. match(LITERAL_switch);
  1057. match(LPAREN);
  1058. sce=strictContextExpression(false);
  1059. switchSce_AST = (AST)returnAST;
  1060. match(RPAREN);
  1061. nlsWarn();
  1062. match(LCURLY);
  1063. nls();
  1064. {
  1065. _loop284:
  1066. do {
  1067. if ((LA(1)==LITERAL_default||LA(1)==LITERAL_case)) {
  1068. casesGroup();
  1069. cg_AST = (AST)returnAST;
  1070. if ( inputState.guessing==0 ) {
  1071. casesGroup_AST = (AST)astFactory.make( (new ASTArray(3)).add(null).add(casesGroup_AST).add(cg_AST));
  1072. }
  1073. }
  1074. else {
  1075. break _loop284;
  1076. }
  1077. } while (true);
  1078. }
  1079. match(RCURLY);
  1080. if ( inputState.guessing==0 ) {
  1081. statement_AST = (AST)currentAST.root;
  1082. statement_AST = (AST)astFactory.make( (new ASTArray(3)).add(create(LITERAL_switch,"switch",first,LT(1))).add(switchSce_AST).add(casesGroup_AST));
  1083. currentAST.root = statement_AST;
  1084. currentAST.child = statement_AST!=null &&statement_AST.getFirstChild()!=null ?
  1085. statement_AST.getFirstChild() : statement_AST;
  1086. currentAST.advanceChildToEnd();
  1087. }
  1088. statement_AST = (AST)currentAST.root;
  1089. break;
  1090. }
  1091. case LITERAL_try:
  1092. {
  1093. tryBlock();
  1094. astFactory.addASTChild(currentAST, returnAST);
  1095. statement_AST = (AST)currentAST.root;
  1096. break;
  1097. }
  1098. case LITERAL_return:
  1099. case LITERAL_break:
  1100. case LITERAL_continue:
  1101. case LITERAL_throw:
  1102. case LITERAL_assert:
  1103. {
  1104. branchStatement();
  1105. astFactory.addASTChild(currentAST, returnAST);
  1106. statement_AST = (AST)currentAST.root;
  1107. break;
  1108. }
  1109. default:
  1110. boolean synPredMatched267 = false;
  1111. if (((_tokenSet_8.member(LA(1))) && (_tokenSet_9.member(LA(2))))) {
  1112. int _m267 = mark();
  1113. synPredMatched267 = true;
  1114. inputState.guessing++;
  1115. try {
  1116. {
  1117. genericMethodStart();
  1118. }
  1119. }
  1120. catch (RecognitionException pe) {
  1121. synPredMatched267 = false;
  1122. }
  1123. rewind(_m267);
  1124. inputState.guessing--;
  1125. }
  1126. if ( synPredMatched267 ) {
  1127. genericMethod();
  1128. astFactory.addASTChild(currentAST, returnAST);
  1129. statement_AST = (AST)currentAST.root;
  1130. }
  1131. else {
  1132. boolean synPredMatched269 = false;
  1133. if (((_tokenSet_8.member(LA(1))) && (_tokenSet_10.member(LA(2))))) {
  1134. int _m269 = mark();
  1135. synPredMatched269 = true;
  1136. inputState.guessing++;
  1137. try {
  1138. {
  1139. multipleAssignmentDeclarationStart();
  1140. }
  1141. }
  1142. catch (RecognitionException pe) {
  1143. synPredMatched269 = false;
  1144. }
  1145. rewind(_m269);
  1146. inputState.guessing--;
  1147. }
  1148. if ( synPredMatched269 ) {
  1149. multipleAssignmentDeclaration();
  1150. astFactory.addASTChild(currentAST, returnAST);
  1151. statement_AST = (AST)currentAST.root;
  1152. }
  1153. else {
  1154. boolean synPredMatched271 = false;
  1155. if (((_tokenSet_11.member(LA(1))) && (_tokenSet_12.member(LA(2))))) {
  1156. int _m271 = mark();
  1157. synPredMatched271 = true;
  1158. inputState.guessing++;
  1159. try {
  1160. {
  1161. declarationStart();
  1162. }
  1163. }
  1164. catch (RecognitionException pe) {
  1165. synPredMatched271 = false;
  1166. }
  1167. rewind(_m271);
  1168. inputState.guessing--;
  1169. }
  1170. if ( synPredMatched271 ) {
  1171. declaration();
  1172. astFactory.addASTChild(currentAST, returnAST);
  1173. statement_AST = (AST)currentAST.root;
  1174. }
  1175. else {
  1176. boolean synPredMatched273 = false;
  1177. if (((LA(1)==IDENT) && (LA(2)==COLON))) {
  1178. int _m273 = mark();
  1179. synPredMatched273 = true;
  1180. inputState.guessing++;
  1181. try {
  1182. {
  1183. match(IDENT);
  1184. match(COLON);
  1185. }
  1186. }
  1187. catch (RecognitionException pe) {
  1188. synPredMatched273 = false;
  1189. }
  1190. rewind(_m273);
  1191. inputState.guessing--;
  1192. }
  1193. if ( synPredMatched273 ) {
  1194. statementLabelPrefix();
  1195. pfx_AST = (AST)returnAST;
  1196. if ( inputState.guessing==0 ) {
  1197. statement_AST = (AST)currentAST.root;
  1198. statement_AST = pfx_AST;
  1199. currentAST.root = statement_AST;
  1200. currentAST.child = statement_AST!=null &&statement_AST.getFirstChild()!=null ?
  1201. statement_AST.getFirstChild() : statement_AST;
  1202. currentAST.advanceChildToEnd();
  1203. }
  1204. {
  1205. boolean synPredMatched276 = false;
  1206. if (((LA(1)==LCURLY) && (_tokenSet_13.member(LA(2))))) {
  1207. int _m276 = mark();
  1208. synPredMatched276 = true;
  1209. inputState.guessing++;
  1210. try {
  1211. {
  1212. match(LCURLY);
  1213. }
  1214. }
  1215. catch (RecognitionException pe) {
  1216. synPredMatched276 = false;
  1217. }
  1218. rewind(_m276);
  1219. inputState.guessing--;
  1220. }
  1221. if ( synPredMatched276 ) {
  1222. openOrClosableBlock();
  1223. astFactory.addASTChild(currentAST, returnAST);
  1224. }
  1225. else if ((_tokenSet_14.member(LA(1))) && (_tokenSet_1.member(LA(2)))) {
  1226. statement(COLON);
  1227. astFactory.addASTChild(currentAST, returnAST);
  1228. }
  1229. else {
  1230. throw new NoViableAltException(LT(1), getFilename());
  1231. }
  1232. }
  1233. statement_AST = (AST)currentAST.root;
  1234. }
  1235. else if ((_tokenSet_15.member(LA(1))) && (_tokenSet_1.member(LA(2)))) {
  1236. expressionStatement(prevToken);
  1237. es_AST = (AST)returnAST;
  1238. astFactory.addASTChild(currentAST, returnAST);
  1239. statement_AST = (AST)currentAST.root;
  1240. }
  1241. else if ((_tokenSet_16.member(LA(1))) && (_tokenSet_17.member(LA(2)))) {
  1242. modifiersOpt();
  1243. m_AST = (AST)returnAST;
  1244. typeDefinitionInternal(m_AST);
  1245. astFactory.addASTChild(currentAST, returnAST);
  1246. statement_AST = (AST)currentAST.root;
  1247. }
  1248. else if ((LA(1)==LITERAL_synchronized) && (LA(2)==LPAREN)) {
  1249. match(LITERAL_synchronized);
  1250. match(LPAREN);
  1251. sce=strictContextExpression(false);
  1252. synch_sce_AST = (AST)returnAST;
  1253. match(RPAREN);
  1254. nlsWarn();
  1255. compoundStatement();
  1256. synch_cs_AST = (AST)returnAST;
  1257. if ( inputState.guessing==0 ) {
  1258. statement_AST = (AST)currentAST.root;
  1259. statement_AST = (AST)astFactory.make( (new ASTArray(3)).add(create(LITERAL_synchronized,"synchronized",first,LT(1))).add(synch_sce_AST).add(synch_cs_AST));
  1260. currentAST.root = statement_AST;
  1261. currentAST.child = statement_AST!=null &&statement_AST.getFirstChild()!=null ?
  1262. statement_AST.getFirstChild() : statement_AST;
  1263. currentAST.advanceChildToEnd();
  1264. }
  1265. statement_AST = (AST)currentAST.root;
  1266. }
  1267. else {
  1268. throw new NoViableAltException(LT(1), getFilename());
  1269. }
  1270. }}}}
  1271. returnAST = statement_AST;
  1272. }
  1273. /** A statement separator is either a semicolon or a significant newline.
  1274. * Any number of additional (insignificant) newlines may accompany it.
  1275. */
  1276. public final void sep() throws RecognitionException, TokenStreamException {
  1277. returnAST = null;
  1278. ASTPair currentAST = new ASTPair();
  1279. AST sep_AST = null;
  1280. switch ( LA(1)) {
  1281. case SEMI:
  1282. {
  1283. match(SEMI);
  1284. {
  1285. _loop530:
  1286. do {
  1287. if ((LA(1)==NLS) && (_tokenSet_18.member(LA(2)))) {
  1288. match(NLS);
  1289. }
  1290. else {
  1291. break _loop530;
  1292. }
  1293. } while (true);
  1294. }
  1295. if ( inputState.guessing==0 ) {
  1296. sepToken = SEMI;
  1297. }
  1298. break;
  1299. }
  1300. case NLS:
  1301. {
  1302. match(NLS);
  1303. if ( inputState.guessing==0 ) {
  1304. sepToken = NLS;
  1305. }
  1306. {
  1307. _loop534:
  1308. do {
  1309. if ((LA(1)==SEMI) && (_tokenSet_18.member(LA(2)))) {
  1310. match(SEMI);
  1311. {
  1312. _loop533:
  1313. do {
  1314. if ((LA(1)==NLS) && (_tokenSet_18.member(LA(2)))) {
  1315. match(NLS);
  1316. }
  1317. else {
  1318. break _loop533;
  1319. }
  1320. } while (true);
  1321. }
  1322. if ( inputState.guessing==0 ) {
  1323. sepToken = SEMI;
  1324. }
  1325. }
  1326. else {
  1327. break _loop534;
  1328. }
  1329. } while (true);
  1330. }
  1331. break;
  1332. }
  1333. default:
  1334. {
  1335. throw new NoViableAltException(LT(1), getFilename());
  1336. }
  1337. }
  1338. returnAST = sep_AST;
  1339. }
  1340. /** A Groovy script or simple expression. Can be anything legal inside {...}. */
  1341. public final void snippetUnit() throws RecognitionException, TokenStreamException {
  1342. returnAST = null;
  1343. ASTPair currentAST = new ASTPair();
  1344. AST snippetUnit_AST = null;
  1345. nls();
  1346. blockBody(EOF);
  1347. astFactory.addASTChild(currentAST, returnAST);
  1348. snippetUnit_AST = (AST)currentAST.root;
  1349. returnAST = snippetUnit_AST;
  1350. }
  1351. /** A block body is a parade of zero or more statements or expressions. */
  1352. public final void blockBody(
  1353. int prevToken
  1354. ) throws RecognitionException, TokenStreamException {
  1355. returnAST = null;
  1356. ASTPair currentAST = new ASTPair();
  1357. AST blockBody_AST = null;
  1358. {
  1359. switch ( LA(1)) {
  1360. case FINAL:
  1361. case ABSTRACT:
  1362. case STRICTFP:
  1363. case LITERAL_import:
  1364. case LITERAL_static:
  1365. case LITERAL_def:
  1366. case LBRACK:
  1367. case IDENT:
  1368. case STRING_LITERAL:
  1369. case LPAREN:
  1370. case LITERAL_class:
  1371. case LITERAL_interface:
  1372. case LITERAL_enum:
  1373. case AT:
  1374. case LITERAL_super:
  1375. case LITERAL_void:
  1376. case LITERAL_boolean:
  1377. case LITERAL_byte:
  1378. case LITERAL_char:
  1379. case LITERAL_short:
  1380. case LITERAL_int:
  1381. case LITERAL_float:
  1382. case LITERAL_long:
  1383. case LITERAL_double:
  1384. case LITERAL_private:
  1385. case LITERAL_public:
  1386. case LITERAL_protected:
  1387. case LITERAL_transient:
  1388. case LITERAL_native:
  1389. case LITERAL_threadsafe:
  1390. case LITERAL_synchronized:
  1391. case LITERAL_volatile:
  1392. case LCURLY:
  1393. case LITERAL_this:
  1394. case LITERAL_if:
  1395. case LITERAL_while:
  1396. case LITERAL_switch:
  1397. case LITERAL_for:
  1398. case LITERAL_return:
  1399. case LITERAL_break:
  1400. case LITERAL_continue:
  1401. case LITERAL_throw:
  1402. case LITERAL_assert:
  1403. case PLUS:
  1404. case MINUS:
  1405. case LITERAL_try:
  1406. case LITERAL_false:
  1407. case LITERAL_new:
  1408. case LITERAL_null:
  1409. case LITERAL_true:
  1410. case INC:
  1411. case DEC:
  1412. case BNOT:
  1413. case LNOT:
  1414. case STRING_CTOR_START:
  1415. case NUM_INT:
  1416. case NUM_FLOAT:
  1417. case NUM_LONG:
  1418. case NUM_DOUBLE:
  1419. case NUM_BIG_INT:
  1420. case NUM_BIG_DECIMAL:
  1421. {
  1422. statement(prevToken);
  1423. astFactory.addASTChild(currentAST, returnAST);
  1424. break;
  1425. }
  1426. case EOF:
  1427. case RCURLY:
  1428. case SEMI:
  1429. case NLS:
  1430. {
  1431. break;
  1432. }
  1433. default:
  1434. {
  1435. throw new NoViableAltException(LT(1), getFilename());
  1436. }
  1437. }
  1438. }
  1439. {
  1440. _loop261:
  1441. do {
  1442. if ((LA(1)==SEMI||LA(1)==NLS)) {
  1443. sep();
  1444. {
  1445. switch ( LA(1)) {
  1446. case FINAL:
  1447. case ABSTRACT:
  1448. case STRICTFP:
  1449. case LITERAL_import:
  1450. case LITERAL_static:
  1451. case LITERAL_def:
  1452. case LBRACK:
  1453. case IDENT:
  1454. case STRING_LITERAL:
  1455. case LPAREN:
  1456. case LITERAL_class:
  1457. case LITERAL_interface:
  1458. case LITERAL_enum:
  1459. case AT:
  1460. case LITERAL_super:
  1461. case LITERAL_void:
  1462. case LITERAL_boolean:
  1463. case LITERAL_byte:
  1464. case LITERAL_char:
  1465. case LITERAL_short:
  1466. case LITERAL_int:
  1467. case LITERAL_float:
  1468. case LITERAL_long:
  1469. case LITERAL_double:
  1470. case LITERAL_private:
  1471. case LITERAL_public:
  1472. case LITERAL_protected:
  1473. case LITERAL_transient:
  1474. case LITERAL_native:
  1475. case LITERAL_threadsafe:
  1476. case LITERAL_synchronized:
  1477. case LITERAL_volatile:
  1478. case LCURLY:
  1479. case LITERAL_this:
  1480. case LITERAL_if:
  1481. case LITERAL_while:
  1482. case LITERAL_switch:
  1483. case LITERAL_for:
  1484. case LITERAL_return:
  1485. case LITERAL_break:
  1486. case LITERAL_continue:
  1487. case LITERAL_throw:
  1488. case LITERAL_assert:
  1489. case PLUS:
  1490. case MINUS:
  1491. case LITERAL_try:
  1492. case LITERAL_false:
  1493. case LITERAL_new:
  1494. case LITERAL_null:
  1495. case LITERAL_true:
  1496. case INC:
  1497. case DEC:
  1498. case BNOT:
  1499. case LNOT:
  1500. case STRING_CTOR_START:
  1501. case NUM_INT:
  1502. case NUM_FLOAT:
  1503. case NUM_LONG:
  1504. case NUM_DOUBLE:
  1505. case NUM_BIG_INT:
  1506. case NUM_BIG_DECIMAL:
  1507. {
  1508. statement(sepToken);
  1509. astFactory.addASTChild(currentAST, returnAST);
  1510. break;
  1511. }
  1512. case EOF:
  1513. case RCURLY:
  1514. case SEMI:
  1515. case NLS:
  1516. {
  1517. break;
  1518. }
  1519. default:
  1520. {
  1521. throw new NoViableAltException(LT(1), getFilename());
  1522. }
  1523. }
  1524. }
  1525. }
  1526. else {
  1527. break _loop261;
  1528. }
  1529. } while (true);
  1530. }
  1531. blockBody_AST = (AST)currentAST.root;
  1532. returnAST = blockBody_AST;
  1533. }
  1534. public final void identifier() throws RecognitionException, TokenStreamException {
  1535. returnAST = null;
  1536. ASTPair currentAST = new ASTPair();
  1537. AST identifier_AST = null;
  1538. Token i1 = null;
  1539. AST i1_AST = null;
  1540. Token d = null;
  1541. AST d_AST = null;
  1542. Token i2 = null;
  1543. AST i2_AST = null;
  1544. Token first = LT(1);
  1545. i1 = LT(1);
  1546. i1_AST = astFactory.create(i1);
  1547. match(IDENT);
  1548. {
  1549. _loop71:
  1550. do {
  1551. if ((LA(1)==DOT)) {
  1552. d = LT(1);
  1553. d_AST = astFactory.create(d);
  1554. match(DOT);
  1555. nls();
  1556. i2 = LT(1);
  1557. i2_AST = astFactory.create(i2);
  1558. match(IDENT);
  1559. if ( inputState.guessing==0 ) {
  1560. i1_AST = (AST)astFactory.make( (new ASTArray(3)).add(create(DOT,".",first,LT(1))).add(i1_AST).add(i2_AST));
  1561. }
  1562. }
  1563. else {
  1564. break _loop71;
  1565. }
  1566. } while (true);
  1567. }
  1568. if ( inputState.guessing==0 ) {
  1569. identifier_AST = (AST)currentAST.root;
  1570. identifier_AST = i1_AST;
  1571. currentAST.root = identifier_AST;
  1572. currentAST.child = identifier_AST!=null &&identifier_AST.getFirstChild()!=null ?
  1573. identifier_AST.getFirstChild() : identifier_AST;
  1574. currentAST.advanceChildToEnd();
  1575. }
  1576. identifier_AST = (AST)currentAST.root;
  1577. returnAST = identifier_AST;
  1578. }
  1579. public final void importStatement() throws RecognitionException, TokenStreamException {
  1580. returnAST = null;
  1581. ASTPair currentAST = new ASTPair();
  1582. AST importStatement_AST = null;
  1583. AST is_AST = null;
  1584. Token first = LT(1); boolean isStatic = false;

Large files files are truncated, but you can click here to view the full file