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 /** The file that is parsed. */
54 private static IFile fileToParse;
56 /** The current segment */
57 private static PHPSegmentWithChildren 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 PHPOutlineInfo outlineInfo;
63 /** The error level of the current ParseException. */
64 private static int errorLevel = ERROR;
65 /** The message of the current ParseException. If it's null it's because the parse exception wasn't handled */
66 private static String errorMessage;
68 private static int errorStart = -1;
69 private static int errorEnd = -1;
74 public final void setFileToParse(final IFile fileToParse) {
75 this.fileToParse = fileToParse;
78 public PHPParser(final IFile fileToParse) {
79 this(new StringReader(""));
80 this.fileToParse = fileToParse;
83 public static final void phpParserTester(final String strEval) throws CoreException, ParseException {
84 PHPParserTokenManager.SwitchTo(PHPParserTokenManager.PHPPARSING);
85 final StringReader stream = new StringReader(strEval);
86 if (jj_input_stream == null) {
87 jj_input_stream = new SimpleCharStream(stream, 1, 1);
89 ReInit(new StringReader(strEval));
93 public static final void htmlParserTester(final String strEval) throws CoreException, ParseException {
94 final StringReader stream = new StringReader(strEval);
95 if (jj_input_stream == null) {
96 jj_input_stream = new SimpleCharStream(stream, 1, 1);
102 public final PHPOutlineInfo parseInfo(final Object parent, final String s) {
103 outlineInfo = new PHPOutlineInfo(parent);
104 currentSegment = outlineInfo.getDeclarations();
105 final StringReader stream = new StringReader(s);
106 if (jj_input_stream == null) {
107 jj_input_stream = new SimpleCharStream(stream, 1, 1);
112 } catch (ParseException e) {
113 processParseException(e);
119 * This method will process the parse exception.
120 * If the error message is null, the parse exception wasn't catched and a trace is written in the log
121 * @param e the ParseException
123 private static void processParseException(final ParseException e) {
124 if (errorMessage == null) {
125 PHPeclipsePlugin.log(e);
126 errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it";
133 * Create marker for the parse error
134 * @param e the ParseException
136 private static void setMarker(final ParseException e) {
138 if (errorStart == -1) {
139 setMarker(fileToParse,
141 jj_input_stream.tokenBegin,
142 jj_input_stream.tokenBegin + e.currentToken.image.length(),
144 "Line " + e.currentToken.beginLine);
146 setMarker(fileToParse,
151 "Line " + e.currentToken.beginLine);
155 } catch (CoreException e2) {
156 PHPeclipsePlugin.log(e2);
161 * Create markers according to the external parser output
163 private static void createMarkers(final String output, final IFile file) throws CoreException {
164 // delete all markers
165 file.deleteMarkers(IMarker.PROBLEM, false, 0);
170 while ((brIndx = output.indexOf("<br />", indx)) != -1) {
171 // newer php error output (tested with 4.2.3)
172 scanLine(output, file, indx, brIndx);
177 while ((brIndx = output.indexOf("<br>", indx)) != -1) {
178 // older php error output (tested with 4.2.3)
179 scanLine(output, file, indx, brIndx);
185 private static void scanLine(final String output,
188 final int brIndx) throws CoreException {
190 StringBuffer lineNumberBuffer = new StringBuffer(10);
192 current = output.substring(indx, brIndx);
194 if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) {
195 int onLine = current.indexOf("on line <b>");
197 lineNumberBuffer.delete(0, lineNumberBuffer.length());
198 for (int i = onLine; i < current.length(); i++) {
199 ch = current.charAt(i);
200 if ('0' <= ch && '9' >= ch) {
201 lineNumberBuffer.append(ch);
205 int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
207 Hashtable attributes = new Hashtable();
209 current = current.replaceAll("\n", "");
210 current = current.replaceAll("<b>", "");
211 current = current.replaceAll("</b>", "");
212 MarkerUtilities.setMessage(attributes, current);
214 if (current.indexOf(PARSE_ERROR_STRING) != -1)
215 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
216 else if (current.indexOf(PARSE_WARNING_STRING) != -1)
217 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
219 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
220 MarkerUtilities.setLineNumber(attributes, lineNumber);
221 MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
226 public final void parse(final String s) throws CoreException {
227 final StringReader stream = new StringReader(s);
228 if (jj_input_stream == null) {
229 jj_input_stream = new SimpleCharStream(stream, 1, 1);
234 } catch (ParseException e) {
235 processParseException(e);
240 * Call the php parse command ( php -l -f <filename> )
241 * and create markers according to the external parser output
243 public static void phpExternalParse(final IFile file) {
244 final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
245 final String filename = file.getLocation().toString();
247 final String[] arguments = { filename };
248 final MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
249 final String command = form.format(arguments);
251 final String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: ");
254 // parse the buffer to find the errors and warnings
255 createMarkers(parserResult, file);
256 } catch (CoreException e) {
257 PHPeclipsePlugin.log(e);
261 public static final void parse() throws ParseException {
266 PARSER_END(PHPParser)
270 <PHPSTARTSHORT : "<?"> : PHPPARSING
271 | <PHPSTARTLONG : "<?php"> : PHPPARSING
272 | <PHPECHOSTART : "<?="> : PHPPARSING
277 <PHPEND :"?>"> : DEFAULT
299 <PHPPARSING> SPECIAL_TOKEN :
301 "//" : IN_SINGLE_LINE_COMMENT
303 "#" : IN_SINGLE_LINE_COMMENT
305 <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
307 "/*" : IN_MULTI_LINE_COMMENT
310 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
312 <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : PHPPARSING
315 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
317 <SINGLE_LINE_COMMENT_PHPEND : "?>" > : DEFAULT
323 <FORMAL_COMMENT: "*/" > : PHPPARSING
326 <IN_MULTI_LINE_COMMENT>
329 <MULTI_LINE_COMMENT: "*/" > : PHPPARSING
332 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
342 | <FUNCTION : "function">
345 | <ELSEIF : "elseif">
351 /* LANGUAGE CONSTRUCT */
356 | <INCLUDE : "include">
357 | <REQUIRE : "require">
358 | <INCLUDE_ONCE : "include_once">
359 | <REQUIRE_ONCE : "require_once">
360 | <GLOBAL : "global">
361 | <STATIC : "static">
362 | <CLASSACCESS : "->">
363 | <STATICCLASSACCESS : "::">
364 | <ARRAYASSIGN : "=>">
371 /* RESERVED WORDS AND LITERALS */
377 | <CONTINUE : "continue">
378 | <_DEFAULT : "default">
380 | <EXTENDS : "extends">
385 | <RETURN : "return">
387 | <SWITCH : "switch">
392 | <ENDWHILE : "endwhile">
394 | <ENDFOR : "endfor">
395 | <FOREACH : "foreach">
404 | <OBJECT : "object">
406 | <BOOLEAN : "boolean">
408 | <DOUBLE : "double">
411 | <INTEGER : "integer">
425 <DECIMAL_LITERAL> (["l","L"])?
426 | <HEX_LITERAL> (["l","L"])?
427 | <OCTAL_LITERAL> (["l","L"])?
430 < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
432 < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
434 < #OCTAL_LITERAL: "0" (["0"-"7"])* >
436 < FLOATING_POINT_LITERAL:
437 (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
438 | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
439 | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
440 | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
443 < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
445 < STRING_LITERAL: (<STRING_1> | <STRING_2> | <STRING_3>)>
480 < IDENTIFIER: (<LETTER>|<SPECIAL>) (<LETTER>|<DIGIT>|<SPECIAL>)* >
483 ["a"-"z"] | ["A"-"Z"]
491 "_" | ["\u007f"-"\u00ff"]
521 | <BANGDOUBLEEQUAL : "!==">
522 | <TRIPLEEQUAL : "===">
529 | <PLUSASSIGN : "+=">
530 | <MINUSASSIGN : "-=">
531 | <STARASSIGN : "*=">
532 | <SLASHASSIGN : "/=">
538 | <TILDEEQUAL : "~=">
562 | <RSIGNEDSHIFT : ">>">
563 | <RUNSIGNEDSHIFT : ">>>">
564 | <LSHIFTASSIGN : "<<=">
565 | <RSIGNEDSHIFTASSIGN : ">>=">
570 < DOLLAR_ID: <DOLLAR> <IDENTIFIER> >
586 } catch (TokenMgrError e) {
587 errorMessage = e.getMessage();
589 throw generateParseException();
595 final int start = jj_input_stream.bufpos;
598 <PHPECHOSTART> Expression() [ <SEMICOLON> ] <PHPEND>
603 setMarker(fileToParse,
604 "You should use '<?php' instead of '<?' it will avoid some problems with XML",
606 jj_input_stream.bufpos,
608 "Line " + token.beginLine);
609 } catch (CoreException e) {
610 PHPeclipsePlugin.log(e);
616 } catch (ParseException e) {
617 errorMessage = "'?>' expected";
629 void ClassDeclaration() :
631 final PHPClassDeclaration classDeclaration;
632 final Token className;
638 {pos = jj_input_stream.bufpos;}
639 className = <IDENTIFIER>
640 } catch (ParseException e) {
641 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
649 } catch (ParseException e) {
650 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
656 if (currentSegment != null) {
657 classDeclaration = new PHPClassDeclaration(currentSegment,className.image,pos);
658 currentSegment.add(classDeclaration);
659 currentSegment = classDeclaration;
664 if (currentSegment != null) {
665 currentSegment = (PHPSegmentWithChildren) currentSegment.getParent();
675 } catch (ParseException e) {
676 errorMessage = "'{' expected";
680 ( ClassBodyDeclaration() )*
683 } catch (ParseException e) {
684 errorMessage = "'var', 'function' or '}' expected";
690 void ClassBodyDeclaration() :
698 void FieldDeclaration() :
700 PHPVarDeclaration variableDeclaration;
703 <VAR> variableDeclaration = VariableDeclarator()
705 if (currentSegment != null) {
706 currentSegment.add(variableDeclaration);
710 variableDeclaration = VariableDeclarator()
712 if (currentSegment != null) {
713 currentSegment.add(variableDeclaration);
719 } catch (ParseException e) {
720 errorMessage = "';' expected after variable declaration";
726 PHPVarDeclaration VariableDeclarator() :
728 final String varName;
730 final int pos = jj_input_stream.bufpos;
733 varName = VariableDeclaratorId()
737 varValue = VariableInitializer()
738 {return new PHPVarDeclaration(currentSegment,varName,pos,varValue);}
739 } catch (ParseException e) {
740 errorMessage = "Literal expression expected in variable initializer";
745 {return new PHPVarDeclaration(currentSegment,varName,pos);}
748 String VariableDeclaratorId() :
751 final StringBuffer buff = new StringBuffer();
757 ( LOOKAHEAD(2) expr = VariableSuffix()
760 {return buff.toString();}
761 } catch (ParseException e) {
762 errorMessage = "'$' expected for variable identifier";
774 token = <DOLLAR_ID> [<LBRACE> expr = Expression() <RBRACE>]
779 return token + "{" + expr + "}";
782 <DOLLAR> expr = VariableName()
786 String VariableName():
792 <LBRACE> expr = Expression() <RBRACE>
793 {return "{"+expr+"}";}
795 token = <IDENTIFIER> [<LBRACE> expr = Expression() <RBRACE>]
800 return token + "{" + expr + "}";
803 <DOLLAR> expr = VariableName()
806 token = <DOLLAR_ID> [expr = VariableName()]
811 return token.image + expr;
815 String VariableInitializer() :
824 <MINUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
825 {return "-" + token.image;}
827 <PLUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
828 {return "+" + token.image;}
830 expr = ArrayDeclarator()
834 {return token.image;}
837 String ArrayVariable() :
840 final StringBuffer buff = new StringBuffer();
845 [<ARRAYASSIGN> expr = Expression()
846 {buff.append("=>").append(expr);}]
847 {return buff.toString();}
850 String ArrayInitializer() :
853 final StringBuffer buff = new StringBuffer("(");
856 <LPAREN> [ expr = ArrayVariable()
858 ( LOOKAHEAD(2) <COMMA> expr = ArrayVariable()
859 {buff.append(",").append(expr);}
864 return buff.toString();
868 void MethodDeclaration() :
870 final PHPFunctionDeclaration functionDeclaration;
875 functionDeclaration = MethodDeclarator()
876 } catch (ParseException e) {
877 if (errorMessage != null) {
880 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
885 if (currentSegment != null) {
886 currentSegment.add(functionDeclaration);
887 currentSegment = functionDeclaration;
892 if (currentSegment != null) {
893 currentSegment = (PHPSegmentWithChildren) currentSegment.getParent();
898 PHPFunctionDeclaration MethodDeclarator() :
900 final Token identifier;
901 final StringBuffer methodDeclaration = new StringBuffer();
902 final String formalParameters;
903 final int pos = jj_input_stream.bufpos;
906 [ <BIT_AND> {methodDeclaration.append("&");} ]
907 identifier = <IDENTIFIER>
908 {methodDeclaration.append(identifier);}
909 formalParameters = FormalParameters()
911 methodDeclaration.append(formalParameters);
912 return new PHPFunctionDeclaration(currentSegment,methodDeclaration.toString(),pos);
916 String FormalParameters() :
919 final StringBuffer buff = new StringBuffer("(");
924 } catch (ParseException e) {
925 errorMessage = "Formal parameter expected after function identifier";
927 jj_consume_token(token.kind);
929 [ expr = FormalParameter()
932 <COMMA> expr = FormalParameter()
933 {buff.append(",").append(expr);}
938 } catch (ParseException e) {
939 errorMessage = "')' expected";
945 return buff.toString();
949 String FormalParameter() :
951 final PHPVarDeclaration variableDeclaration;
952 final StringBuffer buff = new StringBuffer();
955 [<BIT_AND> {buff.append("&");}] variableDeclaration = VariableDeclarator()
957 buff.append(variableDeclaration.toString());
958 return buff.toString();
993 String Expression() :
996 final String assignOperator;
1000 expr = PrintExpression()
1003 expr = ListExpression()
1006 expr = ConditionalExpression()
1008 assignOperator = AssignmentOperator()
1010 expr2 = Expression()
1011 {return expr + assignOperator + expr2;}
1012 } catch (ParseException e) {
1013 errorMessage = "expression expected";
1021 String AssignmentOperator() :
1038 | <RSIGNEDSHIFTASSIGN>
1052 String ConditionalExpression() :
1055 String expr2 = null;
1056 String expr3 = null;
1059 expr = ConditionalOrExpression() [ <HOOK> expr2 = Expression() <COLON> expr3 = ConditionalExpression() ]
1061 if (expr3 == null) {
1064 return expr + "?" + expr2 + ":" + expr3;
1069 String ConditionalOrExpression() :
1073 final StringBuffer buff = new StringBuffer();
1076 expr = ConditionalAndExpression()
1077 {buff.append(expr);}
1079 (operator = <SC_OR> | operator = <_ORL>) expr = ConditionalAndExpression()
1081 buff.append(operator.image);
1086 return buff.toString();
1090 String ConditionalAndExpression() :
1094 final StringBuffer buff = new StringBuffer();
1097 expr = ConcatExpression()
1098 {buff.append(expr);}
1100 (operator = <SC_AND> | operator = <_ANDL>) expr = ConcatExpression()
1102 buff.append(operator.image);
1106 {return buff.toString();}
1109 String ConcatExpression() :
1112 final StringBuffer buff = new StringBuffer();
1115 expr = InclusiveOrExpression()
1116 {buff.append(expr);}
1118 <DOT> expr = InclusiveOrExpression()
1119 {buff.append(".").append(expr);}
1121 {return buff.toString();}
1124 String InclusiveOrExpression() :
1127 final StringBuffer buff = new StringBuffer();
1130 expr = ExclusiveOrExpression()
1131 {buff.append(expr);}
1133 <BIT_OR> expr = ExclusiveOrExpression()
1134 {buff.append("|").append(expr);}
1136 {return buff.toString();}
1139 String ExclusiveOrExpression() :
1142 final StringBuffer buff = new StringBuffer();
1145 expr = AndExpression()
1150 <XOR> expr = AndExpression()
1157 return buff.toString();
1161 String AndExpression() :
1164 final StringBuffer buff = new StringBuffer();
1167 expr = EqualityExpression()
1172 <BIT_AND> expr = EqualityExpression()
1174 buff.append("&").append(expr);
1177 {return buff.toString();}
1180 String EqualityExpression() :
1184 final StringBuffer buff = new StringBuffer();
1187 expr = RelationalExpression()
1188 {buff.append(expr);}
1193 | operator = <BANGDOUBLEEQUAL>
1194 | operator = <TRIPLEEQUAL>
1197 expr = RelationalExpression()
1198 } catch (ParseException e) {
1199 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected after '"+operator.image+"'";
1204 buff.append(operator.image);
1208 {return buff.toString();}
1211 String RelationalExpression() :
1215 final StringBuffer buff = new StringBuffer();
1218 expr = ShiftExpression()
1219 {buff.append(expr);}
1221 ( operator = <LT> | operator = <GT> | operator = <LE> | operator = <GE> ) expr = ShiftExpression()
1222 {buff.append(operator.image).append(expr);}
1224 {return buff.toString();}
1227 String ShiftExpression() :
1231 final StringBuffer buff = new StringBuffer();
1234 expr = AdditiveExpression()
1235 {buff.append(expr);}
1237 (operator = <LSHIFT> | operator = <RSIGNEDSHIFT> | operator = <RUNSIGNEDSHIFT> ) expr = AdditiveExpression()
1239 buff.append(operator.image);
1243 {return buff.toString();}
1246 String AdditiveExpression() :
1250 final StringBuffer buff = new StringBuffer();
1253 expr = MultiplicativeExpression()
1254 {buff.append(expr);}
1256 ( operator = <PLUS> | operator = <MINUS> ) expr = MultiplicativeExpression()
1258 buff.append(operator.image);
1262 {return buff.toString();}
1265 String MultiplicativeExpression() :
1269 final StringBuffer buff = new StringBuffer();}
1271 expr = UnaryExpression()
1272 {buff.append(expr);}
1274 ( operator = <STAR> | operator = <SLASH> | operator = <REM> ) expr = UnaryExpression()
1276 buff.append(operator.image);
1280 {return buff.toString();}
1284 * An unary expression starting with @, & or nothing
1286 String UnaryExpression() :
1290 final StringBuffer buff = new StringBuffer();
1293 token = <BIT_AND> expr = UnaryExpressionNoPrefix()
1295 if (token == null) {
1298 return token.image + expr;
1301 (<AT> {buff.append("@");})* expr = UnaryExpressionNoPrefix()
1302 {return buff.append(expr).toString();}
1305 String UnaryExpressionNoPrefix() :
1311 ( token = <PLUS> | token = <MINUS> ) expr = UnaryExpression()
1313 return token.image + expr;
1316 expr = PreIncrementExpression()
1319 expr = PreDecrementExpression()
1322 expr = UnaryExpressionNotPlusMinus()
1327 String PreIncrementExpression() :
1332 <INCR> expr = PrimaryExpression()
1336 String PreDecrementExpression() :
1341 <DECR> expr = PrimaryExpression()
1345 String UnaryExpressionNotPlusMinus() :
1350 <BANG> expr = UnaryExpression()
1351 {return "!" + expr;}
1353 LOOKAHEAD( <LPAREN> Type() <RPAREN> )
1354 expr = CastExpression()
1357 expr = PostfixExpression()
1363 <LPAREN> expr = Expression()
1366 } catch (ParseException e) {
1367 errorMessage = "')' expected";
1371 {return "("+expr+")";}
1374 String CastExpression() :
1376 final String type, expr;
1379 <LPAREN> type = Type() <RPAREN> expr = UnaryExpression()
1380 {return "(" + type + ")" + expr;}
1383 String PostfixExpression() :
1386 Token operator = null;
1389 expr = PrimaryExpression() [ operator = <INCR> | operator = <DECR> ]
1391 if (operator == null) {
1394 return expr + operator.image;
1398 String PrimaryExpression() :
1400 final Token identifier;
1402 final StringBuffer buff = new StringBuffer();
1406 identifier = <IDENTIFIER> <STATICCLASSACCESS> expr = ClassIdentifier()
1407 {buff.append(identifier.image).append("::").append(expr);}
1409 expr = PrimarySuffix()
1410 {buff.append(expr);}
1412 {return buff.toString();}
1414 expr = PrimaryPrefix() {buff.append(expr);}
1415 ( expr = PrimarySuffix() {buff.append(expr);} )*
1416 {return buff.toString();}
1418 expr = ArrayDeclarator()
1419 {return "array" + expr;}
1422 String ArrayDeclarator() :
1427 <ARRAY> expr = ArrayInitializer()
1428 {return "array" + expr;}
1431 String PrimaryPrefix() :
1437 token = <IDENTIFIER>
1438 {return token.image;}
1440 <NEW> expr = ClassIdentifier()
1442 return "new " + expr;
1445 expr = VariableDeclaratorId()
1449 String ClassIdentifier():
1455 token = <IDENTIFIER>
1456 {return token.image;}
1458 expr = VariableDeclaratorId()
1462 String PrimarySuffix() :
1470 expr = VariableSuffix()
1474 String VariableSuffix() :
1481 expr = VariableName()
1482 } catch (ParseException e) {
1483 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
1487 {return "->" + expr;}
1489 <LBRACKET> [ expr = Expression() ]
1492 } catch (ParseException e) {
1493 errorMessage = "']' expected";
1501 return "[" + expr + "]";
1511 token = <INTEGER_LITERAL>
1512 {return token.image;}
1514 token = <FLOATING_POINT_LITERAL>
1515 {return token.image;}
1517 token = <STRING_LITERAL>
1518 {return token.image;}
1520 expr = BooleanLiteral()
1523 expr = NullLiteral()
1527 String BooleanLiteral() :
1537 String NullLiteral() :
1544 String Arguments() :
1549 <LPAREN> [ expr = ArgumentList() ]
1552 } catch (ParseException e) {
1553 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
1561 return "(" + expr + ")";
1565 String ArgumentList() :
1568 final StringBuffer buff = new StringBuffer();
1572 {buff.append(expr);}
1576 } catch (ParseException e) {
1577 errorMessage = "expression expected after a comma in argument list";
1582 buff.append(",").append(expr);
1585 {return buff.toString();}
1589 * A Statement without break
1591 void StatementNoBreak() :
1597 (<SEMICOLON> | <PHPEND> {PHPParserTokenManager.SwitchTo(PHPParserTokenManager.DEFAULT);})
1598 } catch (ParseException e) {
1599 errorMessage = "';' expected";
1611 StatementExpression()
1614 } catch (ParseException e) {
1615 errorMessage = "';' expected after expression";
1638 [<AT>] IncludeStatement()
1646 * A Normal statement
1656 void IncludeStatement() :
1659 final int pos = jj_input_stream.bufpos;
1665 if (currentSegment != null) {
1666 currentSegment.add(new PHPReqIncDeclaration(currentSegment, "require",pos,expr));
1670 (<SEMICOLON> | <PHPEND> {PHPParserTokenManager.SwitchTo(PHPParserTokenManager.DEFAULT);})
1671 } catch (ParseException e) {
1672 errorMessage = "';' expected";
1680 if (currentSegment != null) {
1681 currentSegment.add(new PHPReqIncDeclaration(currentSegment, "require_once",pos,expr));
1685 (<SEMICOLON> | <PHPEND> {PHPParserTokenManager.SwitchTo(PHPParserTokenManager.DEFAULT);})
1686 } catch (ParseException e) {
1687 errorMessage = "';' expected";
1695 if (currentSegment != null) {
1696 currentSegment.add(new PHPReqIncDeclaration(currentSegment, "include",pos,expr));
1700 (<SEMICOLON> | <PHPEND> {PHPParserTokenManager.SwitchTo(PHPParserTokenManager.DEFAULT);})
1701 } catch (ParseException e) {
1702 errorMessage = "';' expected";
1710 if (currentSegment != null) {
1711 currentSegment.add(new PHPReqIncDeclaration(currentSegment, "include_once",pos,expr));
1715 (<SEMICOLON> | <PHPEND> {PHPParserTokenManager.SwitchTo(PHPParserTokenManager.DEFAULT);})
1716 } catch (ParseException e) {
1717 errorMessage = "';' expected";
1723 String PrintExpression() :
1725 final StringBuffer buff = new StringBuffer("print ");
1729 <PRINT> expr = Expression()
1732 return buff.toString();
1736 String ListExpression() :
1738 final StringBuffer buff = new StringBuffer("list(");
1745 } catch (ParseException e) {
1746 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
1751 expr = VariableDeclaratorId()
1752 {buff.append(expr);}
1757 } catch (ParseException e) {
1758 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
1762 expr = VariableDeclaratorId()
1763 {buff.append(",").append(expr);}
1768 } catch (ParseException e) {
1769 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
1773 [ <ASSIGN> expr = Expression() {buff.append("(").append(expr);}]
1774 {return buff.toString();}
1777 void EchoStatement() :
1780 <ECHO> Expression() (<COMMA> Expression())*
1782 (<SEMICOLON> | <PHPEND> {PHPParserTokenManager.SwitchTo(PHPParserTokenManager.DEFAULT);})
1783 } catch (ParseException e) {
1784 errorMessage = "';' expected after 'echo' statement";
1790 void GlobalStatement() :
1793 <GLOBAL> VariableDeclaratorId() (<COMMA> VariableDeclaratorId())*
1795 (<SEMICOLON> | <PHPEND> {PHPParserTokenManager.SwitchTo(PHPParserTokenManager.DEFAULT);})
1796 } catch (ParseException e) {
1797 errorMessage = "';' expected";
1803 void StaticStatement() :
1806 <STATIC> VariableDeclarator() (<COMMA> VariableDeclarator())*
1808 (<SEMICOLON> | <PHPEND> {PHPParserTokenManager.SwitchTo(PHPParserTokenManager.DEFAULT);})
1809 } catch (ParseException e) {
1810 errorMessage = "';' expected";
1816 void LabeledStatement() :
1819 <IDENTIFIER> <COLON> Statement()
1827 } catch (ParseException e) {
1828 errorMessage = "'{' expected";
1832 ( BlockStatement() )*
1835 } catch (ParseException e) {
1836 errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected";
1842 void BlockStatement() :
1853 * A Block statement that will not contain any 'break'
1855 void BlockStatementNoBreak() :
1865 void LocalVariableDeclaration() :
1868 LocalVariableDeclarator() ( <COMMA> LocalVariableDeclarator() )*
1871 void LocalVariableDeclarator() :
1874 VariableDeclaratorId() [ <ASSIGN> Expression() ]
1877 void EmptyStatement() :
1883 void StatementExpression() :
1886 PreIncrementExpression()
1888 PreDecrementExpression()
1896 AssignmentOperator() Expression()
1900 void SwitchStatement() :
1902 Token breakToken = null;
1909 } catch (ParseException e) {
1910 errorMessage = "'(' expected after 'switch'";
1917 } catch (ParseException e) {
1918 errorMessage = "')' expected";
1924 } catch (ParseException e) {
1925 errorMessage = "'{' expected";
1930 line = SwitchLabel()
1931 ( BlockStatementNoBreak() )*
1932 [ breakToken = BreakStatement() ]
1935 if (breakToken == null) {
1936 setMarker(fileToParse,
1937 "You should use put a 'break' at the end of your statement",
1942 } catch (CoreException e) {
1943 PHPeclipsePlugin.log(e);
1949 } catch (ParseException e) {
1950 errorMessage = "'}' expected";
1956 Token BreakStatement() :
1961 token = <BREAK> [ Expression() ]
1964 } catch (ParseException e) {
1965 errorMessage = "';' expected after 'break' keyword";
1980 } catch (ParseException e) {
1981 if (errorMessage != null) throw e;
1982 errorMessage = "expression expected after 'case' keyword";
1988 } catch (ParseException e) {
1989 errorMessage = "':' expected after case expression";
1993 {return token.beginLine;}
1998 } catch (ParseException e) {
1999 errorMessage = "':' expected after 'default' keyword";
2003 {return token.beginLine;}
2006 void IfStatement() :
2009 final int pos = jj_input_stream.bufpos;
2012 token = <IF> Condition("if") IfStatement0(pos,pos+token.image.length())
2015 void Condition(final String keyword) :
2020 } catch (ParseException e) {
2021 errorMessage = "'(' expected after " + keyword + " keyword";
2028 } catch (ParseException e) {
2029 errorMessage = "')' expected after " + keyword + " keyword";
2035 void IfStatement0(final int start,final int end) :
2038 <COLON> (Statement())* (ElseIfStatementColon())* [ElseStatementColon()]
2041 setMarker(fileToParse,
2042 "Ugly syntax detected, you should if () {...} instead of if (): ... endif;",
2046 "Line " + token.beginLine);
2047 } catch (CoreException e) {
2048 PHPeclipsePlugin.log(e);
2052 } catch (ParseException e) {
2053 errorMessage = "'endif' expected";
2059 } catch (ParseException e) {
2060 errorMessage = "';' expected after 'endif' keyword";
2065 Statement() ( LOOKAHEAD(1) ElseIfStatement() )* [ LOOKAHEAD(1) <ELSE> Statement() ]
2068 void ElseIfStatementColon() :
2071 <ELSEIF> Condition("elseif") <COLON> (Statement())*
2074 void ElseStatementColon() :
2077 <ELSE> <COLON> (Statement())*
2080 void ElseIfStatement() :
2083 <ELSEIF> Condition("elseif") Statement()
2086 void WhileStatement() :
2089 final int pos = jj_input_stream.bufpos;
2092 token = <WHILE> Condition("while") WhileStatement0(pos,pos + token.image.length())
2095 void WhileStatement0(final int start, final int end) :
2098 <COLON> (Statement())*
2100 setMarker(fileToParse,
2101 "Ugly syntax detected, you should while () {...} instead of while (): ... endwhile;",
2105 "Line " + token.beginLine);
2106 } catch (CoreException e) {
2107 PHPeclipsePlugin.log(e);
2111 } catch (ParseException e) {
2112 errorMessage = "'endwhile' expected";
2117 (<SEMICOLON> | <PHPEND> {PHPParserTokenManager.SwitchTo(PHPParserTokenManager.DEFAULT);})
2118 } catch (ParseException e) {
2119 errorMessage = "';' expected after 'endwhile' keyword";
2127 void DoStatement() :
2130 <DO> Statement() <WHILE> Condition("while")
2132 (<SEMICOLON> | <PHPEND> {PHPParserTokenManager.SwitchTo(PHPParserTokenManager.DEFAULT);})
2133 } catch (ParseException e) {
2134 errorMessage = "';' expected";
2140 void ForeachStatement() :
2146 } catch (ParseException e) {
2147 errorMessage = "'(' expected after 'foreach' keyword";
2153 } catch (ParseException e) {
2154 errorMessage = "variable expected";
2158 [ VariableSuffix() ]
2161 } catch (ParseException e) {
2162 errorMessage = "'as' expected";
2168 } catch (ParseException e) {
2169 errorMessage = "variable expected";
2173 [ <ARRAYASSIGN> Expression() ]
2176 } catch (ParseException e) {
2177 errorMessage = "')' expected after 'foreach' keyword";
2183 } catch (ParseException e) {
2184 if (errorMessage != null) throw e;
2185 errorMessage = "statement expected";
2191 void ForStatement() :
2194 final int pos = jj_input_stream.bufpos;
2200 } catch (ParseException e) {
2201 errorMessage = "'(' expected after 'for' keyword";
2205 [ ForInit() ] <SEMICOLON> [ Expression() ] <SEMICOLON> [ StatementExpressionList() ] <RPAREN>
2209 <COLON> (Statement())*
2212 setMarker(fileToParse,
2213 "Ugly syntax detected, you should for () {...} instead of for (): ... endfor;",
2215 pos+token.image.length(),
2217 "Line " + token.beginLine);
2218 } catch (CoreException e) {
2219 PHPeclipsePlugin.log(e);
2224 } catch (ParseException e) {
2225 errorMessage = "'endfor' expected";
2231 } catch (ParseException e) {
2232 errorMessage = "';' expected after 'endfor' keyword";
2242 LOOKAHEAD(LocalVariableDeclaration())
2243 LocalVariableDeclaration()
2245 StatementExpressionList()
2248 void StatementExpressionList() :
2251 StatementExpression() ( <COMMA> StatementExpression() )*
2254 void ContinueStatement() :
2257 <CONTINUE> [ <IDENTIFIER> ]
2260 } catch (ParseException e) {
2261 errorMessage = "';' expected after 'continue' statement";
2267 void ReturnStatement() :
2270 <RETURN> [ Expression() ]
2273 } catch (ParseException e) {
2274 errorMessage = "';' expected after 'return' statement";