/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
- /* Generated By:JavaCC: Do not edit this line. PHPParser.java */
- package gatchan.phpparser.parser;
- //{{{ Imports
- import java.util.ArrayList;
- import java.io.*;
- import java.util.List;
- import java.util.Stack;
- import net.sourceforge.phpdt.internal.compiler.ast.declarations.VariableUsage;
- import net.sourceforge.phpdt.internal.compiler.ast.*;
- import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
- //}}}
- //{{{ PHPParser class
- /**
- * @author Matthieu Casanova <chocolat.mou@gmail.com>
- * @version $Id: PHPParser.java 20113 2011-10-18 17:21:33Z kpouer $
- */
- public class PHPParser implements PHPParserConstants {
- //{{{ Fields
- //{{{ constants for methods and function distinction (some keywords are allowed in method classes
- public static final int CONST_METHOD = 0;
- public static final int CONST_FUNCTION = 1;
- //}}}
- public static final int ERROR = 2;
- public static final int WARNING = 1;
- public static final int INFO = 0;
- /** The current segment. */
- private Outlineable currentSegment;
- /** The message of the current ParseException. If it's null it's because the parse exception wasn't handled */
- private String errorMessage;
- private int errorStart = -1;
- private int errorEnd = -1;
- private PHPDocument phpDocument;
- public static final String SYNTAX_ERROR_CHAR = "syntax error";
- /**
- * The point where html starts.
- * It will be used by the token manager to create HTMLCode objects
- */
- private int htmlStart;
- private int htmlLineStart;
- private int htmlColumnStart;
- //ast stack
- private static final int AstStackIncrement = 100;
- /** The stack of node. */
- private Statement[] nodes;
- /** The cursor in expression stack. */
- private int nodePtr;
- private final List<PHPParserListener> parserListeners = new ArrayList<PHPParserListener>();
- private String path;
- /** Tell if the parsing should be stopped. */
- private boolean shouldStop;
- private Stack<Scope> scopeStack;
- private Scope scope;
- private final List tempList = new ArrayList();
- /**
- * The current namespace
- */
- private String namespace;
- //}}}
- //{{{ PHPParser constructor
- public PHPParser()
- {
- } //}}}
- //{{{ setPath() method
- /**
- * Set the path of the file that is currently parsed.
- * This path will be sent in parse errors and messages
- *
- * @param path the path of the parsed file
- */
- public void setPath(String path)
- {
- this.path = path;
- } //}}}
- //{{{ getPath()
- public String getPath()
- {
- return path;
- } //}}}
- //{{{ stop()
- /**
- * Ask the parser to stop his work.
- */
- public void stop()
- {
- shouldStop = true;
- } //}}}
- //{{{ isStopped()
- public boolean isStopped()
- {
- return shouldStop;
- } //}}}
- //{{{ addParserListener(PHPParserListener listener)
- public void addParserListener(PHPParserListener listener)
- {
- if (!parserListeners.contains(listener))
- parserListeners.add(listener);
- } //}}}
- //{{{ removeParserListener(PHPParserListener listener)
- public void removeParserListener(PHPParserListener listener)
- {
- parserListeners.remove(listener);
- } //}}}
- //{{{ fireParseError(PHPParseErrorEvent e)
- public void fireParseError(PHPParseErrorEvent e)
- {
- for (PHPParserListener listener : parserListeners)
- listener.parseError(e);
- } //}}}
- //{{{ fireParseError() methods
- public void fireParseError(String message, String expected, Token token)
- {
- fireParseError(new PHPParseErrorEvent(ERROR,
- path,
- message,
- expected,
- token));
- }
- public void fireParseError(String message, AstNode node)
- {
- fireParseError(new PHPParseErrorEvent(ERROR,
- path,
- message,
- node.getSourceStart(),
- node.getSourceEnd(),
- node.getBeginLine(),
- node.getEndLine(),
- node.getBeginColumn(),
- node.getEndColumn()));
- } //}}}
- //{{{ fireParseMessage(PHPParseMessageEvent e)
- public void fireParseMessage(PHPParseMessageEvent e)
- {
- for (PHPParserListener listener: parserListeners)
- listener.parseMessage(e);
- } //}}}
- //{{{ phpParserTester(String strEval)
- public void phpParserTester(String strEval) throws ParseException
- {
- StringReader stream = new StringReader(strEval);
- if (jj_input_stream == null)
- {
- jj_input_stream = new SimpleCharStream(stream, 1, 1);
- token_source = new PHPParserTokenManager(jj_input_stream);
- }
- ReInit(new StringReader(strEval));
- init();
- phpDocument = new PHPDocument("_root");
- scope = new Scope();
- scopeStack = new Stack<Scope>();
- scopeStack.push(scope);
- currentSegment = phpDocument;
- token_source.SwitchTo(PHPPARSING);
- phpTest();
- } //}}}
- //{{{ htmlParserTester() methods
- public void htmlParserTester(File fileName) throws FileNotFoundException, ParseException
- {
- Reader stream = new FileReader(fileName);
- if (jj_input_stream == null)
- {
- jj_input_stream = new SimpleCharStream(stream, 1, 1);
- token_source = new PHPParserTokenManager(jj_input_stream);
- }
- ReInit(stream);
- init();
- phpDocument = new PHPDocument("_root");
- scope = new Scope();
- scopeStack = new Stack<Scope>();
- scopeStack.push(scope);
- currentSegment = phpDocument;
- phpFile();
- }
- public void htmlParserTester(String strEval) throws ParseException
- {
- StringReader stream = new StringReader(strEval);
- if (jj_input_stream == null)
- {
- jj_input_stream = new SimpleCharStream(stream, 1, 1);
- token_source = new PHPParserTokenManager(jj_input_stream);
- }
- ReInit(stream);
- init();
- phpDocument = new PHPDocument("_root");
- scope = new Scope();
- scopeStack = new Stack<Scope>();
- scopeStack.push(scope);
- currentSegment = phpDocument;
- phpFile();
- } //}}}
- //{{{ init()
- /**
- * Reinitialize the parser.
- */
- private void init()
- {
- nodes = new Statement[AstStackIncrement];
- nodePtr = -1;
- htmlStart = 0;
- htmlColumnStart = 0;
- htmlLineStart = 0;
- } //}}}
- //{{{ pushOnAstNodes(Statement node)
- /**
- * Add an php node on the stack.
- * @param node the node that will be added to the stack
- */
- private void pushOnAstNodes(Statement node)
- {
- try
- {
- nodes[++nodePtr] = node;
- }
- catch (IndexOutOfBoundsException e)
- {
- int oldStackLength = nodes.length;
- Statement[] oldStack = nodes;
- nodes = new Statement[oldStackLength + AstStackIncrement];
- System.arraycopy(oldStack, 0, nodes, 0, oldStackLength);
- nodePtr = oldStackLength;
- nodes[nodePtr] = node;
- }
- } //}}}
- //{{{ parse() methods
- public void parse() throws ParseException
- {
- phpFile();
- }
- public void parse(String s) throws ParseException
- {
- Reader reader = new StringReader(s);
- parse(reader);
- }
- public void parse(Reader reader) throws ParseException
- {
- phpDocument = new PHPDocument("_root");
- scope = new Scope();
- scopeStack = new Stack<Scope>();
- scopeStack.push(scope);
- currentSegment = phpDocument;
- if (jj_input_stream == null)
- {
- jj_input_stream = new SimpleCharStream(reader, 1, 1);
- jj_input_stream.setTabSize(1);
- token_source = new PHPParserTokenManager(jj_input_stream);
- }
- ReInit(reader);
- init();
- parse();
- Statement[] astNodes = new Statement[nodes.length];
- phpDocument.setNodes(astNodes);
- System.arraycopy(nodes,0,astNodes,0,nodes.length);
- phpDocument.analyzeCode(this);
- } //}}}
- //{{{ createNewHTMLCode()
- /**
- * Put a new html block in the stack.
- */
- public void createNewHTMLCode()
- {
- int currentPosition = token.sourceStart;
- if (currentPosition == htmlStart ||
- currentPosition < htmlStart ||
- currentPosition > jj_input_stream.getCurrentBuffer().length())
- {
- return;
- }
- // todo : reactivate this
- //String html = jj_input_stream.getCurrentBuffer().substring(htmlStart, currentPosition);
- String html = "";
- pushOnAstNodes(new HTMLCode(html, htmlStart,currentPosition,htmlLineStart,token.endLine,htmlColumnStart,token.endColumn));
- } //}}}
- //{{{ error_skipto(int kind)
- Token error_skipto(int kind)
- {
- // ParseException e = generateParseException(); // generate the exception object.
- // System.out.println(e.toString()); // print the error message
- Token t;
- do
- {
- t = getNextToken();
- }
- while (t.kind != kind && t.kind != EOF && t.kind != RBRACE);
- return t;
- } //}}}
- //{{{ getPHPDocument()
- public PHPDocument getPHPDocument()
- {
- return phpDocument;
- } //}}}
- //{{{ setTypeFromScope(Variable variable)
- private void setTypeFromScope(Variable variable)
- {
- VariableUsage usage = scope.getVariable(variable.getName(),variable.getBeginLine(),variable.getBeginColumn());
- if (usage != null)
- {
- variable.setType(usage.getType());
- }
- }
- //}}}
- //{{{ PHP Structures
- //{{{ phpTest()
- final public void phpTest() throws ParseException {
- Php();
- jj_consume_token(0);
- }
- //}}}
- //{{{ phpFile()
- final public void phpFile() throws ParseException {
- try {
- label_1:
- while (true) {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case PHPSTARTSHORT:
- case PHPSTARTLONG:
- case PHPECHOSTART:
- case PHPEND:
- case ABSTRACT:
- case INTERFACE:
- case FINAL:
- case TRY:
- case THROW:
- case CLASS:
- case FUNCTION:
- case NAMESPACE:
- case USE:
- case IF:
- case ARRAY:
- case BREAK:
- case LIST:
- case PRINT:
- case ECHO:
- case INCLUDE:
- case REQUIRE:
- case INCLUDE_ONCE:
- case REQUIRE_ONCE:
- case GLOBAL:
- case STATIC:
- case CONST:
- case CONTINUE:
- case DO:
- case FOR:
- case NEW:
- case CLONE:
- case RETURN:
- case SWITCH:
- case WHILE:
- case FOREACH:
- case DEFINE:
- case GOTO:
- case NULL:
- case SUPER:
- case THIS:
- case TRUE:
- case FALSE:
- case STRING:
- case OBJECT:
- case BOOL:
- case BOOLEAN:
- case REAL:
- case DOUBLE:
- case FLOAT:
- case INT:
- case INTEGER:
- case AT:
- case BANG:
- case TILDE:
- case PLUS_PLUS:
- case MINUS_MINUS:
- case PLUS:
- case MINUS:
- case BIT_AND:
- case INTEGER_LITERAL:
- case FLOATING_POINT_LITERAL:
- case STRING_LITERAL:
- case DOUBLEQUOTE:
- case HEREDOCSTARTTOKEN:
- case DOLLAR:
- case IDENTIFIER:
- case LPAREN:
- case SEMICOLON:
- case LBRACE:
- ;
- break;
- default:
- jj_la1[0] = jj_gen;
- break label_1;
- }
- PhpBlock();
- }
- createNewHTMLCode();
- } catch (TokenMgrError e) {
- //{{{ Parse Error
- fireParseError(new PHPParseErrorEvent(ERROR,
- path,
- e.getMessage(),
- e.getMessage(),
- null,
- jj_input_stream.getBeginOffset(),
- jj_input_stream.getEndOffset(),
- jj_input_stream.getBeginLine(),
- jj_input_stream.getEndLine(),
- jj_input_stream.getBeginColumn(),
- jj_input_stream.getEndColumn())); //}}}
- }
- }
- //}}}
- //{{{ PhpBlock()
- /**
- * A php block is a <?= expression [;]?>
- * or <?php somephpcode ?>
- * or <? somephpcode ?>
- */
- final public void PhpBlock() throws ParseException {
- PHPEchoBlock phpEchoBlock;
- Token token,phpEnd;
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case PHPECHOSTART:
- phpEchoBlock = phpEchoBlock();
- pushOnAstNodes(phpEchoBlock);
- break;
- case PHPSTARTSHORT:
- case PHPSTARTLONG:
- case PHPEND:
- case ABSTRACT:
- case INTERFACE:
- case FINAL:
- case TRY:
- case THROW:
- case CLASS:
- case FUNCTION:
- case NAMESPACE:
- case USE:
- case IF:
- case ARRAY:
- case BREAK:
- case LIST:
- case PRINT:
- case ECHO:
- case INCLUDE:
- case REQUIRE:
- case INCLUDE_ONCE:
- case REQUIRE_ONCE:
- case GLOBAL:
- case STATIC:
- case CONST:
- case CONTINUE:
- case DO:
- case FOR:
- case NEW:
- case CLONE:
- case RETURN:
- case SWITCH:
- case WHILE:
- case FOREACH:
- case DEFINE:
- case GOTO:
- case NULL:
- case SUPER:
- case THIS:
- case TRUE:
- case FALSE:
- case STRING:
- case OBJECT:
- case BOOL:
- case BOOLEAN:
- case REAL:
- case DOUBLE:
- case FLOAT:
- case INT:
- case INTEGER:
- case AT:
- case BANG:
- case TILDE:
- case PLUS_PLUS:
- case MINUS_MINUS:
- case PLUS:
- case MINUS:
- case BIT_AND:
- case INTEGER_LITERAL:
- case FLOATING_POINT_LITERAL:
- case STRING_LITERAL:
- case DOUBLEQUOTE:
- case HEREDOCSTARTTOKEN:
- case DOLLAR:
- case IDENTIFIER:
- case LPAREN:
- case SEMICOLON:
- case LBRACE:
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case PHPSTARTSHORT:
- case PHPSTARTLONG:
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case PHPSTARTLONG:
- jj_consume_token(PHPSTARTLONG);
- break;
- case PHPSTARTSHORT:
- token = jj_consume_token(PHPSTARTSHORT);
- fireParseMessage(new PHPParseMessageEvent(INFO,
- PHPParseMessageEvent.MESSAGE_SHORT_OPEN_TAG,
- path,
- "You should use '<?php' instead of '<?' it will avoid some problems with XML",
- token));
- break;
- default:
- jj_la1[1] = jj_gen;
- jj_consume_token(-1);
- throw new ParseException();
- }
- break;
- default:
- jj_la1[2] = jj_gen;
- ;
- }
- createNewHTMLCode();
- Php();
- try {
- phpEnd = jj_consume_token(PHPEND);
- htmlStart = phpEnd.sourceEnd;
- htmlLineStart = phpEnd.endLine;
- htmlColumnStart = phpEnd.endColumn;
- } catch (ParseException e) {
- fireParseMessage(new PHPParseMessageEvent(INFO,
- PHPParseMessageEvent.MESSAGE_PHP_CLOSING_MISSING,
- path,
- "'?>' is missing",
- e.currentToken));
- }
- break;
- default:
- jj_la1[3] = jj_gen;
- jj_consume_token(-1);
- throw new ParseException();
- }
- }
- //}}}
- //{{{ phpEchoBlock()
- final public PHPEchoBlock phpEchoBlock() throws ParseException {
- Expression expr;
- PHPEchoBlock echoBlock;
- Token echoStartToken;
- Token echoEndToken;
- echoStartToken = jj_consume_token(PHPECHOSTART);
- createNewHTMLCode();
- expr = Expression();
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case SEMICOLON:
- jj_consume_token(SEMICOLON);
- break;
- default:
- jj_la1[4] = jj_gen;
- ;
- }
- try {
- echoEndToken = jj_consume_token(PHPEND);
- htmlStart = echoEndToken.sourceEnd;
- htmlLineStart = echoEndToken.endLine;
- htmlColumnStart = echoEndToken.endColumn;
- echoBlock = new PHPEchoBlock(expr,echoStartToken.sourceStart,
- echoEndToken.sourceEnd,
- echoStartToken.beginLine,
- echoEndToken.endLine,
- echoStartToken.beginColumn,
- echoEndToken.endColumn);
- } catch (ParseException e) {
- fireParseMessage(new PHPParseMessageEvent(INFO,
- PHPParseMessageEvent.MESSAGE_PHP_CLOSING_MISSING,
- path,
- "'?>' is missing",
- e.currentToken));
- echoBlock = new PHPEchoBlock(expr,
- echoStartToken.sourceStart,
- e.currentToken.sourceEnd,
- echoStartToken.beginLine,
- e.currentToken.endLine,
- echoStartToken.beginColumn,
- e.currentToken.endColumn);
- }
- pushOnAstNodes(echoBlock);
- {if (true) return echoBlock;}
- throw new Error("Missing return statement in function");
- }
- //}}}
- //{{{ Php()
- final public void Php() throws ParseException {
- label_2:
- while (true) {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case ABSTRACT:
- case INTERFACE:
- case FINAL:
- case TRY:
- case THROW:
- case CLASS:
- case FUNCTION:
- case NAMESPACE:
- case USE:
- case IF:
- case ARRAY:
- case BREAK:
- case LIST:
- case PRINT:
- case ECHO:
- case INCLUDE:
- case REQUIRE:
- case INCLUDE_ONCE:
- case REQUIRE_ONCE:
- case GLOBAL:
- case STATIC:
- case CONST:
- case CONTINUE:
- case DO:
- case FOR:
- case NEW:
- case CLONE:
- case RETURN:
- case SWITCH:
- case WHILE:
- case FOREACH:
- case DEFINE:
- case GOTO:
- case NULL:
- case SUPER:
- case THIS:
- case TRUE:
- case FALSE:
- case STRING:
- case OBJECT:
- case BOOL:
- case BOOLEAN:
- case REAL:
- case DOUBLE:
- case FLOAT:
- case INT:
- case INTEGER:
- case AT:
- case BANG:
- case TILDE:
- case PLUS_PLUS:
- case MINUS_MINUS:
- case PLUS:
- case MINUS:
- case BIT_AND:
- case INTEGER_LITERAL:
- case FLOATING_POINT_LITERAL:
- case STRING_LITERAL:
- case DOUBLEQUOTE:
- case HEREDOCSTARTTOKEN:
- case DOLLAR:
- case IDENTIFIER:
- case LPAREN:
- case SEMICOLON:
- case LBRACE:
- ;
- break;
- default:
- jj_la1[5] = jj_gen;
- break label_2;
- }
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case NAMESPACE:
- namespace();
- break;
- case USE:
- useNamespace();
- break;
- case CONST:
- constantStatement();
- break;
- case ABSTRACT:
- case INTERFACE:
- case FINAL:
- case TRY:
- case THROW:
- case CLASS:
- case FUNCTION:
- case IF:
- case ARRAY:
- case BREAK:
- case LIST:
- case PRINT:
- case ECHO:
- case INCLUDE:
- case REQUIRE:
- case INCLUDE_ONCE:
- case REQUIRE_ONCE:
- case GLOBAL:
- case STATIC:
- case CONTINUE:
- case DO:
- case FOR:
- case NEW:
- case CLONE:
- case RETURN:
- case SWITCH:
- case WHILE:
- case FOREACH:
- case DEFINE:
- case GOTO:
- case NULL:
- case SUPER:
- case THIS:
- case TRUE:
- case FALSE:
- case STRING:
- case OBJECT:
- case BOOL:
- case BOOLEAN:
- case REAL:
- case DOUBLE:
- case FLOAT:
- case INT:
- case INTEGER:
- case AT:
- case BANG:
- case TILDE:
- case PLUS_PLUS:
- case MINUS_MINUS:
- case PLUS:
- case MINUS:
- case BIT_AND:
- case INTEGER_LITERAL:
- case FLOATING_POINT_LITERAL:
- case STRING_LITERAL:
- case DOUBLEQUOTE:
- case HEREDOCSTARTTOKEN:
- case DOLLAR:
- case IDENTIFIER:
- case LPAREN:
- case SEMICOLON:
- case LBRACE:
- BlockStatement();
- break;
- default:
- jj_la1[6] = jj_gen;
- jj_consume_token(-1);
- throw new ParseException();
- }
- }
- }
- //}}}
- //}}}
- //{{{ namespace() method
- final public Namespace namespace() throws ParseException {
- Token namespaceToken;
- Token namespaceNameToken = null;
- Token semicolon;
- int sourceEnd;
- int endLine;
- int endColumn;
- namespace = null;
- namespaceToken = jj_consume_token(NAMESPACE);
- sourceEnd = namespaceToken.sourceEnd;
- endLine = namespaceToken.endLine;
- endColumn = namespaceToken.endColumn;
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case LBRACE:
- jj_consume_token(LBRACE);
- label_3:
- while (true) {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case ABSTRACT:
- case INTERFACE:
- case FINAL:
- case TRY:
- case THROW:
- case CLASS:
- case FUNCTION:
- case USE:
- case IF:
- case ARRAY:
- case BREAK:
- case LIST:
- case PRINT:
- case ECHO:
- case INCLUDE:
- case REQUIRE:
- case INCLUDE_ONCE:
- case REQUIRE_ONCE:
- case GLOBAL:
- case STATIC:
- case CONST:
- case CONTINUE:
- case DO:
- case FOR:
- case NEW:
- case CLONE:
- case RETURN:
- case SWITCH:
- case WHILE:
- case FOREACH:
- case DEFINE:
- case GOTO:
- case NULL:
- case SUPER:
- case THIS:
- case TRUE:
- case FALSE:
- case STRING:
- case OBJECT:
- case BOOL:
- case BOOLEAN:
- case REAL:
- case DOUBLE:
- case FLOAT:
- case INT:
- case INTEGER:
- case AT:
- case BANG:
- case TILDE:
- case PLUS_PLUS:
- case MINUS_MINUS:
- case PLUS:
- case MINUS:
- case BIT_AND:
- case INTEGER_LITERAL:
- case FLOATING_POINT_LITERAL:
- case STRING_LITERAL:
- case DOUBLEQUOTE:
- case HEREDOCSTARTTOKEN:
- case DOLLAR:
- case IDENTIFIER:
- case LPAREN:
- case SEMICOLON:
- case LBRACE:
- ;
- break;
- default:
- jj_la1[7] = jj_gen;
- break label_3;
- }
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case USE:
- useNamespace();
- break;
- case CONST:
- constantStatement();
- break;
- case ABSTRACT:
- case INTERFACE:
- case FINAL:
- case TRY:
- case THROW:
- case CLASS:
- case FUNCTION:
- case IF:
- case ARRAY:
- case BREAK:
- case LIST:
- case PRINT:
- case ECHO:
- case INCLUDE:
- case REQUIRE:
- case INCLUDE_ONCE:
- case REQUIRE_ONCE:
- case GLOBAL:
- case STATIC:
- case CONTINUE:
- case DO:
- case FOR:
- case NEW:
- case CLONE:
- case RETURN:
- case SWITCH:
- case WHILE:
- case FOREACH:
- case DEFINE:
- case GOTO:
- case NULL:
- case SUPER:
- case THIS:
- case TRUE:
- case FALSE:
- case STRING:
- case OBJECT:
- case BOOL:
- case BOOLEAN:
- case REAL:
- case DOUBLE:
- case FLOAT:
- case INT:
- case INTEGER:
- case AT:
- case BANG:
- case TILDE:
- case PLUS_PLUS:
- case MINUS_MINUS:
- case PLUS:
- case MINUS:
- case BIT_AND:
- case INTEGER_LITERAL:
- case FLOATING_POINT_LITERAL:
- case STRING_LITERAL:
- case DOUBLEQUOTE:
- case HEREDOCSTARTTOKEN:
- case DOLLAR:
- case IDENTIFIER:
- case LPAREN:
- case SEMICOLON:
- case LBRACE:
- BlockStatement();
- break;
- default:
- jj_la1[8] = jj_gen;
- jj_consume_token(-1);
- throw new ParseException();
- }
- }
- jj_consume_token(RBRACE);
- String namespaceName = namespaceNameToken == null ? null : namespaceNameToken.image;
- namespace = Namespace.getNamespace(namespaceName);
- {if (true) return new Namespace(namespace,
- namespaceToken.sourceStart,
- sourceEnd,
- namespaceToken.beginLine,
- endLine,
- namespaceToken.beginColumn,
- endColumn);}
- break;
- case NAMESPACE_NAME:
- namespaceNameToken = jj_consume_token(NAMESPACE_NAME);
- try {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case LBRACE:
- jj_consume_token(LBRACE);
- label_4:
- while (true) {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case ABSTRACT:
- case INTERFACE:
- case FINAL:
- case TRY:
- case THROW:
- case CLASS:
- case FUNCTION:
- case USE:
- case IF:
- case ARRAY:
- case BREAK:
- case LIST:
- case PRINT:
- case ECHO:
- case INCLUDE:
- case REQUIRE:
- case INCLUDE_ONCE:
- case REQUIRE_ONCE:
- case GLOBAL:
- case STATIC:
- case CONST:
- case CONTINUE:
- case DO:
- case FOR:
- case NEW:
- case CLONE:
- case RETURN:
- case SWITCH:
- case WHILE:
- case FOREACH:
- case DEFINE:
- case GOTO:
- case NULL:
- case SUPER:
- case THIS:
- case TRUE:
- case FALSE:
- case STRING:
- case OBJECT:
- case BOOL:
- case BOOLEAN:
- case REAL:
- case DOUBLE:
- case FLOAT:
- case INT:
- case INTEGER:
- case AT:
- case BANG:
- case TILDE:
- case PLUS_PLUS:
- case MINUS_MINUS:
- case PLUS:
- case MINUS:
- case BIT_AND:
- case INTEGER_LITERAL:
- case FLOATING_POINT_LITERAL:
- case STRING_LITERAL:
- case DOUBLEQUOTE:
- case HEREDOCSTARTTOKEN:
- case DOLLAR:
- case IDENTIFIER:
- case LPAREN:
- case SEMICOLON:
- case LBRACE:
- ;
- break;
- default:
- jj_la1[9] = jj_gen;
- break label_4;
- }
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case USE:
- useNamespace();
- break;
- case CONST:
- constantStatement();
- break;
- case ABSTRACT:
- case INTERFACE:
- case FINAL:
- case TRY:
- case THROW:
- case CLASS:
- case FUNCTION:
- case IF:
- case ARRAY:
- case BREAK:
- case LIST:
- case PRINT:
- case ECHO:
- case INCLUDE:
- case REQUIRE:
- case INCLUDE_ONCE:
- case REQUIRE_ONCE:
- case GLOBAL:
- case STATIC:
- case CONTINUE:
- case DO:
- case FOR:
- case NEW:
- case CLONE:
- case RETURN:
- case SWITCH:
- case WHILE:
- case FOREACH:
- case DEFINE:
- case GOTO:
- case NULL:
- case SUPER:
- case THIS:
- case TRUE:
- case FALSE:
- case STRING:
- case OBJECT:
- case BOOL:
- case BOOLEAN:
- case REAL:
- case DOUBLE:
- case FLOAT:
- case INT:
- case INTEGER:
- case AT:
- case BANG:
- case TILDE:
- case PLUS_PLUS:
- case MINUS_MINUS:
- case PLUS:
- case MINUS:
- case BIT_AND:
- case INTEGER_LITERAL:
- case FLOATING_POINT_LITERAL:
- case STRING_LITERAL:
- case DOUBLEQUOTE:
- case HEREDOCSTARTTOKEN:
- case DOLLAR:
- case IDENTIFIER:
- case LPAREN:
- case SEMICOLON:
- case LBRACE:
- BlockStatement();
- break;
- default:
- jj_la1[10] = jj_gen;
- jj_consume_token(-1);
- throw new ParseException();
- }
- }
- jj_consume_token(RBRACE);
- namespace = Namespace.getNamespace(namespaceNameToken.image);
- {if (true) return new Namespace(namespace,
- namespaceToken.sourceStart,
- sourceEnd,
- namespaceToken.beginLine,
- endLine,
- namespaceToken.beginColumn,
- endColumn);}
- break;
- case SEMICOLON:
- semicolon = jj_consume_token(SEMICOLON);
- sourceEnd = semicolon.sourceEnd;
- endLine = semicolon.endLine;
- endColumn = semicolon.endColumn;
- break;
- default:
- jj_la1[11] = jj_gen;
- jj_consume_token(-1);
- throw new ParseException();
- }
- } catch (ParseException e) {
- fireParseError("{ ...} or ; expected",";",e.currentToken.next);
- }
- namespace = Namespace.getNamespace(namespaceNameToken.image);
- {if (true) return new Namespace(namespace,
- namespaceToken.sourceStart,
- sourceEnd,
- namespaceToken.beginLine,
- endLine,
- namespaceToken.beginColumn,
- endColumn);}
- break;
- default:
- jj_la1[12] = jj_gen;
- jj_consume_token(-1);
- throw new ParseException();
- }
- throw new Error("Missing return statement in function");
- }
- //}}}
- //{{{ useNamespace() method
- final public UseNamespace useNamespace() throws ParseException {
- Token useToken;
- Token namespaceNameToken;
- Token semicolon;
- int sourceEnd;
- int endLine;
- int endColumn;
- String namespaceName;
- //{{{ <USE>
- useToken = jj_consume_token(USE);
- sourceEnd = useToken.sourceEnd;
- endLine = useToken.endLine;
- endColumn = useToken.endColumn;
- try {
- namespaceNameToken = namespaceIdentifier();
- namespaceName = namespaceNameToken.image;
- sourceEnd = namespaceNameToken.sourceEnd;
- endLine = namespaceNameToken.endLine;
- endColumn = namespaceNameToken.endColumn;
- } catch (ParseException e) {
- fireParseError("namespace expected",";",e.currentToken.next);
- {
- namespaceName = SYNTAX_ERROR_CHAR;
- }
- }
- try {
- semicolon = jj_consume_token(SEMICOLON);
- sourceEnd = semicolon.sourceEnd;
- endLine = semicolon.endLine;
- endColumn = semicolon.endColumn;
- } catch (ParseException e) {
- fireParseError("; expected",";",e.currentToken.next);
- }
- {if (true) return new UseNamespace(namespaceName,
- useToken.sourceStart,
- sourceEnd,
- useToken.beginLine,
- endLine,
- useToken.beginColumn,
- endColumn);}
- throw new Error("Missing return statement in function");
- }
- //}}}
- //{{{ interfaceDeclaration()
- final public InterfaceDeclaration interfaceDeclaration() throws ParseException {
- Token modifierToken;
- Token interfaceToken, rBraceToken;
- Token nameToken;
- InterfaceDeclaration interfaceDeclaration;
- String interfaceNameImage = SYNTAX_ERROR_CHAR;
- MethodDeclaration methodDeclaration;
- List<ConstantIdentifier> superInterfaces = null;
- List<Modifier> modifiers = new ArrayList<Modifier>(1);
- List<ClassConstant> classConstants;
- //{{{ interface <IDENTIFIER>
- interfaceToken = jj_consume_token(INTERFACE);
- try {
- nameToken = jj_consume_token(IDENTIFIER);
- interfaceNameImage = nameToken.image;
- } catch (ParseException e) {
- fireParseError("identifier expected","identifier",e.currentToken.next);
- }
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case EXTENDS:
- jj_consume_token(EXTENDS);
- nameToken = jj_consume_token(IDENTIFIER);
- superInterfaces = new ArrayList<ConstantIdentifier>();
- superInterfaces.add(new ConstantIdentifier(nameToken));
- label_5:
- while (true) {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case COMMA:
- ;
- break;
- default:
- jj_la1[13] = jj_gen;
- break label_5;
- }
- jj_consume_token(COMMA);
- nameToken = jj_consume_token(IDENTIFIER);
- superInterfaces.add(new ConstantIdentifier(nameToken));
- }
- break;
- default:
- jj_la1[14] = jj_gen;
- ;
- }
- interfaceDeclaration = new InterfaceDeclaration(namespace,
- path,
- currentSegment,
- interfaceNameImage,
- superInterfaces,
- interfaceToken.sourceStart,
- interfaceToken.beginLine,
- interfaceToken.beginColumn);
- currentSegment.add(interfaceDeclaration);
- currentSegment = interfaceDeclaration;
- scope = new Scope();
- scopeStack.push(scope);
- try {
- jj_consume_token(LBRACE);
- } catch (ParseException e) {
- fireParseError("{ expected","{",e.currentToken.next);
- }
- label_6:
- while (true) {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case PUBLIC:
- case FUNCTION:
- case STATIC:
- case CONST:
- ;
- break;
- default:
- jj_la1[15] = jj_gen;
- break label_6;
- }
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case PUBLIC:
- case FUNCTION:
- case STATIC:
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case PUBLIC:
- case STATIC:
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case PUBLIC:
- //{{{ public [static]
- modifierToken = jj_consume_token(PUBLIC);
- modifiers.add(new Modifier(modifierToken));
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case STATIC:
- try {
- modifierToken = jj_consume_token(STATIC);
- modifiers.add(new Modifier(modifierToken));
- } catch (ParseException e) {
- fireParseError("static or function token expected","static|function",e.currentToken.next);
- }
- break;
- default:
- jj_la1[16] = jj_gen;
- ;
- }
- break;
- case STATIC:
- //{{{ static [public]
- modifierToken = jj_consume_token(STATIC);
- modifiers.add(new Modifier(modifierToken));
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case PUBLIC:
- try {
- modifierToken = jj_consume_token(PUBLIC);
- modifiers.add(new Modifier(modifierToken));
- } catch (ParseException e) {
- fireParseError("public or function token expected","public|function",e.currentToken.next);
- }
- break;
- default:
- jj_la1[17] = jj_gen;
- ;
- }
- break;
- default:
- jj_la1[18] = jj_gen;
- jj_consume_token(-1);
- throw new ParseException();
- }
- break;
- default:
- jj_la1[19] = jj_gen;
- ;
- }
- methodDeclaration = interfaceMethodDeclaration(modifiers);
- interfaceDeclaration.add(methodDeclaration);
- break;
- case CONST:
- classConstants = classConstant();
- for (ClassConstant classConstant : classConstants)
- {
- interfaceDeclaration.addConstant(classConstant);
- }
- break;
- default:
- jj_la1[20] = jj_gen;
- jj_consume_token(-1);
- throw new ParseException();
- }
- }
- try {
- rBraceToken = jj_consume_token(RBRACE);
- interfaceDeclaration.setSourceEnd(rBraceToken.sourceEnd);
- interfaceDeclaration.setEndLine(rBraceToken.endLine);
- interfaceDeclaration.setEndColumn(rBraceToken.endColumn);
- } catch (ParseException e) {
- fireParseError("} expected","}",e.currentToken.next);
- }
- currentSegment = interfaceDeclaration.getParent();
- scope = scopeStack.pop();
- {if (true) return interfaceDeclaration;}
- throw new Error("Missing return statement in function");
- }
- //}}}
- //{{{ classConstant() method
- final public List<ClassConstant> classConstant() throws ParseException {
- Token constToken, token;
- String constName = SYNTAX_ERROR_CHAR;
- List<ClassConstant> constants = new ArrayList<ClassConstant>();
- ClassConstant classConstant;
- constToken = jj_consume_token(CONST);
- classConstant = _classConstant(constToken);
- constants.add(classConstant);
- label_7:
- while (true) {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case COMMA:
- ;
- break;
- default:
- jj_la1[21] = jj_gen;
- break label_7;
- }
- token = jj_consume_token(COMMA);
- classConstant = _classConstant(token);
- constants.add(classConstant);
- }
- try {
- token = jj_consume_token(SEMICOLON);
- } catch (ParseException e) {
- fireParseError("';' expected",";",e.currentToken.next);
- }
- {if (true) return constants;}
- throw new Error("Missing return statement in function");
- }
- //}}}
- //{{{ _classConstant() method
- final public ClassConstant _classConstant(Token startToken) throws ParseException {
- Token identifier;
- Token token;
- String constName = SYNTAX_ERROR_CHAR;
- Expression initializer = null;
- int end, endLine, endColumn;
- end = startToken.sourceEnd;
- endLine = startToken.endLine;
- endColumn = startToken.endColumn;
- try {
- identifier = methodIdentifier();
- startToken = identifier;
- constName = identifier.image;
- end = identifier.sourceEnd;
- endLine = identifier.endLine;
- endColumn = identifier.endColumn;
- } catch (ParseException e) {
- fireParseError("constant expected","constant",e.currentToken.next);
- }
- try {
- token = jj_consume_token(ASSIGN);
- end = token.sourceEnd;
- endLine = token.endLine;
- endColumn = token.endColumn;
- } catch (ParseException e) {
- fireParseError("'=' expected","=",e.currentToken.next);
- }
- try {
- initializer = VariableInitializer();
- end = initializer.getSourceEnd();
- endLine = initializer.getEndLine();
- endColumn = initializer.getEndColumn();
- } catch (ParseException e) {
- fireParseError("expression expected","expression",e.currentToken.next);
- }
- {if (true) return new ClassConstant(namespace,
- path,
- currentSegment,
- constName,
- initializer,
- startToken.sourceStart,
- end,
- startToken.beginLine,
- endLine,
- startToken.beginColumn,
- endColumn);}
- throw new Error("Missing return statement in function");
- }
- //}}}
- //{{{ interfaceMethodDeclaration(Liscodifiers)
- /**
- * A Method Declaration.
- * <b>function</b> MetodDeclarator() Block()
- *
- * @return a MethodDeclaration
- */
- final public MethodDeclaration interfaceMethodDeclaration(List<Modifier> modifiers) throws ParseException {
- MethodDeclaration functionDeclaration;
- MethodHeader methodHeader;
- Token functionToken;
- functionToken = jj_consume_token(FUNCTION);
- methodHeader = methodHeader(functionToken,CONST_METHOD, modifiers);
- functionDeclaration = new MethodDeclaration(currentSegment,methodHeader);
- try {
- jj_consume_token(SEMICOLON);
- } catch (ParseException e) {
- fireParseError("unexpected token : "+e.currentToken.image, ";",
- e.currentToken);
- }
- {if (true) return functionDeclaration;}
- throw new Error("Missing return statement in function");
- }
- //}}}
- //{{{ Class methods
- //{{{ classDeclaration()
- /**
- * A Class declaration.
- * class <IDENTIFIER> [extends <IDENTIFIER>] Class body
- *
- * @return a ClassDeclaration
- */
- final public ClassDeclaration classDeclaration() throws ParseException {
- ClassHeader classHeader;
- ClassDeclaration classDeclaration;
- Token abstractToken = null;
- Token finalToken = null;
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case ABSTRACT:
- abstractToken = jj_consume_token(ABSTRACT);
- classHeader = classHeader(abstractToken);
- classDeclaration = new ClassDeclaration(currentSegment,
- classHeader,
- classHeader.getSourceStart(),
- classHeader.getSourceEnd(),
- classHeader.getBeginLine(),
- classHeader.getEndLine(),
- classHeader.getBeginColumn(),
- classHeader.getEndColumn());
- currentSegment.add(classDeclaration);
- currentSegment = classDeclaration;
- scope = new Scope();
- scopeStack.push(scope);
- abstractClassBody(classDeclaration);
- currentSegment = currentSegment.getParent();
- scope = scopeStack.pop();
- pushOnAstNodes(classDeclaration);
- {if (true) return classDeclaration;}
- break;
- case FINAL:
- case CLASS:
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case FINAL:
- finalToken = jj_consume_token(FINAL);
- break;
- default:
- jj_la1[22] = jj_gen;
- ;
- }
- classHeader = classHeader(finalToken);
- if (finalToken != null)
- {
- classHeader.addModifier(new Modifier(finalToken));
- }
- classDeclaration = new ClassDeclaration(currentSegment,
- classHeader,
- classHeader.getSourceStart(),
- classHeader.getSourceEnd(),
- classHeader.getBeginLine(),
- classHeader.getEndLine(),
- classHeader.getBeginColumn(),
- classHeader.getEndColumn());
- currentSegment.add(classDeclaration);
- currentSegment = classDeclaration;
- scope = new Scope();
- scopeStack.push(scope);
- classBody(classDeclaration);
- currentSegment = currentSegment.getParent();
- scope = scopeStack.pop();
- pushOnAstNodes(classDeclaration);
- {if (true) return classDeclaration;}
- break;
- default:
- jj_la1[23] = jj_gen;
- jj_consume_token(-1);
- throw new ParseException();
- }
- throw new Error("Missing return statement in function");
- }
- //}}}
- //{{{ classHeader(Token abstractToken)
- final public ClassHeader classHeader(Token abstractToken) throws ParseException {
- Token classToken;
- Token className = null;
- Token superclassName = null;
- Token firstToken = abstractToken;
- List<InterfaceIdentifier> interfaces = null;
- try {
- classToken = jj_consume_token(CLASS);
- if (firstToken == null) firstToken = classToken;
- } catch (ParseException e) {
- fireParseError("identifier expected","identifier", e.currentToken.next);
- }
- try {
- className = jj_consume_token(IDENTIFIER);
- } catch (ParseException e) {
- fireParseError("identifier expected","identifier",e.currentToken.next);
- }
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case EXTENDS:
- jj_consume_token(EXTENDS);
- try {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case IDENTIFIER:
- superclassName = jj_consume_token(IDENTIFIER);
- break;
- case OBJECT:
- superclassName = jj_consume_token(OBJECT);
- break;
- default:
- jj_la1[24] = jj_gen;
- jj_consume_to…