/plugins/PHPParser/tags/PHPParser-1.4.1/src/gatchan/phpparser/parser/PHPParser.java

# · Java · 2069 lines · 1836 code · 89 blank · 144 comment · 101 complexity · 0d6fd0310aa3367d4108826a0a3cb609 MD5 · raw file

Large files are truncated click here to view the full file

  1. /* Generated By:JavaCC: Do not edit this line. PHPParser.java */
  2. package gatchan.phpparser.parser;
  3. //{{{ Imports
  4. import java.util.ArrayList;
  5. import java.io.*;
  6. import java.util.List;
  7. import java.util.Stack;
  8. import net.sourceforge.phpdt.internal.compiler.ast.declarations.VariableUsage;
  9. import net.sourceforge.phpdt.internal.compiler.ast.*;
  10. import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
  11. //}}}
  12. //{{{ PHPParser class
  13. /**
  14. * @author Matthieu Casanova <chocolat.mou@gmail.com>
  15. * @version $Id: PHPParser.java 20113 2011-10-18 17:21:33Z kpouer $
  16. */
  17. public class PHPParser implements PHPParserConstants {
  18. //{{{ Fields
  19. //{{{ constants for methods and function distinction (some keywords are allowed in method classes
  20. public static final int CONST_METHOD = 0;
  21. public static final int CONST_FUNCTION = 1;
  22. //}}}
  23. public static final int ERROR = 2;
  24. public static final int WARNING = 1;
  25. public static final int INFO = 0;
  26. /** The current segment. */
  27. private Outlineable currentSegment;
  28. /** The message of the current ParseException. If it's null it's because the parse exception wasn't handled */
  29. private String errorMessage;
  30. private int errorStart = -1;
  31. private int errorEnd = -1;
  32. private PHPDocument phpDocument;
  33. public static final String SYNTAX_ERROR_CHAR = "syntax error";
  34. /**
  35. * The point where html starts.
  36. * It will be used by the token manager to create HTMLCode objects
  37. */
  38. private int htmlStart;
  39. private int htmlLineStart;
  40. private int htmlColumnStart;
  41. //ast stack
  42. private static final int AstStackIncrement = 100;
  43. /** The stack of node. */
  44. private Statement[] nodes;
  45. /** The cursor in expression stack. */
  46. private int nodePtr;
  47. private final List<PHPParserListener> parserListeners = new ArrayList<PHPParserListener>();
  48. private String path;
  49. /** Tell if the parsing should be stopped. */
  50. private boolean shouldStop;
  51. private Stack<Scope> scopeStack;
  52. private Scope scope;
  53. private final List tempList = new ArrayList();
  54. /**
  55. * The current namespace
  56. */
  57. private String namespace;
  58. //}}}
  59. //{{{ PHPParser constructor
  60. public PHPParser()
  61. {
  62. } //}}}
  63. //{{{ setPath() method
  64. /**
  65. * Set the path of the file that is currently parsed.
  66. * This path will be sent in parse errors and messages
  67. *
  68. * @param path the path of the parsed file
  69. */
  70. public void setPath(String path)
  71. {
  72. this.path = path;
  73. } //}}}
  74. //{{{ getPath()
  75. public String getPath()
  76. {
  77. return path;
  78. } //}}}
  79. //{{{ stop()
  80. /**
  81. * Ask the parser to stop his work.
  82. */
  83. public void stop()
  84. {
  85. shouldStop = true;
  86. } //}}}
  87. //{{{ isStopped()
  88. public boolean isStopped()
  89. {
  90. return shouldStop;
  91. } //}}}
  92. //{{{ addParserListener(PHPParserListener listener)
  93. public void addParserListener(PHPParserListener listener)
  94. {
  95. if (!parserListeners.contains(listener))
  96. parserListeners.add(listener);
  97. } //}}}
  98. //{{{ removeParserListener(PHPParserListener listener)
  99. public void removeParserListener(PHPParserListener listener)
  100. {
  101. parserListeners.remove(listener);
  102. } //}}}
  103. //{{{ fireParseError(PHPParseErrorEvent e)
  104. public void fireParseError(PHPParseErrorEvent e)
  105. {
  106. for (PHPParserListener listener : parserListeners)
  107. listener.parseError(e);
  108. } //}}}
  109. //{{{ fireParseError() methods
  110. public void fireParseError(String message, String expected, Token token)
  111. {
  112. fireParseError(new PHPParseErrorEvent(ERROR,
  113. path,
  114. message,
  115. expected,
  116. token));
  117. }
  118. public void fireParseError(String message, AstNode node)
  119. {
  120. fireParseError(new PHPParseErrorEvent(ERROR,
  121. path,
  122. message,
  123. node.getSourceStart(),
  124. node.getSourceEnd(),
  125. node.getBeginLine(),
  126. node.getEndLine(),
  127. node.getBeginColumn(),
  128. node.getEndColumn()));
  129. } //}}}
  130. //{{{ fireParseMessage(PHPParseMessageEvent e)
  131. public void fireParseMessage(PHPParseMessageEvent e)
  132. {
  133. for (PHPParserListener listener: parserListeners)
  134. listener.parseMessage(e);
  135. } //}}}
  136. //{{{ phpParserTester(String strEval)
  137. public void phpParserTester(String strEval) throws ParseException
  138. {
  139. StringReader stream = new StringReader(strEval);
  140. if (jj_input_stream == null)
  141. {
  142. jj_input_stream = new SimpleCharStream(stream, 1, 1);
  143. token_source = new PHPParserTokenManager(jj_input_stream);
  144. }
  145. ReInit(new StringReader(strEval));
  146. init();
  147. phpDocument = new PHPDocument("_root");
  148. scope = new Scope();
  149. scopeStack = new Stack<Scope>();
  150. scopeStack.push(scope);
  151. currentSegment = phpDocument;
  152. token_source.SwitchTo(PHPPARSING);
  153. phpTest();
  154. } //}}}
  155. //{{{ htmlParserTester() methods
  156. public void htmlParserTester(File fileName) throws FileNotFoundException, ParseException
  157. {
  158. Reader stream = new FileReader(fileName);
  159. if (jj_input_stream == null)
  160. {
  161. jj_input_stream = new SimpleCharStream(stream, 1, 1);
  162. token_source = new PHPParserTokenManager(jj_input_stream);
  163. }
  164. ReInit(stream);
  165. init();
  166. phpDocument = new PHPDocument("_root");
  167. scope = new Scope();
  168. scopeStack = new Stack<Scope>();
  169. scopeStack.push(scope);
  170. currentSegment = phpDocument;
  171. phpFile();
  172. }
  173. public void htmlParserTester(String strEval) throws ParseException
  174. {
  175. StringReader stream = new StringReader(strEval);
  176. if (jj_input_stream == null)
  177. {
  178. jj_input_stream = new SimpleCharStream(stream, 1, 1);
  179. token_source = new PHPParserTokenManager(jj_input_stream);
  180. }
  181. ReInit(stream);
  182. init();
  183. phpDocument = new PHPDocument("_root");
  184. scope = new Scope();
  185. scopeStack = new Stack<Scope>();
  186. scopeStack.push(scope);
  187. currentSegment = phpDocument;
  188. phpFile();
  189. } //}}}
  190. //{{{ init()
  191. /**
  192. * Reinitialize the parser.
  193. */
  194. private void init()
  195. {
  196. nodes = new Statement[AstStackIncrement];
  197. nodePtr = -1;
  198. htmlStart = 0;
  199. htmlColumnStart = 0;
  200. htmlLineStart = 0;
  201. } //}}}
  202. //{{{ pushOnAstNodes(Statement node)
  203. /**
  204. * Add an php node on the stack.
  205. * @param node the node that will be added to the stack
  206. */
  207. private void pushOnAstNodes(Statement node)
  208. {
  209. try
  210. {
  211. nodes[++nodePtr] = node;
  212. }
  213. catch (IndexOutOfBoundsException e)
  214. {
  215. int oldStackLength = nodes.length;
  216. Statement[] oldStack = nodes;
  217. nodes = new Statement[oldStackLength + AstStackIncrement];
  218. System.arraycopy(oldStack, 0, nodes, 0, oldStackLength);
  219. nodePtr = oldStackLength;
  220. nodes[nodePtr] = node;
  221. }
  222. } //}}}
  223. //{{{ parse() methods
  224. public void parse() throws ParseException
  225. {
  226. phpFile();
  227. }
  228. public void parse(String s) throws ParseException
  229. {
  230. Reader reader = new StringReader(s);
  231. parse(reader);
  232. }
  233. public void parse(Reader reader) throws ParseException
  234. {
  235. phpDocument = new PHPDocument("_root");
  236. scope = new Scope();
  237. scopeStack = new Stack<Scope>();
  238. scopeStack.push(scope);
  239. currentSegment = phpDocument;
  240. if (jj_input_stream == null)
  241. {
  242. jj_input_stream = new SimpleCharStream(reader, 1, 1);
  243. jj_input_stream.setTabSize(1);
  244. token_source = new PHPParserTokenManager(jj_input_stream);
  245. }
  246. ReInit(reader);
  247. init();
  248. parse();
  249. Statement[] astNodes = new Statement[nodes.length];
  250. phpDocument.setNodes(astNodes);
  251. System.arraycopy(nodes,0,astNodes,0,nodes.length);
  252. phpDocument.analyzeCode(this);
  253. } //}}}
  254. //{{{ createNewHTMLCode()
  255. /**
  256. * Put a new html block in the stack.
  257. */
  258. public void createNewHTMLCode()
  259. {
  260. int currentPosition = token.sourceStart;
  261. if (currentPosition == htmlStart ||
  262. currentPosition < htmlStart ||
  263. currentPosition > jj_input_stream.getCurrentBuffer().length())
  264. {
  265. return;
  266. }
  267. // todo : reactivate this
  268. //String html = jj_input_stream.getCurrentBuffer().substring(htmlStart, currentPosition);
  269. String html = "";
  270. pushOnAstNodes(new HTMLCode(html, htmlStart,currentPosition,htmlLineStart,token.endLine,htmlColumnStart,token.endColumn));
  271. } //}}}
  272. //{{{ error_skipto(int kind)
  273. Token error_skipto(int kind)
  274. {
  275. // ParseException e = generateParseException(); // generate the exception object.
  276. // System.out.println(e.toString()); // print the error message
  277. Token t;
  278. do
  279. {
  280. t = getNextToken();
  281. }
  282. while (t.kind != kind && t.kind != EOF && t.kind != RBRACE);
  283. return t;
  284. } //}}}
  285. //{{{ getPHPDocument()
  286. public PHPDocument getPHPDocument()
  287. {
  288. return phpDocument;
  289. } //}}}
  290. //{{{ setTypeFromScope(Variable variable)
  291. private void setTypeFromScope(Variable variable)
  292. {
  293. VariableUsage usage = scope.getVariable(variable.getName(),variable.getBeginLine(),variable.getBeginColumn());
  294. if (usage != null)
  295. {
  296. variable.setType(usage.getType());
  297. }
  298. }
  299. //}}}
  300. //{{{ PHP Structures
  301. //{{{ phpTest()
  302. final public void phpTest() throws ParseException {
  303. Php();
  304. jj_consume_token(0);
  305. }
  306. //}}}
  307. //{{{ phpFile()
  308. final public void phpFile() throws ParseException {
  309. try {
  310. label_1:
  311. while (true) {
  312. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  313. case PHPSTARTSHORT:
  314. case PHPSTARTLONG:
  315. case PHPECHOSTART:
  316. case PHPEND:
  317. case ABSTRACT:
  318. case INTERFACE:
  319. case FINAL:
  320. case TRY:
  321. case THROW:
  322. case CLASS:
  323. case FUNCTION:
  324. case NAMESPACE:
  325. case USE:
  326. case IF:
  327. case ARRAY:
  328. case BREAK:
  329. case LIST:
  330. case PRINT:
  331. case ECHO:
  332. case INCLUDE:
  333. case REQUIRE:
  334. case INCLUDE_ONCE:
  335. case REQUIRE_ONCE:
  336. case GLOBAL:
  337. case STATIC:
  338. case CONST:
  339. case CONTINUE:
  340. case DO:
  341. case FOR:
  342. case NEW:
  343. case CLONE:
  344. case RETURN:
  345. case SWITCH:
  346. case WHILE:
  347. case FOREACH:
  348. case DEFINE:
  349. case GOTO:
  350. case NULL:
  351. case SUPER:
  352. case THIS:
  353. case TRUE:
  354. case FALSE:
  355. case STRING:
  356. case OBJECT:
  357. case BOOL:
  358. case BOOLEAN:
  359. case REAL:
  360. case DOUBLE:
  361. case FLOAT:
  362. case INT:
  363. case INTEGER:
  364. case AT:
  365. case BANG:
  366. case TILDE:
  367. case PLUS_PLUS:
  368. case MINUS_MINUS:
  369. case PLUS:
  370. case MINUS:
  371. case BIT_AND:
  372. case INTEGER_LITERAL:
  373. case FLOATING_POINT_LITERAL:
  374. case STRING_LITERAL:
  375. case DOUBLEQUOTE:
  376. case HEREDOCSTARTTOKEN:
  377. case DOLLAR:
  378. case IDENTIFIER:
  379. case LPAREN:
  380. case SEMICOLON:
  381. case LBRACE:
  382. ;
  383. break;
  384. default:
  385. jj_la1[0] = jj_gen;
  386. break label_1;
  387. }
  388. PhpBlock();
  389. }
  390. createNewHTMLCode();
  391. } catch (TokenMgrError e) {
  392. //{{{ Parse Error
  393. fireParseError(new PHPParseErrorEvent(ERROR,
  394. path,
  395. e.getMessage(),
  396. e.getMessage(),
  397. null,
  398. jj_input_stream.getBeginOffset(),
  399. jj_input_stream.getEndOffset(),
  400. jj_input_stream.getBeginLine(),
  401. jj_input_stream.getEndLine(),
  402. jj_input_stream.getBeginColumn(),
  403. jj_input_stream.getEndColumn())); //}}}
  404. }
  405. }
  406. //}}}
  407. //{{{ PhpBlock()
  408. /**
  409. * A php block is a <?= expression [;]?>
  410. * or <?php somephpcode ?>
  411. * or <? somephpcode ?>
  412. */
  413. final public void PhpBlock() throws ParseException {
  414. PHPEchoBlock phpEchoBlock;
  415. Token token,phpEnd;
  416. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  417. case PHPECHOSTART:
  418. phpEchoBlock = phpEchoBlock();
  419. pushOnAstNodes(phpEchoBlock);
  420. break;
  421. case PHPSTARTSHORT:
  422. case PHPSTARTLONG:
  423. case PHPEND:
  424. case ABSTRACT:
  425. case INTERFACE:
  426. case FINAL:
  427. case TRY:
  428. case THROW:
  429. case CLASS:
  430. case FUNCTION:
  431. case NAMESPACE:
  432. case USE:
  433. case IF:
  434. case ARRAY:
  435. case BREAK:
  436. case LIST:
  437. case PRINT:
  438. case ECHO:
  439. case INCLUDE:
  440. case REQUIRE:
  441. case INCLUDE_ONCE:
  442. case REQUIRE_ONCE:
  443. case GLOBAL:
  444. case STATIC:
  445. case CONST:
  446. case CONTINUE:
  447. case DO:
  448. case FOR:
  449. case NEW:
  450. case CLONE:
  451. case RETURN:
  452. case SWITCH:
  453. case WHILE:
  454. case FOREACH:
  455. case DEFINE:
  456. case GOTO:
  457. case NULL:
  458. case SUPER:
  459. case THIS:
  460. case TRUE:
  461. case FALSE:
  462. case STRING:
  463. case OBJECT:
  464. case BOOL:
  465. case BOOLEAN:
  466. case REAL:
  467. case DOUBLE:
  468. case FLOAT:
  469. case INT:
  470. case INTEGER:
  471. case AT:
  472. case BANG:
  473. case TILDE:
  474. case PLUS_PLUS:
  475. case MINUS_MINUS:
  476. case PLUS:
  477. case MINUS:
  478. case BIT_AND:
  479. case INTEGER_LITERAL:
  480. case FLOATING_POINT_LITERAL:
  481. case STRING_LITERAL:
  482. case DOUBLEQUOTE:
  483. case HEREDOCSTARTTOKEN:
  484. case DOLLAR:
  485. case IDENTIFIER:
  486. case LPAREN:
  487. case SEMICOLON:
  488. case LBRACE:
  489. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  490. case PHPSTARTSHORT:
  491. case PHPSTARTLONG:
  492. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  493. case PHPSTARTLONG:
  494. jj_consume_token(PHPSTARTLONG);
  495. break;
  496. case PHPSTARTSHORT:
  497. token = jj_consume_token(PHPSTARTSHORT);
  498. fireParseMessage(new PHPParseMessageEvent(INFO,
  499. PHPParseMessageEvent.MESSAGE_SHORT_OPEN_TAG,
  500. path,
  501. "You should use '<?php' instead of '<?' it will avoid some problems with XML",
  502. token));
  503. break;
  504. default:
  505. jj_la1[1] = jj_gen;
  506. jj_consume_token(-1);
  507. throw new ParseException();
  508. }
  509. break;
  510. default:
  511. jj_la1[2] = jj_gen;
  512. ;
  513. }
  514. createNewHTMLCode();
  515. Php();
  516. try {
  517. phpEnd = jj_consume_token(PHPEND);
  518. htmlStart = phpEnd.sourceEnd;
  519. htmlLineStart = phpEnd.endLine;
  520. htmlColumnStart = phpEnd.endColumn;
  521. } catch (ParseException e) {
  522. fireParseMessage(new PHPParseMessageEvent(INFO,
  523. PHPParseMessageEvent.MESSAGE_PHP_CLOSING_MISSING,
  524. path,
  525. "'?>' is missing",
  526. e.currentToken));
  527. }
  528. break;
  529. default:
  530. jj_la1[3] = jj_gen;
  531. jj_consume_token(-1);
  532. throw new ParseException();
  533. }
  534. }
  535. //}}}
  536. //{{{ phpEchoBlock()
  537. final public PHPEchoBlock phpEchoBlock() throws ParseException {
  538. Expression expr;
  539. PHPEchoBlock echoBlock;
  540. Token echoStartToken;
  541. Token echoEndToken;
  542. echoStartToken = jj_consume_token(PHPECHOSTART);
  543. createNewHTMLCode();
  544. expr = Expression();
  545. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  546. case SEMICOLON:
  547. jj_consume_token(SEMICOLON);
  548. break;
  549. default:
  550. jj_la1[4] = jj_gen;
  551. ;
  552. }
  553. try {
  554. echoEndToken = jj_consume_token(PHPEND);
  555. htmlStart = echoEndToken.sourceEnd;
  556. htmlLineStart = echoEndToken.endLine;
  557. htmlColumnStart = echoEndToken.endColumn;
  558. echoBlock = new PHPEchoBlock(expr,echoStartToken.sourceStart,
  559. echoEndToken.sourceEnd,
  560. echoStartToken.beginLine,
  561. echoEndToken.endLine,
  562. echoStartToken.beginColumn,
  563. echoEndToken.endColumn);
  564. } catch (ParseException e) {
  565. fireParseMessage(new PHPParseMessageEvent(INFO,
  566. PHPParseMessageEvent.MESSAGE_PHP_CLOSING_MISSING,
  567. path,
  568. "'?>' is missing",
  569. e.currentToken));
  570. echoBlock = new PHPEchoBlock(expr,
  571. echoStartToken.sourceStart,
  572. e.currentToken.sourceEnd,
  573. echoStartToken.beginLine,
  574. e.currentToken.endLine,
  575. echoStartToken.beginColumn,
  576. e.currentToken.endColumn);
  577. }
  578. pushOnAstNodes(echoBlock);
  579. {if (true) return echoBlock;}
  580. throw new Error("Missing return statement in function");
  581. }
  582. //}}}
  583. //{{{ Php()
  584. final public void Php() throws ParseException {
  585. label_2:
  586. while (true) {
  587. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  588. case ABSTRACT:
  589. case INTERFACE:
  590. case FINAL:
  591. case TRY:
  592. case THROW:
  593. case CLASS:
  594. case FUNCTION:
  595. case NAMESPACE:
  596. case USE:
  597. case IF:
  598. case ARRAY:
  599. case BREAK:
  600. case LIST:
  601. case PRINT:
  602. case ECHO:
  603. case INCLUDE:
  604. case REQUIRE:
  605. case INCLUDE_ONCE:
  606. case REQUIRE_ONCE:
  607. case GLOBAL:
  608. case STATIC:
  609. case CONST:
  610. case CONTINUE:
  611. case DO:
  612. case FOR:
  613. case NEW:
  614. case CLONE:
  615. case RETURN:
  616. case SWITCH:
  617. case WHILE:
  618. case FOREACH:
  619. case DEFINE:
  620. case GOTO:
  621. case NULL:
  622. case SUPER:
  623. case THIS:
  624. case TRUE:
  625. case FALSE:
  626. case STRING:
  627. case OBJECT:
  628. case BOOL:
  629. case BOOLEAN:
  630. case REAL:
  631. case DOUBLE:
  632. case FLOAT:
  633. case INT:
  634. case INTEGER:
  635. case AT:
  636. case BANG:
  637. case TILDE:
  638. case PLUS_PLUS:
  639. case MINUS_MINUS:
  640. case PLUS:
  641. case MINUS:
  642. case BIT_AND:
  643. case INTEGER_LITERAL:
  644. case FLOATING_POINT_LITERAL:
  645. case STRING_LITERAL:
  646. case DOUBLEQUOTE:
  647. case HEREDOCSTARTTOKEN:
  648. case DOLLAR:
  649. case IDENTIFIER:
  650. case LPAREN:
  651. case SEMICOLON:
  652. case LBRACE:
  653. ;
  654. break;
  655. default:
  656. jj_la1[5] = jj_gen;
  657. break label_2;
  658. }
  659. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  660. case NAMESPACE:
  661. namespace();
  662. break;
  663. case USE:
  664. useNamespace();
  665. break;
  666. case CONST:
  667. constantStatement();
  668. break;
  669. case ABSTRACT:
  670. case INTERFACE:
  671. case FINAL:
  672. case TRY:
  673. case THROW:
  674. case CLASS:
  675. case FUNCTION:
  676. case IF:
  677. case ARRAY:
  678. case BREAK:
  679. case LIST:
  680. case PRINT:
  681. case ECHO:
  682. case INCLUDE:
  683. case REQUIRE:
  684. case INCLUDE_ONCE:
  685. case REQUIRE_ONCE:
  686. case GLOBAL:
  687. case STATIC:
  688. case CONTINUE:
  689. case DO:
  690. case FOR:
  691. case NEW:
  692. case CLONE:
  693. case RETURN:
  694. case SWITCH:
  695. case WHILE:
  696. case FOREACH:
  697. case DEFINE:
  698. case GOTO:
  699. case NULL:
  700. case SUPER:
  701. case THIS:
  702. case TRUE:
  703. case FALSE:
  704. case STRING:
  705. case OBJECT:
  706. case BOOL:
  707. case BOOLEAN:
  708. case REAL:
  709. case DOUBLE:
  710. case FLOAT:
  711. case INT:
  712. case INTEGER:
  713. case AT:
  714. case BANG:
  715. case TILDE:
  716. case PLUS_PLUS:
  717. case MINUS_MINUS:
  718. case PLUS:
  719. case MINUS:
  720. case BIT_AND:
  721. case INTEGER_LITERAL:
  722. case FLOATING_POINT_LITERAL:
  723. case STRING_LITERAL:
  724. case DOUBLEQUOTE:
  725. case HEREDOCSTARTTOKEN:
  726. case DOLLAR:
  727. case IDENTIFIER:
  728. case LPAREN:
  729. case SEMICOLON:
  730. case LBRACE:
  731. BlockStatement();
  732. break;
  733. default:
  734. jj_la1[6] = jj_gen;
  735. jj_consume_token(-1);
  736. throw new ParseException();
  737. }
  738. }
  739. }
  740. //}}}
  741. //}}}
  742. //{{{ namespace() method
  743. final public Namespace namespace() throws ParseException {
  744. Token namespaceToken;
  745. Token namespaceNameToken = null;
  746. Token semicolon;
  747. int sourceEnd;
  748. int endLine;
  749. int endColumn;
  750. namespace = null;
  751. namespaceToken = jj_consume_token(NAMESPACE);
  752. sourceEnd = namespaceToken.sourceEnd;
  753. endLine = namespaceToken.endLine;
  754. endColumn = namespaceToken.endColumn;
  755. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  756. case LBRACE:
  757. jj_consume_token(LBRACE);
  758. label_3:
  759. while (true) {
  760. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  761. case ABSTRACT:
  762. case INTERFACE:
  763. case FINAL:
  764. case TRY:
  765. case THROW:
  766. case CLASS:
  767. case FUNCTION:
  768. case USE:
  769. case IF:
  770. case ARRAY:
  771. case BREAK:
  772. case LIST:
  773. case PRINT:
  774. case ECHO:
  775. case INCLUDE:
  776. case REQUIRE:
  777. case INCLUDE_ONCE:
  778. case REQUIRE_ONCE:
  779. case GLOBAL:
  780. case STATIC:
  781. case CONST:
  782. case CONTINUE:
  783. case DO:
  784. case FOR:
  785. case NEW:
  786. case CLONE:
  787. case RETURN:
  788. case SWITCH:
  789. case WHILE:
  790. case FOREACH:
  791. case DEFINE:
  792. case GOTO:
  793. case NULL:
  794. case SUPER:
  795. case THIS:
  796. case TRUE:
  797. case FALSE:
  798. case STRING:
  799. case OBJECT:
  800. case BOOL:
  801. case BOOLEAN:
  802. case REAL:
  803. case DOUBLE:
  804. case FLOAT:
  805. case INT:
  806. case INTEGER:
  807. case AT:
  808. case BANG:
  809. case TILDE:
  810. case PLUS_PLUS:
  811. case MINUS_MINUS:
  812. case PLUS:
  813. case MINUS:
  814. case BIT_AND:
  815. case INTEGER_LITERAL:
  816. case FLOATING_POINT_LITERAL:
  817. case STRING_LITERAL:
  818. case DOUBLEQUOTE:
  819. case HEREDOCSTARTTOKEN:
  820. case DOLLAR:
  821. case IDENTIFIER:
  822. case LPAREN:
  823. case SEMICOLON:
  824. case LBRACE:
  825. ;
  826. break;
  827. default:
  828. jj_la1[7] = jj_gen;
  829. break label_3;
  830. }
  831. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  832. case USE:
  833. useNamespace();
  834. break;
  835. case CONST:
  836. constantStatement();
  837. break;
  838. case ABSTRACT:
  839. case INTERFACE:
  840. case FINAL:
  841. case TRY:
  842. case THROW:
  843. case CLASS:
  844. case FUNCTION:
  845. case IF:
  846. case ARRAY:
  847. case BREAK:
  848. case LIST:
  849. case PRINT:
  850. case ECHO:
  851. case INCLUDE:
  852. case REQUIRE:
  853. case INCLUDE_ONCE:
  854. case REQUIRE_ONCE:
  855. case GLOBAL:
  856. case STATIC:
  857. case CONTINUE:
  858. case DO:
  859. case FOR:
  860. case NEW:
  861. case CLONE:
  862. case RETURN:
  863. case SWITCH:
  864. case WHILE:
  865. case FOREACH:
  866. case DEFINE:
  867. case GOTO:
  868. case NULL:
  869. case SUPER:
  870. case THIS:
  871. case TRUE:
  872. case FALSE:
  873. case STRING:
  874. case OBJECT:
  875. case BOOL:
  876. case BOOLEAN:
  877. case REAL:
  878. case DOUBLE:
  879. case FLOAT:
  880. case INT:
  881. case INTEGER:
  882. case AT:
  883. case BANG:
  884. case TILDE:
  885. case PLUS_PLUS:
  886. case MINUS_MINUS:
  887. case PLUS:
  888. case MINUS:
  889. case BIT_AND:
  890. case INTEGER_LITERAL:
  891. case FLOATING_POINT_LITERAL:
  892. case STRING_LITERAL:
  893. case DOUBLEQUOTE:
  894. case HEREDOCSTARTTOKEN:
  895. case DOLLAR:
  896. case IDENTIFIER:
  897. case LPAREN:
  898. case SEMICOLON:
  899. case LBRACE:
  900. BlockStatement();
  901. break;
  902. default:
  903. jj_la1[8] = jj_gen;
  904. jj_consume_token(-1);
  905. throw new ParseException();
  906. }
  907. }
  908. jj_consume_token(RBRACE);
  909. String namespaceName = namespaceNameToken == null ? null : namespaceNameToken.image;
  910. namespace = Namespace.getNamespace(namespaceName);
  911. {if (true) return new Namespace(namespace,
  912. namespaceToken.sourceStart,
  913. sourceEnd,
  914. namespaceToken.beginLine,
  915. endLine,
  916. namespaceToken.beginColumn,
  917. endColumn);}
  918. break;
  919. case NAMESPACE_NAME:
  920. namespaceNameToken = jj_consume_token(NAMESPACE_NAME);
  921. try {
  922. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  923. case LBRACE:
  924. jj_consume_token(LBRACE);
  925. label_4:
  926. while (true) {
  927. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  928. case ABSTRACT:
  929. case INTERFACE:
  930. case FINAL:
  931. case TRY:
  932. case THROW:
  933. case CLASS:
  934. case FUNCTION:
  935. case USE:
  936. case IF:
  937. case ARRAY:
  938. case BREAK:
  939. case LIST:
  940. case PRINT:
  941. case ECHO:
  942. case INCLUDE:
  943. case REQUIRE:
  944. case INCLUDE_ONCE:
  945. case REQUIRE_ONCE:
  946. case GLOBAL:
  947. case STATIC:
  948. case CONST:
  949. case CONTINUE:
  950. case DO:
  951. case FOR:
  952. case NEW:
  953. case CLONE:
  954. case RETURN:
  955. case SWITCH:
  956. case WHILE:
  957. case FOREACH:
  958. case DEFINE:
  959. case GOTO:
  960. case NULL:
  961. case SUPER:
  962. case THIS:
  963. case TRUE:
  964. case FALSE:
  965. case STRING:
  966. case OBJECT:
  967. case BOOL:
  968. case BOOLEAN:
  969. case REAL:
  970. case DOUBLE:
  971. case FLOAT:
  972. case INT:
  973. case INTEGER:
  974. case AT:
  975. case BANG:
  976. case TILDE:
  977. case PLUS_PLUS:
  978. case MINUS_MINUS:
  979. case PLUS:
  980. case MINUS:
  981. case BIT_AND:
  982. case INTEGER_LITERAL:
  983. case FLOATING_POINT_LITERAL:
  984. case STRING_LITERAL:
  985. case DOUBLEQUOTE:
  986. case HEREDOCSTARTTOKEN:
  987. case DOLLAR:
  988. case IDENTIFIER:
  989. case LPAREN:
  990. case SEMICOLON:
  991. case LBRACE:
  992. ;
  993. break;
  994. default:
  995. jj_la1[9] = jj_gen;
  996. break label_4;
  997. }
  998. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  999. case USE:
  1000. useNamespace();
  1001. break;
  1002. case CONST:
  1003. constantStatement();
  1004. break;
  1005. case ABSTRACT:
  1006. case INTERFACE:
  1007. case FINAL:
  1008. case TRY:
  1009. case THROW:
  1010. case CLASS:
  1011. case FUNCTION:
  1012. case IF:
  1013. case ARRAY:
  1014. case BREAK:
  1015. case LIST:
  1016. case PRINT:
  1017. case ECHO:
  1018. case INCLUDE:
  1019. case REQUIRE:
  1020. case INCLUDE_ONCE:
  1021. case REQUIRE_ONCE:
  1022. case GLOBAL:
  1023. case STATIC:
  1024. case CONTINUE:
  1025. case DO:
  1026. case FOR:
  1027. case NEW:
  1028. case CLONE:
  1029. case RETURN:
  1030. case SWITCH:
  1031. case WHILE:
  1032. case FOREACH:
  1033. case DEFINE:
  1034. case GOTO:
  1035. case NULL:
  1036. case SUPER:
  1037. case THIS:
  1038. case TRUE:
  1039. case FALSE:
  1040. case STRING:
  1041. case OBJECT:
  1042. case BOOL:
  1043. case BOOLEAN:
  1044. case REAL:
  1045. case DOUBLE:
  1046. case FLOAT:
  1047. case INT:
  1048. case INTEGER:
  1049. case AT:
  1050. case BANG:
  1051. case TILDE:
  1052. case PLUS_PLUS:
  1053. case MINUS_MINUS:
  1054. case PLUS:
  1055. case MINUS:
  1056. case BIT_AND:
  1057. case INTEGER_LITERAL:
  1058. case FLOATING_POINT_LITERAL:
  1059. case STRING_LITERAL:
  1060. case DOUBLEQUOTE:
  1061. case HEREDOCSTARTTOKEN:
  1062. case DOLLAR:
  1063. case IDENTIFIER:
  1064. case LPAREN:
  1065. case SEMICOLON:
  1066. case LBRACE:
  1067. BlockStatement();
  1068. break;
  1069. default:
  1070. jj_la1[10] = jj_gen;
  1071. jj_consume_token(-1);
  1072. throw new ParseException();
  1073. }
  1074. }
  1075. jj_consume_token(RBRACE);
  1076. namespace = Namespace.getNamespace(namespaceNameToken.image);
  1077. {if (true) return new Namespace(namespace,
  1078. namespaceToken.sourceStart,
  1079. sourceEnd,
  1080. namespaceToken.beginLine,
  1081. endLine,
  1082. namespaceToken.beginColumn,
  1083. endColumn);}
  1084. break;
  1085. case SEMICOLON:
  1086. semicolon = jj_consume_token(SEMICOLON);
  1087. sourceEnd = semicolon.sourceEnd;
  1088. endLine = semicolon.endLine;
  1089. endColumn = semicolon.endColumn;
  1090. break;
  1091. default:
  1092. jj_la1[11] = jj_gen;
  1093. jj_consume_token(-1);
  1094. throw new ParseException();
  1095. }
  1096. } catch (ParseException e) {
  1097. fireParseError("{ ...} or ; expected",";",e.currentToken.next);
  1098. }
  1099. namespace = Namespace.getNamespace(namespaceNameToken.image);
  1100. {if (true) return new Namespace(namespace,
  1101. namespaceToken.sourceStart,
  1102. sourceEnd,
  1103. namespaceToken.beginLine,
  1104. endLine,
  1105. namespaceToken.beginColumn,
  1106. endColumn);}
  1107. break;
  1108. default:
  1109. jj_la1[12] = jj_gen;
  1110. jj_consume_token(-1);
  1111. throw new ParseException();
  1112. }
  1113. throw new Error("Missing return statement in function");
  1114. }
  1115. //}}}
  1116. //{{{ useNamespace() method
  1117. final public UseNamespace useNamespace() throws ParseException {
  1118. Token useToken;
  1119. Token namespaceNameToken;
  1120. Token semicolon;
  1121. int sourceEnd;
  1122. int endLine;
  1123. int endColumn;
  1124. String namespaceName;
  1125. //{{{ <USE>
  1126. useToken = jj_consume_token(USE);
  1127. sourceEnd = useToken.sourceEnd;
  1128. endLine = useToken.endLine;
  1129. endColumn = useToken.endColumn;
  1130. try {
  1131. namespaceNameToken = namespaceIdentifier();
  1132. namespaceName = namespaceNameToken.image;
  1133. sourceEnd = namespaceNameToken.sourceEnd;
  1134. endLine = namespaceNameToken.endLine;
  1135. endColumn = namespaceNameToken.endColumn;
  1136. } catch (ParseException e) {
  1137. fireParseError("namespace expected",";",e.currentToken.next);
  1138. {
  1139. namespaceName = SYNTAX_ERROR_CHAR;
  1140. }
  1141. }
  1142. try {
  1143. semicolon = jj_consume_token(SEMICOLON);
  1144. sourceEnd = semicolon.sourceEnd;
  1145. endLine = semicolon.endLine;
  1146. endColumn = semicolon.endColumn;
  1147. } catch (ParseException e) {
  1148. fireParseError("; expected",";",e.currentToken.next);
  1149. }
  1150. {if (true) return new UseNamespace(namespaceName,
  1151. useToken.sourceStart,
  1152. sourceEnd,
  1153. useToken.beginLine,
  1154. endLine,
  1155. useToken.beginColumn,
  1156. endColumn);}
  1157. throw new Error("Missing return statement in function");
  1158. }
  1159. //}}}
  1160. //{{{ interfaceDeclaration()
  1161. final public InterfaceDeclaration interfaceDeclaration() throws ParseException {
  1162. Token modifierToken;
  1163. Token interfaceToken, rBraceToken;
  1164. Token nameToken;
  1165. InterfaceDeclaration interfaceDeclaration;
  1166. String interfaceNameImage = SYNTAX_ERROR_CHAR;
  1167. MethodDeclaration methodDeclaration;
  1168. List<ConstantIdentifier> superInterfaces = null;
  1169. List<Modifier> modifiers = new ArrayList<Modifier>(1);
  1170. List<ClassConstant> classConstants;
  1171. //{{{ interface <IDENTIFIER>
  1172. interfaceToken = jj_consume_token(INTERFACE);
  1173. try {
  1174. nameToken = jj_consume_token(IDENTIFIER);
  1175. interfaceNameImage = nameToken.image;
  1176. } catch (ParseException e) {
  1177. fireParseError("identifier expected","identifier",e.currentToken.next);
  1178. }
  1179. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1180. case EXTENDS:
  1181. jj_consume_token(EXTENDS);
  1182. nameToken = jj_consume_token(IDENTIFIER);
  1183. superInterfaces = new ArrayList<ConstantIdentifier>();
  1184. superInterfaces.add(new ConstantIdentifier(nameToken));
  1185. label_5:
  1186. while (true) {
  1187. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1188. case COMMA:
  1189. ;
  1190. break;
  1191. default:
  1192. jj_la1[13] = jj_gen;
  1193. break label_5;
  1194. }
  1195. jj_consume_token(COMMA);
  1196. nameToken = jj_consume_token(IDENTIFIER);
  1197. superInterfaces.add(new ConstantIdentifier(nameToken));
  1198. }
  1199. break;
  1200. default:
  1201. jj_la1[14] = jj_gen;
  1202. ;
  1203. }
  1204. interfaceDeclaration = new InterfaceDeclaration(namespace,
  1205. path,
  1206. currentSegment,
  1207. interfaceNameImage,
  1208. superInterfaces,
  1209. interfaceToken.sourceStart,
  1210. interfaceToken.beginLine,
  1211. interfaceToken.beginColumn);
  1212. currentSegment.add(interfaceDeclaration);
  1213. currentSegment = interfaceDeclaration;
  1214. scope = new Scope();
  1215. scopeStack.push(scope);
  1216. try {
  1217. jj_consume_token(LBRACE);
  1218. } catch (ParseException e) {
  1219. fireParseError("{ expected","{",e.currentToken.next);
  1220. }
  1221. label_6:
  1222. while (true) {
  1223. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1224. case PUBLIC:
  1225. case FUNCTION:
  1226. case STATIC:
  1227. case CONST:
  1228. ;
  1229. break;
  1230. default:
  1231. jj_la1[15] = jj_gen;
  1232. break label_6;
  1233. }
  1234. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1235. case PUBLIC:
  1236. case FUNCTION:
  1237. case STATIC:
  1238. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1239. case PUBLIC:
  1240. case STATIC:
  1241. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1242. case PUBLIC:
  1243. //{{{ public [static]
  1244. modifierToken = jj_consume_token(PUBLIC);
  1245. modifiers.add(new Modifier(modifierToken));
  1246. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1247. case STATIC:
  1248. try {
  1249. modifierToken = jj_consume_token(STATIC);
  1250. modifiers.add(new Modifier(modifierToken));
  1251. } catch (ParseException e) {
  1252. fireParseError("static or function token expected","static|function",e.currentToken.next);
  1253. }
  1254. break;
  1255. default:
  1256. jj_la1[16] = jj_gen;
  1257. ;
  1258. }
  1259. break;
  1260. case STATIC:
  1261. //{{{ static [public]
  1262. modifierToken = jj_consume_token(STATIC);
  1263. modifiers.add(new Modifier(modifierToken));
  1264. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1265. case PUBLIC:
  1266. try {
  1267. modifierToken = jj_consume_token(PUBLIC);
  1268. modifiers.add(new Modifier(modifierToken));
  1269. } catch (ParseException e) {
  1270. fireParseError("public or function token expected","public|function",e.currentToken.next);
  1271. }
  1272. break;
  1273. default:
  1274. jj_la1[17] = jj_gen;
  1275. ;
  1276. }
  1277. break;
  1278. default:
  1279. jj_la1[18] = jj_gen;
  1280. jj_consume_token(-1);
  1281. throw new ParseException();
  1282. }
  1283. break;
  1284. default:
  1285. jj_la1[19] = jj_gen;
  1286. ;
  1287. }
  1288. methodDeclaration = interfaceMethodDeclaration(modifiers);
  1289. interfaceDeclaration.add(methodDeclaration);
  1290. break;
  1291. case CONST:
  1292. classConstants = classConstant();
  1293. for (ClassConstant classConstant : classConstants)
  1294. {
  1295. interfaceDeclaration.addConstant(classConstant);
  1296. }
  1297. break;
  1298. default:
  1299. jj_la1[20] = jj_gen;
  1300. jj_consume_token(-1);
  1301. throw new ParseException();
  1302. }
  1303. }
  1304. try {
  1305. rBraceToken = jj_consume_token(RBRACE);
  1306. interfaceDeclaration.setSourceEnd(rBraceToken.sourceEnd);
  1307. interfaceDeclaration.setEndLine(rBraceToken.endLine);
  1308. interfaceDeclaration.setEndColumn(rBraceToken.endColumn);
  1309. } catch (ParseException e) {
  1310. fireParseError("} expected","}",e.currentToken.next);
  1311. }
  1312. currentSegment = interfaceDeclaration.getParent();
  1313. scope = scopeStack.pop();
  1314. {if (true) return interfaceDeclaration;}
  1315. throw new Error("Missing return statement in function");
  1316. }
  1317. //}}}
  1318. //{{{ classConstant() method
  1319. final public List<ClassConstant> classConstant() throws ParseException {
  1320. Token constToken, token;
  1321. String constName = SYNTAX_ERROR_CHAR;
  1322. List<ClassConstant> constants = new ArrayList<ClassConstant>();
  1323. ClassConstant classConstant;
  1324. constToken = jj_consume_token(CONST);
  1325. classConstant = _classConstant(constToken);
  1326. constants.add(classConstant);
  1327. label_7:
  1328. while (true) {
  1329. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1330. case COMMA:
  1331. ;
  1332. break;
  1333. default:
  1334. jj_la1[21] = jj_gen;
  1335. break label_7;
  1336. }
  1337. token = jj_consume_token(COMMA);
  1338. classConstant = _classConstant(token);
  1339. constants.add(classConstant);
  1340. }
  1341. try {
  1342. token = jj_consume_token(SEMICOLON);
  1343. } catch (ParseException e) {
  1344. fireParseError("';' expected",";",e.currentToken.next);
  1345. }
  1346. {if (true) return constants;}
  1347. throw new Error("Missing return statement in function");
  1348. }
  1349. //}}}
  1350. //{{{ _classConstant() method
  1351. final public ClassConstant _classConstant(Token startToken) throws ParseException {
  1352. Token identifier;
  1353. Token token;
  1354. String constName = SYNTAX_ERROR_CHAR;
  1355. Expression initializer = null;
  1356. int end, endLine, endColumn;
  1357. end = startToken.sourceEnd;
  1358. endLine = startToken.endLine;
  1359. endColumn = startToken.endColumn;
  1360. try {
  1361. identifier = methodIdentifier();
  1362. startToken = identifier;
  1363. constName = identifier.image;
  1364. end = identifier.sourceEnd;
  1365. endLine = identifier.endLine;
  1366. endColumn = identifier.endColumn;
  1367. } catch (ParseException e) {
  1368. fireParseError("constant expected","constant",e.currentToken.next);
  1369. }
  1370. try {
  1371. token = jj_consume_token(ASSIGN);
  1372. end = token.sourceEnd;
  1373. endLine = token.endLine;
  1374. endColumn = token.endColumn;
  1375. } catch (ParseException e) {
  1376. fireParseError("'=' expected","=",e.currentToken.next);
  1377. }
  1378. try {
  1379. initializer = VariableInitializer();
  1380. end = initializer.getSourceEnd();
  1381. endLine = initializer.getEndLine();
  1382. endColumn = initializer.getEndColumn();
  1383. } catch (ParseException e) {
  1384. fireParseError("expression expected","expression",e.currentToken.next);
  1385. }
  1386. {if (true) return new ClassConstant(namespace,
  1387. path,
  1388. currentSegment,
  1389. constName,
  1390. initializer,
  1391. startToken.sourceStart,
  1392. end,
  1393. startToken.beginLine,
  1394. endLine,
  1395. startToken.beginColumn,
  1396. endColumn);}
  1397. throw new Error("Missing return statement in function");
  1398. }
  1399. //}}}
  1400. //{{{ interfaceMethodDeclaration(Liscodifiers)
  1401. /**
  1402. * A Method Declaration.
  1403. * <b>function</b> MetodDeclarator() Block()
  1404. *
  1405. * @return a MethodDeclaration
  1406. */
  1407. final public MethodDeclaration interfaceMethodDeclaration(List<Modifier> modifiers) throws ParseException {
  1408. MethodDeclaration functionDeclaration;
  1409. MethodHeader methodHeader;
  1410. Token functionToken;
  1411. functionToken = jj_consume_token(FUNCTION);
  1412. methodHeader = methodHeader(functionToken,CONST_METHOD, modifiers);
  1413. functionDeclaration = new MethodDeclaration(currentSegment,methodHeader);
  1414. try {
  1415. jj_consume_token(SEMICOLON);
  1416. } catch (ParseException e) {
  1417. fireParseError("unexpected token : "+e.currentToken.image, ";",
  1418. e.currentToken);
  1419. }
  1420. {if (true) return functionDeclaration;}
  1421. throw new Error("Missing return statement in function");
  1422. }
  1423. //}}}
  1424. //{{{ Class methods
  1425. //{{{ classDeclaration()
  1426. /**
  1427. * A Class declaration.
  1428. * class <IDENTIFIER> [extends <IDENTIFIER>] Class body
  1429. *
  1430. * @return a ClassDeclaration
  1431. */
  1432. final public ClassDeclaration classDeclaration() throws ParseException {
  1433. ClassHeader classHeader;
  1434. ClassDeclaration classDeclaration;
  1435. Token abstractToken = null;
  1436. Token finalToken = null;
  1437. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1438. case ABSTRACT:
  1439. abstractToken = jj_consume_token(ABSTRACT);
  1440. classHeader = classHeader(abstractToken);
  1441. classDeclaration = new ClassDeclaration(currentSegment,
  1442. classHeader,
  1443. classHeader.getSourceStart(),
  1444. classHeader.getSourceEnd(),
  1445. classHeader.getBeginLine(),
  1446. classHeader.getEndLine(),
  1447. classHeader.getBeginColumn(),
  1448. classHeader.getEndColumn());
  1449. currentSegment.add(classDeclaration);
  1450. currentSegment = classDeclaration;
  1451. scope = new Scope();
  1452. scopeStack.push(scope);
  1453. abstractClassBody(classDeclaration);
  1454. currentSegment = currentSegment.getParent();
  1455. scope = scopeStack.pop();
  1456. pushOnAstNodes(classDeclaration);
  1457. {if (true) return classDeclaration;}
  1458. break;
  1459. case FINAL:
  1460. case CLASS:
  1461. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1462. case FINAL:
  1463. finalToken = jj_consume_token(FINAL);
  1464. break;
  1465. default:
  1466. jj_la1[22] = jj_gen;
  1467. ;
  1468. }
  1469. classHeader = classHeader(finalToken);
  1470. if (finalToken != null)
  1471. {
  1472. classHeader.addModifier(new Modifier(finalToken));
  1473. }
  1474. classDeclaration = new ClassDeclaration(currentSegment,
  1475. classHeader,
  1476. classHeader.getSourceStart(),
  1477. classHeader.getSourceEnd(),
  1478. classHeader.getBeginLine(),
  1479. classHeader.getEndLine(),
  1480. classHeader.getBeginColumn(),
  1481. classHeader.getEndColumn());
  1482. currentSegment.add(classDeclaration);
  1483. currentSegment = classDeclaration;
  1484. scope = new Scope();
  1485. scopeStack.push(scope);
  1486. classBody(classDeclaration);
  1487. currentSegment = currentSegment.getParent();
  1488. scope = scopeStack.pop();
  1489. pushOnAstNodes(classDeclaration);
  1490. {if (true) return classDeclaration;}
  1491. break;
  1492. default:
  1493. jj_la1[23] = jj_gen;
  1494. jj_consume_token(-1);
  1495. throw new ParseException();
  1496. }
  1497. throw new Error("Missing return statement in function");
  1498. }
  1499. //}}}
  1500. //{{{ classHeader(Token abstractToken)
  1501. final public ClassHeader classHeader(Token abstractToken) throws ParseException {
  1502. Token classToken;
  1503. Token className = null;
  1504. Token superclassName = null;
  1505. Token firstToken = abstractToken;
  1506. List<InterfaceIdentifier> interfaces = null;
  1507. try {
  1508. classToken = jj_consume_token(CLASS);
  1509. if (firstToken == null) firstToken = classToken;
  1510. } catch (ParseException e) {
  1511. fireParseError("identifier expected","identifier", e.currentToken.next);
  1512. }
  1513. try {
  1514. className = jj_consume_token(IDENTIFIER);
  1515. } catch (ParseException e) {
  1516. fireParseError("identifier expected","identifier",e.currentToken.next);
  1517. }
  1518. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1519. case EXTENDS:
  1520. jj_consume_token(EXTENDS);
  1521. try {
  1522. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1523. case IDENTIFIER:
  1524. superclassName = jj_consume_token(IDENTIFIER);
  1525. break;
  1526. case OBJECT:
  1527. superclassName = jj_consume_token(OBJECT);
  1528. break;
  1529. default:
  1530. jj_la1[24] = jj_gen;
  1531. jj_consume_to