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.io.StringReader;
33 import java.text.MessageFormat;
35 import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
36 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
37 import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo;
38 import net.sourceforge.phpdt.internal.compiler.parser.PHPSegmentWithChildren;
39 import net.sourceforge.phpdt.internal.compiler.parser.PHPFunctionDeclaration;
40 import net.sourceforge.phpdt.internal.compiler.parser.PHPClassDeclaration;
41 import net.sourceforge.phpdt.internal.compiler.parser.PHPVarDeclaration;
42 import net.sourceforge.phpdt.internal.compiler.parser.PHPReqIncDeclaration;
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 private static IFile fileToParse;
55 /** The current segment */
56 private static PHPSegmentWithChildren currentSegment;
58 private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$
59 private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
60 PHPOutlineInfo outlineInfo;
61 private static int errorLevel = ERROR;
62 private static String errorMessage;
67 public final void setFileToParse(final IFile fileToParse) {
68 this.fileToParse = fileToParse;
71 public PHPParser(final IFile fileToParse) {
72 this(new StringReader(""));
73 this.fileToParse = fileToParse;
76 public static final void phpParserTester(final String strEval) throws CoreException, ParseException {
77 PHPParserTokenManager.SwitchTo(PHPParserTokenManager.PHPPARSING);
78 final StringReader stream = new StringReader(strEval);
79 if (jj_input_stream == null) {
80 jj_input_stream = new SimpleCharStream(stream, 1, 1);
82 ReInit(new StringReader(strEval));
86 public static final void htmlParserTester(final String strEval) throws CoreException, ParseException {
87 final StringReader stream = new StringReader(strEval);
88 if (jj_input_stream == null) {
89 jj_input_stream = new SimpleCharStream(stream, 1, 1);
95 public final PHPOutlineInfo parseInfo(final Object parent, final String s) {
96 outlineInfo = new PHPOutlineInfo(parent);
97 currentSegment = outlineInfo.getDeclarations();
98 final StringReader stream = new StringReader(s);
99 if (jj_input_stream == null) {
100 jj_input_stream = new SimpleCharStream(stream, 1, 1);
105 } catch (ParseException e) {
106 processParseException(e);
112 * This method will process the parse exception.
113 * If the error message is null, the parse exception wasn't catched and a trace is written in the log
114 * @param e the ParseException
116 private static void processParseException(final ParseException e) {
117 if (errorMessage == null) {
118 PHPeclipsePlugin.log(e);
119 errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it";
126 * Create marker for the parse error
127 * @param e the ParseException
129 private static void setMarker(final ParseException e) {
131 setMarker(fileToParse,
133 jj_input_stream.tokenBegin,
134 jj_input_stream.tokenBegin + e.currentToken.image.length(),
136 "Line " + e.currentToken.beginLine);
137 } catch (CoreException e2) {
138 PHPeclipsePlugin.log(e2);
143 * Create markers according to the external parser output
145 private static void createMarkers(final String output, final IFile file) throws CoreException {
146 // delete all markers
147 file.deleteMarkers(IMarker.PROBLEM, false, 0);
152 while ((brIndx = output.indexOf("<br />", indx)) != -1) {
153 // newer php error output (tested with 4.2.3)
154 scanLine(output, file, indx, brIndx);
159 while ((brIndx = output.indexOf("<br>", indx)) != -1) {
160 // older php error output (tested with 4.2.3)
161 scanLine(output, file, indx, brIndx);
167 private static void scanLine(final String output,
170 final int brIndx) throws CoreException {
172 StringBuffer lineNumberBuffer = new StringBuffer(10);
174 current = output.substring(indx, brIndx);
176 if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) {
177 int onLine = current.indexOf("on line <b>");
179 lineNumberBuffer.delete(0, lineNumberBuffer.length());
180 for (int i = onLine; i < current.length(); i++) {
181 ch = current.charAt(i);
182 if ('0' <= ch && '9' >= ch) {
183 lineNumberBuffer.append(ch);
187 int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
189 Hashtable attributes = new Hashtable();
191 current = current.replaceAll("\n", "");
192 current = current.replaceAll("<b>", "");
193 current = current.replaceAll("</b>", "");
194 MarkerUtilities.setMessage(attributes, current);
196 if (current.indexOf(PARSE_ERROR_STRING) != -1)
197 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
198 else if (current.indexOf(PARSE_WARNING_STRING) != -1)
199 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
201 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
202 MarkerUtilities.setLineNumber(attributes, lineNumber);
203 MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
208 public final void parse(final String s) throws CoreException {
209 final StringReader stream = new StringReader(s);
210 if (jj_input_stream == null) {
211 jj_input_stream = new SimpleCharStream(stream, 1, 1);
216 } catch (ParseException e) {
217 processParseException(e);
222 * Call the php parse command ( php -l -f <filename> )
223 * and create markers according to the external parser output
225 public static void phpExternalParse(final IFile file) {
226 final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
227 final String filename = file.getLocation().toString();
229 final String[] arguments = { filename };
230 final MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
231 final String command = form.format(arguments);
233 final String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: ");
236 // parse the buffer to find the errors and warnings
237 createMarkers(parserResult, file);
238 } catch (CoreException e) {
239 PHPeclipsePlugin.log(e);
243 public static final void parse() throws ParseException {
248 PARSER_END(PHPParser)
252 <PHPSTARTSHORT : "<?"> : PHPPARSING
253 | <PHPSTARTLONG : "<?php"> : PHPPARSING
254 | <PHPECHOSTART : "<?="> : PHPPARSING
259 <PHPEND :"?>"> : DEFAULT
281 <PHPPARSING> SPECIAL_TOKEN :
283 "//" | "#" : IN_SINGLE_LINE_COMMENT
285 <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
287 "/*" : IN_MULTI_LINE_COMMENT
290 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
292 <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : PHPPARSING
295 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
297 <SINGLE_LINE_COMMENT_PHPEND : "?>" > : DEFAULT
303 <FORMAL_COMMENT: "*/" > : PHPPARSING
306 <IN_MULTI_LINE_COMMENT>
309 <MULTI_LINE_COMMENT: "*/" > : PHPPARSING
312 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
322 | <FUNCTION : "function">
325 | <ELSEIF : "elseif">
331 /* LANGUAGE CONSTRUCT */
336 | <INCLUDE : "include">
337 | <REQUIRE : "require">
338 | <INCLUDE_ONCE : "include_once">
339 | <REQUIRE_ONCE : "require_once">
340 | <GLOBAL : "global">
341 | <STATIC : "static">
342 | <CLASSACCESS : "->">
343 | <STATICCLASSACCESS : "::">
344 | <ARRAYASSIGN : "=>">
351 /* RESERVED WORDS AND LITERALS */
357 | <CONTINUE : "continue">
358 | <_DEFAULT : "default">
360 | <EXTENDS : "extends">
365 | <RETURN : "return">
367 | <SWITCH : "switch">
372 | <ENDWHILE : "endwhile">
374 | <ENDFOR : "endfor">
375 | <FOREACH : "foreach">
384 | <OBJECT : "object">
386 | <BOOLEAN : "boolean">
388 | <DOUBLE : "double">
391 | <INTEGER : "integer">
405 <DECIMAL_LITERAL> (["l","L"])?
406 | <HEX_LITERAL> (["l","L"])?
407 | <OCTAL_LITERAL> (["l","L"])?
410 < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
412 < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
414 < #OCTAL_LITERAL: "0" (["0"-"7"])* >
416 < FLOATING_POINT_LITERAL:
417 (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
418 | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
419 | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
420 | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
423 < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
425 < STRING_LITERAL: (<STRING_1> | <STRING_2> | <STRING_3>)>
460 < IDENTIFIER: (<LETTER>|<SPECIAL>) (<LETTER>|<DIGIT>|<SPECIAL>)* >
463 ["a"-"z"] | ["A"-"Z"]
471 "_" | ["\u007f"-"\u00ff"]
501 | <BANGDOUBLEEQUAL : "!==">
502 | <TRIPLEEQUAL : "===">
509 | <PLUSASSIGN : "+=">
510 | <MINUSASSIGN : "-=">
511 | <STARASSIGN : "*=">
512 | <SLASHASSIGN : "/=">
518 | <TILDEEQUAL : "~=">
542 | <RSIGNEDSHIFT : ">>">
543 | <RUNSIGNEDSHIFT : ">>>">
544 | <LSHIFTASSIGN : "<<=">
545 | <RSIGNEDSHIFTASSIGN : ">>=">
550 < DOLLAR_ID: <DOLLAR> <IDENTIFIER> >
566 } catch (TokenMgrError e) {
567 errorMessage = e.getMessage();
569 throw generateParseException();
575 final int start = jj_input_stream.bufpos;
578 <PHPECHOSTART> Expression() [ <SEMICOLON> ] <PHPEND>
583 setMarker(fileToParse,
584 "You should use '<?php' instead of '<?' it will avoid some problems with XML",
586 jj_input_stream.bufpos,
588 "Line " + token.beginLine);
589 } catch (CoreException e) {
590 PHPeclipsePlugin.log(e);
596 } catch (ParseException e) {
597 errorMessage = "'?>' expected";
609 void ClassDeclaration() :
611 final PHPClassDeclaration classDeclaration;
612 final Token className;
613 final int pos = jj_input_stream.bufpos;
616 <CLASS> className = <IDENTIFIER> [ <EXTENDS> <IDENTIFIER> ]
618 if (currentSegment != null) {
619 classDeclaration = new PHPClassDeclaration(currentSegment,className.image,pos);
620 currentSegment.add(classDeclaration);
621 currentSegment = classDeclaration;
626 if (currentSegment != null) {
627 currentSegment = (PHPSegmentWithChildren) currentSegment.getParent();
637 } catch (ParseException e) {
638 errorMessage = "'{' expected";
642 ( ClassBodyDeclaration() )*
645 } catch (ParseException e) {
646 errorMessage = "'var', 'function' or '}' expected";
652 void ClassBodyDeclaration() :
660 void FieldDeclaration() :
662 PHPVarDeclaration variableDeclaration;
665 <VAR> variableDeclaration = VariableDeclarator()
667 if (currentSegment != null) {
668 currentSegment.add(variableDeclaration);
672 variableDeclaration = VariableDeclarator()
674 if (currentSegment != null) {
675 currentSegment.add(variableDeclaration);
681 } catch (ParseException e) {
682 errorMessage = "';' expected after variable declaration";
688 PHPVarDeclaration VariableDeclarator() :
690 final String varName;
692 final int pos = jj_input_stream.bufpos;
695 varName = VariableDeclaratorId()
699 varValue = VariableInitializer()
700 {return new PHPVarDeclaration(currentSegment,varName,pos,varValue);}
701 } catch (ParseException e) {
702 errorMessage = "Literal expression expected in variable initializer";
707 {return new PHPVarDeclaration(currentSegment,varName,pos);}
710 String VariableDeclaratorId() :
713 final StringBuffer buff = new StringBuffer();
719 ( LOOKAHEAD(2) expr = VariableSuffix()
722 {return buff.toString();}
723 } catch (ParseException e) {
724 errorMessage = "'$' expected for variable identifier";
736 token = <DOLLAR_ID> [<LBRACE> expr = Expression() <RBRACE>]
741 return token + "{" + expr + "}";
744 <DOLLAR> expr = VariableName()
748 String VariableName():
754 <LBRACE> expr = Expression() <RBRACE>
755 {return "{"+expr+"}";}
757 token = <IDENTIFIER> [<LBRACE> expr = Expression() <RBRACE>]
762 return token + "{" + expr + "}";
765 <DOLLAR> expr = VariableName()
768 token = <DOLLAR_ID> [expr = VariableName()]
773 return token.image + expr;
777 String VariableInitializer() :
786 <MINUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
787 {return "-" + token.image;}
789 <PLUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
790 {return "+" + token.image;}
792 expr = ArrayDeclarator()
796 {return token.image;}
799 String ArrayVariable() :
802 final StringBuffer buff = new StringBuffer();
807 [<ARRAYASSIGN> expr = Expression()
808 {buff.append("=>").append(expr);}]
809 {return buff.toString();}
812 String ArrayInitializer() :
815 final StringBuffer buff = new StringBuffer("(");
818 <LPAREN> [ expr = ArrayVariable()
820 ( LOOKAHEAD(2) <COMMA> expr = ArrayVariable()
821 {buff.append(",").append(expr);}
826 return buff.toString();
830 void MethodDeclaration() :
832 final PHPFunctionDeclaration functionDeclaration;
837 functionDeclaration = MethodDeclarator()
838 } catch (ParseException e) {
839 if (errorMessage != null) {
842 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
847 if (currentSegment != null) {
848 currentSegment.add(functionDeclaration);
849 currentSegment = functionDeclaration;
854 if (currentSegment != null) {
855 currentSegment = (PHPSegmentWithChildren) currentSegment.getParent();
860 PHPFunctionDeclaration MethodDeclarator() :
862 final Token identifier;
863 final StringBuffer methodDeclaration = new StringBuffer();
864 final String formalParameters;
865 final int pos = jj_input_stream.bufpos;
868 [ <BIT_AND> {methodDeclaration.append("&");} ]
869 identifier = <IDENTIFIER>
870 {methodDeclaration.append(identifier);}
871 formalParameters = FormalParameters()
873 methodDeclaration.append(formalParameters);
874 return new PHPFunctionDeclaration(currentSegment,methodDeclaration.toString(),pos);
878 String FormalParameters() :
881 final StringBuffer buff = new StringBuffer("(");
886 } catch (ParseException e) {
887 errorMessage = "Formal parameter expected after function identifier";
889 jj_consume_token(token.kind);
891 [ expr = FormalParameter()
894 <COMMA> expr = FormalParameter()
895 {buff.append(",").append(expr);}
900 } catch (ParseException e) {
901 errorMessage = "')' expected";
907 return buff.toString();
911 String FormalParameter() :
913 final PHPVarDeclaration variableDeclaration;
914 final StringBuffer buff = new StringBuffer();
917 [<BIT_AND> {buff.append("&");}] variableDeclaration = VariableDeclarator()
919 buff.append(variableDeclaration.toString());
920 return buff.toString();
955 String Expression() :
958 final String assignOperator;
962 expr = PrintExpression()
965 expr = ListExpression()
968 expr = ConditionalExpression()
970 assignOperator = AssignmentOperator()
973 {return expr + assignOperator + expr2;}
974 } catch (ParseException e) {
975 errorMessage = "expression expected";
983 String AssignmentOperator() :
1000 | <RSIGNEDSHIFTASSIGN>
1014 String ConditionalExpression() :
1017 String expr2 = null;
1018 String expr3 = null;
1021 expr = ConditionalOrExpression() [ <HOOK> expr2 = Expression() <COLON> expr3 = ConditionalExpression() ]
1023 if (expr3 == null) {
1026 return expr + "?" + expr2 + ":" + expr3;
1031 String ConditionalOrExpression() :
1035 final StringBuffer buff = new StringBuffer();
1038 expr = ConditionalAndExpression()
1039 {buff.append(expr);}
1041 (operator = <SC_OR> | operator = <_ORL>) expr = ConditionalAndExpression()
1043 buff.append(operator.image);
1048 return buff.toString();
1052 String ConditionalAndExpression() :
1056 final StringBuffer buff = new StringBuffer();
1059 expr = ConcatExpression()
1060 {buff.append(expr);}
1062 (operator = <SC_AND> | operator = <_ANDL>) expr = ConcatExpression()
1064 buff.append(operator.image);
1068 {return buff.toString();}
1071 String ConcatExpression() :
1074 final StringBuffer buff = new StringBuffer();
1077 expr = InclusiveOrExpression()
1078 {buff.append(expr);}
1080 <DOT> expr = InclusiveOrExpression()
1081 {buff.append(".").append(expr);}
1083 {return buff.toString();}
1086 String InclusiveOrExpression() :
1089 final StringBuffer buff = new StringBuffer();
1092 expr = ExclusiveOrExpression()
1093 {buff.append(expr);}
1095 <BIT_OR> expr = ExclusiveOrExpression()
1096 {buff.append("|").append(expr);}
1098 {return buff.toString();}
1101 String ExclusiveOrExpression() :
1104 final StringBuffer buff = new StringBuffer();
1107 expr = AndExpression()
1112 <XOR> expr = AndExpression()
1119 return buff.toString();
1123 String AndExpression() :
1126 final StringBuffer buff = new StringBuffer();
1129 expr = EqualityExpression()
1134 <BIT_AND> expr = EqualityExpression()
1136 buff.append("&").append(expr);
1139 {return buff.toString();}
1142 String EqualityExpression() :
1146 final StringBuffer buff = new StringBuffer();
1149 expr = RelationalExpression()
1150 {buff.append(expr);}
1155 | operator = <BANGDOUBLEEQUAL>
1156 | operator = <TRIPLEEQUAL>
1158 expr = RelationalExpression()
1160 buff.append(operator.image);
1164 {return buff.toString();}
1167 String RelationalExpression() :
1171 final StringBuffer buff = new StringBuffer();
1174 expr = ShiftExpression()
1175 {buff.append(expr);}
1177 ( operator = <LT> | operator = <GT> | operator = <LE> | operator = <GE> ) expr = ShiftExpression()
1178 {buff.append(operator.image).append(expr);}
1180 {return buff.toString();}
1183 String ShiftExpression() :
1187 final StringBuffer buff = new StringBuffer();
1190 expr = AdditiveExpression()
1191 {buff.append(expr);}
1193 (operator = <LSHIFT> | operator = <RSIGNEDSHIFT> | operator = <RUNSIGNEDSHIFT> ) expr = AdditiveExpression()
1195 buff.append(operator.image);
1199 {return buff.toString();}
1202 String AdditiveExpression() :
1206 final StringBuffer buff = new StringBuffer();
1209 expr = MultiplicativeExpression()
1210 {buff.append(expr);}
1212 ( operator = <PLUS> | operator = <MINUS> ) expr = MultiplicativeExpression()
1214 buff.append(operator.image);
1218 {return buff.toString();}
1221 String MultiplicativeExpression() :
1225 final StringBuffer buff = new StringBuffer();}
1227 expr = UnaryExpression()
1228 {buff.append(expr);}
1230 ( operator = <STAR> | operator = <SLASH> | operator = <REM> ) expr = UnaryExpression()
1232 buff.append(operator.image);
1236 {return buff.toString();}
1240 * An unary expression starting with @, & or nothing
1242 String UnaryExpression() :
1246 final StringBuffer buff = new StringBuffer();
1249 token = <BIT_AND> expr = UnaryExpressionNoPrefix()
1251 if (token == null) {
1254 return token.image + expr;
1257 (<AT> {buff.append("@");})* expr = UnaryExpressionNoPrefix()
1258 {return buff.append(expr).toString();}
1261 String UnaryExpressionNoPrefix() :
1267 ( token = <PLUS> | token = <MINUS> ) expr = UnaryExpression()
1269 return token.image + expr;
1272 expr = PreIncrementExpression()
1275 expr = PreDecrementExpression()
1278 expr = UnaryExpressionNotPlusMinus()
1283 String PreIncrementExpression() :
1288 <INCR> expr = PrimaryExpression()
1292 String PreDecrementExpression() :
1297 <DECR> expr = PrimaryExpression()
1301 String UnaryExpressionNotPlusMinus() :
1306 <BANG> expr = UnaryExpression()
1307 {return "!" + expr;}
1309 LOOKAHEAD( <LPAREN> Type() <RPAREN> )
1310 expr = CastExpression()
1313 expr = PostfixExpression()
1319 <LPAREN> expr = Expression()
1322 } catch (ParseException e) {
1323 errorMessage = "')' expected";
1327 {return "("+expr+")";}
1330 String CastExpression() :
1332 final String type, expr;
1335 <LPAREN> type = Type() <RPAREN> expr = UnaryExpression()
1336 {return "(" + type + ")" + expr;}
1339 String PostfixExpression() :
1342 Token operator = null;
1345 expr = PrimaryExpression() [ operator = <INCR> | operator = <DECR> ]
1347 if (operator == null) {
1350 return expr + operator.image;
1354 String PrimaryExpression() :
1356 final Token identifier;
1358 final StringBuffer buff = new StringBuffer();
1362 identifier = <IDENTIFIER> <STATICCLASSACCESS> expr = ClassIdentifier()
1363 {buff.append(identifier.image).append("::").append(expr);}
1365 expr = PrimarySuffix()
1366 {buff.append(expr);}
1368 {return buff.toString();}
1370 expr = PrimaryPrefix() {buff.append(expr);}
1371 ( expr = PrimarySuffix() {buff.append(expr);} )*
1372 {return buff.toString();}
1374 expr = ArrayDeclarator()
1375 {return "array" + expr;}
1378 String ArrayDeclarator() :
1383 <ARRAY> expr = ArrayInitializer()
1384 {return "array" + expr;}
1387 String PrimaryPrefix() :
1393 token = <IDENTIFIER>
1394 {return token.image;}
1396 <NEW> expr = ClassIdentifier()
1398 return "new " + expr;
1401 expr = VariableDeclaratorId()
1405 String ClassIdentifier():
1411 token = <IDENTIFIER>
1412 {return token.image;}
1414 expr = VariableDeclaratorId()
1418 String PrimarySuffix() :
1426 expr = VariableSuffix()
1430 String VariableSuffix() :
1437 expr = VariableName()
1438 } catch (ParseException e) {
1439 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
1443 {return "->" + expr;}
1445 <LBRACKET> [ expr = Expression() ]
1448 } catch (ParseException e) {
1449 errorMessage = "']' expected";
1457 return "[" + expr + "]";
1467 token = <INTEGER_LITERAL>
1468 {return token.image;}
1470 token = <FLOATING_POINT_LITERAL>
1471 {return token.image;}
1473 token = <STRING_LITERAL>
1474 {return token.image;}
1476 expr = BooleanLiteral()
1479 expr = NullLiteral()
1483 String BooleanLiteral() :
1493 String NullLiteral() :
1500 String Arguments() :
1505 <LPAREN> [ expr = ArgumentList() ]
1508 } catch (ParseException e) {
1509 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
1517 return "(" + expr + ")";
1521 String ArgumentList() :
1524 final StringBuffer buff = new StringBuffer();
1528 {buff.append(expr);}
1532 } catch (ParseException e) {
1533 errorMessage = "expression expected after a comma in argument list";
1538 buff.append(",").append(expr);
1541 {return buff.toString();}
1545 * A Statement without break
1547 void StatementNoBreak() :
1553 (<SEMICOLON> | <PHPEND>)
1554 } catch (ParseException e) {
1555 errorMessage = "';' expected";
1567 StatementExpression()
1570 } catch (ParseException e) {
1571 errorMessage = "';' expected after expression";
1594 [<AT>] IncludeStatement()
1602 * A Normal statement
1612 void IncludeStatement() :
1615 final int pos = jj_input_stream.bufpos;
1621 if (currentSegment != null) {
1622 currentSegment.add(new PHPReqIncDeclaration(currentSegment, "require",pos,expr));
1626 (<SEMICOLON> | "?>")
1627 } catch (ParseException e) {
1628 errorMessage = "';' expected";
1636 if (currentSegment != null) {
1637 currentSegment.add(new PHPReqIncDeclaration(currentSegment, "require_once",pos,expr));
1641 (<SEMICOLON> | "?>")
1642 } catch (ParseException e) {
1643 errorMessage = "';' expected";
1651 if (currentSegment != null) {
1652 currentSegment.add(new PHPReqIncDeclaration(currentSegment, "include",pos,expr));
1656 (<SEMICOLON> | "?>")
1657 } catch (ParseException e) {
1658 errorMessage = "';' expected";
1666 if (currentSegment != null) {
1667 currentSegment.add(new PHPReqIncDeclaration(currentSegment, "include_once",pos,expr));
1671 (<SEMICOLON> | "?>")
1672 } catch (ParseException e) {
1673 errorMessage = "';' expected";
1679 String PrintExpression() :
1681 final StringBuffer buff = new StringBuffer("print ");
1685 <PRINT> expr = Expression()
1688 return buff.toString();
1692 String ListExpression() :
1694 final StringBuffer buff = new StringBuffer("list(");
1701 } catch (ParseException e) {
1702 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
1707 expr = VariableDeclaratorId()
1708 {buff.append(expr);}
1713 } catch (ParseException e) {
1714 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
1718 expr = VariableDeclaratorId()
1719 {buff.append(",").append(expr);}
1724 } catch (ParseException e) {
1725 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
1729 [ <ASSIGN> expr = Expression() {buff.append("(").append(expr);}]
1730 {return buff.toString();}
1733 void EchoStatement() :
1736 <ECHO> Expression() (<COMMA> Expression())*
1738 (<SEMICOLON> | "?>")
1739 } catch (ParseException e) {
1740 errorMessage = "';' expected after 'echo' statement";
1746 void GlobalStatement() :
1749 <GLOBAL> VariableDeclaratorId() (<COMMA> VariableDeclaratorId())*
1751 (<SEMICOLON> | "?>")
1752 } catch (ParseException e) {
1753 errorMessage = "';' expected";
1759 void StaticStatement() :
1762 <STATIC> VariableDeclarator() (<COMMA> VariableDeclarator())*
1764 (<SEMICOLON> | "?>")
1765 } catch (ParseException e) {
1766 errorMessage = "';' expected";
1772 void LabeledStatement() :
1775 <IDENTIFIER> <COLON> Statement()
1783 } catch (ParseException e) {
1784 errorMessage = "'{' expected";
1788 ( BlockStatement() )*
1791 } catch (ParseException e) {
1792 errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected";
1798 void BlockStatement() :
1809 * A Block statement that will not contain any 'break'
1811 void BlockStatementNoBreak() :
1821 void LocalVariableDeclaration() :
1824 LocalVariableDeclarator() ( <COMMA> LocalVariableDeclarator() )*
1827 void LocalVariableDeclarator() :
1830 VariableDeclaratorId() [ <ASSIGN> Expression() ]
1833 void EmptyStatement() :
1839 void StatementExpression() :
1842 PreIncrementExpression()
1844 PreDecrementExpression()
1852 AssignmentOperator() Expression()
1856 void SwitchStatement() :
1858 Token breakToken = null;
1865 } catch (ParseException e) {
1866 errorMessage = "'(' expected after 'switch'";
1873 } catch (ParseException e) {
1874 errorMessage = "')' expected";
1880 } catch (ParseException e) {
1881 errorMessage = "'{' expected";
1886 line = SwitchLabel()
1887 ( BlockStatementNoBreak() )*
1888 [ breakToken = <BREAK>
1891 } catch (ParseException e) {
1892 errorMessage = "';' expected after 'break' keyword";
1899 if (breakToken == null) {
1900 setMarker(fileToParse,
1901 "You should use put a 'break' at the end of your statement",
1906 } catch (CoreException e) {
1907 PHPeclipsePlugin.log(e);
1913 } catch (ParseException e) {
1914 errorMessage = "'}' expected";
1928 } catch (ParseException e) {
1929 if (errorMessage != null) throw e;
1930 errorMessage = "expression expected after 'case' keyword";
1936 } catch (ParseException e) {
1937 errorMessage = "':' expected after case expression";
1941 {return token.beginLine;}
1946 } catch (ParseException e) {
1947 errorMessage = "':' expected after 'default' keyword";
1951 {return token.beginLine;}
1954 void IfStatement() :
1957 final int pos = jj_input_stream.bufpos;
1960 token = <IF> Condition("if") IfStatement0(pos,pos+token.image.length())
1963 void Condition(final String keyword) :
1968 } catch (ParseException e) {
1969 errorMessage = "'(' expected after " + keyword + " keyword";
1976 } catch (ParseException e) {
1977 errorMessage = "')' expected after " + keyword + " keyword";
1983 void IfStatement0(final int start,final int end) :
1986 <COLON> (Statement())* (ElseIfStatementColon())* [ElseStatementColon()]
1989 setMarker(fileToParse,
1990 "Ugly syntax detected, you should if () {...} instead of if (): ... endif;",
1994 "Line " + token.beginLine);
1995 } catch (CoreException e) {
1996 PHPeclipsePlugin.log(e);
2000 } catch (ParseException e) {
2001 errorMessage = "'endif' expected";
2007 } catch (ParseException e) {
2008 errorMessage = "';' expected after 'endif' keyword";
2013 Statement() ( LOOKAHEAD(1) ElseIfStatement() )* [ LOOKAHEAD(1) <ELSE> Statement() ]
2016 void ElseIfStatementColon() :
2019 <ELSEIF> Condition("elseif") <COLON> (Statement())*
2022 void ElseStatementColon() :
2025 <ELSE> <COLON> (Statement())*
2028 void ElseIfStatement() :
2031 <ELSEIF> Condition("elseif") Statement()
2034 void WhileStatement() :
2037 final int pos = jj_input_stream.bufpos;
2040 token = <WHILE> Condition("while") WhileStatement0(pos,pos + token.image.length())
2043 void WhileStatement0(final int start, final int end) :
2046 <COLON> (Statement())*
2048 setMarker(fileToParse,
2049 "Ugly syntax detected, you should while () {...} instead of while (): ... endwhile;",
2053 "Line " + token.beginLine);
2054 } catch (CoreException e) {
2055 PHPeclipsePlugin.log(e);
2059 } catch (ParseException e) {
2060 errorMessage = "'endwhile' expected";
2065 (<SEMICOLON> | "?>")
2066 } catch (ParseException e) {
2067 errorMessage = "';' expected after 'endwhile' keyword";
2075 void DoStatement() :
2078 <DO> Statement() <WHILE> Condition("while")
2080 (<SEMICOLON> | "?>")
2081 } catch (ParseException e) {
2082 errorMessage = "';' expected";
2088 void ForeachStatement() :
2094 } catch (ParseException e) {
2095 errorMessage = "'(' expected after 'foreach' keyword";
2101 } catch (ParseException e) {
2102 errorMessage = "variable expected";
2106 [ VariableSuffix() ]
2109 } catch (ParseException e) {
2110 errorMessage = "'as' expected";
2116 } catch (ParseException e) {
2117 errorMessage = "variable expected";
2121 [ <ARRAYASSIGN> Expression() ]
2124 } catch (ParseException e) {
2125 errorMessage = "')' expected after 'foreach' keyword";
2131 } catch (ParseException e) {
2132 if (errorMessage != null) throw e;
2133 errorMessage = "statement expected";
2139 void ForStatement() :
2142 final int pos = jj_input_stream.bufpos;
2148 } catch (ParseException e) {
2149 errorMessage = "'(' expected after 'for' keyword";
2153 [ ForInit() ] <SEMICOLON> [ Expression() ] <SEMICOLON> [ StatementExpressionList() ] <RPAREN>
2157 <COLON> (Statement())*
2160 setMarker(fileToParse,
2161 "Ugly syntax detected, you should for () {...} instead of for (): ... endfor;",
2163 pos+token.image.length(),
2165 "Line " + token.beginLine);
2166 } catch (CoreException e) {
2167 PHPeclipsePlugin.log(e);
2172 } catch (ParseException e) {
2173 errorMessage = "'endfor' expected";
2179 } catch (ParseException e) {
2180 errorMessage = "';' expected after 'endfor' keyword";
2190 LOOKAHEAD(LocalVariableDeclaration())
2191 LocalVariableDeclaration()
2193 StatementExpressionList()
2196 void StatementExpressionList() :
2199 StatementExpression() ( <COMMA> StatementExpression() )*
2202 void BreakStatement() :
2205 <BREAK> [ <IDENTIFIER> ]
2208 } catch (ParseException e) {
2209 errorMessage = "';' expected after 'break' statement";
2215 void ContinueStatement() :
2218 <CONTINUE> [ <IDENTIFIER> ]
2221 } catch (ParseException e) {
2222 errorMessage = "';' expected after 'continue' statement";
2228 void ReturnStatement() :
2231 <RETURN> [ Expression() ]
2234 } catch (ParseException e) {
2235 errorMessage = "';' expected after 'return' statement";