3 CHOICE_AMBIGUITY_CHECK = 2;
4 OTHER_AMBIGUITY_CHECK = 1;
7 DEBUG_LOOKAHEAD = false;
8 DEBUG_TOKEN_MANAGER = false;
9 OPTIMIZE_TOKEN_MANAGER = false;
10 ERROR_REPORTING = true;
11 JAVA_UNICODE_ESCAPE = false;
12 UNICODE_INPUT = false;
14 USER_TOKEN_MANAGER = false;
15 USER_CHAR_STREAM = false;
17 BUILD_TOKEN_MANAGER = true;
19 FORCE_LA_CHECK = false;
22 PARSER_BEGIN(PHPParser)
25 import org.eclipse.core.resources.IFile;
26 import org.eclipse.core.resources.IMarker;
27 import org.eclipse.core.runtime.CoreException;
28 import org.eclipse.ui.texteditor.MarkerUtilities;
29 import org.eclipse.jface.preference.IPreferenceStore;
31 import java.util.Hashtable;
32 import java.util.Enumeration;
33 import java.util.ArrayList;
34 import java.io.StringReader;
36 import java.text.MessageFormat;
38 import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
39 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
40 import net.sourceforge.phpdt.internal.compiler.ast.*;
41 import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren;
42 import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo;
46 * This php parser is inspired by the Java 1.2 grammar example
47 * given with JavaCC. You can get JavaCC at http://www.webgain.com
48 * You can test the parser with the PHPParserTestCase2.java
49 * @author Matthieu Casanova
51 public final class PHPParser extends PHPParserSuperclass {
53 /** The file that is parsed. */
54 private static IFile fileToParse;
56 /** The current segment. */
57 private static OutlineableWithChildren currentSegment;
59 private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$
60 private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
61 static PHPOutlineInfo outlineInfo;
63 public static MethodDeclaration currentFunction;
64 private static boolean assigning;
66 /** The error level of the current ParseException. */
67 private static int errorLevel = ERROR;
68 /** The message of the current ParseException. If it's null it's because the parse exception wasn't handled */
69 private static String errorMessage;
71 private static int errorStart = -1;
72 private static int errorEnd = -1;
73 private static PHPDocument phpDocument;
75 * The point where html starts.
76 * It will be used by the token manager to create HTMLCode objects
78 public static int htmlStart;
81 private final static int AstStackIncrement = 100;
82 /** The stack of node. */
83 private static AstNode[] nodes;
84 /** The cursor in expression stack. */
85 private static int nodePtr;
86 private static VariableDeclaration[] variableDeclarationStack;
87 private static int variableDeclarationPtr;
88 private static Statement[] statementStack;
89 private static int statementPtr;
90 private static ElseIf[] elseIfStack;
91 private static int elseIfPtr;
93 public final void setFileToParse(final IFile fileToParse) {
94 this.fileToParse = fileToParse;
100 public PHPParser(final IFile fileToParse) {
101 this(new StringReader(""));
102 this.fileToParse = fileToParse;
106 * Reinitialize the parser.
108 private static final void init() {
109 nodes = new AstNode[AstStackIncrement];
110 statementStack = new Statement[AstStackIncrement];
111 elseIfStack = new ElseIf[AstStackIncrement];
119 * Add an php node on the stack.
120 * @param node the node that will be added to the stack
122 private static final void pushOnAstNodes(AstNode node) {
124 nodes[++nodePtr] = node;
125 } catch (IndexOutOfBoundsException e) {
126 int oldStackLength = nodes.length;
127 AstNode[] oldStack = nodes;
128 nodes = new AstNode[oldStackLength + AstStackIncrement];
129 System.arraycopy(oldStack, 0, nodes, 0, oldStackLength);
130 nodePtr = oldStackLength;
131 nodes[nodePtr] = node;
135 private static final void pushOnVariableDeclarationStack(VariableDeclaration var) {
137 variableDeclarationStack[++variableDeclarationPtr] = var;
138 } catch (IndexOutOfBoundsException e) {
139 int oldStackLength = variableDeclarationStack.length;
140 VariableDeclaration[] oldStack = variableDeclarationStack;
141 variableDeclarationStack = new VariableDeclaration[oldStackLength + AstStackIncrement];
142 System.arraycopy(oldStack, 0, variableDeclarationStack, 0, oldStackLength);
143 variableDeclarationPtr = oldStackLength;
144 variableDeclarationStack[variableDeclarationPtr] = var;
148 private static final void pushOnStatementStack(Statement statement) {
150 statementStack[++statementPtr] = statement;
151 } catch (IndexOutOfBoundsException e) {
152 int oldStackLength = statementStack.length;
153 Statement[] oldStack = statementStack;
154 statementStack = new Statement[oldStackLength + AstStackIncrement];
155 System.arraycopy(oldStack, 0, statementStack, 0, oldStackLength);
156 statementPtr = oldStackLength;
157 statementStack[statementPtr] = statement;
161 private static final void pushOnElseIfStack(ElseIf elseIf) {
163 elseIfStack[++elseIfPtr] = elseIf;
164 } catch (IndexOutOfBoundsException e) {
165 int oldStackLength = elseIfStack.length;
166 ElseIf[] oldStack = elseIfStack;
167 elseIfStack = new ElseIf[oldStackLength + AstStackIncrement];
168 System.arraycopy(oldStack, 0, elseIfStack, 0, oldStackLength);
169 elseIfPtr = oldStackLength;
170 elseIfStack[elseIfPtr] = elseIf;
174 public static final void phpParserTester(final String strEval) throws CoreException, ParseException {
175 PHPParserTokenManager.SwitchTo(PHPParserTokenManager.PHPPARSING);
176 final StringReader stream = new StringReader(strEval);
177 if (jj_input_stream == null) {
178 jj_input_stream = new SimpleCharStream(stream, 1, 1);
180 ReInit(new StringReader(strEval));
185 public static final void htmlParserTester(final File fileName) throws CoreException, ParseException {
187 final Reader stream = new FileReader(fileName);
188 if (jj_input_stream == null) {
189 jj_input_stream = new SimpleCharStream(stream, 1, 1);
194 } catch (FileNotFoundException e) {
195 e.printStackTrace(); //To change body of catch statement use Options | File Templates.
199 public static final void htmlParserTester(final String strEval) throws CoreException, ParseException {
200 final StringReader stream = new StringReader(strEval);
201 if (jj_input_stream == null) {
202 jj_input_stream = new SimpleCharStream(stream, 1, 1);
209 public final PHPOutlineInfo parseInfo(final Object parent, final String s) {
210 currentSegment = new PHPDocument(parent);
211 outlineInfo = new PHPOutlineInfo(parent);
212 final StringReader stream = new StringReader(s);
213 if (jj_input_stream == null) {
214 jj_input_stream = new SimpleCharStream(stream, 1, 1);
220 phpDocument = new PHPDocument(null);
221 phpDocument.nodes = nodes;
222 PHPeclipsePlugin.log(1,phpDocument.toString());
223 } catch (ParseException e) {
224 processParseException(e);
230 * This method will process the parse exception.
231 * If the error message is null, the parse exception wasn't catched and a trace is written in the log
232 * @param e the ParseException
234 private static void processParseException(final ParseException e) {
235 if (errorMessage == null) {
236 PHPeclipsePlugin.log(e);
237 errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it";
238 errorStart = jj_input_stream.getPosition();
239 errorEnd = errorStart + 1;
246 * Create marker for the parse error
247 * @param e the ParseException
249 private static void setMarker(final ParseException e) {
251 if (errorStart == -1) {
252 setMarker(fileToParse,
254 jj_input_stream.tokenBegin,
255 jj_input_stream.tokenBegin + e.currentToken.image.length(),
257 "Line " + e.currentToken.beginLine);
259 setMarker(fileToParse,
264 "Line " + e.currentToken.beginLine);
268 } catch (CoreException e2) {
269 PHPeclipsePlugin.log(e2);
274 * Create markers according to the external parser output
276 private static void createMarkers(final String output, final IFile file) throws CoreException {
277 // delete all markers
278 file.deleteMarkers(IMarker.PROBLEM, false, 0);
283 while ((brIndx = output.indexOf("<br />", indx)) != -1) {
284 // newer php error output (tested with 4.2.3)
285 scanLine(output, file, indx, brIndx);
290 while ((brIndx = output.indexOf("<br>", indx)) != -1) {
291 // older php error output (tested with 4.2.3)
292 scanLine(output, file, indx, brIndx);
298 private static void scanLine(final String output,
301 final int brIndx) throws CoreException {
303 StringBuffer lineNumberBuffer = new StringBuffer(10);
305 current = output.substring(indx, brIndx);
307 if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) {
308 int onLine = current.indexOf("on line <b>");
310 lineNumberBuffer.delete(0, lineNumberBuffer.length());
311 for (int i = onLine; i < current.length(); i++) {
312 ch = current.charAt(i);
313 if ('0' <= ch && '9' >= ch) {
314 lineNumberBuffer.append(ch);
318 int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
320 Hashtable attributes = new Hashtable();
322 current = current.replaceAll("\n", "");
323 current = current.replaceAll("<b>", "");
324 current = current.replaceAll("</b>", "");
325 MarkerUtilities.setMessage(attributes, current);
327 if (current.indexOf(PARSE_ERROR_STRING) != -1)
328 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
329 else if (current.indexOf(PARSE_WARNING_STRING) != -1)
330 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
332 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
333 MarkerUtilities.setLineNumber(attributes, lineNumber);
334 MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
339 public final void parse(final String s) throws CoreException {
340 final StringReader stream = new StringReader(s);
341 if (jj_input_stream == null) {
342 jj_input_stream = new SimpleCharStream(stream, 1, 1);
348 } catch (ParseException e) {
349 processParseException(e);
354 * Call the php parse command ( php -l -f <filename> )
355 * and create markers according to the external parser output
357 public static void phpExternalParse(final IFile file) {
358 final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
359 final String filename = file.getLocation().toString();
361 final String[] arguments = { filename };
362 final MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
363 final String command = form.format(arguments);
365 final String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: ");
368 // parse the buffer to find the errors and warnings
369 createMarkers(parserResult, file);
370 } catch (CoreException e) {
371 PHPeclipsePlugin.log(e);
376 * Put a new html block in the stack.
378 public static final void createNewHTMLCode() {
379 final int currentPosition = SimpleCharStream.getPosition();
380 if (currentPosition == htmlStart) {
383 final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,currentPosition).toCharArray();
384 pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition));
387 private static final void parse() throws ParseException {
392 PARSER_END(PHPParser)
396 <PHPSTARTSHORT : "<?"> {PHPParser.createNewHTMLCode();} : PHPPARSING
397 | <PHPSTARTLONG : "<?php"> {PHPParser.createNewHTMLCode();} : PHPPARSING
398 | <PHPECHOSTART : "<?="> {PHPParser.createNewHTMLCode();} : PHPPARSING
403 <PHPEND :"?>"> {PHPParser.htmlStart = SimpleCharStream.getPosition();} : DEFAULT
406 /* Skip any character if we are not in php mode */
424 <PHPPARSING> SPECIAL_TOKEN :
426 "//" : IN_SINGLE_LINE_COMMENT
428 "#" : IN_SINGLE_LINE_COMMENT
430 <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
432 "/*" : IN_MULTI_LINE_COMMENT
435 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
437 <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : PHPPARSING
440 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
442 <SINGLE_LINE_COMMENT_PHPEND : "?>" > : DEFAULT
448 <FORMAL_COMMENT: "*/" > : PHPPARSING
451 <IN_MULTI_LINE_COMMENT>
454 <MULTI_LINE_COMMENT: "*/" > : PHPPARSING
457 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
467 | <FUNCTION : "function">
470 | <ELSEIF : "elseif">
477 /* LANGUAGE CONSTRUCT */
482 | <INCLUDE : "include">
483 | <REQUIRE : "require">
484 | <INCLUDE_ONCE : "include_once">
485 | <REQUIRE_ONCE : "require_once">
486 | <GLOBAL : "global">
487 | <STATIC : "static">
488 | <CLASSACCESS : "->">
489 | <STATICCLASSACCESS : "::">
490 | <ARRAYASSIGN : "=>">
493 /* RESERVED WORDS AND LITERALS */
499 | <CONTINUE : "continue">
500 | <_DEFAULT : "default">
502 | <EXTENDS : "extends">
507 | <RETURN : "return">
509 | <SWITCH : "switch">
514 | <ENDWHILE : "endwhile">
515 | <ENDSWITCH: "endswitch">
517 | <ENDFOR : "endfor">
518 | <FOREACH : "foreach">
526 | <OBJECT : "object">
528 | <BOOLEAN : "boolean">
530 | <DOUBLE : "double">
533 | <INTEGER : "integer">
563 | <RSIGNEDSHIFT : ">>">
564 | <RUNSIGNEDSHIFT : ">>>">
573 <DECIMAL_LITERAL> (["l","L"])?
574 | <HEX_LITERAL> (["l","L"])?
575 | <OCTAL_LITERAL> (["l","L"])?
578 <#DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
580 <#HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
582 <#OCTAL_LITERAL: "0" (["0"-"7"])* >
584 <FLOATING_POINT_LITERAL:
585 (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
586 | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
587 | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
588 | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
591 <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
593 <STRING_LITERAL: (<STRING_1> | <STRING_2> | <STRING_3>)>
627 < IDENTIFIER: (<LETTER>|<SPECIAL>) (<LETTER>|<DIGIT>|<SPECIAL>)* >
630 ["a"-"z"] | ["A"-"Z"]
638 "_" | ["\u007f"-"\u00ff"]
663 | <EQUAL_EQUAL : "==">
668 | <BANGDOUBLEEQUAL : "!==">
669 | <TRIPLEEQUAL : "===">
676 | <PLUSASSIGN : "+=">
677 | <MINUSASSIGN : "-=">
678 | <STARASSIGN : "*=">
679 | <SLASHASSIGN : "/=">
685 | <TILDEEQUAL : "~=">
686 | <LSHIFTASSIGN : "<<=">
687 | <RSIGNEDSHIFTASSIGN : ">>=">
692 < DOLLAR_ID: <DOLLAR> <IDENTIFIER> >
700 {PHPParser.createNewHTMLCode();}
709 } catch (TokenMgrError e) {
710 PHPeclipsePlugin.log(e);
711 errorStart = SimpleCharStream.getPosition();
712 errorEnd = errorStart + 1;
713 errorMessage = e.getMessage();
715 throw generateParseException();
720 * A php block is a <?= expression [;]?>
721 * or <?php somephpcode ?>
722 * or <? somephpcode ?>
726 final int start = jj_input_stream.getPosition();
734 setMarker(fileToParse,
735 "You should use '<?php' instead of '<?' it will avoid some problems with XML",
737 jj_input_stream.getPosition(),
739 "Line " + token.beginLine);
740 } catch (CoreException e) {
741 PHPeclipsePlugin.log(e);
747 } catch (ParseException e) {
748 errorMessage = "'?>' expected";
750 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
751 errorEnd = jj_input_stream.getPosition() + 1;
756 PHPEchoBlock phpEchoBlock() :
758 final Expression expr;
759 final int pos = SimpleCharStream.getPosition();
760 PHPEchoBlock echoBlock;
763 <PHPECHOSTART> expr = Expression() [ <SEMICOLON> ] <PHPEND>
765 echoBlock = new PHPEchoBlock(expr,pos,SimpleCharStream.getPosition());
766 pushOnAstNodes(echoBlock);
776 ClassDeclaration ClassDeclaration() :
778 final ClassDeclaration classDeclaration;
779 final Token className;
780 Token superclassName = null;
786 {pos = jj_input_stream.getPosition();}
787 className = <IDENTIFIER>
788 } catch (ParseException e) {
789 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
791 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
792 errorEnd = jj_input_stream.getPosition() + 1;
798 superclassName = <IDENTIFIER>
799 } catch (ParseException e) {
800 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
802 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
803 errorEnd = jj_input_stream.getPosition() + 1;
808 if (superclassName == null) {
809 classDeclaration = new ClassDeclaration(currentSegment,
810 className.image.toCharArray(),
814 classDeclaration = new ClassDeclaration(currentSegment,
815 className.image.toCharArray(),
816 superclassName.image.toCharArray(),
820 currentSegment.add(classDeclaration);
821 currentSegment = classDeclaration;
823 ClassBody(classDeclaration)
824 {currentSegment = (OutlineableWithChildren) currentSegment.getParent();
825 classDeclaration.sourceEnd = SimpleCharStream.getPosition();
826 pushOnAstNodes(classDeclaration);
827 return classDeclaration;}
830 void ClassBody(ClassDeclaration classDeclaration) :
835 } catch (ParseException e) {
836 errorMessage = "unexpected token : '"+ e.currentToken.next.image + "', '{' expected";
838 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
839 errorEnd = jj_input_stream.getPosition() + 1;
842 ( ClassBodyDeclaration(classDeclaration) )*
845 } catch (ParseException e) {
846 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', 'var', 'function' or '}' expected";
848 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
849 errorEnd = jj_input_stream.getPosition() + 1;
855 * A class can contain only methods and fields.
857 void ClassBodyDeclaration(ClassDeclaration classDeclaration) :
859 MethodDeclaration method;
860 FieldDeclaration field;
863 method = MethodDeclaration() {classDeclaration.addMethod(method);}
864 | field = FieldDeclaration() {classDeclaration.addVariable(field);}
868 * A class field declaration : it's var VariableDeclarator() (, VariableDeclarator())*;.
870 FieldDeclaration FieldDeclaration() :
872 VariableDeclaration variableDeclaration;
873 VariableDeclaration[] list;
874 final ArrayList arrayList = new ArrayList();
875 final int pos = SimpleCharStream.getPosition();
878 <VAR> variableDeclaration = VariableDeclarator()
879 {arrayList.add(variableDeclaration);
880 outlineInfo.addVariable(new String(variableDeclaration.name));
881 currentSegment.add(variableDeclaration);}
882 ( <COMMA> variableDeclaration = VariableDeclarator()
883 {arrayList.add(variableDeclaration);
884 outlineInfo.addVariable(new String(variableDeclaration.name));
885 currentSegment.add(variableDeclaration);}
889 } catch (ParseException e) {
890 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected after variable declaration";
892 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
893 errorEnd = jj_input_stream.getPosition() + 1;
897 {list = new VariableDeclaration[arrayList.size()];
898 arrayList.toArray(list);
899 return new FieldDeclaration(list,
901 SimpleCharStream.getPosition());}
904 VariableDeclaration VariableDeclarator() :
906 final String varName, varValue;
907 Expression initializer = null;
908 final int pos = jj_input_stream.getPosition();
911 varName = VariableDeclaratorId()
915 initializer = VariableInitializer()
916 } catch (ParseException e) {
917 errorMessage = "Literal expression expected in variable initializer";
919 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
920 errorEnd = jj_input_stream.getPosition() + 1;
925 if (initializer == null) {
926 return new VariableDeclaration(currentSegment,
927 varName.toCharArray(),
929 jj_input_stream.getPosition());
931 return new VariableDeclaration(currentSegment,
932 varName.toCharArray(),
940 * @return the variable name (with suffix)
942 String VariableDeclaratorId() :
945 Expression expression;
946 final StringBuffer buff = new StringBuffer();
947 final int pos = SimpleCharStream.getPosition();
948 ConstantIdentifier ex;
952 expr = Variable() {buff.append(expr);}
954 {ex = new ConstantIdentifier(expr.toCharArray(),
956 SimpleCharStream.getPosition());}
957 expression = VariableSuffix(ex)
958 {buff.append(expression.toStringExpression());}
960 {return buff.toString();}
961 } catch (ParseException e) {
962 errorMessage = "'$' expected for variable identifier";
964 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
965 errorEnd = jj_input_stream.getPosition() + 1;
972 final StringBuffer buff;
973 Expression expression = null;
978 token = <DOLLAR_ID> [<LBRACE> expression = Expression() <RBRACE>]
980 if (expression == null && !assigning) {
981 return token.image.substring(1);
983 buff = new StringBuffer(token.image);
985 buff.append(expression.toStringExpression());
987 return buff.toString();
990 <DOLLAR> expr = VariableName()
994 String VariableName():
996 final StringBuffer buff;
998 Expression expression = null;
1002 <LBRACE> expression = Expression() <RBRACE>
1003 {buff = new StringBuffer('{');
1004 buff.append(expression.toStringExpression());
1006 return buff.toString();}
1008 token = <IDENTIFIER> [<LBRACE> expression = Expression() <RBRACE>]
1010 if (expression == null) {
1013 buff = new StringBuffer(token.image);
1015 buff.append(expression.toStringExpression());
1017 return buff.toString();
1020 <DOLLAR> expr = VariableName()
1022 buff = new StringBuffer('$');
1024 return buff.toString();
1027 token = <DOLLAR_ID> {return token.image;}
1030 Expression VariableInitializer() :
1032 final Expression expr;
1034 final int pos = SimpleCharStream.getPosition();
1040 <MINUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
1041 {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
1043 SimpleCharStream.getPosition()),
1047 <PLUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
1048 {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
1050 SimpleCharStream.getPosition()),
1054 expr = ArrayDeclarator()
1057 token = <IDENTIFIER>
1058 {return new ConstantIdentifier(token.image.toCharArray(),pos,SimpleCharStream.getPosition());}
1061 ArrayVariableDeclaration ArrayVariable() :
1063 Expression expr,expr2;
1067 [<ARRAYASSIGN> expr2 = Expression()
1068 {return new ArrayVariableDeclaration(expr,expr2);}
1070 {return new ArrayVariableDeclaration(expr,SimpleCharStream.getPosition());}
1073 ArrayVariableDeclaration[] ArrayInitializer() :
1075 ArrayVariableDeclaration expr;
1076 final ArrayList list = new ArrayList();
1079 <LPAREN> [ expr = ArrayVariable()
1081 ( LOOKAHEAD(2) <COMMA> expr = ArrayVariable()
1085 [<COMMA> {list.add(null);}]
1088 ArrayVariableDeclaration[] vars = new ArrayVariableDeclaration[list.size()];
1094 * A Method Declaration.
1095 * <b>function</b> MetodDeclarator() Block()
1097 MethodDeclaration MethodDeclaration() :
1099 final MethodDeclaration functionDeclaration;
1100 Token functionToken;
1104 functionToken = <FUNCTION>
1106 functionDeclaration = MethodDeclarator()
1107 {outlineInfo.addVariable(new String(functionDeclaration.name));}
1108 } catch (ParseException e) {
1109 if (errorMessage != null) throw e;
1110 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
1112 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1113 errorEnd = jj_input_stream.getPosition() + 1;
1117 if (currentSegment != null) {
1118 currentSegment.add(functionDeclaration);
1119 currentSegment = functionDeclaration;
1121 currentFunction = functionDeclaration;
1125 functionDeclaration.statements = block.statements;
1126 currentFunction = null;
1127 if (currentSegment != null) {
1128 currentSegment = (OutlineableWithChildren) currentSegment.getParent();
1130 return functionDeclaration;
1135 * A MethodDeclarator.
1136 * [&] IDENTIFIER(parameters ...).
1137 * @return a function description for the outline
1139 MethodDeclaration MethodDeclarator() :
1141 final Token identifier;
1142 Token reference = null;
1143 final Hashtable formalParameters;
1144 final int pos = SimpleCharStream.getPosition();
1147 [reference = <BIT_AND>] identifier = <IDENTIFIER>
1148 formalParameters = FormalParameters()
1149 {return new MethodDeclaration(currentSegment,
1150 identifier.image.toCharArray(),
1154 SimpleCharStream.getPosition());}
1158 * FormalParameters follows method identifier.
1159 * (FormalParameter())
1161 Hashtable FormalParameters() :
1164 final StringBuffer buff = new StringBuffer("(");
1165 VariableDeclaration var;
1166 final Hashtable parameters = new Hashtable();
1171 } catch (ParseException e) {
1172 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected after function identifier";
1174 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1175 errorEnd = jj_input_stream.getPosition() + 1;
1178 [ var = FormalParameter()
1179 {parameters.put(new String(var.name),var);}
1181 <COMMA> var = FormalParameter()
1182 {parameters.put(new String(var.name),var);}
1187 } catch (ParseException e) {
1188 errorMessage = "')' expected";
1190 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1191 errorEnd = jj_input_stream.getPosition() + 1;
1194 {return parameters;}
1198 * A formal parameter.
1199 * $varname[=value] (,$varname[=value])
1201 VariableDeclaration FormalParameter() :
1203 final VariableDeclaration variableDeclaration;
1207 [token = <BIT_AND>] variableDeclaration = VariableDeclarator()
1209 if (token != null) {
1210 variableDeclaration.setReference(true);
1212 return variableDeclaration;}
1215 ConstantIdentifier Type() :
1218 <STRING> {pos = SimpleCharStream.getPosition();
1219 return new ConstantIdentifier(Types.STRING,
1221 | <BOOL> {pos = SimpleCharStream.getPosition();
1222 return new ConstantIdentifier(Types.BOOL,
1224 | <BOOLEAN> {pos = SimpleCharStream.getPosition();
1225 return new ConstantIdentifier(Types.BOOLEAN,
1227 | <REAL> {pos = SimpleCharStream.getPosition();
1228 return new ConstantIdentifier(Types.REAL,
1230 | <DOUBLE> {pos = SimpleCharStream.getPosition();
1231 return new ConstantIdentifier(Types.DOUBLE,
1233 | <FLOAT> {pos = SimpleCharStream.getPosition();
1234 return new ConstantIdentifier(Types.FLOAT,
1236 | <INT> {pos = SimpleCharStream.getPosition();
1237 return new ConstantIdentifier(Types.INT,
1239 | <INTEGER> {pos = SimpleCharStream.getPosition();
1240 return new ConstantIdentifier(Types.INTEGER,
1242 | <OBJECT> {pos = SimpleCharStream.getPosition();
1243 return new ConstantIdentifier(Types.OBJECT,
1247 Expression Expression() :
1249 final Expression expr;
1252 expr = PrintExpression() {return expr;}
1253 | expr = ListExpression() {return expr;}
1254 | LOOKAHEAD(varAssignation())
1255 expr = varAssignation() {return expr;}
1256 | expr = ConditionalExpression() {return expr;}
1260 * A Variable assignation.
1261 * varName (an assign operator) any expression
1263 VarAssignation varAssignation() :
1266 final Expression expression;
1267 final int assignOperator;
1268 final int pos = SimpleCharStream.getPosition();
1271 varName = VariableDeclaratorId()
1272 assignOperator = AssignmentOperator()
1274 expression = Expression()
1275 } catch (ParseException e) {
1276 if (errorMessage != null) {
1279 errorMessage = "expression expected";
1281 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1282 errorEnd = jj_input_stream.getPosition() + 1;
1285 {return new VarAssignation(varName.toCharArray(),
1289 SimpleCharStream.getPosition());}
1292 int AssignmentOperator() :
1295 <ASSIGN> {return VarAssignation.EQUAL;}
1296 | <STARASSIGN> {return VarAssignation.STAR_EQUAL;}
1297 | <SLASHASSIGN> {return VarAssignation.SLASH_EQUAL;}
1298 | <REMASSIGN> {return VarAssignation.REM_EQUAL;}
1299 | <PLUSASSIGN> {return VarAssignation.PLUS_EQUAL;}
1300 | <MINUSASSIGN> {return VarAssignation.MINUS_EQUAL;}
1301 | <LSHIFTASSIGN> {return VarAssignation.LSHIFT_EQUAL;}
1302 | <RSIGNEDSHIFTASSIGN> {return VarAssignation.RSIGNEDSHIFT_EQUAL;}
1303 | <ANDASSIGN> {return VarAssignation.AND_EQUAL;}
1304 | <XORASSIGN> {return VarAssignation.XOR_EQUAL;}
1305 | <ORASSIGN> {return VarAssignation.OR_EQUAL;}
1306 | <DOTASSIGN> {return VarAssignation.DOT_EQUAL;}
1307 | <TILDEEQUAL> {return VarAssignation.TILDE_EQUAL;}
1310 Expression ConditionalExpression() :
1312 final Expression expr;
1313 Expression expr2 = null;
1314 Expression expr3 = null;
1317 expr = ConditionalOrExpression() [ <HOOK> expr2 = Expression() <COLON> expr3 = ConditionalExpression() ]
1319 if (expr3 == null) {
1322 return new ConditionalExpression(expr,expr2,expr3);
1326 Expression ConditionalOrExpression() :
1328 Expression expr,expr2;
1332 expr = ConditionalAndExpression()
1335 <OR_OR> {operator = OperatorIds.OR_OR;}
1336 | <_ORL> {operator = OperatorIds.ORL;}
1337 ) expr2 = ConditionalAndExpression()
1339 expr = new BinaryExpression(expr,expr2,operator);
1345 Expression ConditionalAndExpression() :
1347 Expression expr,expr2;
1351 expr = ConcatExpression()
1353 ( <AND_AND> {operator = OperatorIds.AND_AND;}
1354 | <_ANDL> {operator = OperatorIds.ANDL;})
1355 expr2 = ConcatExpression() {expr = new BinaryExpression(expr,expr2,operator);}
1360 Expression ConcatExpression() :
1362 Expression expr,expr2;
1365 expr = InclusiveOrExpression()
1367 <DOT> expr2 = InclusiveOrExpression()
1368 {expr = new BinaryExpression(expr,expr2,OperatorIds.DOT);}
1373 Expression InclusiveOrExpression() :
1375 Expression expr,expr2;
1378 expr = ExclusiveOrExpression()
1379 (<BIT_OR> expr2 = ExclusiveOrExpression()
1380 {expr = new BinaryExpression(expr,expr2,OperatorIds.OR);}
1385 Expression ExclusiveOrExpression() :
1387 Expression expr,expr2;
1390 expr = AndExpression()
1392 <XOR> expr2 = AndExpression()
1393 {expr = new BinaryExpression(expr,expr2,OperatorIds.XOR);}
1398 Expression AndExpression() :
1400 Expression expr,expr2;
1403 expr = EqualityExpression()
1405 <BIT_AND> expr2 = EqualityExpression()
1406 {expr = new BinaryExpression(expr,expr2,OperatorIds.AND);}
1411 Expression EqualityExpression() :
1413 Expression expr,expr2;
1417 expr = RelationalExpression()
1419 ( <EQUAL_EQUAL> {operator = OperatorIds.EQUAL_EQUAL;}
1420 | <DIF> {operator = OperatorIds.DIF;}
1421 | <NOT_EQUAL> {operator = OperatorIds.DIF;}
1422 | <BANGDOUBLEEQUAL> {operator = OperatorIds.BANG_EQUAL_EQUAL;}
1423 | <TRIPLEEQUAL> {operator = OperatorIds.EQUAL_EQUAL_EQUAL;}
1426 expr2 = RelationalExpression()
1427 } catch (ParseException e) {
1428 if (errorMessage != null) {
1431 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1433 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1434 errorEnd = jj_input_stream.getPosition() + 1;
1438 expr = new BinaryExpression(expr,expr2,operator);
1444 Expression RelationalExpression() :
1446 Expression expr,expr2;
1450 expr = ShiftExpression()
1452 ( <LT> {operator = OperatorIds.LESS;}
1453 | <GT> {operator = OperatorIds.GREATER;}
1454 | <LE> {operator = OperatorIds.LESS_EQUAL;}
1455 | <GE> {operator = OperatorIds.GREATER_EQUAL;})
1456 expr2 = ShiftExpression()
1457 {expr = new BinaryExpression(expr,expr2,operator);}
1462 Expression ShiftExpression() :
1464 Expression expr,expr2;
1468 expr = AdditiveExpression()
1470 ( <LSHIFT> {operator = OperatorIds.LEFT_SHIFT;}
1471 | <RSIGNEDSHIFT> {operator = OperatorIds.RIGHT_SHIFT;}
1472 | <RUNSIGNEDSHIFT> {operator = OperatorIds.UNSIGNED_RIGHT_SHIFT;})
1473 expr2 = AdditiveExpression()
1474 {expr = new BinaryExpression(expr,expr2,operator);}
1479 Expression AdditiveExpression() :
1481 Expression expr,expr2;
1485 expr = MultiplicativeExpression()
1487 ( <PLUS> {operator = OperatorIds.PLUS;}
1488 | <MINUS> {operator = OperatorIds.MINUS;} )
1489 expr2 = MultiplicativeExpression()
1490 {expr = new BinaryExpression(expr,expr2,operator);}
1495 Expression MultiplicativeExpression() :
1497 Expression expr,expr2;
1502 expr = UnaryExpression()
1503 } catch (ParseException e) {
1504 if (errorMessage != null) throw e;
1505 errorMessage = "unexpected token '"+e.currentToken.next.image+"'";
1507 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1508 errorEnd = jj_input_stream.getPosition() + 1;
1512 ( <STAR> {operator = OperatorIds.MULTIPLY;}
1513 | <SLASH> {operator = OperatorIds.DIVIDE;}
1514 | <REMAINDER> {operator = OperatorIds.REMAINDER;})
1515 expr2 = UnaryExpression()
1516 {expr = new BinaryExpression(expr,expr2,operator);}
1522 * An unary expression starting with @, & or nothing
1524 Expression UnaryExpression() :
1527 final int pos = SimpleCharStream.getPosition();
1530 <BIT_AND> expr = UnaryExpressionNoPrefix()
1531 {return new PrefixedUnaryExpression(expr,OperatorIds.AND,pos);}
1533 expr = AtUnaryExpression() {return expr;}
1536 Expression AtUnaryExpression() :
1539 final int pos = SimpleCharStream.getPosition();
1543 expr = AtUnaryExpression()
1544 {return new PrefixedUnaryExpression(expr,OperatorIds.AT,pos);}
1546 expr = UnaryExpressionNoPrefix()
1551 Expression UnaryExpressionNoPrefix() :
1555 final int pos = SimpleCharStream.getPosition();
1558 ( <PLUS> {operator = OperatorIds.PLUS;}
1559 | <MINUS> {operator = OperatorIds.MINUS;})
1560 expr = UnaryExpression()
1561 {return new PrefixedUnaryExpression(expr,operator,pos);}
1563 expr = PreIncDecExpression()
1566 expr = UnaryExpressionNotPlusMinus()
1571 Expression PreIncDecExpression() :
1573 final Expression expr;
1575 final int pos = SimpleCharStream.getPosition();
1578 ( <INCR> {operator = OperatorIds.PLUS_PLUS;}
1579 | <DECR> {operator = OperatorIds.MINUS_MINUS;})
1580 expr = PrimaryExpression()
1581 {return new PrefixedUnaryExpression(expr,operator,pos);}
1584 Expression UnaryExpressionNotPlusMinus() :
1587 final int pos = SimpleCharStream.getPosition();
1590 <BANG> expr = UnaryExpression() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
1591 | LOOKAHEAD( <LPAREN> (Type() | <ARRAY>) <RPAREN> )
1592 expr = CastExpression() {return expr;}
1593 | expr = PostfixExpression() {return expr;}
1594 | expr = Literal() {return expr;}
1595 | <LPAREN> expr = Expression()
1598 } catch (ParseException e) {
1599 errorMessage = "')' expected";
1601 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1602 errorEnd = jj_input_stream.getPosition() + 1;
1608 CastExpression CastExpression() :
1610 final ConstantIdentifier type;
1611 final Expression expr;
1612 final int pos = SimpleCharStream.getPosition();
1617 | <ARRAY> {type = new ConstantIdentifier(Types.ARRAY,pos,SimpleCharStream.getPosition());})
1618 <RPAREN> expr = UnaryExpression()
1619 {return new CastExpression(type,expr,pos,SimpleCharStream.getPosition());}
1622 Expression PostfixExpression() :
1626 final int pos = SimpleCharStream.getPosition();
1629 expr = PrimaryExpression()
1630 [ <INCR> {operator = OperatorIds.PLUS_PLUS;}
1631 | <DECR> {operator = OperatorIds.MINUS_MINUS;}]
1633 if (operator == -1) {
1636 return new PostfixedUnaryExpression(expr,operator,pos);
1640 Expression PrimaryExpression() :
1642 final Token identifier;
1644 final StringBuffer buff = new StringBuffer();
1645 final int pos = SimpleCharStream.getPosition();
1649 identifier = <IDENTIFIER> <STATICCLASSACCESS> expr = ClassIdentifier()
1650 {expr = new ClassAccess(new ConstantIdentifier(identifier.image.toCharArray(),
1652 SimpleCharStream.getPosition()),
1654 ClassAccess.STATIC);}
1655 (expr = PrimarySuffix(expr))*
1658 expr = PrimaryPrefix()
1659 (expr = PrimarySuffix(expr))*
1662 expr = ArrayDeclarator()
1666 ArrayInitializer ArrayDeclarator() :
1668 final ArrayVariableDeclaration[] vars;
1669 final int pos = SimpleCharStream.getPosition();
1672 <ARRAY> vars = ArrayInitializer()
1673 {return new ArrayInitializer(vars,pos,SimpleCharStream.getPosition());}
1676 Expression PrimaryPrefix() :
1678 final Expression expr;
1681 final int pos = SimpleCharStream.getPosition();
1684 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1686 SimpleCharStream.getPosition());}
1687 | <NEW> expr = ClassIdentifier() {return new PrefixedUnaryExpression(expr,
1690 | var = VariableDeclaratorId() {return new ConstantIdentifier(var.toCharArray(),
1692 SimpleCharStream.getPosition());}
1695 PrefixedUnaryExpression classInstantiation() :
1698 final StringBuffer buff;
1699 final int pos = SimpleCharStream.getPosition();
1702 <NEW> expr = ClassIdentifier()
1704 {buff = new StringBuffer(expr.toStringExpression());}
1705 expr = PrimaryExpression()
1706 {buff.append(expr.toStringExpression());
1707 expr = new ConstantIdentifier(buff.toString().toCharArray(),
1709 SimpleCharStream.getPosition());}
1711 {return new PrefixedUnaryExpression(expr,
1716 ConstantIdentifier ClassIdentifier():
1720 final int pos = SimpleCharStream.getPosition();
1723 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1725 SimpleCharStream.getPosition());}
1726 | expr = VariableDeclaratorId() {return new ConstantIdentifier(expr.toCharArray(),
1728 SimpleCharStream.getPosition());}
1731 AbstractSuffixExpression PrimarySuffix(Expression prefix) :
1733 final AbstractSuffixExpression expr;
1736 expr = Arguments(prefix) {return expr;}
1737 | expr = VariableSuffix(prefix) {return expr;}
1740 AbstractSuffixExpression VariableSuffix(Expression prefix) :
1743 final int pos = SimpleCharStream.getPosition();
1744 Expression expression = null;
1749 expr = VariableName()
1750 } catch (ParseException e) {
1751 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
1753 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1754 errorEnd = jj_input_stream.getPosition() + 1;
1757 {return new ClassAccess(prefix,
1758 new ConstantIdentifier(expr.toCharArray(),pos,SimpleCharStream.getPosition()),
1759 ClassAccess.NORMAL);}
1761 <LBRACKET> [ expression = Expression() | expression = Type() ] //Not good
1764 } catch (ParseException e) {
1765 errorMessage = "']' expected";
1767 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1768 errorEnd = jj_input_stream.getPosition() + 1;
1771 {return new ArrayDeclarator(prefix,expression,SimpleCharStream.getPosition());}
1780 token = <INTEGER_LITERAL> {pos = SimpleCharStream.getPosition();
1781 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1782 | token = <FLOATING_POINT_LITERAL> {pos = SimpleCharStream.getPosition();
1783 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1784 | token = <STRING_LITERAL> {pos = SimpleCharStream.getPosition();
1785 return new StringLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1786 | <TRUE> {pos = SimpleCharStream.getPosition();
1787 return new TrueLiteral(pos-4,pos);}
1788 | <FALSE> {pos = SimpleCharStream.getPosition();
1789 return new FalseLiteral(pos-4,pos);}
1790 | <NULL> {pos = SimpleCharStream.getPosition();
1791 return new NullLiteral(pos-4,pos);}
1794 FunctionCall Arguments(Expression func) :
1796 ArgumentDeclaration[] args = null;
1799 <LPAREN> [ args = ArgumentList() ]
1802 } catch (ParseException e) {
1803 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
1805 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1806 errorEnd = jj_input_stream.getPosition() + 1;
1809 {return new FunctionCall(func,args,SimpleCharStream.getPosition());}
1813 * An argument list is a list of arguments separated by comma :
1814 * argumentDeclaration() (, argumentDeclaration)*
1815 * @return an array of arguments
1817 ArgumentDeclaration[] ArgumentList() :
1819 ArgumentDeclaration arg;
1820 final ArrayList list = new ArrayList();
1821 ArgumentDeclaration argument;
1824 arg = argumentDeclaration()
1828 arg = argumentDeclaration()
1830 } catch (ParseException e) {
1831 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. An expression expected after a comma in argument list";
1833 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1834 errorEnd = jj_input_stream.getPosition() + 1;
1839 ArgumentDeclaration[] args = new ArgumentDeclaration[list.size()];
1845 * Here is an argument declaration.
1846 * It's [&]$variablename[=variableInitializer]
1848 ArgumentDeclaration argumentDeclaration() :
1850 boolean reference = false;
1852 Expression initializer = null;
1853 final int pos = SimpleCharStream.getPosition();
1856 [<BIT_AND> {reference = true;}]
1857 varName = VariableDeclaratorId()
1861 initializer = VariableInitializer()
1862 } catch (ParseException e) {
1863 errorMessage = "Literal expression expected in variable initializer";
1865 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1866 errorEnd = jj_input_stream.getPosition() + 1;
1871 if (initializer == null) {
1872 return new ArgumentDeclaration(varName.toCharArray(),
1876 return new ArgumentDeclaration(varName.toCharArray(),
1883 * A Statement without break.
1885 Statement StatementNoBreak() :
1887 final Statement statement;
1892 statement = Expression()
1895 } catch (ParseException e) {
1896 if (e.currentToken.next.kind != 4) {
1897 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1899 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1900 errorEnd = jj_input_stream.getPosition() + 1;
1906 statement = LabeledStatement() {return statement;}
1907 | statement = Block() {return statement;}
1908 | statement = EmptyStatement() {return statement;}
1909 | statement = StatementExpression()
1912 } catch (ParseException e) {
1913 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1915 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1916 errorEnd = jj_input_stream.getPosition() + 1;
1920 | statement = SwitchStatement() {return statement;}
1921 | statement = IfStatement() {return statement;}
1922 | statement = WhileStatement() {return statement;}
1923 | statement = DoStatement() {return statement;}
1924 | statement = ForStatement() {return statement;}
1925 | statement = ForeachStatement() {return statement;}
1926 | statement = ContinueStatement() {return statement;}
1927 | statement = ReturnStatement() {return statement;}
1928 | statement = EchoStatement() {return statement;}
1929 | [token=<AT>] statement = IncludeStatement()
1930 {if (token != null) {
1931 ((InclusionStatement)statement).silent = true;
1934 | statement = StaticStatement() {return statement;}
1935 | statement = GlobalStatement() {return statement;}
1939 * A Normal statement.
1941 Statement Statement() :
1943 final Statement statement;
1946 statement = StatementNoBreak() {return statement;}
1947 | statement = BreakStatement() {return statement;}
1951 * An html block inside a php syntax.
1953 HTMLBlock htmlBlock() :
1955 final int startIndex = nodePtr;
1956 AstNode[] blockNodes;
1960 <PHPEND> (phpEchoBlock())*
1962 (<PHPSTARTLONG> | <PHPSTARTSHORT>)
1963 } catch (ParseException e) {
1964 errorMessage = "End of file unexpected, '<?php' expected";
1966 errorStart = jj_input_stream.getPosition();
1967 errorEnd = jj_input_stream.getPosition();
1971 nbNodes = nodePtr-startIndex - 1;
1972 blockNodes = new AstNode[nbNodes];
1973 System.arraycopy(nodes,startIndex,blockNodes,0,nbNodes);
1974 return new HTMLBlock(nodes);}
1978 * An include statement. It's "include" an expression;
1980 InclusionStatement IncludeStatement() :
1982 final Expression expr;
1985 final int pos = jj_input_stream.getPosition();
1986 final InclusionStatement inclusionStatement;
1989 ( <REQUIRE> {keyword = InclusionStatement.REQUIRE;}
1990 | <REQUIRE_ONCE> {keyword = InclusionStatement.REQUIRE_ONCE;}
1991 | <INCLUDE> {keyword = InclusionStatement.INCLUDE;}
1992 | <INCLUDE_ONCE> {keyword = InclusionStatement.INCLUDE_ONCE;})
1995 } catch (ParseException e) {
1996 if (errorMessage != null) {
1999 errorMessage = "unexpected token '"+ e.currentToken.next.image+"', expression expected";
2001 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2002 errorEnd = jj_input_stream.getPosition() + 1;
2005 {inclusionStatement = new InclusionStatement(currentSegment,
2009 currentSegment.add(inclusionStatement);
2013 } catch (ParseException e) {
2014 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
2016 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2017 errorEnd = jj_input_stream.getPosition() + 1;
2020 {return inclusionStatement;}
2023 PrintExpression PrintExpression() :
2025 final Expression expr;
2026 final int pos = SimpleCharStream.getPosition();
2029 <PRINT> expr = Expression() {return new PrintExpression(expr,pos,SimpleCharStream.getPosition());}
2032 ListExpression ListExpression() :
2035 Expression expression = null;
2036 ArrayList list = new ArrayList();
2037 final int pos = SimpleCharStream.getPosition();
2043 } catch (ParseException e) {
2044 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
2046 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2047 errorEnd = jj_input_stream.getPosition() + 1;
2051 expr = VariableDeclaratorId()
2054 {if (expr == null) list.add(null);}
2058 } catch (ParseException e) {
2059 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
2061 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2062 errorEnd = jj_input_stream.getPosition() + 1;
2065 expr = VariableDeclaratorId()
2070 } catch (ParseException e) {
2071 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
2073 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2074 errorEnd = jj_input_stream.getPosition() + 1;
2077 [ <ASSIGN> expression = Expression()
2079 String[] strings = new String[list.size()];
2080 list.toArray(strings);
2081 return new ListExpression(strings,
2084 SimpleCharStream.getPosition());}
2087 String[] strings = new String[list.size()];
2088 list.toArray(strings);
2089 return new ListExpression(strings,pos,SimpleCharStream.getPosition());}
2093 * An echo statement.
2094 * echo anyexpression (, otherexpression)*
2096 EchoStatement EchoStatement() :
2098 final ArrayList expressions = new ArrayList();
2100 final int pos = SimpleCharStream.getPosition();
2103 <ECHO> expr = Expression()
2104 {expressions.add(expr);}
2106 <COMMA> expr = Expression()
2107 {expressions.add(expr);}
2112 Expression[] exprs = new Expression[expressions.size()];
2113 expressions.toArray(exprs);
2114 return new EchoStatement(exprs,pos);}
2115 } catch (ParseException e) {
2116 if (e.currentToken.next.kind != 4) {
2117 errorMessage = "';' expected after 'echo' statement";
2119 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2120 errorEnd = jj_input_stream.getPosition() + 1;
2126 GlobalStatement GlobalStatement() :
2128 final int pos = jj_input_stream.getPosition();
2130 ArrayList vars = new ArrayList();
2131 GlobalStatement global;
2135 expr = VariableDeclaratorId()
2138 expr = VariableDeclaratorId()
2144 String[] strings = new String[vars.size()];
2145 vars.toArray(strings);
2146 global = new GlobalStatement(currentSegment,
2149 SimpleCharStream.getPosition());
2150 currentSegment.add(global);
2152 } catch (ParseException e) {
2153 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2155 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2156 errorEnd = jj_input_stream.getPosition() + 1;
2161 StaticStatement StaticStatement() :
2163 final int pos = SimpleCharStream.getPosition();
2164 final ArrayList vars = new ArrayList();
2165 VariableDeclaration expr;
2168 <STATIC> expr = VariableDeclarator() {vars.add(new String(expr.name));}
2169 (<COMMA> expr = VariableDeclarator() {vars.add(new String(expr.name));})*
2173 String[] strings = new String[vars.size()];
2174 vars.toArray(strings);
2175 return new StaticStatement(strings,
2177 SimpleCharStream.getPosition());}
2178 } catch (ParseException e) {
2179 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2181 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2182 errorEnd = jj_input_stream.getPosition() + 1;
2187 LabeledStatement LabeledStatement() :
2189 final int pos = SimpleCharStream.getPosition();
2191 final Statement statement;
2194 label = <IDENTIFIER> <COLON> statement = Statement()
2195 {return new LabeledStatement(label.image.toCharArray(),statement,pos,SimpleCharStream.getPosition());}
2207 final int pos = SimpleCharStream.getPosition();
2208 final ArrayList list = new ArrayList();
2209 Statement statement;
2214 } catch (ParseException e) {
2215 errorMessage = "'{' expected";
2217 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2218 errorEnd = jj_input_stream.getPosition() + 1;
2221 ( statement = BlockStatement() {list.add(statement);}
2222 | statement = htmlBlock() {list.add(statement);})*
2225 } catch (ParseException e) {
2226 errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected";
2228 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2229 errorEnd = jj_input_stream.getPosition() + 1;
2233 Statement[] statements = new Statement[list.size()];
2234 list.toArray(statements);
2235 return new Block(statements,pos,SimpleCharStream.getPosition());}
2238 Statement BlockStatement() :
2240 final Statement statement;
2243 statement = Statement() {return statement;}
2244 | statement = ClassDeclaration() {return statement;}
2245 | statement = MethodDeclaration() {return statement;}
2249 * A Block statement that will not contain any 'break'
2251 Statement BlockStatementNoBreak() :
2253 final Statement statement;
2256 statement = StatementNoBreak() {return statement;}
2257 | statement = ClassDeclaration() {return statement;}
2258 | statement = MethodDeclaration() {return statement;}
2261 VariableDeclaration[] LocalVariableDeclaration() :
2263 final ArrayList list = new ArrayList();
2264 VariableDeclaration var;
2267 var = LocalVariableDeclarator()
2269 ( <COMMA> var = LocalVariableDeclarator() {list.add(var);})*
2271 VariableDeclaration[] vars = new VariableDeclaration[list.size()];
2276 VariableDeclaration LocalVariableDeclarator() :
2278 final String varName;
2279 Expression initializer = null;
2280 final int pos = SimpleCharStream.getPosition();
2283 varName = VariableDeclaratorId() [ <ASSIGN> initializer = Expression() ]
2285 if (initializer == null) {
2286 return new VariableDeclaration(currentSegment,
2287 varName.toCharArray(),
2289 jj_input_stream.getPosition());
2291 return new VariableDeclaration(currentSegment,
2292 varName.toCharArray(),
2298 EmptyStatement EmptyStatement() :
2304 {pos = SimpleCharStream.getPosition();
2305 return new EmptyStatement(pos-1,pos);}
2308 Statement StatementExpression() :
2310 Expression expr,expr2;
2314 expr = PreIncDecExpression() {return expr;}
2316 expr = PrimaryExpression()
2317 [ <INCR> {return new PostfixedUnaryExpression(expr,
2318 OperatorIds.PLUS_PLUS,
2319 SimpleCharStream.getPosition());}
2320 | <DECR> {return new PostfixedUnaryExpression(expr,
2321 OperatorIds.MINUS_MINUS,
2322 SimpleCharStream.getPosition());}
2323 | operator = AssignmentOperator() expr2 = Expression()
2324 {return new BinaryExpression(expr,expr2,operator);}
2329 SwitchStatement SwitchStatement() :
2331 final Expression variable;
2332 final AbstractCase[] cases;
2333 final int pos = SimpleCharStream.getPosition();
2339 } catch (ParseException e) {
2340 errorMessage = "'(' expected after 'switch'";
2342 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2343 errorEnd = jj_input_stream.getPosition() + 1;
2347 variable = Expression()
2348 } catch (ParseException e) {
2349 if (errorMessage != null) {
2352 errorMessage = "expression expected";
2354 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2355 errorEnd = jj_input_stream.getPosition() + 1;
2360 } catch (ParseException e) {
2361 errorMessage = "')' expected";
2363 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2364 errorEnd = jj_input_stream.getPosition() + 1;
2367 (cases = switchStatementBrace() | cases = switchStatementColon(pos, pos + 6))
2368 {return new SwitchStatement(variable,cases,pos,SimpleCharStream.getPosition());}
2371 AbstractCase[] switchStatementBrace() :
2374 final ArrayList cases = new ArrayList();
2378 ( cas = switchLabel0() {cases.add(cas);})*
2382 AbstractCase[] abcase = new AbstractCase[cases.size()];
2383 cases.toArray(abcase);
2385 } catch (ParseException e) {
2386 errorMessage = "'}' expected";
2388 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2389 errorEnd = jj_input_stream.getPosition() + 1;
2394 * A Switch statement with : ... endswitch;
2395 * @param start the begin offset of the switch
2396 * @param end the end offset of the switch
2398 AbstractCase[] switchStatementColon(final int start, final int end) :
2401 final ArrayList cases = new ArrayList();
2406 setMarker(fileToParse,
2407 "Ugly syntax detected, you should switch () {...} instead of switch (): ... enswitch;",
2411 "Line " + token.beginLine);
2412 } catch (CoreException e) {
2413 PHPeclipsePlugin.log(e);
2415 ( cas = switchLabel0() {cases.add(cas);})*
2418 } catch (ParseException e) {
2419 errorMessage = "'endswitch' expected";
2421 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2422 errorEnd = jj_input_stream.getPosition() + 1;
2428 AbstractCase[] abcase = new AbstractCase[cases.size()];
2429 cases.toArray(abcase);
2431 } catch (ParseException e) {
2432 errorMessage = "';' expected after 'endswitch' keyword";
2434 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2435 errorEnd = jj_input_stream.getPosition() + 1;
2440 AbstractCase switchLabel0() :
2442 final Expression expr;
2443 Statement statement;
2444 final ArrayList stmts = new ArrayList();
2445 final int pos = SimpleCharStream.getPosition();
2448 expr = SwitchLabel()
2449 ( statement = BlockStatementNoBreak() {stmts.add(statement);}
2450 | statement = htmlBlock() {stmts.add(statement);})*
2451 [ statement = BreakStatement() {stmts.add(statement);}]
2453 Statement[] stmtsArray = new Statement[stmts.size()];
2454 stmts.toArray(stmtsArray);
2455 if (expr == null) {//it's a default
2456 return new DefaultCase(stmtsArray,pos,SimpleCharStream.getPosition());
2458 return new Case(expr,stmtsArray,pos,SimpleCharStream.getPosition());}
2463 * case Expression() :
2465 * @return the if it was a case and null if not
2467 Expression SwitchLabel() :
2470 final Expression expr;
2476 } catch (ParseException e) {
2477 if (errorMessage != null) throw e;
2478 errorMessage = "expression expected after 'case' keyword";
2480 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2481 errorEnd = jj_input_stream.getPosition() + 1;
2487 } catch (ParseException e) {
2488 errorMessage = "':' expected after case expression";
2490 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2491 errorEnd = jj_input_stream.getPosition() + 1;
2499 } catch (ParseException e) {
2500 errorMessage = "':' expected after 'default' keyword";
2502 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2503 errorEnd = jj_input_stream.getPosition() + 1;
2508 Break BreakStatement() :
2510 Expression expression = null;
2511 final int start = SimpleCharStream.getPosition();
2514 <BREAK> [ expression = Expression() ]
2517 } catch (ParseException e) {
2518 errorMessage = "';' expected after 'break' keyword";
2520 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2521 errorEnd = jj_input_stream.getPosition() + 1;
2524 {return new Break(expression, start, SimpleCharStream.getPosition());}
2527 IfStatement IfStatement() :
2529 final int pos = jj_input_stream.getPosition();
2530 Expression condition;
2531 IfStatement ifStatement;
2534 <IF> condition = Condition("if") ifStatement = IfStatement0(condition, pos,pos+2)
2535 {return ifStatement;}
2539 Expression Condition(final String keyword) :
2541 final Expression condition;
2546 } catch (ParseException e) {
2547 errorMessage = "'(' expected after " + keyword + " keyword";
2549 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length();
2550 errorEnd = errorStart +1;
2551 processParseException(e);
2553 condition = Expression()
2557 } catch (ParseException e) {
2558 errorMessage = "')' expected after " + keyword + " keyword";
2560 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2561 errorEnd = jj_input_stream.getPosition() + 1;
2566 IfStatement IfStatement0(Expression condition, final int start,final int end) :
2568 Statement statement;
2570 final Statement[] statementsArray;
2571 ElseIf elseifStatement;
2572 Else elseStatement = null;
2574 final ArrayList elseIfList = new ArrayList();
2576 int pos = SimpleCharStream.getPosition();
2581 {stmts = new ArrayList();}
2582 ( statement = Statement() {stmts.add(statement);}
2583 | statement = htmlBlock() {stmts.add(statement);})*
2584 {endStatements = SimpleCharStream.getPosition();}
2585 (elseifStatement = ElseIfStatementColon() {elseIfList.add(elseifStatement);})*
2586 [elseStatement = ElseStatementColon()]
2589 setMarker(fileToParse,
2590 "Ugly syntax detected, you should if () {...} instead of if (): ... endif;",
2594 "Line " + token.beginLine);
2595 } catch (CoreException e) {
2596 PHPeclipsePlugin.log(e);
2600 } catch (ParseException e) {
2601 errorMessage = "'endif' expected";
2603 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2604 errorEnd = jj_input_stream.getPosition() + 1;
2609 } catch (ParseException e) {
2610 errorMessage = "';' expected after 'endif' keyword";
2612 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2613 errorEnd = jj_input_stream.getPosition() + 1;
2617 elseIfs = new ElseIf[elseIfList.size()];
2618 elseIfList.toArray(elseIfs);
2619 if (stmts.size() == 1) {
2620 return new IfStatement(condition,
2621 (Statement) stmts.get(0),
2625 SimpleCharStream.getPosition());
2627 statementsArray = new Statement[stmts.size()];
2628 stmts.toArray(statementsArray);
2629 return new IfStatement(condition,
2630 new Block(statementsArray,pos,endStatements),
2634 SimpleCharStream.getPosition());
2639 (stmt = Statement() | stmt = htmlBlock())
2640 ( LOOKAHEAD(1) elseifStatement = ElseIfStatement() {elseIfList.add(elseifStatement);})*
2644 {pos = SimpleCharStream.getPosition();}
2645 statement = Statement()
2646 {elseStatement = new Else(statement,pos,SimpleCharStream.getPosition());}
2647 } catch (ParseException e) {
2648 if (errorMessage != null) {
2651 errorMessage = "unexpected token '"+e.currentToken.next.image+"', a statement was expected";
2653 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2654 errorEnd = jj_input_stream.getPosition() + 1;
2659 elseIfs = new ElseIf[elseIfList.size()];
2660 elseIfList.toArray(elseIfs);
2661 return new IfStatement(condition,
2666 SimpleCharStream.getPosition());}
2669 ElseIf ElseIfStatementColon() :
2671 Expression condition;
2672 Statement statement;
2673 final ArrayList list = new ArrayList();
2674 final int pos = SimpleCharStream.getPosition();
2677 <ELSEIF> condition = Condition("elseif")
2678 <COLON> ( statement = Statement() {list.add(statement);}
2679 | statement = htmlBlock() {list.add(statement);})*
2681 Statement[] stmtsArray = new Statement[list.size()];
2682 list.toArray(stmtsArray);
2683 return new ElseIf(condition,stmtsArray ,pos,SimpleCharStream.getPosition());}
2686 Else ElseStatementColon() :
2688 Statement statement;
2689 final ArrayList list = new ArrayList();
2690 final int pos = SimpleCharStream.getPosition();
2693 <ELSE> <COLON> ( statement = Statement() {list.add(statement);}
2694 | statement = htmlBlock() {list.add(statement);})*
2696 Statement[] stmtsArray = new Statement[list.size()];
2697 list.toArray(stmtsArray);
2698 return new Else(stmtsArray,pos,SimpleCharStream.getPosition());}
2701 ElseIf ElseIfStatement() :
2703 Expression condition;
2704 Statement statement;
2705 final ArrayList list = new ArrayList();
2706 final int pos = SimpleCharStream.getPosition();
2709 <ELSEIF> condition = Condition("elseif") statement = Statement() {list.add(statement);/*todo:do better*/}
2711 Statement[] stmtsArray = new Statement[list.size()];
2712 list.toArray(stmtsArray);
2713 return new ElseIf(condition,stmtsArray,pos,SimpleCharStream.getPosition());}
2716 WhileStatement WhileStatement() :
2718 final Expression condition;
2719 final Statement action;
2720 final int pos = SimpleCharStream.getPosition();
2724 condition = Condition("while")
2725 action = WhileStatement0(pos,pos + 5)
2726 {return new WhileStatement(condition,action,pos,SimpleCharStream.getPosition());}
2729 Statement WhileStatement0(final int start, final int end) :
2731 Statement statement;
2732 final ArrayList stmts = new ArrayList();
2733 final int pos = SimpleCharStream.getPosition();
2736 <COLON> (statement = Statement() {stmts.add(statement);})*
2738 setMarker(fileToParse,
2739 "Ugly syntax detected, you should while () {...} instead of while (): ... endwhile;",
2743 "Line " + token.beginLine);
2744 } catch (CoreException e) {
2745 PHPeclipsePlugin.log(e);
2749 } catch (ParseException e) {
2750 errorMessage = "'endwhile' expected";
2752 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2753 errorEnd = jj_input_stream.getPosition() + 1;
2759 Statement[] stmtsArray = new Statement[stmts.size()];
2760 stmts.toArray(stmtsArray);
2761 return new Block(stmtsArray,pos,SimpleCharStream.getPosition());}
2762 } catch (ParseException e) {
2763 errorMessage = "';' expected after 'endwhile' keyword";
2765 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2766 errorEnd = jj_input_stream.getPosition() + 1;
2770 statement = Statement()
2774 DoStatement DoStatement() :
2776 final Statement action;
2777 final Expression condition;
2778 final int pos = SimpleCharStream.getPosition();
2781 <DO> action = Statement() <WHILE> condition = Condition("while")
2784 {return new DoStatement(condition,action,pos,SimpleCharStream.getPosition());}
2785 } catch (ParseException e) {
2786 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
2788 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2789 errorEnd = jj_input_stream.getPosition() + 1;
2794 ForeachStatement ForeachStatement() :
2796 Statement statement;
2797 Expression expression;
2798 final StringBuffer buff = new StringBuffer();
2799 final int pos = SimpleCharStream.getPosition();
2800 ArrayVariableDeclaration variable;
2806 } catch (ParseException e) {
2807 errorMessage = "'(' expected after 'foreach' keyword";
2809 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2810 errorEnd = jj_input_stream.getPosition() + 1;
2814 expression = Expression()
2815 } catch (ParseException e) {
2816 errorMessage = "variable expected";
2818 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2819 errorEnd = jj_input_stream.getPosition() + 1;
2824 } catch (ParseException e) {
2825 errorMessage = "'as' expected";
2827 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2828 errorEnd = jj_input_stream.getPosition() + 1;
2832 variable = ArrayVariable()
2833 } catch (ParseException e) {
2834 errorMessage = "variable expected";
2836 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2837 errorEnd = jj_input_stream.getPosition() + 1;
2842 } catch (ParseException e) {
2843 errorMessage = "')' expected after 'foreach' keyword";
2845 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2846 errorEnd = jj_input_stream.getPosition() + 1;
2850 statement = Statement()
2851 } catch (ParseException e) {
2852 if (errorMessage != null) throw e;
2853 errorMessage = "statement expected";
2855 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2856 errorEnd = jj_input_stream.getPosition() + 1;
2859 {return new ForeachStatement(expression,
2863 SimpleCharStream.getPosition());}
2867 ForStatement ForStatement() :
2870 final int pos = SimpleCharStream.getPosition();
2871 Statement[] initializations = null;
2872 Expression condition = null;
2873 Statement[] increments = null;
2875 final ArrayList list = new ArrayList();
2876 final int startBlock, endBlock;
2882 } catch (ParseException e) {
2883 errorMessage = "'(' expected after 'for' keyword";
2885 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2886 errorEnd = jj_input_stream.getPosition() + 1;
2889 [ initializations = ForInit() ] <SEMICOLON>
2890 [ condition = Expression() ] <SEMICOLON>
2891 [ increments = StatementExpressionList() ] <RPAREN>
2893 action = Statement()
2894 {return new ForStatement(initializations,condition,increments,action,pos,SimpleCharStream.getPosition());}
2897 {startBlock = SimpleCharStream.getPosition();}
2898 (action = Statement() {list.add(action);})*
2901 setMarker(fileToParse,
2902 "Ugly syntax detected, you should for () {...} instead of for (): ... endfor;",
2904 pos+token.image.length(),
2906 "Line " + token.beginLine);
2907 } catch (CoreException e) {
2908 PHPeclipsePlugin.log(e);
2911 {endBlock = SimpleCharStream.getPosition();}
2914 } catch (ParseException e) {
2915 errorMessage = "'endfor' expected";
2917 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2918 errorEnd = jj_input_stream.getPosition() + 1;
2924 Statement[] stmtsArray = new Statement[list.size()];
2925 list.toArray(stmtsArray);
2926 return new ForStatement(initializations,condition,increments,new Block(stmtsArray,startBlock,endBlock),pos,SimpleCharStream.getPosition());}
2927 } catch (ParseException e) {
2928 errorMessage = "';' expected after 'endfor' keyword";
2930 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2931 errorEnd = jj_input_stream.getPosition() + 1;
2937 Statement[] ForInit() :
2939 Statement[] statements;
2942 LOOKAHEAD(LocalVariableDeclaration())
2943 statements = LocalVariableDeclaration()
2944 {return statements;}
2946 statements = StatementExpressionList()
2947 {return statements;}
2950 Statement[] StatementExpressionList() :
2952 final ArrayList list = new ArrayList();
2956 expr = StatementExpression() {list.add(expr);}
2957 (<COMMA> StatementExpression() {list.add(expr);})*
2959 Statement[] stmtsArray = new Statement[list.size()];
2960 list.toArray(stmtsArray);
2964 Continue ContinueStatement() :
2966 Expression expr = null;
2967 final int pos = SimpleCharStream.getPosition();
2970 <CONTINUE> [ expr = Expression() ]
2973 {return new Continue(expr,pos,SimpleCharStream.getPosition());}
2974 } catch (ParseException e) {
2975 errorMessage = "';' expected after 'continue' statement";
2977 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2978 errorEnd = jj_input_stream.getPosition() + 1;
2983 ReturnStatement ReturnStatement() :
2985 Expression expr = null;
2986 final int pos = SimpleCharStream.getPosition();
2989 <RETURN> [ expr = Expression() ]
2992 {return new ReturnStatement(expr,pos,SimpleCharStream.getPosition());}
2993 } catch (ParseException e) {
2994 errorMessage = "';' expected after 'return' statement";
2996 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2997 errorEnd = jj_input_stream.getPosition() + 1;