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) {
1112 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
1114 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1115 errorEnd = jj_input_stream.getPosition() + 1;
1119 if (currentSegment != null) {
1120 currentSegment.add(functionDeclaration);
1121 currentSegment = functionDeclaration;
1123 currentFunction = functionDeclaration;
1127 functionDeclaration.statements = block.statements;
1128 currentFunction = null;
1129 if (currentSegment != null) {
1130 currentSegment = (OutlineableWithChildren) currentSegment.getParent();
1132 return functionDeclaration;
1137 * A MethodDeclarator.
1138 * [&] IDENTIFIER(parameters ...).
1139 * @return a function description for the outline
1141 MethodDeclaration MethodDeclarator() :
1143 final Token identifier;
1144 Token reference = null;
1145 final Hashtable formalParameters;
1146 final int pos = SimpleCharStream.getPosition();
1149 [ reference = <BIT_AND> ]
1150 identifier = <IDENTIFIER>
1151 formalParameters = FormalParameters()
1152 {return new MethodDeclaration(currentSegment,
1153 identifier.image.toCharArray(),
1157 SimpleCharStream.getPosition());}
1161 * FormalParameters follows method identifier.
1162 * (FormalParameter())
1164 Hashtable FormalParameters() :
1167 final StringBuffer buff = new StringBuffer("(");
1168 VariableDeclaration var;
1169 final Hashtable parameters = new Hashtable();
1174 } catch (ParseException e) {
1175 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected after function identifier";
1177 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1178 errorEnd = jj_input_stream.getPosition() + 1;
1181 [ var = FormalParameter()
1182 {parameters.put(new String(var.name),var);}
1184 <COMMA> var = FormalParameter()
1185 {parameters.put(new String(var.name),var);}
1190 } catch (ParseException e) {
1191 errorMessage = "')' expected";
1193 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1194 errorEnd = jj_input_stream.getPosition() + 1;
1197 {return parameters;}
1201 * A formal parameter.
1202 * $varname[=value] (,$varname[=value])
1204 VariableDeclaration FormalParameter() :
1206 final VariableDeclaration variableDeclaration;
1210 [token = <BIT_AND>] variableDeclaration = VariableDeclarator()
1212 if (token != null) {
1213 variableDeclaration.setReference(true);
1215 return variableDeclaration;}
1218 ConstantIdentifier Type() :
1221 <STRING> {pos = SimpleCharStream.getPosition();
1222 return new ConstantIdentifier(Types.STRING,
1224 | <BOOL> {pos = SimpleCharStream.getPosition();
1225 return new ConstantIdentifier(Types.BOOL,
1227 | <BOOLEAN> {pos = SimpleCharStream.getPosition();
1228 return new ConstantIdentifier(Types.BOOLEAN,
1230 | <REAL> {pos = SimpleCharStream.getPosition();
1231 return new ConstantIdentifier(Types.REAL,
1233 | <DOUBLE> {pos = SimpleCharStream.getPosition();
1234 return new ConstantIdentifier(Types.DOUBLE,
1236 | <FLOAT> {pos = SimpleCharStream.getPosition();
1237 return new ConstantIdentifier(Types.FLOAT,
1239 | <INT> {pos = SimpleCharStream.getPosition();
1240 return new ConstantIdentifier(Types.INT,
1242 | <INTEGER> {pos = SimpleCharStream.getPosition();
1243 return new ConstantIdentifier(Types.INTEGER,
1245 | <OBJECT> {pos = SimpleCharStream.getPosition();
1246 return new ConstantIdentifier(Types.OBJECT,
1250 Expression Expression() :
1252 final Expression expr;
1255 expr = PrintExpression() {return expr;}
1256 | expr = ListExpression() {return expr;}
1257 | LOOKAHEAD(varAssignation())
1258 expr = varAssignation() {return expr;}
1259 | expr = ConditionalExpression() {return expr;}
1263 * A Variable assignation.
1264 * varName (an assign operator) any expression
1266 VarAssignation varAssignation() :
1269 final Expression expression;
1270 final int assignOperator;
1271 final int pos = SimpleCharStream.getPosition();
1274 varName = VariableDeclaratorId()
1275 assignOperator = AssignmentOperator()
1277 expression = Expression()
1278 } catch (ParseException e) {
1279 if (errorMessage != null) {
1282 errorMessage = "expression expected";
1284 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1285 errorEnd = jj_input_stream.getPosition() + 1;
1288 {return new VarAssignation(varName.toCharArray(),
1292 SimpleCharStream.getPosition());}
1295 int AssignmentOperator() :
1298 <ASSIGN> {return VarAssignation.EQUAL;}
1299 | <STARASSIGN> {return VarAssignation.STAR_EQUAL;}
1300 | <SLASHASSIGN> {return VarAssignation.SLASH_EQUAL;}
1301 | <REMASSIGN> {return VarAssignation.REM_EQUAL;}
1302 | <PLUSASSIGN> {return VarAssignation.PLUS_EQUAL;}
1303 | <MINUSASSIGN> {return VarAssignation.MINUS_EQUAL;}
1304 | <LSHIFTASSIGN> {return VarAssignation.LSHIFT_EQUAL;}
1305 | <RSIGNEDSHIFTASSIGN> {return VarAssignation.RSIGNEDSHIFT_EQUAL;}
1306 | <ANDASSIGN> {return VarAssignation.AND_EQUAL;}
1307 | <XORASSIGN> {return VarAssignation.XOR_EQUAL;}
1308 | <ORASSIGN> {return VarAssignation.OR_EQUAL;}
1309 | <DOTASSIGN> {return VarAssignation.DOT_EQUAL;}
1310 | <TILDEEQUAL> {return VarAssignation.TILDE_EQUAL;}
1313 Expression ConditionalExpression() :
1315 final Expression expr;
1316 Expression expr2 = null;
1317 Expression expr3 = null;
1320 expr = ConditionalOrExpression() [ <HOOK> expr2 = Expression() <COLON> expr3 = ConditionalExpression() ]
1322 if (expr3 == null) {
1325 return new ConditionalExpression(expr,expr2,expr3);
1329 Expression ConditionalOrExpression() :
1331 Expression expr,expr2;
1335 expr = ConditionalAndExpression()
1338 <OR_OR> {operator = OperatorIds.OR_OR;}
1339 | <_ORL> {operator = OperatorIds.ORL;}
1340 ) expr2 = ConditionalAndExpression()
1342 expr = new BinaryExpression(expr,expr2,operator);
1348 Expression ConditionalAndExpression() :
1350 Expression expr,expr2;
1354 expr = ConcatExpression()
1356 ( <AND_AND> {operator = OperatorIds.AND_AND;}
1357 | <_ANDL> {operator = OperatorIds.ANDL;})
1358 expr2 = ConcatExpression() {expr = new BinaryExpression(expr,expr2,operator);}
1363 Expression ConcatExpression() :
1365 Expression expr,expr2;
1368 expr = InclusiveOrExpression()
1370 <DOT> expr2 = InclusiveOrExpression()
1371 {expr = new BinaryExpression(expr,expr2,OperatorIds.DOT);}
1376 Expression InclusiveOrExpression() :
1378 Expression expr,expr2;
1381 expr = ExclusiveOrExpression()
1382 (<BIT_OR> expr2 = ExclusiveOrExpression()
1383 {expr = new BinaryExpression(expr,expr2,OperatorIds.OR);}
1388 Expression ExclusiveOrExpression() :
1390 Expression expr,expr2;
1393 expr = AndExpression()
1395 <XOR> expr2 = AndExpression()
1396 {expr = new BinaryExpression(expr,expr2,OperatorIds.XOR);}
1401 Expression AndExpression() :
1403 Expression expr,expr2;
1406 expr = EqualityExpression()
1408 <BIT_AND> expr2 = EqualityExpression()
1409 {expr = new BinaryExpression(expr,expr2,OperatorIds.AND);}
1414 Expression EqualityExpression() :
1416 Expression expr,expr2;
1420 expr = RelationalExpression()
1422 ( <EQUAL_EQUAL> {operator = OperatorIds.EQUAL_EQUAL;}
1423 | <DIF> {operator = OperatorIds.DIF;}
1424 | <NOT_EQUAL> {operator = OperatorIds.DIF;}
1425 | <BANGDOUBLEEQUAL> {operator = OperatorIds.BANG_EQUAL_EQUAL;}
1426 | <TRIPLEEQUAL> {operator = OperatorIds.EQUAL_EQUAL_EQUAL;}
1429 expr2 = RelationalExpression()
1430 } catch (ParseException e) {
1431 if (errorMessage != null) {
1434 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1436 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1437 errorEnd = jj_input_stream.getPosition() + 1;
1441 expr = new BinaryExpression(expr,expr2,operator);
1447 Expression RelationalExpression() :
1449 Expression expr,expr2;
1453 expr = ShiftExpression()
1455 ( <LT> {operator = OperatorIds.LESS;}
1456 | <GT> {operator = OperatorIds.GREATER;}
1457 | <LE> {operator = OperatorIds.LESS_EQUAL;}
1458 | <GE> {operator = OperatorIds.GREATER_EQUAL;})
1459 expr2 = ShiftExpression()
1460 {expr = new BinaryExpression(expr,expr2,operator);}
1465 Expression ShiftExpression() :
1467 Expression expr,expr2;
1471 expr = AdditiveExpression()
1473 ( <LSHIFT> {operator = OperatorIds.LEFT_SHIFT;}
1474 | <RSIGNEDSHIFT> {operator = OperatorIds.RIGHT_SHIFT;}
1475 | <RUNSIGNEDSHIFT> {operator = OperatorIds.UNSIGNED_RIGHT_SHIFT;})
1476 expr2 = AdditiveExpression()
1477 {expr = new BinaryExpression(expr,expr2,operator);}
1482 Expression AdditiveExpression() :
1484 Expression expr,expr2;
1488 expr = MultiplicativeExpression()
1490 ( <PLUS> {operator = OperatorIds.PLUS;}
1491 | <MINUS> {operator = OperatorIds.MINUS;} )
1492 expr2 = MultiplicativeExpression()
1493 {expr = new BinaryExpression(expr,expr2,operator);}
1498 Expression MultiplicativeExpression() :
1500 Expression expr,expr2;
1505 expr = UnaryExpression()
1506 } catch (ParseException e) {
1507 if (errorMessage != null) {
1510 errorMessage = "unexpected token '"+e.currentToken.next.image+"'";
1512 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1513 errorEnd = jj_input_stream.getPosition() + 1;
1517 ( <STAR> {operator = OperatorIds.MULTIPLY;}
1518 | <SLASH> {operator = OperatorIds.DIVIDE;}
1519 | <REMAINDER> {operator = OperatorIds.REMAINDER;})
1520 expr2 = UnaryExpression()
1521 {expr = new BinaryExpression(expr,expr2,operator);}
1527 * An unary expression starting with @, & or nothing
1529 Expression UnaryExpression() :
1532 final int pos = SimpleCharStream.getPosition();
1535 <BIT_AND> expr = UnaryExpressionNoPrefix()
1536 {return new PrefixedUnaryExpression(expr,OperatorIds.AND,pos);}
1538 expr = AtUnaryExpression()
1542 Expression AtUnaryExpression() :
1545 final int pos = SimpleCharStream.getPosition();
1549 expr = AtUnaryExpression()
1550 {return new PrefixedUnaryExpression(expr,OperatorIds.AT,pos);}
1552 expr = UnaryExpressionNoPrefix()
1557 Expression UnaryExpressionNoPrefix() :
1561 final int pos = SimpleCharStream.getPosition();
1564 ( <PLUS> {operator = OperatorIds.PLUS;}
1565 | <MINUS> {operator = OperatorIds.MINUS;})
1566 expr = UnaryExpression()
1567 {return new PrefixedUnaryExpression(expr,operator,pos);}
1569 expr = PreIncDecExpression()
1572 expr = UnaryExpressionNotPlusMinus()
1577 Expression PreIncDecExpression() :
1579 final Expression expr;
1581 final int pos = SimpleCharStream.getPosition();
1584 ( <INCR> {operator = OperatorIds.PLUS_PLUS;}
1585 | <DECR> {operator = OperatorIds.MINUS_MINUS;})
1586 expr = PrimaryExpression()
1587 {return new PrefixedUnaryExpression(expr,operator,pos);}
1590 Expression UnaryExpressionNotPlusMinus() :
1593 final int pos = SimpleCharStream.getPosition();
1596 <BANG> expr = UnaryExpression() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
1597 | LOOKAHEAD( <LPAREN> (Type() | <ARRAY>) <RPAREN> )
1598 expr = CastExpression() {return expr;}
1599 | expr = PostfixExpression() {return expr;}
1600 | expr = Literal() {return expr;}
1601 | <LPAREN> expr = Expression()
1604 } catch (ParseException e) {
1605 errorMessage = "')' expected";
1607 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1608 errorEnd = jj_input_stream.getPosition() + 1;
1614 CastExpression CastExpression() :
1616 final ConstantIdentifier type;
1617 final Expression expr;
1618 final int pos = SimpleCharStream.getPosition();
1623 | <ARRAY> {type = new ConstantIdentifier(Types.ARRAY,pos,SimpleCharStream.getPosition());})
1624 <RPAREN> expr = UnaryExpression()
1625 {return new CastExpression(type,expr,pos,SimpleCharStream.getPosition());}
1628 Expression PostfixExpression() :
1632 final int pos = SimpleCharStream.getPosition();
1635 expr = PrimaryExpression()
1636 [ <INCR> {operator = OperatorIds.PLUS_PLUS;}
1637 | <DECR> {operator = OperatorIds.MINUS_MINUS;}]
1639 if (operator == -1) {
1642 return new PostfixedUnaryExpression(expr,operator,pos);
1646 Expression PrimaryExpression() :
1648 final Token identifier;
1650 final StringBuffer buff = new StringBuffer();
1651 final int pos = SimpleCharStream.getPosition();
1655 identifier = <IDENTIFIER> <STATICCLASSACCESS> expr = ClassIdentifier()
1656 {expr = new ClassAccess(new ConstantIdentifier(identifier.image.toCharArray(),
1658 SimpleCharStream.getPosition()),
1660 ClassAccess.STATIC);}
1661 (expr = PrimarySuffix(expr))*
1664 expr = PrimaryPrefix()
1665 (expr = PrimarySuffix(expr))*
1668 expr = ArrayDeclarator()
1672 ArrayInitializer ArrayDeclarator() :
1674 final ArrayVariableDeclaration[] vars;
1675 final int pos = SimpleCharStream.getPosition();
1678 <ARRAY> vars = ArrayInitializer()
1679 {return new ArrayInitializer(vars,pos,SimpleCharStream.getPosition());}
1682 Expression PrimaryPrefix() :
1684 final Expression expr;
1687 final int pos = SimpleCharStream.getPosition();
1690 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1692 SimpleCharStream.getPosition());}
1693 | <NEW> expr = ClassIdentifier() {return new PrefixedUnaryExpression(expr,
1696 | var = VariableDeclaratorId() {return new ConstantIdentifier(var.toCharArray(),
1698 SimpleCharStream.getPosition());}
1701 PrefixedUnaryExpression classInstantiation() :
1704 final StringBuffer buff;
1705 final int pos = SimpleCharStream.getPosition();
1708 <NEW> expr = ClassIdentifier()
1710 {buff = new StringBuffer(expr.toStringExpression());}
1711 expr = PrimaryExpression()
1712 {buff.append(expr.toStringExpression());
1713 expr = new ConstantIdentifier(buff.toString().toCharArray(),
1715 SimpleCharStream.getPosition());}
1717 {return new PrefixedUnaryExpression(expr,
1722 ConstantIdentifier ClassIdentifier():
1726 final int pos = SimpleCharStream.getPosition();
1729 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1731 SimpleCharStream.getPosition());}
1732 | expr = VariableDeclaratorId() {return new ConstantIdentifier(expr.toCharArray(),
1734 SimpleCharStream.getPosition());}
1737 AbstractSuffixExpression PrimarySuffix(Expression prefix) :
1739 final AbstractSuffixExpression expr;
1742 expr = Arguments(prefix) {return expr;}
1743 | expr = VariableSuffix(prefix) {return expr;}
1746 AbstractSuffixExpression VariableSuffix(Expression prefix) :
1749 final int pos = SimpleCharStream.getPosition();
1750 Expression expression = null;
1755 expr = VariableName()
1756 } catch (ParseException e) {
1757 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
1759 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1760 errorEnd = jj_input_stream.getPosition() + 1;
1763 {return new ClassAccess(prefix,
1764 new ConstantIdentifier(expr.toCharArray(),pos,SimpleCharStream.getPosition()),
1765 ClassAccess.NORMAL);}
1767 <LBRACKET> [ expression = Expression() | expression = Type() ] //Not good
1770 } catch (ParseException e) {
1771 errorMessage = "']' expected";
1773 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1774 errorEnd = jj_input_stream.getPosition() + 1;
1777 {return new ArrayDeclarator(prefix,expression,SimpleCharStream.getPosition());}
1786 token = <INTEGER_LITERAL> {pos = SimpleCharStream.getPosition();
1787 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1788 | token = <FLOATING_POINT_LITERAL> {pos = SimpleCharStream.getPosition();
1789 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1790 | token = <STRING_LITERAL> {pos = SimpleCharStream.getPosition();
1791 return new StringLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1792 | <TRUE> {pos = SimpleCharStream.getPosition();
1793 return new TrueLiteral(pos-4,pos);}
1794 | <FALSE> {pos = SimpleCharStream.getPosition();
1795 return new FalseLiteral(pos-4,pos);}
1796 | <NULL> {pos = SimpleCharStream.getPosition();
1797 return new NullLiteral(pos-4,pos);}
1800 FunctionCall Arguments(Expression func) :
1802 ArgumentDeclaration[] args = null;
1805 <LPAREN> [ args = ArgumentList() ]
1808 } catch (ParseException e) {
1809 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
1811 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1812 errorEnd = jj_input_stream.getPosition() + 1;
1815 {return new FunctionCall(func,args,SimpleCharStream.getPosition());}
1818 ArgumentDeclaration[] ArgumentList() :
1820 ArgumentDeclaration arg;
1821 final ArrayList list = new ArrayList();
1822 ArgumentDeclaration argument;
1825 arg = argumentDeclaration()
1829 arg = argumentDeclaration()
1831 } catch (ParseException e) {
1832 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. An expression expected after a comma in argument list";
1834 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1835 errorEnd = jj_input_stream.getPosition() + 1;
1840 ArgumentDeclaration[] args = new ArgumentDeclaration[list.size()];
1845 ArgumentDeclaration argumentDeclaration() :
1847 boolean reference = false;
1849 Expression initializer = null;
1850 final int pos = SimpleCharStream.getPosition();
1853 [<BIT_AND> {reference = true;}]
1854 varName = VariableDeclaratorId()
1858 initializer = VariableInitializer()
1859 } catch (ParseException e) {
1860 errorMessage = "Literal expression expected in variable initializer";
1862 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1863 errorEnd = jj_input_stream.getPosition() + 1;
1868 if (initializer == null) {
1869 return new ArgumentDeclaration(varName.toCharArray(),
1873 return new ArgumentDeclaration(varName.toCharArray(),
1880 * A Statement without break.
1882 Statement StatementNoBreak() :
1884 final Statement statement;
1889 statement = Expression()
1892 } catch (ParseException e) {
1893 if (e.currentToken.next.kind != 4) {
1894 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1896 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1897 errorEnd = jj_input_stream.getPosition() + 1;
1903 statement = LabeledStatement() {return statement;}
1904 | statement = Block() {return statement;}
1905 | statement = EmptyStatement() {return statement;}
1906 | statement = StatementExpression()
1909 } catch (ParseException e) {
1910 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1912 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1913 errorEnd = jj_input_stream.getPosition() + 1;
1917 | statement = SwitchStatement() {return statement;}
1918 | statement = IfStatement() {return statement;}
1919 | statement = WhileStatement() {return statement;}
1920 | statement = DoStatement() {return statement;}
1921 | statement = ForStatement() {return statement;}
1922 | statement = ForeachStatement() {return statement;}
1923 | statement = ContinueStatement() {return statement;}
1924 | statement = ReturnStatement() {return statement;}
1925 | statement = EchoStatement() {return statement;}
1926 | [token=<AT>] statement = IncludeStatement()
1927 {if (token != null) {
1928 ((InclusionStatement)statement).silent = true;
1931 | statement = StaticStatement() {return statement;}
1932 | statement = GlobalStatement() {return statement;}
1936 * A Normal statement.
1938 Statement Statement() :
1940 final Statement statement;
1943 statement = StatementNoBreak() {return statement;}
1944 | statement = BreakStatement() {return statement;}
1948 * An html block inside a php syntax.
1950 HTMLBlock htmlBlock() :
1952 final int startIndex = nodePtr;
1953 AstNode[] blockNodes;
1957 <PHPEND> (phpEchoBlock())*
1959 (<PHPSTARTLONG> | <PHPSTARTSHORT>)
1960 } catch (ParseException e) {
1961 errorMessage = "End of file unexpected, '<?php' expected";
1963 errorStart = jj_input_stream.getPosition();
1964 errorEnd = jj_input_stream.getPosition();
1968 nbNodes = nodePtr-startIndex;
1969 blockNodes = new AstNode[nbNodes];
1970 System.arraycopy(nodes,startIndex,blockNodes,0,nbNodes);
1971 return new HTMLBlock(nodes);}
1975 * An include statement. It's "include" an expression;
1977 InclusionStatement IncludeStatement() :
1979 final Expression expr;
1982 final int pos = jj_input_stream.getPosition();
1983 final InclusionStatement inclusionStatement;
1986 ( <REQUIRE> {keyword = InclusionStatement.REQUIRE;}
1987 | <REQUIRE_ONCE> {keyword = InclusionStatement.REQUIRE_ONCE;}
1988 | <INCLUDE> {keyword = InclusionStatement.INCLUDE;}
1989 | <INCLUDE_ONCE> {keyword = InclusionStatement.INCLUDE_ONCE;})
1992 } catch (ParseException e) {
1993 if (errorMessage != null) {
1996 errorMessage = "unexpected token '"+ e.currentToken.next.image+"', expression expected";
1998 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1999 errorEnd = jj_input_stream.getPosition() + 1;
2002 {inclusionStatement = new InclusionStatement(currentSegment,
2006 currentSegment.add(inclusionStatement);
2010 } catch (ParseException e) {
2011 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
2013 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2014 errorEnd = jj_input_stream.getPosition() + 1;
2017 {return inclusionStatement;}
2020 PrintExpression PrintExpression() :
2022 final Expression expr;
2023 final int pos = SimpleCharStream.getPosition();
2026 <PRINT> expr = Expression() {return new PrintExpression(expr,pos,SimpleCharStream.getPosition());}
2029 ListExpression ListExpression() :
2032 Expression expression = null;
2033 ArrayList list = new ArrayList();
2034 final int pos = SimpleCharStream.getPosition();
2040 } catch (ParseException e) {
2041 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
2043 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2044 errorEnd = jj_input_stream.getPosition() + 1;
2048 expr = VariableDeclaratorId()
2051 {if (expr == null) list.add(null);}
2055 } catch (ParseException e) {
2056 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
2058 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2059 errorEnd = jj_input_stream.getPosition() + 1;
2062 expr = VariableDeclaratorId()
2067 } catch (ParseException e) {
2068 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
2070 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2071 errorEnd = jj_input_stream.getPosition() + 1;
2074 [ <ASSIGN> expression = Expression()
2076 String[] strings = new String[list.size()];
2077 list.toArray(strings);
2078 return new ListExpression(strings,
2081 SimpleCharStream.getPosition());}
2084 String[] strings = new String[list.size()];
2085 list.toArray(strings);
2086 return new ListExpression(strings,pos,SimpleCharStream.getPosition());}
2090 * An echo statement.
2091 * echo anyexpression (, otherexpression)*
2093 EchoStatement EchoStatement() :
2095 final ArrayList expressions = new ArrayList();
2097 final int pos = SimpleCharStream.getPosition();
2100 <ECHO> expr = Expression()
2101 {expressions.add(expr);}
2103 <COMMA> expr = Expression()
2104 {expressions.add(expr);}
2109 Expression[] exprs = new Expression[expressions.size()];
2110 expressions.toArray(exprs);
2111 return new EchoStatement(exprs,pos);}
2112 } catch (ParseException e) {
2113 if (e.currentToken.next.kind != 4) {
2114 errorMessage = "';' expected after 'echo' statement";
2116 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2117 errorEnd = jj_input_stream.getPosition() + 1;
2123 GlobalStatement GlobalStatement() :
2125 final int pos = jj_input_stream.getPosition();
2127 ArrayList vars = new ArrayList();
2128 GlobalStatement global;
2132 expr = VariableDeclaratorId()
2135 expr = VariableDeclaratorId()
2141 String[] strings = new String[vars.size()];
2142 vars.toArray(strings);
2143 global = new GlobalStatement(currentSegment,
2146 SimpleCharStream.getPosition());
2147 currentSegment.add(global);
2149 } catch (ParseException e) {
2150 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2152 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2153 errorEnd = jj_input_stream.getPosition() + 1;
2158 StaticStatement StaticStatement() :
2160 final int pos = SimpleCharStream.getPosition();
2161 final ArrayList vars = new ArrayList();
2162 VariableDeclaration expr;
2165 <STATIC> expr = VariableDeclarator() {vars.add(new String(expr.name));}
2166 (<COMMA> expr = VariableDeclarator() {vars.add(new String(expr.name));})*
2170 String[] strings = new String[vars.size()];
2171 vars.toArray(strings);
2172 return new StaticStatement(strings,
2174 SimpleCharStream.getPosition());}
2175 } catch (ParseException e) {
2176 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2178 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2179 errorEnd = jj_input_stream.getPosition() + 1;
2184 LabeledStatement LabeledStatement() :
2186 final int pos = SimpleCharStream.getPosition();
2188 final Statement statement;
2191 label = <IDENTIFIER> <COLON> statement = Statement()
2192 {return new LabeledStatement(label.image.toCharArray(),statement,pos,SimpleCharStream.getPosition());}
2204 final int pos = SimpleCharStream.getPosition();
2205 final ArrayList list = new ArrayList();
2206 Statement statement;
2211 } catch (ParseException e) {
2212 errorMessage = "'{' expected";
2214 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2215 errorEnd = jj_input_stream.getPosition() + 1;
2218 ( statement = BlockStatement() {list.add(statement);}
2219 | statement = htmlBlock() {list.add(statement);})*
2222 } catch (ParseException e) {
2223 errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected";
2225 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2226 errorEnd = jj_input_stream.getPosition() + 1;
2230 Statement[] statements = new Statement[list.size()];
2231 list.toArray(statements);
2232 return new Block(statements,pos,SimpleCharStream.getPosition());}
2235 Statement BlockStatement() :
2237 final Statement statement;
2240 statement = Statement() {return statement;}
2241 | statement = ClassDeclaration() {return statement;}
2242 | statement = MethodDeclaration() {return statement;}
2246 * A Block statement that will not contain any 'break'
2248 Statement BlockStatementNoBreak() :
2250 final Statement statement;
2253 statement = StatementNoBreak() {return statement;}
2254 | statement = ClassDeclaration() {return statement;}
2255 | statement = MethodDeclaration() {return statement;}
2258 VariableDeclaration[] LocalVariableDeclaration() :
2260 final ArrayList list = new ArrayList();
2261 VariableDeclaration var;
2264 var = LocalVariableDeclarator()
2266 ( <COMMA> var = LocalVariableDeclarator() {list.add(var);})*
2268 VariableDeclaration[] vars = new VariableDeclaration[list.size()];
2273 VariableDeclaration LocalVariableDeclarator() :
2275 final String varName;
2276 Expression initializer = null;
2277 final int pos = SimpleCharStream.getPosition();
2280 varName = VariableDeclaratorId() [ <ASSIGN> initializer = Expression() ]
2282 if (initializer == null) {
2283 return new VariableDeclaration(currentSegment,
2284 varName.toCharArray(),
2286 jj_input_stream.getPosition());
2288 return new VariableDeclaration(currentSegment,
2289 varName.toCharArray(),
2295 EmptyStatement EmptyStatement() :
2301 {pos = SimpleCharStream.getPosition();
2302 return new EmptyStatement(pos-1,pos);}
2305 Statement StatementExpression() :
2307 Expression expr,expr2;
2311 expr = PreIncDecExpression() {return expr;}
2313 expr = PrimaryExpression()
2314 [ <INCR> {return new PostfixedUnaryExpression(expr,
2315 OperatorIds.PLUS_PLUS,
2316 SimpleCharStream.getPosition());}
2317 | <DECR> {return new PostfixedUnaryExpression(expr,
2318 OperatorIds.MINUS_MINUS,
2319 SimpleCharStream.getPosition());}
2320 | operator = AssignmentOperator() expr2 = Expression()
2321 {return new BinaryExpression(expr,expr2,operator);}
2326 SwitchStatement SwitchStatement() :
2328 final Expression variable;
2329 final AbstractCase[] cases;
2330 final int pos = SimpleCharStream.getPosition();
2336 } catch (ParseException e) {
2337 errorMessage = "'(' expected after 'switch'";
2339 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2340 errorEnd = jj_input_stream.getPosition() + 1;
2344 variable = Expression()
2345 } catch (ParseException e) {
2346 if (errorMessage != null) {
2349 errorMessage = "expression expected";
2351 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2352 errorEnd = jj_input_stream.getPosition() + 1;
2357 } catch (ParseException e) {
2358 errorMessage = "')' expected";
2360 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2361 errorEnd = jj_input_stream.getPosition() + 1;
2364 (cases = switchStatementBrace() | cases = switchStatementColon(pos, pos + 6))
2365 {return new SwitchStatement(variable,cases,pos,SimpleCharStream.getPosition());}
2368 AbstractCase[] switchStatementBrace() :
2371 final ArrayList cases = new ArrayList();
2375 ( cas = switchLabel0() {cases.add(cas);})*
2379 AbstractCase[] abcase = new AbstractCase[cases.size()];
2380 cases.toArray(abcase);
2382 } catch (ParseException e) {
2383 errorMessage = "'}' expected";
2385 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2386 errorEnd = jj_input_stream.getPosition() + 1;
2391 * A Switch statement with : ... endswitch;
2392 * @param start the begin offset of the switch
2393 * @param end the end offset of the switch
2395 AbstractCase[] switchStatementColon(final int start, final int end) :
2398 final ArrayList cases = new ArrayList();
2403 setMarker(fileToParse,
2404 "Ugly syntax detected, you should switch () {...} instead of switch (): ... enswitch;",
2408 "Line " + token.beginLine);
2409 } catch (CoreException e) {
2410 PHPeclipsePlugin.log(e);
2412 ( cas = switchLabel0() {cases.add(cas);})*
2415 } catch (ParseException e) {
2416 errorMessage = "'endswitch' expected";
2418 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2419 errorEnd = jj_input_stream.getPosition() + 1;
2425 AbstractCase[] abcase = new AbstractCase[cases.size()];
2426 cases.toArray(abcase);
2428 } catch (ParseException e) {
2429 errorMessage = "';' expected after 'endswitch' keyword";
2431 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2432 errorEnd = jj_input_stream.getPosition() + 1;
2437 AbstractCase switchLabel0() :
2439 final Expression expr;
2440 Statement statement;
2441 final ArrayList stmts = new ArrayList();
2442 final int pos = SimpleCharStream.getPosition();
2445 expr = SwitchLabel()
2446 ( statement = BlockStatementNoBreak() {stmts.add(statement);}
2447 | statement = htmlBlock() {stmts.add(statement);})*
2448 [ statement = BreakStatement() {stmts.add(statement);}]
2450 Statement[] stmtsArray = new Statement[stmts.size()];
2451 stmts.toArray(stmtsArray);
2452 if (expr == null) {//it's a default
2453 return new DefaultCase(stmtsArray,pos,SimpleCharStream.getPosition());
2455 return new Case(expr,stmtsArray,pos,SimpleCharStream.getPosition());}
2460 * case Expression() :
2462 * @return the if it was a case and null if not
2464 Expression SwitchLabel() :
2467 final Expression expr;
2473 } catch (ParseException e) {
2474 if (errorMessage != null) throw e;
2475 errorMessage = "expression expected after 'case' keyword";
2477 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2478 errorEnd = jj_input_stream.getPosition() + 1;
2484 } catch (ParseException e) {
2485 errorMessage = "':' expected after case expression";
2487 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2488 errorEnd = jj_input_stream.getPosition() + 1;
2496 } catch (ParseException e) {
2497 errorMessage = "':' expected after 'default' keyword";
2499 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2500 errorEnd = jj_input_stream.getPosition() + 1;
2505 Break BreakStatement() :
2507 Expression expression = null;
2508 final int start = SimpleCharStream.getPosition();
2511 <BREAK> [ expression = Expression() ]
2514 } catch (ParseException e) {
2515 errorMessage = "';' expected after 'break' keyword";
2517 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2518 errorEnd = jj_input_stream.getPosition() + 1;
2521 {return new Break(expression, start, SimpleCharStream.getPosition());}
2524 IfStatement IfStatement() :
2526 final int pos = jj_input_stream.getPosition();
2527 Expression condition;
2528 IfStatement ifStatement;
2531 <IF> condition = Condition("if") ifStatement = IfStatement0(condition, pos,pos+2)
2532 {return ifStatement;}
2536 Expression Condition(final String keyword) :
2538 final Expression condition;
2543 } catch (ParseException e) {
2544 errorMessage = "'(' expected after " + keyword + " keyword";
2546 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length();
2547 errorEnd = errorStart +1;
2548 processParseException(e);
2550 condition = Expression()
2554 } catch (ParseException e) {
2555 errorMessage = "')' expected after " + keyword + " keyword";
2557 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2558 errorEnd = jj_input_stream.getPosition() + 1;
2563 IfStatement IfStatement0(Expression condition, final int start,final int end) :
2565 Statement statement;
2567 final Statement[] statementsArray;
2568 ElseIf elseifStatement;
2569 Else elseStatement = null;
2571 final ArrayList elseIfList = new ArrayList();
2573 int pos = SimpleCharStream.getPosition();
2578 {stmts = new ArrayList();}
2579 ( statement = Statement() {stmts.add(statement);}
2580 | statement = htmlBlock() {stmts.add(statement);})*
2581 {endStatements = SimpleCharStream.getPosition();}
2582 (elseifStatement = ElseIfStatementColon() {elseIfList.add(elseifStatement);})*
2583 [elseStatement = ElseStatementColon()]
2586 setMarker(fileToParse,
2587 "Ugly syntax detected, you should if () {...} instead of if (): ... endif;",
2591 "Line " + token.beginLine);
2592 } catch (CoreException e) {
2593 PHPeclipsePlugin.log(e);
2597 } catch (ParseException e) {
2598 errorMessage = "'endif' expected";
2600 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2601 errorEnd = jj_input_stream.getPosition() + 1;
2606 } catch (ParseException e) {
2607 errorMessage = "';' expected after 'endif' keyword";
2609 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2610 errorEnd = jj_input_stream.getPosition() + 1;
2614 elseIfs = new ElseIf[elseIfList.size()];
2615 elseIfList.toArray(elseIfs);
2616 if (stmts.size() == 1) {
2617 return new IfStatement(condition,
2618 (Statement) stmts.get(0),
2622 SimpleCharStream.getPosition());
2624 statementsArray = new Statement[stmts.size()];
2625 stmts.toArray(statementsArray);
2626 return new IfStatement(condition,
2627 new Block(statementsArray,pos,endStatements),
2631 SimpleCharStream.getPosition());
2636 (stmt = Statement() | stmt = htmlBlock())
2637 ( LOOKAHEAD(1) elseifStatement = ElseIfStatement() {elseIfList.add(elseifStatement);})*
2641 {pos = SimpleCharStream.getPosition();}
2642 statement = Statement()
2643 {elseStatement = new Else(statement,pos,SimpleCharStream.getPosition());}
2644 } catch (ParseException e) {
2645 if (errorMessage != null) {
2648 errorMessage = "unexpected token '"+e.currentToken.next.image+"', a statement was expected";
2650 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2651 errorEnd = jj_input_stream.getPosition() + 1;
2656 elseIfs = new ElseIf[elseIfList.size()];
2657 elseIfList.toArray(elseIfs);
2658 return new IfStatement(condition,
2663 SimpleCharStream.getPosition());}
2666 ElseIf ElseIfStatementColon() :
2668 Expression condition;
2669 Statement statement;
2670 final ArrayList list = new ArrayList();
2671 final int pos = SimpleCharStream.getPosition();
2674 <ELSEIF> condition = Condition("elseif")
2675 <COLON> ( statement = Statement() {list.add(statement);}
2676 | statement = htmlBlock() {list.add(statement);})*
2678 Statement[] stmtsArray = new Statement[list.size()];
2679 list.toArray(stmtsArray);
2680 return new ElseIf(condition,stmtsArray ,pos,SimpleCharStream.getPosition());}
2683 Else ElseStatementColon() :
2685 Statement statement;
2686 final ArrayList list = new ArrayList();
2687 final int pos = SimpleCharStream.getPosition();
2690 <ELSE> <COLON> ( statement = Statement() {list.add(statement);}
2691 | statement = htmlBlock() {list.add(statement);})*
2693 Statement[] stmtsArray = new Statement[list.size()];
2694 list.toArray(stmtsArray);
2695 return new Else(stmtsArray,pos,SimpleCharStream.getPosition());}
2698 ElseIf ElseIfStatement() :
2700 Expression condition;
2701 Statement statement;
2702 final ArrayList list = new ArrayList();
2703 final int pos = SimpleCharStream.getPosition();
2706 <ELSEIF> condition = Condition("elseif") statement = Statement() {list.add(statement);/*todo:do better*/}
2708 Statement[] stmtsArray = new Statement[list.size()];
2709 list.toArray(stmtsArray);
2710 return new ElseIf(condition,stmtsArray,pos,SimpleCharStream.getPosition());}
2713 WhileStatement WhileStatement() :
2715 final Expression condition;
2716 final Statement action;
2717 final int pos = SimpleCharStream.getPosition();
2721 condition = Condition("while")
2722 action = WhileStatement0(pos,pos + 5)
2723 {return new WhileStatement(condition,action,pos,SimpleCharStream.getPosition());}
2726 Statement WhileStatement0(final int start, final int end) :
2728 Statement statement;
2729 final ArrayList stmts = new ArrayList();
2730 final int pos = SimpleCharStream.getPosition();
2733 <COLON> (statement = Statement() {stmts.add(statement);})*
2735 setMarker(fileToParse,
2736 "Ugly syntax detected, you should while () {...} instead of while (): ... endwhile;",
2740 "Line " + token.beginLine);
2741 } catch (CoreException e) {
2742 PHPeclipsePlugin.log(e);
2746 } catch (ParseException e) {
2747 errorMessage = "'endwhile' expected";
2749 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2750 errorEnd = jj_input_stream.getPosition() + 1;
2756 Statement[] stmtsArray = new Statement[stmts.size()];
2757 stmts.toArray(stmtsArray);
2758 return new Block(stmtsArray,pos,SimpleCharStream.getPosition());}
2759 } catch (ParseException e) {
2760 errorMessage = "';' expected after 'endwhile' keyword";
2762 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2763 errorEnd = jj_input_stream.getPosition() + 1;
2767 statement = Statement()
2771 DoStatement DoStatement() :
2773 final Statement action;
2774 final Expression condition;
2775 final int pos = SimpleCharStream.getPosition();
2778 <DO> action = Statement() <WHILE> condition = Condition("while")
2781 {return new DoStatement(condition,action,pos,SimpleCharStream.getPosition());}
2782 } catch (ParseException e) {
2783 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
2785 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2786 errorEnd = jj_input_stream.getPosition() + 1;
2791 ForeachStatement ForeachStatement() :
2793 Statement statement;
2794 Expression expression;
2795 final StringBuffer buff = new StringBuffer();
2796 final int pos = SimpleCharStream.getPosition();
2797 ArrayVariableDeclaration variable;
2803 } catch (ParseException e) {
2804 errorMessage = "'(' expected after 'foreach' keyword";
2806 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2807 errorEnd = jj_input_stream.getPosition() + 1;
2811 expression = Expression()
2812 } catch (ParseException e) {
2813 errorMessage = "variable expected";
2815 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2816 errorEnd = jj_input_stream.getPosition() + 1;
2821 } catch (ParseException e) {
2822 errorMessage = "'as' expected";
2824 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2825 errorEnd = jj_input_stream.getPosition() + 1;
2829 variable = ArrayVariable()
2830 } catch (ParseException e) {
2831 errorMessage = "variable expected";
2833 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2834 errorEnd = jj_input_stream.getPosition() + 1;
2839 } catch (ParseException e) {
2840 errorMessage = "')' expected after 'foreach' keyword";
2842 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2843 errorEnd = jj_input_stream.getPosition() + 1;
2847 statement = Statement()
2848 } catch (ParseException e) {
2849 if (errorMessage != null) throw e;
2850 errorMessage = "statement expected";
2852 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2853 errorEnd = jj_input_stream.getPosition() + 1;
2856 {return new ForeachStatement(expression,
2860 SimpleCharStream.getPosition());}
2864 ForStatement ForStatement() :
2867 final int pos = SimpleCharStream.getPosition();
2868 Statement[] initializations = null;
2869 Expression condition = null;
2870 Statement[] increments = null;
2872 final ArrayList list = new ArrayList();
2873 final int startBlock, endBlock;
2879 } catch (ParseException e) {
2880 errorMessage = "'(' expected after 'for' keyword";
2882 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2883 errorEnd = jj_input_stream.getPosition() + 1;
2886 [ initializations = ForInit() ] <SEMICOLON>
2887 [ condition = Expression() ] <SEMICOLON>
2888 [ increments = StatementExpressionList() ] <RPAREN>
2890 action = Statement()
2891 {return new ForStatement(initializations,condition,increments,action,pos,SimpleCharStream.getPosition());}
2894 {startBlock = SimpleCharStream.getPosition();}
2895 (action = Statement() {list.add(action);})*
2898 setMarker(fileToParse,
2899 "Ugly syntax detected, you should for () {...} instead of for (): ... endfor;",
2901 pos+token.image.length(),
2903 "Line " + token.beginLine);
2904 } catch (CoreException e) {
2905 PHPeclipsePlugin.log(e);
2908 {endBlock = SimpleCharStream.getPosition();}
2911 } catch (ParseException e) {
2912 errorMessage = "'endfor' expected";
2914 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2915 errorEnd = jj_input_stream.getPosition() + 1;
2921 Statement[] stmtsArray = new Statement[list.size()];
2922 list.toArray(stmtsArray);
2923 return new ForStatement(initializations,condition,increments,new Block(stmtsArray,startBlock,endBlock),pos,SimpleCharStream.getPosition());}
2924 } catch (ParseException e) {
2925 errorMessage = "';' expected after 'endfor' keyword";
2927 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2928 errorEnd = jj_input_stream.getPosition() + 1;
2934 Statement[] ForInit() :
2936 Statement[] statements;
2939 LOOKAHEAD(LocalVariableDeclaration())
2940 statements = LocalVariableDeclaration()
2941 {return statements;}
2943 statements = StatementExpressionList()
2944 {return statements;}
2947 Statement[] StatementExpressionList() :
2949 final ArrayList list = new ArrayList();
2953 expr = StatementExpression() {list.add(expr);}
2954 (<COMMA> StatementExpression() {list.add(expr);})*
2956 Statement[] stmtsArray = new Statement[list.size()];
2957 list.toArray(stmtsArray);
2961 Continue ContinueStatement() :
2963 Expression expr = null;
2964 final int pos = SimpleCharStream.getPosition();
2967 <CONTINUE> [ expr = Expression() ]
2970 {return new Continue(expr,pos,SimpleCharStream.getPosition());}
2971 } catch (ParseException e) {
2972 errorMessage = "';' expected after 'continue' statement";
2974 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2975 errorEnd = jj_input_stream.getPosition() + 1;
2980 ReturnStatement ReturnStatement() :
2982 Expression expr = null;
2983 final int pos = SimpleCharStream.getPosition();
2986 <RETURN> [ expr = Expression() ]
2989 {return new ReturnStatement(expr,pos,SimpleCharStream.getPosition());}
2990 } catch (ParseException e) {
2991 errorMessage = "';' expected after 'return' statement";
2993 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2994 errorEnd = jj_input_stream.getPosition() + 1;