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.io.StringReader;
35 import java.text.MessageFormat;
37 import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
38 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
39 import net.sourceforge.phpdt.internal.compiler.parser.*;
40 import net.sourceforge.phpdt.internal.compiler.ast.*;
44 * This php parser is inspired by the Java 1.2 grammar example
45 * given with JavaCC. You can get JavaCC at http://www.webgain.com
46 * You can test the parser with the PHPParserTestCase2.java
47 * @author Matthieu Casanova
49 public final class PHPParser extends PHPParserSuperclass {
51 /** The file that is parsed. */
52 private static IFile fileToParse;
54 /** The current segment. */
55 private static PHPSegmentWithChildren currentSegment;
57 private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$
58 private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
59 static PHPOutlineInfo outlineInfo;
61 private static PHPFunctionDeclaration currentFunction;
62 private static boolean assigning;
64 /** The error level of the current ParseException. */
65 private static int errorLevel = ERROR;
66 /** The message of the current ParseException. If it's null it's because the parse exception wasn't handled */
67 private static String errorMessage;
69 private static int errorStart = -1;
70 private static int errorEnd = -1;
73 private final static int AstStackIncrement = 100;
74 /** The stack of node. */
75 private static AstNode[] astStack;
76 /** The cursor in expression stack. */
77 private static int expressionPtr;
79 public final void setFileToParse(final IFile fileToParse) {
80 this.fileToParse = fileToParse;
86 public PHPParser(final IFile fileToParse) {
87 this(new StringReader(""));
88 this.fileToParse = fileToParse;
91 public static final void phpParserTester(final String strEval) throws CoreException, ParseException {
92 PHPParserTokenManager.SwitchTo(PHPParserTokenManager.PHPPARSING);
93 final StringReader stream = new StringReader(strEval);
94 if (jj_input_stream == null) {
95 jj_input_stream = new SimpleCharStream(stream, 1, 1);
97 ReInit(new StringReader(strEval));
98 astStack = new AstNode[AstStackIncrement];
102 public static final void htmlParserTester(final File fileName) throws CoreException, ParseException {
104 final Reader stream = new FileReader(fileName);
105 if (jj_input_stream == null) {
106 jj_input_stream = new SimpleCharStream(stream, 1, 1);
109 astStack = new AstNode[AstStackIncrement];
111 } catch (FileNotFoundException e) {
112 e.printStackTrace(); //To change body of catch statement use Options | File Templates.
116 public static final void htmlParserTester(final String strEval) throws CoreException, ParseException {
117 final StringReader stream = new StringReader(strEval);
118 if (jj_input_stream == null) {
119 jj_input_stream = new SimpleCharStream(stream, 1, 1);
122 astStack = new AstNode[AstStackIncrement];
126 public final PHPOutlineInfo parseInfo(final Object parent, final String s) {
127 outlineInfo = new PHPOutlineInfo(parent);
128 currentSegment = outlineInfo.getDeclarations();
129 final StringReader stream = new StringReader(s);
130 if (jj_input_stream == null) {
131 jj_input_stream = new SimpleCharStream(stream, 1, 1);
134 astStack = new AstNode[AstStackIncrement];
137 } catch (ParseException e) {
138 processParseException(e);
144 * This method will process the parse exception.
145 * If the error message is null, the parse exception wasn't catched and a trace is written in the log
146 * @param e the ParseException
148 private static void processParseException(final ParseException e) {
149 if (errorMessage == null) {
150 PHPeclipsePlugin.log(e);
151 errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it";
152 errorStart = jj_input_stream.getPosition();
153 errorEnd = errorStart + 1;
160 * Create marker for the parse error
161 * @param e the ParseException
163 private static void setMarker(final ParseException e) {
165 if (errorStart == -1) {
166 setMarker(fileToParse,
168 jj_input_stream.tokenBegin,
169 jj_input_stream.tokenBegin + e.currentToken.image.length(),
171 "Line " + e.currentToken.beginLine);
173 setMarker(fileToParse,
178 "Line " + e.currentToken.beginLine);
182 } catch (CoreException e2) {
183 PHPeclipsePlugin.log(e2);
188 * Create markers according to the external parser output
190 private static void createMarkers(final String output, final IFile file) throws CoreException {
191 // delete all markers
192 file.deleteMarkers(IMarker.PROBLEM, false, 0);
197 while ((brIndx = output.indexOf("<br />", indx)) != -1) {
198 // newer php error output (tested with 4.2.3)
199 scanLine(output, file, indx, brIndx);
204 while ((brIndx = output.indexOf("<br>", indx)) != -1) {
205 // older php error output (tested with 4.2.3)
206 scanLine(output, file, indx, brIndx);
212 private static void scanLine(final String output,
215 final int brIndx) throws CoreException {
217 StringBuffer lineNumberBuffer = new StringBuffer(10);
219 current = output.substring(indx, brIndx);
221 if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) {
222 int onLine = current.indexOf("on line <b>");
224 lineNumberBuffer.delete(0, lineNumberBuffer.length());
225 for (int i = onLine; i < current.length(); i++) {
226 ch = current.charAt(i);
227 if ('0' <= ch && '9' >= ch) {
228 lineNumberBuffer.append(ch);
232 int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
234 Hashtable attributes = new Hashtable();
236 current = current.replaceAll("\n", "");
237 current = current.replaceAll("<b>", "");
238 current = current.replaceAll("</b>", "");
239 MarkerUtilities.setMessage(attributes, current);
241 if (current.indexOf(PARSE_ERROR_STRING) != -1)
242 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
243 else if (current.indexOf(PARSE_WARNING_STRING) != -1)
244 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
246 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
247 MarkerUtilities.setLineNumber(attributes, lineNumber);
248 MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
253 public final void parse(final String s) throws CoreException {
254 final StringReader stream = new StringReader(s);
255 if (jj_input_stream == null) {
256 jj_input_stream = new SimpleCharStream(stream, 1, 1);
259 astStack = new AstNode[AstStackIncrement];
262 } catch (ParseException e) {
263 processParseException(e);
268 * Call the php parse command ( php -l -f <filename> )
269 * and create markers according to the external parser output
271 public static void phpExternalParse(final IFile file) {
272 final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
273 final String filename = file.getLocation().toString();
275 final String[] arguments = { filename };
276 final MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
277 final String command = form.format(arguments);
279 final String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: ");
282 // parse the buffer to find the errors and warnings
283 createMarkers(parserResult, file);
284 } catch (CoreException e) {
285 PHPeclipsePlugin.log(e);
289 private static final void parse() throws ParseException {
294 PARSER_END(PHPParser)
298 <PHPSTARTSHORT : "<?"> : PHPPARSING
299 | <PHPSTARTLONG : "<?php"> : PHPPARSING
300 | <PHPECHOSTART : "<?="> : PHPPARSING
305 <PHPEND :"?>"> : DEFAULT
308 /* Skip any character if we are not in php mode */
326 <PHPPARSING> SPECIAL_TOKEN :
328 "//" : IN_SINGLE_LINE_COMMENT
330 "#" : IN_SINGLE_LINE_COMMENT
332 <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
334 "/*" : IN_MULTI_LINE_COMMENT
337 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
339 <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : PHPPARSING
342 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
344 <SINGLE_LINE_COMMENT_PHPEND : "?>" > : DEFAULT
350 <FORMAL_COMMENT: "*/" > : PHPPARSING
353 <IN_MULTI_LINE_COMMENT>
356 <MULTI_LINE_COMMENT: "*/" > : PHPPARSING
359 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
369 | <FUNCTION : "function">
372 | <ELSEIF : "elseif">
379 /* LANGUAGE CONSTRUCT */
384 | <INCLUDE : "include">
385 | <REQUIRE : "require">
386 | <INCLUDE_ONCE : "include_once">
387 | <REQUIRE_ONCE : "require_once">
388 | <GLOBAL : "global">
389 | <STATIC : "static">
390 | <CLASSACCESS : "->">
391 | <STATICCLASSACCESS : "::">
392 | <ARRAYASSIGN : "=>">
395 /* RESERVED WORDS AND LITERALS */
401 | <CONTINUE : "continue">
402 | <_DEFAULT : "default">
404 | <EXTENDS : "extends">
409 | <RETURN : "return">
411 | <SWITCH : "switch">
416 | <ENDWHILE : "endwhile">
417 | <ENDSWITCH: "endswitch">
419 | <ENDFOR : "endfor">
420 | <FOREACH : "foreach">
428 | <OBJECT : "object">
430 | <BOOLEAN : "boolean">
432 | <DOUBLE : "double">
435 | <INTEGER : "integer">
448 <DECIMAL_LITERAL> (["l","L"])?
449 | <HEX_LITERAL> (["l","L"])?
450 | <OCTAL_LITERAL> (["l","L"])?
453 < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
455 < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
457 < #OCTAL_LITERAL: "0" (["0"-"7"])* >
459 < FLOATING_POINT_LITERAL:
460 (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
461 | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
462 | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
463 | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
466 < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
468 < STRING_LITERAL: (<STRING_1> | <STRING_2> | <STRING_3>)>
502 < IDENTIFIER: (<LETTER>|<SPECIAL>) (<LETTER>|<DIGIT>|<SPECIAL>)* >
505 ["a"-"z"] | ["A"-"Z"]
513 "_" | ["\u007f"-"\u00ff"]
543 | <BANGDOUBLEEQUAL : "!==">
544 | <TRIPLEEQUAL : "===">
551 | <PLUSASSIGN : "+=">
552 | <MINUSASSIGN : "-=">
553 | <STARASSIGN : "*=">
554 | <SLASHASSIGN : "/=">
560 | <TILDEEQUAL : "~=">
585 | <RSIGNEDSHIFT : ">>">
586 | <RUNSIGNEDSHIFT : ">>>">
587 | <LSHIFTASSIGN : "<<=">
588 | <RSIGNEDSHIFTASSIGN : ">>=">
593 < DOLLAR_ID: <DOLLAR> <IDENTIFIER> >
609 } catch (TokenMgrError e) {
610 PHPeclipsePlugin.log(e);
611 errorStart = SimpleCharStream.getPosition();
612 errorEnd = errorStart + 1;
613 errorMessage = e.getMessage();
615 throw generateParseException();
620 * A php block is a <?= expression [;]?>
621 * or <?php somephpcode ?>
622 * or <? somephpcode ?>
626 final int start = jj_input_stream.getPosition();
634 setMarker(fileToParse,
635 "You should use '<?php' instead of '<?' it will avoid some problems with XML",
637 jj_input_stream.getPosition(),
639 "Line " + token.beginLine);
640 } catch (CoreException e) {
641 PHPeclipsePlugin.log(e);
647 } catch (ParseException e) {
648 errorMessage = "'?>' expected";
650 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
651 errorEnd = jj_input_stream.getPosition() + 1;
656 void phpEchoBlock() :
659 <PHPECHOSTART> Expression() [ <SEMICOLON> ] <PHPEND>
668 void ClassDeclaration() :
670 final PHPClassDeclaration classDeclaration;
671 final Token className;
677 {pos = jj_input_stream.getPosition();}
678 className = <IDENTIFIER>
679 } catch (ParseException e) {
680 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
682 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
683 errorEnd = jj_input_stream.getPosition() + 1;
690 } catch (ParseException e) {
691 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
693 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
694 errorEnd = jj_input_stream.getPosition() + 1;
699 if (currentSegment != null) {
700 classDeclaration = new PHPClassDeclaration(currentSegment,className.image,pos);
701 currentSegment.add(classDeclaration);
702 currentSegment = classDeclaration;
707 if (currentSegment != null) {
708 currentSegment = (PHPSegmentWithChildren) currentSegment.getParent();
718 } catch (ParseException e) {
719 errorMessage = "unexpected token : '"+ e.currentToken.next.image + "', '{' expected";
721 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
722 errorEnd = jj_input_stream.getPosition() + 1;
725 ( ClassBodyDeclaration() )*
728 } catch (ParseException e) {
729 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', 'var', 'function' or '}' expected";
731 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
732 errorEnd = jj_input_stream.getPosition() + 1;
738 * A class can contain only methods and fields.
740 void ClassBodyDeclaration() :
748 * A class field declaration : it's var VariableDeclarator() (, VariableDeclarator())*;.
750 void FieldDeclaration() :
752 PHPVarDeclaration variableDeclaration;
755 <VAR> variableDeclaration = VariableDeclarator()
757 outlineInfo.addVariable(variableDeclaration.getVariable().getName());
758 if (currentSegment != null) {
759 currentSegment.add(variableDeclaration);
763 variableDeclaration = VariableDeclarator()
765 if (currentSegment != null) {
766 currentSegment.add(variableDeclaration);
772 } catch (ParseException e) {
773 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected after variable declaration";
775 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
776 errorEnd = jj_input_stream.getPosition() + 1;
781 PHPVarDeclaration VariableDeclarator() :
783 final String varName, varValue;
784 final int pos = jj_input_stream.getPosition();
787 varName = VariableDeclaratorId()
791 varValue = VariableInitializer()
792 {return new PHPVarDeclaration(currentSegment,varName,pos,varValue);}
793 } catch (ParseException e) {
794 errorMessage = "Literal expression expected in variable initializer";
796 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
797 errorEnd = jj_input_stream.getPosition() + 1;
801 {return new PHPVarDeclaration(currentSegment,varName,pos);}
804 String VariableDeclaratorId() :
807 final StringBuffer buff = new StringBuffer();
811 expr = Variable() {buff.append(expr);}
813 expr = VariableSuffix() {buff.append(expr);}
815 {return buff.toString();}
816 } catch (ParseException e) {
817 errorMessage = "'$' expected for variable identifier";
819 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
820 errorEnd = jj_input_stream.getPosition() + 1;
831 token = <DOLLAR_ID> [<LBRACE> expr = Expression() <RBRACE>]
833 if (expr == null && !assigning) {
834 if (currentFunction != null) {
835 PHPVarDeclaration var = currentFunction.getParameter(token.image.substring(1));
837 var.getVariable().setUsed(true);
840 return token.image.substring(1);
842 return token + "{" + expr + "}";
845 <DOLLAR> expr = VariableName()
849 String VariableName():
855 <LBRACE> expr = Expression() <RBRACE>
856 {return "{"+expr+"}";}
858 token = <IDENTIFIER> [<LBRACE> expr = Expression() <RBRACE>]
861 if (currentFunction != null) {
862 PHPVarDeclaration var = currentFunction.getParameter(token.image);
864 var.getVariable().setUsed(true);
869 return token + "{" + expr + "}";
872 <DOLLAR> expr = VariableName()
874 if (currentFunction != null) {
875 PHPVarDeclaration var = currentFunction.getParameter(expr);
877 var.getVariable().setUsed(true);
885 if (currentFunction != null) {
886 PHPVarDeclaration var = currentFunction.getParameter(token.image.substring(1));
888 var.getVariable().setUsed(true);
891 return token.image + expr;
894 token = <DOLLAR_ID> [expr = VariableName()]
899 return token.image + expr;
903 String VariableInitializer() :
912 <MINUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
913 {return "-" + token.image;}
915 <PLUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
916 {return "+" + token.image;}
918 expr = ArrayDeclarator()
922 {return token.image;}
925 String ArrayVariable() :
928 final StringBuffer buff = new StringBuffer();
933 [<ARRAYASSIGN> expr = Expression()
934 {buff.append("=>").append(expr);}]
935 {return buff.toString();}
938 String ArrayInitializer() :
941 final StringBuffer buff = new StringBuffer("(");
944 <LPAREN> [ expr = ArrayVariable()
946 ( LOOKAHEAD(2) <COMMA> expr = ArrayVariable()
947 {buff.append(",").append(expr);}
950 [<COMMA> {buff.append(",");}]
954 return buff.toString();
959 * A Method Declaration.
960 * <b>function</b> MetodDeclarator() Block()
962 void MethodDeclaration() :
964 final PHPFunctionDeclaration functionDeclaration;
968 functionToken = <FUNCTION>
970 functionDeclaration = MethodDeclarator()
971 {outlineInfo.addVariable(functionDeclaration.getName());}
972 } catch (ParseException e) {
973 if (errorMessage != null) {
976 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
978 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
979 errorEnd = jj_input_stream.getPosition() + 1;
983 if (currentSegment != null) {
984 currentSegment.add(functionDeclaration);
985 currentSegment = functionDeclaration;
987 currentFunction = functionDeclaration;
991 Hashtable parameters = currentFunction.getParameters();
992 Enumeration vars = parameters.elements();
993 while (vars.hasMoreElements()) {
994 PHPVarDeclaration o = (PHPVarDeclaration) vars.nextElement();
995 if (!o.getVariable().isUsed()) {
997 setMarker(fileToParse,
998 "Parameter "+o.getVariable().getName()+" is never used in function",
999 functionToken.beginLine,
1001 "Line " + token.beginLine);
1002 } catch (CoreException e) {
1003 PHPeclipsePlugin.log(e);
1007 currentFunction = null;
1008 if (currentSegment != null) {
1009 currentSegment = (PHPSegmentWithChildren) currentSegment.getParent();
1015 * A MethodDeclarator.
1016 * [&] IDENTIFIER(parameters ...).
1017 * @return a function description for the outline
1019 PHPFunctionDeclaration MethodDeclarator() :
1021 final Token identifier;
1022 final StringBuffer methodDeclaration = new StringBuffer();
1023 final Hashtable formalParameters;
1024 final int pos = jj_input_stream.getPosition();
1027 [ <BIT_AND> {methodDeclaration.append("&");} ]
1028 identifier = <IDENTIFIER>
1029 formalParameters = FormalParameters()
1031 methodDeclaration.append(identifier);
1032 return new PHPFunctionDeclaration(currentSegment,methodDeclaration.toString(),pos,formalParameters);
1037 * FormalParameters follows method identifier.
1038 * (FormalParameter())
1040 Hashtable FormalParameters() :
1043 final StringBuffer buff = new StringBuffer("(");
1044 PHPVarDeclaration var;
1045 final Hashtable parameters = new Hashtable();
1050 } catch (ParseException e) {
1051 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected after function identifier";
1053 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1054 errorEnd = jj_input_stream.getPosition() + 1;
1057 [ var = FormalParameter()
1058 {parameters.put(var.getVariable().getName(),var);}
1060 <COMMA> var = FormalParameter()
1061 {parameters.put(var.getVariable().getName(),var);}
1066 } catch (ParseException e) {
1067 errorMessage = "')' expected";
1069 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1070 errorEnd = jj_input_stream.getPosition() + 1;
1073 {return parameters;}
1077 * A formal parameter.
1078 * $varname[=value] (,$varname[=value])
1080 PHPVarDeclaration FormalParameter() :
1082 final PHPVarDeclaration variableDeclaration;
1086 [token = <BIT_AND>] variableDeclaration = VariableDeclarator()
1088 if (token != null) {
1089 variableDeclaration.getVariable().setReference(true);
1091 return variableDeclaration;
1098 <STRING> {return "string";}
1099 | <BOOL> {return "bool";}
1100 | <BOOLEAN> {return "boolean";}
1101 | <REAL> {return "real";}
1102 | <DOUBLE> {return "double";}
1103 | <FLOAT> {return "float";}
1104 | <INT> {return "int";}
1105 | <INTEGER> {return "integer";}
1106 | <OBJECT> {return "object";}
1109 String Expression() :
1112 final String assignOperator;
1116 expr = PrintExpression() {return expr;}
1117 | expr = ListExpression() {return expr;}
1118 | LOOKAHEAD(varAssignation())
1119 expr = varAssignation() {return expr;}
1120 | expr = ConditionalExpression() {return expr;}
1124 * A Variable assignation.
1125 * varName (an assign operator) any expression
1127 String varAssignation() :
1129 String varName,assignOperator,expr2;
1130 PHPVarDeclaration variable;
1131 final int pos = SimpleCharStream.getPosition();
1134 varName = VariableDeclaratorId()
1135 assignOperator = AssignmentOperator()
1137 expr2 = Expression()
1138 } catch (ParseException e) {
1139 if (errorMessage != null) {
1142 errorMessage = "expression expected";
1144 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1145 errorEnd = jj_input_stream.getPosition() + 1;
1148 {return varName + assignOperator + expr2;}
1151 String AssignmentOperator() :
1154 <ASSIGN> {return "=";}
1155 | <STARASSIGN> {return "*=";}
1156 | <SLASHASSIGN> {return "/=";}
1157 | <REMASSIGN> {return "%=";}
1158 | <PLUSASSIGN> {return "+=";}
1159 | <MINUSASSIGN> {return "-=";}
1160 | <LSHIFTASSIGN> {return "<<=";}
1161 | <RSIGNEDSHIFTASSIGN> {return ">>=";}
1162 | <ANDASSIGN> {return "&=";}
1163 | <XORASSIGN> {return "|=";}
1164 | <ORASSIGN> {return "|=";}
1165 | <DOTASSIGN> {return ".=";}
1166 | <TILDEEQUAL> {return "~=";}
1169 String ConditionalExpression() :
1172 String expr2 = null;
1173 String expr3 = null;
1176 expr = ConditionalOrExpression() [ <HOOK> expr2 = Expression() <COLON> expr3 = ConditionalExpression() ]
1178 if (expr3 == null) {
1181 return expr + "?" + expr2 + ":" + expr3;
1186 String ConditionalOrExpression() :
1190 final StringBuffer buff = new StringBuffer();
1193 expr = ConditionalAndExpression()
1194 {buff.append(expr);}
1196 (operator = <SC_OR> | operator = <_ORL>) expr = ConditionalAndExpression()
1198 buff.append(operator.image);
1203 return buff.toString();
1207 String ConditionalAndExpression() :
1211 final StringBuffer buff = new StringBuffer();
1214 expr = ConcatExpression()
1215 {buff.append(expr);}
1217 (operator = <SC_AND> | operator = <_ANDL>) expr = ConcatExpression()
1219 buff.append(operator.image);
1223 {return buff.toString();}
1226 String ConcatExpression() :
1229 final StringBuffer buff = new StringBuffer();
1232 expr = InclusiveOrExpression()
1233 {buff.append(expr);}
1235 <DOT> expr = InclusiveOrExpression()
1236 {buff.append(".").append(expr);}
1238 {return buff.toString();}
1241 String InclusiveOrExpression() :
1244 final StringBuffer buff = new StringBuffer();
1247 expr = ExclusiveOrExpression()
1248 {buff.append(expr);}
1250 <BIT_OR> expr = ExclusiveOrExpression()
1251 {buff.append("|").append(expr);}
1253 {return buff.toString();}
1256 String ExclusiveOrExpression() :
1259 final StringBuffer buff = new StringBuffer();
1262 expr = AndExpression()
1267 <XOR> expr = AndExpression()
1274 return buff.toString();
1278 String AndExpression() :
1281 final StringBuffer buff = new StringBuffer();
1284 expr = EqualityExpression()
1289 <BIT_AND> expr = EqualityExpression()
1291 buff.append("&").append(expr);
1294 {return buff.toString();}
1297 String EqualityExpression() :
1301 final StringBuffer buff = new StringBuffer();
1304 expr = RelationalExpression()
1305 {buff.append(expr);}
1310 | operator = <BANGDOUBLEEQUAL>
1311 | operator = <TRIPLEEQUAL>
1314 expr = RelationalExpression()
1315 } catch (ParseException e) {
1316 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected after '"+operator.image+"'";
1318 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1319 errorEnd = jj_input_stream.getPosition() + 1;
1323 buff.append(operator.image);
1327 {return buff.toString();}
1330 String RelationalExpression() :
1334 final StringBuffer buff = new StringBuffer();
1337 expr = ShiftExpression()
1338 {buff.append(expr);}
1340 ( operator = <LT> | operator = <GT> | operator = <LE> | operator = <GE> ) expr = ShiftExpression()
1341 {buff.append(operator.image).append(expr);}
1343 {return buff.toString();}
1346 String ShiftExpression() :
1350 final StringBuffer buff = new StringBuffer();
1353 expr = AdditiveExpression()
1354 {buff.append(expr);}
1356 (operator = <LSHIFT> | operator = <RSIGNEDSHIFT> | operator = <RUNSIGNEDSHIFT> ) expr = AdditiveExpression()
1358 buff.append(operator.image);
1362 {return buff.toString();}
1365 String AdditiveExpression() :
1369 final StringBuffer buff = new StringBuffer();
1372 expr = MultiplicativeExpression()
1373 {buff.append(expr);}
1375 ( operator = <PLUS> | operator = <MINUS> ) expr = MultiplicativeExpression()
1377 buff.append(operator.image);
1381 {return buff.toString();}
1384 String MultiplicativeExpression() :
1388 final StringBuffer buff = new StringBuffer();}
1391 expr = UnaryExpression()
1392 } catch (ParseException e) {
1393 errorMessage = "unexpected token '"+e.currentToken.next.image+"'";
1395 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1396 errorEnd = jj_input_stream.getPosition() + 1;
1399 {buff.append(expr);}
1401 ( operator = <STAR> | operator = <SLASH> | operator = <REM> ) expr = UnaryExpression()
1403 buff.append(operator.image);
1407 {return buff.toString();}
1411 * An unary expression starting with @, & or nothing
1413 String UnaryExpression() :
1417 final StringBuffer buff = new StringBuffer();
1420 token = <BIT_AND> expr = UnaryExpressionNoPrefix()
1422 if (token == null) {
1425 return token.image + expr;
1427 | (<AT> {buff.append("@");})*
1428 expr = UnaryExpressionNoPrefix()
1429 {return buff.append(expr).toString();}
1432 String UnaryExpressionNoPrefix() :
1438 ( token = <PLUS> | token = <MINUS> ) expr = UnaryExpression()
1440 return token.image + expr;
1443 expr = PreIncDecExpression()
1446 expr = UnaryExpressionNotPlusMinus()
1451 String PreIncDecExpression() :
1457 (token = <INCR> | token = <DECR>) expr = PrimaryExpression()
1458 {return token.image + expr;}
1461 String UnaryExpressionNotPlusMinus() :
1466 <BANG> expr = UnaryExpression() {return "!" + expr;}
1467 | LOOKAHEAD( <LPAREN> (Type() | <ARRAY>) <RPAREN> )
1468 expr = CastExpression() {return expr;}
1469 | expr = PostfixExpression() {return expr;}
1470 | expr = Literal() {return expr;}
1471 | <LPAREN> expr = Expression()
1474 } catch (ParseException e) {
1475 errorMessage = "')' expected";
1477 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1478 errorEnd = jj_input_stream.getPosition() + 1;
1481 {return "("+expr+")";}
1484 String CastExpression() :
1486 final String type, expr;
1489 <LPAREN> (type = Type() | <ARRAY> {type = "array";}) <RPAREN> expr = UnaryExpression()
1490 {return "(" + type + ")" + expr;}
1493 String PostfixExpression() :
1496 Token operator = null;
1499 expr = PrimaryExpression() [ operator = <INCR> | operator = <DECR> ]
1501 if (operator == null) {
1504 return expr + operator.image;
1508 String PrimaryExpression() :
1510 final Token identifier;
1512 final StringBuffer buff = new StringBuffer();
1516 identifier = <IDENTIFIER> <STATICCLASSACCESS> expr = ClassIdentifier()
1517 {buff.append(identifier.image).append("::").append(expr);}
1519 expr = PrimarySuffix()
1520 {buff.append(expr);}
1522 {return buff.toString();}
1524 expr = PrimaryPrefix() {buff.append(expr);}
1525 ( expr = PrimarySuffix() {buff.append(expr);} )*
1526 {return buff.toString();}
1528 expr = ArrayDeclarator()
1529 {return "array" + expr;}
1532 String ArrayDeclarator() :
1537 <ARRAY> expr = ArrayInitializer()
1538 {return "array" + expr;}
1541 String PrimaryPrefix() :
1547 token = <IDENTIFIER> {return token.image;}
1548 | <NEW> expr = ClassIdentifier() {return "new " + expr;}
1549 | expr = VariableDeclaratorId() {return expr;}
1552 String classInstantiation() :
1555 final StringBuffer buff = new StringBuffer("new ");
1558 <NEW> expr = ClassIdentifier()
1559 {buff.append(expr);}
1561 expr = PrimaryExpression()
1562 {buff.append(expr);}
1564 {return buff.toString();}
1567 String ClassIdentifier():
1573 token = <IDENTIFIER> {return token.image;}
1574 | expr = VariableDeclaratorId() {return expr;}
1577 String PrimarySuffix() :
1582 expr = Arguments() {return expr;}
1583 | expr = VariableSuffix() {return expr;}
1586 String VariableSuffix() :
1593 expr = VariableName()
1594 } catch (ParseException e) {
1595 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
1597 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1598 errorEnd = jj_input_stream.getPosition() + 1;
1601 {return "->" + expr;}
1603 <LBRACKET> [ expr = Expression() | expr = Type() ] //Not good
1606 } catch (ParseException e) {
1607 errorMessage = "']' expected";
1609 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1610 errorEnd = jj_input_stream.getPosition() + 1;
1617 return "[" + expr + "]";
1627 token = <INTEGER_LITERAL> {return token.image;}
1628 | token = <FLOATING_POINT_LITERAL> {return token.image;}
1629 | token = <STRING_LITERAL> {return token.image;}
1630 | expr = BooleanLiteral() {return expr;}
1631 | <NULL> {return "null";}
1634 String BooleanLiteral() :
1637 <TRUE> {return "true";}
1638 | <FALSE> {return "false";}
1641 String Arguments() :
1646 <LPAREN> [ expr = ArgumentList() ]
1649 } catch (ParseException e) {
1650 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
1652 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1653 errorEnd = jj_input_stream.getPosition() + 1;
1660 return "(" + expr + ")";
1664 String ArgumentList() :
1667 final StringBuffer buff = new StringBuffer();
1671 {buff.append(expr);}
1675 } catch (ParseException e) {
1676 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. An expression expected after a comma in argument list";
1678 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1679 errorEnd = jj_input_stream.getPosition() + 1;
1682 {buff.append(",").append(expr);}
1684 {return buff.toString();}
1688 * A Statement without break.
1690 void StatementNoBreak() :
1697 } catch (ParseException e) {
1698 if (e.currentToken.next.kind != 4) {
1699 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1701 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1702 errorEnd = jj_input_stream.getPosition() + 1;
1710 | StatementExpression()
1713 } catch (ParseException e) {
1714 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1716 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1717 errorEnd = jj_input_stream.getPosition() + 1;
1725 | ForeachStatement()
1726 | ContinueStatement()
1729 | [<AT>] IncludeStatement()
1735 * A Normal statement.
1745 * An html block inside a php syntax.
1750 <PHPEND> (phpEchoBlock())*
1752 (<PHPSTARTLONG> | <PHPSTARTSHORT>)
1753 } catch (ParseException e) {
1754 errorMessage = "End of file unexpected, '<?php' expected";
1756 errorStart = jj_input_stream.getPosition();
1757 errorEnd = jj_input_stream.getPosition();
1763 * An include statement. It's "include" an expression;
1765 void IncludeStatement() :
1769 final int pos = jj_input_stream.getPosition();
1773 | token = <REQUIRE_ONCE>
1775 | token = <INCLUDE_ONCE> )
1778 } catch (ParseException e) {
1779 if (errorMessage != null) {
1782 errorMessage = "unexpected token '"+ e.currentToken.next.image+"', expression expected";
1784 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1785 errorEnd = jj_input_stream.getPosition() + 1;
1789 if (currentSegment != null) {
1790 currentSegment.add(new PHPReqIncDeclaration(currentSegment, token.image,pos,expr));
1795 } catch (ParseException e) {
1796 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1798 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1799 errorEnd = jj_input_stream.getPosition() + 1;
1804 String PrintExpression() :
1809 <PRINT> expr = Expression() {return "print " + expr;}
1812 String ListExpression() :
1814 final StringBuffer buff = new StringBuffer("list(");
1821 } catch (ParseException e) {
1822 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
1824 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1825 errorEnd = jj_input_stream.getPosition() + 1;
1829 expr = VariableDeclaratorId()
1830 {buff.append(expr);}
1835 } catch (ParseException e) {
1836 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
1838 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1839 errorEnd = jj_input_stream.getPosition() + 1;
1842 expr = VariableDeclaratorId()
1843 {buff.append(",").append(expr);}
1848 } catch (ParseException e) {
1849 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
1851 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1852 errorEnd = jj_input_stream.getPosition() + 1;
1855 [ <ASSIGN> expr = Expression() {buff.append("(").append(expr);}]
1856 {return buff.toString();}
1860 * An echo statement.
1861 * echo anyexpression (, otherexpression)*
1863 void EchoStatement() :
1866 <ECHO> Expression() (<COMMA> Expression())*
1869 } catch (ParseException e) {
1870 if (e.currentToken.next.kind != 4) {
1871 errorMessage = "';' expected after 'echo' statement";
1873 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1874 errorEnd = jj_input_stream.getPosition() + 1;
1880 void GlobalStatement() :
1882 final int pos = jj_input_stream.getPosition();
1887 expr = VariableDeclaratorId()
1888 {if (currentSegment != null) {
1889 currentSegment.add(new PHPGlobalDeclaration(currentSegment, "global",pos,expr));
1892 expr = VariableDeclaratorId()
1893 {if (currentSegment != null) {
1894 currentSegment.add(new PHPGlobalDeclaration(currentSegment, "global",pos,expr));
1899 } catch (ParseException e) {
1900 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
1902 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1903 errorEnd = jj_input_stream.getPosition() + 1;
1908 void StaticStatement() :
1911 <STATIC> VariableDeclarator() (<COMMA> VariableDeclarator())*
1914 } catch (ParseException e) {
1915 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
1917 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1918 errorEnd = jj_input_stream.getPosition() + 1;
1923 void LabeledStatement() :
1926 <IDENTIFIER> <COLON> Statement()
1934 } catch (ParseException e) {
1935 errorMessage = "'{' expected";
1937 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1938 errorEnd = jj_input_stream.getPosition() + 1;
1941 ( BlockStatement() | htmlBlock())*
1944 } catch (ParseException e) {
1945 errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected";
1947 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1948 errorEnd = jj_input_stream.getPosition() + 1;
1953 void BlockStatement() :
1957 | ClassDeclaration()
1958 | MethodDeclaration()
1962 * A Block statement that will not contain any 'break'
1964 void BlockStatementNoBreak() :
1968 | ClassDeclaration()
1969 | MethodDeclaration()
1972 void LocalVariableDeclaration() :
1975 LocalVariableDeclarator() ( <COMMA> LocalVariableDeclarator() )*
1978 void LocalVariableDeclarator() :
1981 VariableDeclaratorId() [ <ASSIGN> Expression() ]
1984 void EmptyStatement() :
1990 void StatementExpression() :
1993 PreIncDecExpression()
1998 | AssignmentOperator() Expression() ]
2001 void SwitchStatement() :
2003 final int pos = jj_input_stream.getPosition();
2009 } catch (ParseException e) {
2010 errorMessage = "'(' expected after 'switch'";
2012 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2013 errorEnd = jj_input_stream.getPosition() + 1;
2018 } catch (ParseException e) {
2019 if (errorMessage != null) {
2022 errorMessage = "expression expected";
2024 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2025 errorEnd = jj_input_stream.getPosition() + 1;
2030 } catch (ParseException e) {
2031 errorMessage = "')' expected";
2033 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2034 errorEnd = jj_input_stream.getPosition() + 1;
2037 (switchStatementBrace() | switchStatementColon(pos, pos + 6))
2040 void switchStatementBrace() :
2047 } catch (ParseException e) {
2048 errorMessage = "'}' expected";
2050 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2051 errorEnd = jj_input_stream.getPosition() + 1;
2056 * A Switch statement with : ... endswitch;
2057 * @param start the begin offset of the switch
2058 * @param end the end offset of the switch
2060 void switchStatementColon(final int start, final int end) :
2065 setMarker(fileToParse,
2066 "Ugly syntax detected, you should switch () {...} instead of switch (): ... enswitch;",
2070 "Line " + token.beginLine);
2071 } catch (CoreException e) {
2072 PHPeclipsePlugin.log(e);
2077 } catch (ParseException e) {
2078 errorMessage = "'endswitch' expected";
2080 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2081 errorEnd = jj_input_stream.getPosition() + 1;
2086 } catch (ParseException e) {
2087 errorMessage = "';' expected after 'endswitch' keyword";
2089 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2090 errorEnd = jj_input_stream.getPosition() + 1;
2095 void switchLabel0() :
2097 Token breakToken = null;
2101 line = SwitchLabel()
2102 ( BlockStatementNoBreak() | htmlBlock() )*
2103 [ breakToken = BreakStatement() ]
2106 if (breakToken == null) {
2107 setMarker(fileToParse,
2108 "You should use put a 'break' at the end of your statement",
2113 } catch (CoreException e) {
2114 PHPeclipsePlugin.log(e);
2119 Token BreakStatement() :
2124 token = <BREAK> [ Expression() ]
2127 } catch (ParseException e) {
2128 errorMessage = "';' expected after 'break' keyword";
2130 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2131 errorEnd = jj_input_stream.getPosition() + 1;
2145 } catch (ParseException e) {
2146 if (errorMessage != null) throw e;
2147 errorMessage = "expression expected after 'case' keyword";
2149 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2150 errorEnd = jj_input_stream.getPosition() + 1;
2155 } catch (ParseException e) {
2156 errorMessage = "':' expected after case expression";
2158 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2159 errorEnd = jj_input_stream.getPosition() + 1;
2162 {return token.beginLine;}
2167 } catch (ParseException e) {
2168 errorMessage = "':' expected after 'default' keyword";
2170 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2171 errorEnd = jj_input_stream.getPosition() + 1;
2174 {return token.beginLine;}
2177 void IfStatement() :
2180 final int pos = jj_input_stream.getPosition();
2183 token = <IF> Condition("if") IfStatement0(pos,pos+token.image.length())
2186 void Condition(final String keyword) :
2191 } catch (ParseException e) {
2192 errorMessage = "'(' expected after " + keyword + " keyword";
2194 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length();
2195 errorEnd = errorStart +1;
2196 processParseException(e);
2201 } catch (ParseException e) {
2202 errorMessage = "')' expected after " + keyword + " keyword";
2204 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2205 errorEnd = jj_input_stream.getPosition() + 1;
2210 void IfStatement0(final int start,final int end) :
2213 <COLON> (Statement() | htmlBlock())* (ElseIfStatementColon())* [ElseStatementColon()]
2216 setMarker(fileToParse,
2217 "Ugly syntax detected, you should if () {...} instead of if (): ... endif;",
2221 "Line " + token.beginLine);
2222 } catch (CoreException e) {
2223 PHPeclipsePlugin.log(e);
2227 } catch (ParseException e) {
2228 errorMessage = "'endif' expected";
2230 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2231 errorEnd = jj_input_stream.getPosition() + 1;
2236 } catch (ParseException e) {
2237 errorMessage = "';' expected after 'endif' keyword";
2239 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2240 errorEnd = jj_input_stream.getPosition() + 1;
2244 (Statement() | htmlBlock())
2245 ( LOOKAHEAD(1) ElseIfStatement() )*
2250 } catch (ParseException e) {
2251 if (errorMessage != null) {
2254 errorMessage = "unexpected token '"+e.currentToken.next.image+"', a statement was expected";
2256 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2257 errorEnd = jj_input_stream.getPosition() + 1;
2263 void ElseIfStatementColon() :
2266 <ELSEIF> Condition("elseif") <COLON> (Statement() | htmlBlock())*
2269 void ElseStatementColon() :
2272 <ELSE> <COLON> (Statement() | htmlBlock())*
2275 void ElseIfStatement() :
2278 <ELSEIF> Condition("elseif") Statement()
2281 void WhileStatement() :
2284 final int pos = jj_input_stream.getPosition();
2287 token = <WHILE> Condition("while") WhileStatement0(pos,pos + token.image.length())
2290 void WhileStatement0(final int start, final int end) :
2293 <COLON> (Statement())*
2295 setMarker(fileToParse,
2296 "Ugly syntax detected, you should while () {...} instead of while (): ... endwhile;",
2300 "Line " + token.beginLine);
2301 } catch (CoreException e) {
2302 PHPeclipsePlugin.log(e);
2306 } catch (ParseException e) {
2307 errorMessage = "'endwhile' expected";
2309 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2310 errorEnd = jj_input_stream.getPosition() + 1;
2315 } catch (ParseException e) {
2316 errorMessage = "';' expected after 'endwhile' keyword";
2318 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2319 errorEnd = jj_input_stream.getPosition() + 1;
2326 void DoStatement() :
2329 <DO> Statement() <WHILE> Condition("while")
2332 } catch (ParseException e) {
2333 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
2335 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2336 errorEnd = jj_input_stream.getPosition() + 1;
2341 void ForeachStatement() :
2347 } catch (ParseException e) {
2348 errorMessage = "'(' expected after 'foreach' keyword";
2350 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2351 errorEnd = jj_input_stream.getPosition() + 1;
2356 } catch (ParseException e) {
2357 errorMessage = "variable expected";
2359 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2360 errorEnd = jj_input_stream.getPosition() + 1;
2363 ( VariableSuffix() )*
2366 } catch (ParseException e) {
2367 errorMessage = "'as' expected";
2369 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2370 errorEnd = jj_input_stream.getPosition() + 1;
2375 } catch (ParseException e) {
2376 errorMessage = "variable expected";
2378 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2379 errorEnd = jj_input_stream.getPosition() + 1;
2382 [ <ARRAYASSIGN> Expression() ]
2385 } catch (ParseException e) {
2386 errorMessage = "')' expected after 'foreach' keyword";
2388 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2389 errorEnd = jj_input_stream.getPosition() + 1;
2394 } catch (ParseException e) {
2395 if (errorMessage != null) throw e;
2396 errorMessage = "statement expected";
2398 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2399 errorEnd = jj_input_stream.getPosition() + 1;
2404 void ForStatement() :
2407 final int pos = jj_input_stream.getPosition();
2413 } catch (ParseException e) {
2414 errorMessage = "'(' expected after 'for' keyword";
2416 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2417 errorEnd = jj_input_stream.getPosition() + 1;
2420 [ ForInit() ] <SEMICOLON> [ Expression() ] <SEMICOLON> [ StatementExpressionList() ] <RPAREN>
2424 <COLON> (Statement())*
2427 setMarker(fileToParse,
2428 "Ugly syntax detected, you should for () {...} instead of for (): ... endfor;",
2430 pos+token.image.length(),
2432 "Line " + token.beginLine);
2433 } catch (CoreException e) {
2434 PHPeclipsePlugin.log(e);
2439 } catch (ParseException e) {
2440 errorMessage = "'endfor' expected";
2442 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2443 errorEnd = jj_input_stream.getPosition() + 1;
2448 } catch (ParseException e) {
2449 errorMessage = "';' expected after 'endfor' keyword";
2451 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2452 errorEnd = jj_input_stream.getPosition() + 1;
2461 LOOKAHEAD(LocalVariableDeclaration())
2462 LocalVariableDeclaration()
2464 StatementExpressionList()
2467 void StatementExpressionList() :
2470 StatementExpression() ( <COMMA> StatementExpression() )*
2473 void ContinueStatement() :
2476 <CONTINUE> [ Expression() ]
2479 } catch (ParseException e) {
2480 errorMessage = "';' expected after 'continue' statement";
2482 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2483 errorEnd = jj_input_stream.getPosition() + 1;
2488 void ReturnStatement() :
2491 <RETURN> [ Expression() ]
2494 } catch (ParseException e) {
2495 errorMessage = "';' expected after 'return' statement";
2497 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2498 errorEnd = jj_input_stream.getPosition() + 1;