1 /**********************************************************************
2 Copyright (c) 2002 Klaus Hartlage - www.eclipseproject.de
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
9 Klaus Hartlage - www.eclipseproject.de
10 **********************************************************************/
11 package net.sourceforge.phpeclipse.phpeditor.phpparser;
13 import java.text.MessageFormat;
14 import java.util.ArrayList;
15 import java.util.HashMap;
16 import java.util.Hashtable;
17 import java.util.Stack;
19 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
20 import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
21 import net.sourceforge.phpeclipse.phpeditor.PHPString;
22 import net.sourceforge.phpeclipse.phpeditor.php.PHPKeywords;
23 import org.eclipse.core.resources.IFile;
24 import org.eclipse.core.resources.IMarker;
25 import org.eclipse.core.runtime.CoreException;
26 import org.eclipse.core.runtime.IPath;
27 import org.eclipse.jface.preference.IPreferenceStore;
28 import org.eclipse.ui.texteditor.MarkerUtilities;
30 public class PHPParser extends PHPKeywords {
31 // strings for external parser call
32 private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$
33 private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
35 public static final int ERROR = 2;
36 public static final int WARNING = 1;
37 public static final int INFO = 0;
38 private IFile fileToParse;
39 private ArrayList phpList;
41 private int currentPHPString;
42 private boolean phpEnd;
44 private static HashMap keywordMap = null;
52 // row counter for syntax errors:
54 // column counter for syntax errors:
64 private boolean phpMode;
66 final static int TT_EOF = 0;
67 final static int TT_UNDEFINED = 1;
68 final static int TT_HTML = 2;
70 final static int TT_MOD = 30;
71 final static int TT_NOT = 31;
72 final static int TT_DOT = 32;
73 final static int TT_POW = 33;
74 final static int TT_DIV = 34;
75 final static int TT_MULTIPLY = 35;
76 final static int TT_SUBTRACT = 36;
77 final static int TT_ADD = 37;
78 final static int TT_EQUAL = 38;
79 final static int TT_UNEQUAL = 39;
80 final static int TT_GREATER = 40;
81 final static int TT_GREATEREQUAL = 41;
82 final static int TT_LESS = 42;
83 final static int TT_LESSEQUAL = 43;
84 final static int TT_AND = 44;
85 final static int TT_OR = 45;
86 final static int TT_HASH = 46;
87 final static int TT_DDOT = 47;
88 final static int TT_DOTASSIGN = 48;
90 final static int TT_ASSIGN = 49;
91 final static int TT_REF = 50;
92 final static int TT_FOREACH = 51;
93 final static int TT_AMPERSAND = 52;
94 final static int TT_DOLLARLISTOPEN = 53;
95 final static int TT_TILDE = 54;
96 final static int TT_TILDEASSIGN = 55;
97 final static int TT_MODASSIGN = 56;
98 final static int TT_POWASSIGN = 57;
99 final static int TT_RSHIFTASSIGN = 58;
100 final static int TT_LSHIFTASSIGN = 59;
101 final static int TT_ANDASSIGN = 60;
102 final static int TT_QUESTIONMARK = 61;
103 final static int TT_DDOT2 = 62;
104 final static int TT_AT = 63;
105 // final static int TT_HEREDOC = 64;
107 final static int TT_DOLLAROPEN = 127;
108 final static int TT_ARGOPEN = 128;
109 final static int TT_ARGCLOSE = 129;
110 final static int TT_LISTOPEN = 130;
111 final static int TT_LISTCLOSE = 131;
112 final static int TT_PARTOPEN = 132;
113 final static int TT_PARTCLOSE = 133;
114 final static int TT_COMMA = 134;
116 final static int TT_STRING = 136;
117 final static int TT_IDENTIFIER = 138;
118 final static int TT_DIGIT = 139;
119 final static int TT_SEMICOLON = 140;
120 final static int TT_SLOT = 141;
121 final static int TT_SLOTSEQUENCE = 142;
122 final static int TT_DECREMENT = 144;
123 final static int TT_INCREMENT = 145;
124 final static int TT_ADDTO = 146;
125 final static int TT_DIVIDEBY = 147;
126 final static int TT_SUBTRACTFROM = 148;
127 final static int TT_TIMESBY = 149;
128 final static int TT_VARIABLE = 150;
129 final static int TT_INT_NUMBER = 151;
130 final static int TT_DOUBLE_NUMBER = 152;
131 final static int TT_INTERPOLATED_STRING = 153;
132 final static int TT_STRING_CONSTANT = 154;
134 final static int TT_LSHIFT = 155;
135 final static int TT_RSHIFT = 156;
136 final static int TT_EX_EQUAL = 157;
137 final static int TT_EX_UNEQUAL = 158;
138 final static int TT_LINE = 159;
139 // final static int TT_AT = 153; // @
144 *@param sess Description of Parameter
147 public PHPParser(IFile fileToParse) {
148 if (keywordMap == null) {
149 keywordMap = new HashMap();
150 for (int i = 0; i < PHP_KEYWORS.length; i++) {
151 keywordMap.put(PHP_KEYWORS[i], new Integer(PHP_KEYWORD_TOKEN[i]));
154 this.currentPHPString = 0;
155 this.fileToParse = fileToParse;
161 this.columnCount = 0;
168 * Create marker for the parse error
170 private void setMarker(String message, int lineNumber, int errorLevel) throws CoreException {
171 setMarker(fileToParse, message, lineNumber, errorLevel);
174 public static void setMarker(IFile file, String message, int lineNumber, int errorLevel) throws CoreException {
176 Hashtable attributes = new Hashtable();
177 MarkerUtilities.setMessage(attributes, message);
178 switch (errorLevel) {
180 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
183 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
186 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
189 MarkerUtilities.setLineNumber(attributes, lineNumber);
190 MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
194 private void throwSyntaxError(String error) {
196 if (str.length() < chIndx) {
199 // read until end-of-line
201 while (str.length() > eol) {
202 ch = str.charAt(eol++);
208 throw new SyntaxError(rowCount, chIndx - columnCount + 1, str.substring(columnCount, eol), error);
211 private void throwSyntaxError(String error, int startRow) {
213 throw new SyntaxError(startRow, 0, " ", error);
217 * Method Declaration.
221 private void getChar() {
222 if (str.length() > chIndx) {
223 ch = str.charAt(chIndx++);
228 chIndx = str.length() + 1;
234 private void getNextToken_OldVersion() throws CoreException {
237 while (str.length() > chIndx) {
238 ch = str.charAt(chIndx++);
239 token = TT_UNDEFINED;
242 columnCount = chIndx;
243 continue; // while loop
245 if (str.length() == chIndx) {
248 if (!Character.isWhitespace(ch)) {
250 if (str.length() > chIndx) {
251 if (str.charAt(chIndx) == '{') {
253 token = TT_DOLLAROPEN;
260 if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch == '_') || (ch == '$')) {
264 if (ch >= '0' && ch <= '9') {
269 if (str.length() > chIndx) {
270 if (str.charAt(chIndx) == '/') {
272 // read comment until end of line:
273 while ((str.length() > chIndx) && (str.charAt(chIndx) != '\n')) {
277 } else if (str.charAt(chIndx) == '*') {
279 // multi line comment:
280 while (str.length() > chIndx) {
281 if (str.charAt(chIndx) == '*' && (str.length() > (chIndx + 1)) && str.charAt(chIndx + 1) == '/') {
285 ch = str.charAt(chIndx++);
288 columnCount = chIndx;
294 } else if (ch == '#') {
295 // read comment until end of line:
296 while ((str.length() > chIndx) && (str.charAt(chIndx) != '\n')) {
300 } else if (ch == '"') {
301 // read string until end
302 boolean openString = true;
303 while (str.length() > chIndx) {
304 ch = str.charAt(chIndx++);
306 if (str.length() > chIndx) {
307 ch = str.charAt(chIndx++);
309 } else if (ch == '"') {
312 } else if (ch == '\n') {
314 columnCount = chIndx;
318 throwSyntaxError("Open string character '\"' at end of file.");
320 token = TT_INTERPOLATED_STRING;
322 } else if (ch == '\'') {
323 // read string until end
324 boolean openString = true;
325 int startRow = rowCount;
326 while (str.length() > chIndx) {
327 ch = str.charAt(chIndx++);
329 if (str.length() > chIndx) {
330 ch = str.charAt(chIndx++);
332 } else if (ch == '\'') {
335 } else if (ch == '\n') {
337 columnCount = chIndx;
341 throwSyntaxError("Open string character \"'\" at end of file.", startRow);
343 token = TT_STRING_CONSTANT;
345 } else if (ch == '`') {
346 // read string until end
347 boolean openString = true;
348 int startRow = rowCount;
349 while (str.length() > chIndx) {
350 ch = str.charAt(chIndx++);
352 if (str.length() > chIndx) {
353 ch = str.charAt(chIndx++);
355 } else if (ch == '`') {
358 } else if (ch == '\n') {
360 columnCount = chIndx;
364 throwSyntaxError("Open string character \"`\" at end of file.", startRow);
366 token = TT_STRING_CONSTANT;
385 token = TT_LISTCLOSE;
393 token = TT_PARTCLOSE;
401 token = TT_QUESTIONMARK;
408 if (str.length() > chIndx) {
409 if (str.charAt(chIndx) == '=') {
411 token = TT_TILDEASSIGN;
419 if (str.length() > chIndx) {
420 if (str.charAt(chIndx) == '=') {
422 token = TT_DOTASSIGN;
435 if (str.length() > chIndx) {
436 if (str.charAt(chIndx) == '=') {
438 token = TT_MODASSIGN;
445 token = TT_SEMICOLON;
450 if (str.length() > chIndx) {
451 if (str.charAt(chIndx) == '=') {
453 token = TT_POWASSIGN;
462 if (str.length() > chIndx) {
463 if (str.charAt(chIndx) == '=') {
474 if (str.length() > chIndx) {
475 if (str.charAt(chIndx) == '*') {
481 if (str.charAt(chIndx) == '=') {
492 if (str.length() > chIndx) {
493 if (str.charAt(chIndx) == '+') {
495 token = TT_INCREMENT;
499 if (str.charAt(chIndx) == '=') {
509 if (str.length() > chIndx) {
510 if (str.charAt(chIndx) == '-') {
512 token = TT_DECREMENT;
516 if (str.charAt(chIndx) == '=') {
518 token = TT_SUBTRACTFROM;
522 if (str.charAt(chIndx) == '>') {
534 if (str.length() > chIndx) {
535 ch = str.charAt(chIndx);
540 if (str.length() > chIndx) {
541 ch = str.charAt(chIndx);
562 if (str.length() > chIndx) {
563 if (str.charAt(chIndx) == '=') {
566 if (str.length() > chIndx) {
567 ch = str.charAt(chIndx);
571 token = TT_EX_UNEQUAL;
582 if (str.length() > chIndx) {
583 if (str.charAt(chIndx) == '=') {
585 token = TT_GREATEREQUAL;
588 if (str.charAt(chIndx) == '>') {
591 if (str.length() > chIndx) {
592 if (str.charAt(chIndx) == '=') {
594 token = TT_RSHIFTASSIGN;
606 if (str.length() > chIndx) {
607 if (str.charAt(chIndx) == '=') {
609 token = TT_LESSEQUAL;
613 if (str.charAt(chIndx) == '<') {
616 if (str.charAt(chIndx) == '<') {
618 int startRow = rowCount;
619 if (str.length() > chIndx) {
621 ch = str.charAt(++chIndx);
622 if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch == '_')) {
625 token = TT_STRING_CONSTANT;
626 while (str.length() > chIndx) {
627 ch = str.charAt(chIndx++);
629 if (str.length() >= chIndx + identifier.length()) {
630 if (str.substring(chIndx, chIndx + identifier.length()).equals(identifier)) {
631 chIndx += identifier.length();
639 throwSyntaxError("Open heredoc syntax after operator '<<<'.", startRow);
640 } else if (str.charAt(chIndx) == '=') {
642 token = TT_LSHIFTASSIGN;
654 if (str.length() > chIndx) {
655 if (str.charAt(chIndx) == '|') {
665 token = TT_AMPERSAND;
666 if (str.length() > chIndx) {
667 if (str.charAt(chIndx) == '&') {
672 if (str.charAt(chIndx) == '=') {
674 token = TT_ANDASSIGN;
683 if (str.length() > chIndx) {
684 if (str.charAt(chIndx) == ':') {
699 throwSyntaxError("unexpected character: '" + ch + "'");
702 if (token == TT_UNDEFINED) {
703 throwSyntaxError("token not found");
710 chIndx = str.length() + 1;
715 if (phpList != null) {
716 if (currentPHPString < phpList.size()) {
717 token = TT_UNDEFINED;
718 temp = (PHPString) phpList.get(currentPHPString++);
719 this.str = temp.getPHPString();
722 this.rowCount = temp.getLineNumber();
723 this.columnCount = 0;
727 token = TT_UNDEFINED;
733 * gets the next token from input
735 private void getNextToken() throws CoreException {
736 boolean phpFound = false;
743 while (str.length() > chIndx) {
744 token = TT_UNDEFINED;
745 ch = str.charAt(chIndx++);
751 ch2 = str.charAt(chIndx++);
753 ch2 = str.charAt(chIndx++);
754 if (Character.isWhitespace(ch2)) {
759 } else if (ch2 == 'p') {
760 ch2 = str.charAt(chIndx++);
762 ch2 = str.charAt(chIndx++);
771 } else if (ch2 == 'P') {
772 ch2 = str.charAt(chIndx++);
774 ch2 = str.charAt(chIndx++);
793 while (str.length() > chIndx) {
794 ch = str.charAt(chIndx++);
795 token = TT_UNDEFINED;
798 columnCount = chIndx;
799 continue; // while loop
801 if (str.length() == chIndx) {
804 if (!Character.isWhitespace(ch)) {
806 if (str.length() > chIndx) {
807 if (str.charAt(chIndx) == '{') {
809 token = TT_DOLLAROPEN;
816 if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch == '_') || (ch == '$')) {
820 if (ch >= '0' && ch <= '9') {
825 if (str.length() > chIndx) {
826 if (str.charAt(chIndx) == '/') {
829 // read comment until end of line:
830 while ((str.length() > chIndx) && (ch != '\n')) {
831 ch = str.charAt(chIndx++);
833 ch2 = str.charAt(chIndx);
847 } else if (str.charAt(chIndx) == '*') {
849 // multi line comment:
850 while (str.length() > chIndx) {
851 if (str.charAt(chIndx) == '*' && (str.length() > (chIndx + 1)) && str.charAt(chIndx + 1) == '/') {
855 ch = str.charAt(chIndx++);
858 columnCount = chIndx;
864 } else if (ch == '#') {
865 // read comment until end of line:
866 while ((str.length() > chIndx) && (ch != '\n')) {
867 ch = str.charAt(chIndx++);
869 ch2 = str.charAt(chIndx);
883 } else if (ch == '"') {
884 // read string until end
885 boolean openString = true;
886 while (str.length() > chIndx) {
887 ch = str.charAt(chIndx++);
889 if (str.length() > chIndx) {
890 ch = str.charAt(chIndx++);
892 } else if (ch == '"') {
895 } else if (ch == '\n') {
897 columnCount = chIndx;
901 throwSyntaxError("Open string character '\"' at end of file.");
903 token = TT_INTERPOLATED_STRING;
905 } else if (ch == '\'') {
906 // read string until end
907 boolean openString = true;
908 int startRow = rowCount;
909 while (str.length() > chIndx) {
910 ch = str.charAt(chIndx++);
912 if (str.length() > chIndx) {
913 ch = str.charAt(chIndx++);
915 } else if (ch == '\'') {
918 } else if (ch == '\n') {
920 columnCount = chIndx;
924 throwSyntaxError("Open string character \"'\" at end of file.", startRow);
926 token = TT_STRING_CONSTANT;
928 } else if (ch == '`') {
929 // read string until end
930 boolean openString = true;
931 int startRow = rowCount;
932 while (str.length() > chIndx) {
933 ch = str.charAt(chIndx++);
935 if (str.length() > chIndx) {
936 ch = str.charAt(chIndx++);
938 } else if (ch == '`') {
941 } else if (ch == '\n') {
943 columnCount = chIndx;
947 throwSyntaxError("Open string character \"`\" at end of file.", startRow);
949 setMarker("Other string delimiters prefered (found \"`\").", rowCount, PHPParser.INFO);
950 token = TT_STRING_CONSTANT;
969 token = TT_LISTCLOSE;
977 token = TT_PARTCLOSE;
985 token = TT_QUESTIONMARK;
986 if (str.length() > chIndx) {
987 if (str.charAt(chIndx) == '>') {
1003 if (str.length() > chIndx) {
1004 if (str.charAt(chIndx) == '=') {
1006 token = TT_TILDEASSIGN;
1014 if (str.length() > chIndx) {
1015 if (str.charAt(chIndx) == '=') {
1017 token = TT_DOTASSIGN;
1030 if (str.length() > chIndx) {
1031 if (str.charAt(chIndx) == '=') {
1033 token = TT_MODASSIGN;
1040 token = TT_SEMICOLON;
1045 if (str.length() > chIndx) {
1046 if (str.charAt(chIndx) == '=') {
1048 token = TT_POWASSIGN;
1057 if (str.length() > chIndx) {
1058 if (str.charAt(chIndx) == '=') {
1060 token = TT_DIVIDEBY;
1068 token = TT_MULTIPLY;
1069 if (str.length() > chIndx) {
1070 if (str.charAt(chIndx) == '*') {
1076 if (str.charAt(chIndx) == '=') {
1087 if (str.length() > chIndx) {
1088 if (str.charAt(chIndx) == '+') {
1090 token = TT_INCREMENT;
1094 if (str.charAt(chIndx) == '=') {
1103 token = TT_SUBTRACT;
1104 if (str.length() > chIndx) {
1105 if (str.charAt(chIndx) == '-') {
1107 token = TT_DECREMENT;
1111 if (str.charAt(chIndx) == '=') {
1113 token = TT_SUBTRACTFROM;
1117 if (str.charAt(chIndx) == '>') {
1129 if (str.length() > chIndx) {
1130 ch = str.charAt(chIndx);
1135 if (str.length() > chIndx) {
1136 ch = str.charAt(chIndx);
1140 token = TT_EX_EQUAL;
1157 if (str.length() > chIndx) {
1158 if (str.charAt(chIndx) == '=') {
1161 if (str.length() > chIndx) {
1162 ch = str.charAt(chIndx);
1166 token = TT_EX_UNEQUAL;
1177 if (str.length() > chIndx) {
1178 if (str.charAt(chIndx) == '=') {
1180 token = TT_GREATEREQUAL;
1183 if (str.charAt(chIndx) == '>') {
1186 if (str.length() > chIndx) {
1187 if (str.charAt(chIndx) == '=') {
1189 token = TT_RSHIFTASSIGN;
1201 if (str.length() > chIndx) {
1202 if (str.charAt(chIndx) == '=') {
1204 token = TT_LESSEQUAL;
1208 if (str.charAt(chIndx) == '<') {
1211 if (str.charAt(chIndx) == '<') {
1213 int startRow = rowCount;
1214 if (str.length() > chIndx) {
1216 ch = str.charAt(++chIndx);
1217 if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch == '_')) {
1220 token = TT_STRING_CONSTANT;
1221 while (str.length() > chIndx) {
1222 ch = str.charAt(chIndx++);
1224 if (str.length() >= chIndx + identifier.length()) {
1225 if (str.substring(chIndx, chIndx + identifier.length()).equals(identifier)) {
1226 chIndx += identifier.length();
1234 throwSyntaxError("Open heredoc syntax after operator '<<<'.", startRow);
1235 } else if (str.charAt(chIndx) == '=') {
1237 token = TT_LSHIFTASSIGN;
1249 if (str.length() > chIndx) {
1250 if (str.charAt(chIndx) == '|') {
1260 token = TT_AMPERSAND;
1261 if (str.length() > chIndx) {
1262 if (str.charAt(chIndx) == '&') {
1267 if (str.charAt(chIndx) == '=') {
1269 token = TT_ANDASSIGN;
1278 if (str.length() > chIndx) {
1279 if (str.charAt(chIndx) == ':') {
1294 throwSyntaxError("unexpected character: '" + ch + "'");
1297 if (token == TT_UNDEFINED) {
1298 throwSyntaxError("token not found");
1305 } catch (StringIndexOutOfBoundsException e) {
1306 // catched from charAt
1309 chIndx = str.length() + 1;
1314 // if (phpList != null) {
1315 // if (currentPHPString < phpList.size()) {
1316 // token = TT_UNDEFINED;
1317 // temp = (PHPString) phpList.get(currentPHPString++);
1318 // this.str = temp.getPHPString();
1319 // this.token = TT_EOF;
1321 // this.rowCount = temp.getLineNumber();
1322 // this.columnCount = 0;
1326 // token = TT_UNDEFINED;
1332 private void getIdentifier() {
1333 StringBuffer ident = new StringBuffer();
1337 token = TT_VARIABLE;
1339 token = TT_IDENTIFIER;
1342 while ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') || (ch == '_')) {
1346 identifier = ident.toString();
1349 Integer i = (Integer) keywordMap.get(identifier.toLowerCase());
1351 token = i.intValue();
1355 private void getNumber() {
1356 StringBuffer inum = new StringBuffer();
1365 // determine number conversions:
1366 if (firstCh == '0') {
1395 if (numFormat == 16) {
1396 while ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F')) {
1401 while ((ch >= '0' && ch <= '9') || (ch == '.') || (ch == 'E') || (ch == 'e')) {
1402 if ((ch == '.') || (ch == 'E') || (ch == 'e')) {
1403 if (ch == '.' && dFlag != ' ') {
1406 if ((dFlag == 'E') || (dFlag == 'e')) {
1412 if ((ch == '-') || (ch == '+')) {
1426 doubleNumber = new Double(inum.toString());
1427 token = TT_DOUBLE_NUMBER;
1430 longNumber = Long.valueOf(inum.toString(), numFormat);
1431 token = TT_INT_NUMBER;
1435 } catch (Throwable e) {
1436 throwSyntaxError("Number format error: " + inum.toString());
1440 public void htmlParserTester(String input) {
1442 int startLineNumber = 1;
1446 boolean phpMode = false;
1447 boolean phpFound = false;
1449 phpList = new ArrayList();
1450 currentPHPString = 0;
1454 while (i < input.length()) {
1455 ch = input.charAt(i++);
1459 if ((!phpMode) && ch == '<') {
1460 ch2 = input.charAt(i++);
1462 ch2 = input.charAt(i++);
1463 if (Character.isWhitespace(ch2)) {
1468 startLineNumber = lineNumber;
1470 } else if (ch2 == 'p') {
1471 ch2 = input.charAt(i++);
1473 ch2 = input.charAt(i++);
1478 startLineNumber = lineNumber;
1484 } else if (ch2 == 'P') {
1485 ch2 = input.charAt(i++);
1487 ch2 = input.charAt(i++);
1492 startLineNumber = lineNumber;
1505 if (ch == '/' && i < input.length()) {
1506 ch2 = input.charAt(i++);
1508 while (i < input.length()) {
1509 ch = input.charAt(i++);
1510 if (ch == '?' && i < input.length()) {
1511 ch2 = input.charAt(i++);
1515 phpList.add(new PHPString(input.substring(startIndex, i - 2), startLineNumber));
1519 } else if (ch == '\n') {
1525 } else if (ch2 == '*') {
1526 // multi-line comment
1527 while (i < input.length()) {
1528 ch = input.charAt(i++);
1531 } else if (ch == '*' && i < input.length()) {
1532 ch2 = input.charAt(i++);
1543 } else if (ch == '#') {
1544 while (i < input.length()) {
1545 ch = input.charAt(i++);
1546 if (ch == '?' && i < input.length()) {
1547 ch2 = input.charAt(i++);
1551 phpList.add(new PHPString(input.substring(startIndex, i - 2), startLineNumber));
1555 } else if (ch == '\n') {
1561 } else if (ch == '"') {
1563 while (i < input.length()) {
1564 ch = input.charAt(i++);
1567 } else if (ch == '\\' && i < input.length()) { // escape
1569 } else if (ch == '"') {
1574 } else if (ch == '\'') {
1576 while (i < input.length()) {
1577 ch = input.charAt(i++);
1580 } else if (ch == '\\' && i < input.length()) { // escape
1582 } else if (ch == '\'') {
1589 if (ch == '?' && i < input.length()) {
1590 ch2 = input.charAt(i++);
1594 phpList.add(new PHPString(input.substring(startIndex, i - 2), startLineNumber));
1603 setMarker("No PHP source code found.", lineNumber, PHPParser.INFO);
1606 setMarker("Open PHP tag at end of file.", lineNumber, PHPParser.INFO);
1607 phpList.add(new PHPString(input.substring(startIndex, i - 2), startLineNumber));
1609 // for (int j=0;j<phpList.size();j++) {
1610 // String temp = ((PHPString)phpList.get(j)).getPHPString();
1611 // int startIndx = temp.length()-10;
1612 // if (startIndx<0) {
1615 // System.out.println(temp.substring(startIndx)+"?>");
1617 phpParserTester(null, 1);
1619 // for(int j=0;j<phpList.size();j++) {
1620 // temp = (PHPString) phpList.get(j);
1621 // parser.start(temp.getPHPString(), temp.getLineNumber());
1624 } catch (CoreException e) {
1628 public void phpParserTester(String s, int rowCount) throws CoreException {
1631 if (phpList.size() != 0) {
1632 this.str = ((PHPString) phpList.get(currentPHPString++)).getPHPString();
1635 this.token = TT_EOF;
1637 this.rowCount = rowCount;
1638 this.columnCount = 0;
1639 this.phpEnd = false;
1640 this.phpMode = true;
1644 if (token != TT_EOF && token != TT_UNDEFINED) {
1647 if (token != TT_EOF && token != TT_UNDEFINED) {
1648 if (token == TT_ARGCLOSE) {
1649 throwSyntaxError("Too many closing ')'; end-of-file not reached.");
1651 if (token == TT_LISTCLOSE) {
1652 throwSyntaxError("Too many closing '}'; end-of-file not reached.");
1654 if (token == TT_PARTCLOSE) {
1655 throwSyntaxError("Too many closing ']'; end-of-file not reached.");
1658 if (token == TT_ARGOPEN) {
1659 throwSyntaxError("Read character '('; end-of-file not reached.");
1661 if (token == TT_LISTOPEN) {
1662 throwSyntaxError("Read character '{'; end-of-file not reached.");
1664 if (token == TT_PARTOPEN) {
1665 throwSyntaxError("Read character '['; end-of-file not reached.");
1668 throwSyntaxError("End-of-file not reached.");
1671 } catch (SyntaxError err) {
1675 setMarker(err.getMessage(), err.getLine(), ERROR);
1677 // if an error occured,
1678 // try to find keywords 'class' or 'function'
1679 // to parse the rest of the string
1680 while (token != TT_EOF && token != TT_UNDEFINED) {
1681 if (token == TT_class || token == TT_function) {
1686 if (token == TT_EOF || token == TT_UNDEFINED) {
1695 * Parses a string with php tags
1696 * i.e. '<body> <?php phpinfo() ?> </body>'
1698 public void parse(String s) throws CoreException {
1700 this.token = TT_EOF;
1703 this.columnCount = 0;
1704 this.phpEnd = false;
1705 this.phpMode = false;
1709 if (token != TT_EOF && token != TT_UNDEFINED) {
1712 if (token != TT_EOF && token != TT_UNDEFINED) {
1713 if (token == TT_ARGCLOSE) {
1714 throwSyntaxError("Too many closing ')'; end-of-file not reached.");
1716 if (token == TT_LISTCLOSE) {
1717 throwSyntaxError("Too many closing '}'; end-of-file not reached.");
1719 if (token == TT_PARTCLOSE) {
1720 throwSyntaxError("Too many closing ']'; end-of-file not reached.");
1723 if (token == TT_ARGOPEN) {
1724 throwSyntaxError("Read character '('; end-of-file not reached.");
1726 if (token == TT_LISTOPEN) {
1727 throwSyntaxError("Read character '{'; end-of-file not reached.");
1729 if (token == TT_PARTOPEN) {
1730 throwSyntaxError("Read character '['; end-of-file not reached.");
1733 throwSyntaxError("End-of-file not reached.");
1736 } catch (SyntaxError sytaxErr1) {
1737 setMarker(sytaxErr1.getMessage(), sytaxErr1.getLine(), ERROR);
1739 // if an error occured,
1740 // try to find keywords 'class' or 'function'
1741 // to parse the rest of the string
1742 while (token != TT_EOF && token != TT_UNDEFINED) {
1743 if (token == TT_class || token == TT_function) {
1748 if (token == TT_EOF || token == TT_UNDEFINED) {
1751 } catch (SyntaxError sytaxErr2) {
1752 setMarker(sytaxErr2.getMessage(), sytaxErr2.getLine(), ERROR);
1760 public PHPOutlineInfo parseInfo(Object parent, String s) {
1761 PHPOutlineInfo outlineInfo = new PHPOutlineInfo(parent);
1762 // Stack stack = new Stack();
1763 // stack.push(outlineInfo.getDeclarations());
1766 this.token = TT_EOF;
1769 this.columnCount = 0;
1770 this.phpEnd = false;
1771 this.phpMode = false;
1775 parseDeclarations(outlineInfo, outlineInfo.getDeclarations(), false);
1776 } catch (CoreException e) {
1781 private void parseDeclarations(PHPOutlineInfo outlineInfo, PHPClassDeclaration current, boolean goBack) {
1782 // PHPClassDeclaration current = (PHPClassDeclaration) stack.peek();
1783 PHPClassDeclaration temp;
1787 while (token != TT_EOF && token != TT_UNDEFINED) {
1788 if (token == TT_VARIABLE) {
1789 outlineInfo.addVariable(identifier);
1791 } else if (token == TT_function) {
1793 if (token == TT_IDENTIFIER) {
1794 outlineInfo.addVariable(identifier);
1795 current.add(new PHPFunctionDeclaration(current, identifier, chIndx - identifier.length()));
1798 } else if (token == TT_class) {
1800 if (token == TT_IDENTIFIER) {
1801 outlineInfo.addVariable(identifier);
1802 temp = new PHPClassDeclaration(current, identifier, chIndx - identifier.length());
1804 // stack.push(temp);
1806 while (token != TT_LISTOPEN && token != TT_EOF && token != TT_UNDEFINED) {
1809 parseDeclarations(outlineInfo, temp, true);
1812 } else if (token == TT_LISTOPEN) {
1815 } else if (token == TT_LISTCLOSE) {
1818 if (counter == 0 && goBack) {
1825 } catch (CoreException e) {
1829 private void statementList() throws CoreException {
1832 if ((token == TT_LISTCLOSE)
1833 || (token == TT_case)
1834 || (token == TT_default)
1835 || (token == TT_elseif)
1836 || (token == TT_endif)
1837 || (token == TT_endfor)
1838 || (token == TT_endforeach)
1839 || (token == TT_endwhile)
1840 || (token == TT_endswitch)
1841 || (token == TT_EOF)
1842 || (token == TT_UNDEFINED)) {
1848 private void compoundStatement() throws CoreException {
1849 // '{' [statement-list] '}'
1850 if (token == TT_LISTOPEN) {
1853 throwSyntaxError("'{' expected in compound-statement.");
1855 if (token != TT_LISTCLOSE) {
1858 if (token == TT_LISTCLOSE) {
1861 throwSyntaxError("'}' expected in compound-statement.");
1865 private void statement() throws CoreException {
1866 // if (token > TT_KEYWORD && token != TT_list && token != TT_new) {
1867 String keyword = identifier;
1868 if (token == TT_include || token == TT_include_once) {
1871 if (token == TT_SEMICOLON) {
1875 throwSyntaxError("';' character after 'include' or 'include_once' expected.");
1880 } else if (token == TT_require || token == TT_require_once) {
1884 if (token == TT_SEMICOLON) {
1888 throwSyntaxError("';' character after 'require' or 'require_once' expected.");
1893 } else if (token == TT_if) {
1895 if (token == TT_ARGOPEN) {
1898 throwSyntaxError("'(' expected after 'if' keyword.");
1901 if (token == TT_ARGCLOSE) {
1904 throwSyntaxError("')' expected after 'if' condition.");
1909 } else if (token == TT_switch) {
1911 if (token == TT_ARGOPEN) {
1914 throwSyntaxError("'(' expected after 'switch' keyword.");
1917 if (token == TT_ARGCLOSE) {
1920 throwSyntaxError("')' expected after 'switch' condition.");
1924 } else if (token == TT_for) {
1926 if (token == TT_ARGOPEN) {
1929 throwSyntaxError("'(' expected after 'for' keyword.");
1931 if (token == TT_SEMICOLON) {
1935 if (token == TT_SEMICOLON) {
1938 throwSyntaxError("';' expected after 'for'.");
1941 if (token == TT_SEMICOLON) {
1945 if (token == TT_SEMICOLON) {
1948 throwSyntaxError("';' expected after 'for'.");
1951 if (token == TT_ARGCLOSE) {
1955 if (token == TT_ARGCLOSE) {
1958 throwSyntaxError("')' expected after 'for'.");
1963 } else if (token == TT_while) {
1965 if (token == TT_ARGOPEN) {
1968 throwSyntaxError("'(' expected after 'while' keyword.");
1971 if (token == TT_ARGCLOSE) {
1974 throwSyntaxError("')' expected after 'while' condition.");
1978 } else if (token == TT_do) {
1980 if (token == TT_LISTOPEN) {
1983 throwSyntaxError("'{' expected after 'do' keyword.");
1985 if (token != TT_LISTCLOSE) {
1988 if (token == TT_LISTCLOSE) {
1991 throwSyntaxError("'}' expected after 'do' keyword.");
1993 if (token == TT_while) {
1995 if (token == TT_ARGOPEN) {
1998 throwSyntaxError("'(' expected after 'while' keyword.");
2001 if (token == TT_ARGCLOSE) {
2004 throwSyntaxError("')' expected after 'while' condition.");
2007 throwSyntaxError("'while' expected after 'do' keyword.");
2009 if (token == TT_SEMICOLON) {
2013 throwSyntaxError("';' expected after do-while statement.");
2018 } else if (token == TT_foreach) {
2020 if (token == TT_ARGOPEN) {
2023 throwSyntaxError("'(' expected after 'foreach' keyword.");
2026 if (token == TT_as) {
2029 throwSyntaxError("'as' expected after 'foreach' exxpression.");
2032 if (token == TT_FOREACH) {
2036 if (token == TT_ARGCLOSE) {
2039 throwSyntaxError("')' expected after 'foreach' expression.");
2044 } else if (token == TT_continue || token == TT_break || token == TT_return) {
2046 if (token != TT_SEMICOLON) {
2049 if (token == TT_SEMICOLON) {
2053 throwSyntaxError("';' expected after 'continue', 'break' or 'return'.");
2059 } else if (token == TT_echo) {
2062 if (token == TT_SEMICOLON) {
2066 throwSyntaxError("';' expected after 'echo' statement.");
2071 // } else if (token == TT_print) {
2074 // if (token == TT_SEMICOLON) {
2078 // throwSyntaxError("';' expected after 'print' statement.");
2084 } else if (token == TT_global || token == TT_static) {
2087 if (token == TT_SEMICOLON) {
2091 throwSyntaxError("';' expected after 'global' or 'static' statement.");
2097 // } else if (token == TT_unset) {
2099 // if (token == TT_ARGOPEN) {
2102 // throwSyntaxError("'(' expected after 'unset' keyword.");
2105 // if (token == TT_ARGCLOSE) {
2108 // throwSyntaxError("')' expected after 'unset' statement.");
2110 // if (token == TT_SEMICOLON) {
2114 // throwSyntaxError("';' expected after 'unset' statement.");
2120 // } else if (token == TT_exit || token == TT_die) {
2122 // if (token != TT_SEMICOLON) {
2125 // if (token == TT_SEMICOLON) {
2129 // throwSyntaxError("';' expected after 'exit' or 'die' statement.");
2135 } else if (token == TT_define) {
2137 if (token == TT_ARGOPEN) {
2140 throwSyntaxError("'(' expected after 'define' keyword.");
2143 if (token == TT_COMMA) {
2146 throwSyntaxError("',' expected after first 'define' constant.");
2149 if (token == TT_COMMA) {
2153 if (token == TT_ARGCLOSE) {
2156 throwSyntaxError("')' expected after 'define' statement.");
2158 if (token == TT_SEMICOLON) {
2162 throwSyntaxError("';' expected after 'define' statement.");
2167 } else if (token == TT_function) {
2169 functionDefinition();
2171 } else if (token == TT_class) {
2177 // throwSyntaxError("Unexpected keyword '" + keyword + "'");
2178 } else if (token == TT_LISTOPEN) {
2179 // compoundStatement
2181 if (token != TT_LISTCLOSE) {
2184 if (token == TT_LISTCLOSE) {
2188 throwSyntaxError("'}' expected.");
2191 if (token != TT_SEMICOLON) {
2194 if (token == TT_SEMICOLON) {
2199 throwSyntaxError("';' expected after expression.");
2206 private void classDeclarator() throws CoreException {
2208 //identifier 'extends' identifier
2209 if (token == TT_IDENTIFIER) {
2211 if (token == TT_extends) {
2213 if (token == TT_IDENTIFIER) {
2216 throwSyntaxError("Class name expected after keyword 'extends'.");
2220 throwSyntaxError("Class name expected after keyword 'class'.");
2224 private void classBody() throws CoreException {
2225 //'{' [class-element-list] '}'
2226 if (token == TT_LISTOPEN) {
2228 if (token != TT_LISTCLOSE) {
2231 if (token == TT_LISTCLOSE) {
2234 throwSyntaxError("'}' expected at end of class body.");
2237 throwSyntaxError("'{' expected at start of class body.");
2241 private void classElementList() throws CoreException {
2244 } while (token == TT_function || token == TT_var);
2247 private void classElement() throws CoreException {
2249 //function-definition
2250 if (token == TT_function) {
2252 functionDefinition();
2253 } else if (token == TT_var) {
2257 throwSyntaxError("'function' or 'var' expected.");
2261 private void classProperty() throws CoreException {
2262 //'var' variable ';'
2263 //'var' variable '=' constant ';'
2265 if (token == TT_VARIABLE) {
2267 if (token == TT_ASSIGN) {
2272 throwSyntaxError("Variable expected after keyword 'var'.");
2274 if (token != TT_COMMA) {
2279 if (token == TT_SEMICOLON) {
2282 throwSyntaxError("';' expected after variable declaration.");
2286 private void functionDefinition() throws CoreException {
2287 functionDeclarator();
2288 compoundStatement();
2291 private void functionDeclarator() throws CoreException {
2292 //identifier '(' [parameter-list] ')'
2293 if (token == TT_AMPERSAND) {
2296 if (token == TT_IDENTIFIER) {
2298 if (token == TT_ARGOPEN) {
2301 throwSyntaxError("'(' expected in function declaration.");
2303 if (token != TT_ARGCLOSE) {
2306 if (token != TT_ARGCLOSE) {
2307 throwSyntaxError("')' expected in function declaration.");
2314 private void parameterList() throws CoreException {
2315 //parameter-declaration
2316 //parameter-list ',' parameter-declaration
2318 parameterDeclaration();
2319 if (token != TT_COMMA) {
2326 private void parameterDeclaration() throws CoreException {
2328 //variable-reference
2329 if (token == TT_AMPERSAND) {
2331 if (token == TT_VARIABLE) {
2334 throwSyntaxError("Variable expected after reference operator '&'.");
2337 //variable '=' constant
2338 if (token == TT_VARIABLE) {
2340 if (token == TT_ASSIGN) {
2348 private void labeledStatementList() throws CoreException {
2349 if (token != TT_case && token != TT_default) {
2350 throwSyntaxError("'case' or 'default' expected.");
2353 if (token == TT_case) {
2356 if (token == TT_DDOT) {
2358 if (token == TT_case || token == TT_default) { // empty case statement ?
2362 } else if (token == TT_SEMICOLON) {
2363 setMarker("':' expected after 'case' keyword found ';'.", rowCount, PHPParser.INFO);
2365 if (token == TT_case) { // empty case statement ?
2370 throwSyntaxError("':' character after 'case' constant expected.");
2372 } else { // TT_default
2374 if (token == TT_DDOT) {
2378 throwSyntaxError("':' character after 'default' expected.");
2381 } while (token == TT_case || token == TT_default);
2384 // public void labeledStatement() {
2385 // if (token == TT_case) {
2388 // if (token == TT_DDOT) {
2392 // throwSyntaxError("':' character after 'case' constant expected.");
2395 // } else if (token == TT_default) {
2397 // if (token == TT_DDOT) {
2401 // throwSyntaxError("':' character after 'default' expected.");
2407 // public void expressionStatement() {
2410 // private void inclusionStatement() {
2413 // public void compoundStatement() {
2416 // public void selectionStatement() {
2419 // public void iterationStatement() {
2422 // public void jumpStatement() {
2425 // public void outputStatement() {
2428 // public void scopeStatement() {
2431 // public void flowStatement() {
2434 // public void definitionStatement() {
2437 private void ifStatement() throws CoreException {
2438 // ':' statement-list [elseif-list] [else-colon-statement] 'endif' ';'
2439 if (token == TT_DDOT) {
2445 if (token == TT_DDOT) {
2449 if (token == TT_if) { //'else if'
2451 elseifStatementList();
2453 throwSyntaxError("':' expected after 'else'.");
2459 elseifStatementList();
2463 if (token != TT_endif) {
2464 throwSyntaxError("'endif' expected.");
2467 if (token != TT_SEMICOLON) {
2468 throwSyntaxError("';' expected after if-statement.");
2472 // statement [else-statement]
2474 if (token == TT_elseif) {
2476 if (token == TT_ARGOPEN) {
2479 throwSyntaxError("'(' expected after 'elseif' keyword.");
2482 if (token == TT_ARGCLOSE) {
2485 throwSyntaxError("')' expected after 'elseif' condition.");
2488 } else if (token == TT_else) {
2495 private void elseifStatementList() throws CoreException {
2501 if (token == TT_DDOT) {
2506 if (token == TT_if) { //'else if'
2509 throwSyntaxError("':' expected after 'else'.");
2522 private void elseifStatement() throws CoreException {
2523 if (token == TT_ARGOPEN) {
2526 if (token != TT_ARGOPEN) {
2527 throwSyntaxError("')' expected in else-if-statement.");
2530 if (token != TT_DDOT) {
2531 throwSyntaxError("':' expected in else-if-statement.");
2538 private void switchStatement() throws CoreException {
2539 if (token == TT_DDOT) {
2540 // ':' [labeled-statement-list] 'endswitch' ';'
2542 labeledStatementList();
2543 if (token != TT_endswitch) {
2544 throwSyntaxError("'endswitch' expected.");
2547 if (token != TT_SEMICOLON) {
2548 throwSyntaxError("';' expected after switch-statement.");
2552 // '{' [labeled-statement-list] '}'
2553 if (token != TT_LISTOPEN) {
2554 throwSyntaxError("'{' expected in switch statement.");
2557 if (token != TT_LISTCLOSE) {
2558 labeledStatementList();
2560 if (token != TT_LISTCLOSE) {
2561 throwSyntaxError("'}' expected in switch statement.");
2568 private void forStatement() throws CoreException {
2569 if (token == TT_DDOT) {
2572 if (token != TT_endfor) {
2573 throwSyntaxError("'endfor' expected.");
2576 if (token != TT_SEMICOLON) {
2577 throwSyntaxError("';' expected after for-statement.");
2585 private void whileStatement() throws CoreException {
2586 // ':' statement-list 'endwhile' ';'
2587 if (token == TT_DDOT) {
2590 if (token != TT_endwhile) {
2591 throwSyntaxError("'endwhile' expected.");
2594 if (token != TT_SEMICOLON) {
2595 throwSyntaxError("';' expected after while-statement.");
2603 private void foreachStatement() throws CoreException {
2604 if (token == TT_DDOT) {
2607 if (token != TT_endforeach) {
2608 throwSyntaxError("'endforeach' expected.");
2611 if (token != TT_SEMICOLON) {
2612 throwSyntaxError("';' expected after foreach-statement.");
2620 private void exitStatus() throws CoreException {
2621 if (token == TT_ARGOPEN) {
2624 throwSyntaxError("'(' expected in 'exit-status'.");
2626 if (token != TT_ARGCLOSE) {
2629 if (token == TT_ARGCLOSE) {
2632 throwSyntaxError("')' expected after 'exit-status'.");
2636 private void expressionList() throws CoreException {
2639 if (token == TT_COMMA) {
2647 private void expression() throws CoreException {
2648 // if (token == TT_STRING_CONSTANT || token == TT_INTERPOLATED_STRING) {
2651 logicalinclusiveorExpression();
2652 // while (token != TT_SEMICOLON) {
2658 private void postfixExpression() throws CoreException {
2660 boolean castFlag = false;
2675 case TT_STRING_CONSTANT :
2678 case TT_INTERPOLATED_STRING :
2683 if (token == TT_IDENTIFIER) {
2684 // check if identifier is a type:
2686 String str = identifier.toLowerCase();
2687 for (int i = 0; i < PHP_TYPES.length; i++) {
2688 if (PHP_TYPES[i].equals(str)) {
2695 if (token != TT_ARGCLOSE) {
2696 throwSyntaxError(") expected after cast-type '" + ident + "'.");
2706 if (token != TT_ARGCLOSE) {
2707 throwSyntaxError(") expected in postfix-expression.");
2711 case TT_DOUBLE_NUMBER :
2714 case TT_INT_NUMBER :
2717 case TT_DOLLAROPEN :
2720 if (token != TT_LISTCLOSE) {
2721 throwSyntaxError("'}' expected after indirect variable token '${'.");
2728 if (token == TT_LISTOPEN) {
2731 if (token != TT_LISTCLOSE) {
2732 throwSyntaxError("'}' expected after variable '" + ident + "' in variable-expression.");
2735 } else if (token == TT_ARGOPEN) {
2737 if (token != TT_ARGCLOSE) {
2739 if (token != TT_ARGCLOSE) {
2740 throwSyntaxError("')' expected after variable '" + ident + "' in postfix-expression.");
2746 case TT_IDENTIFIER :
2749 if (token == TT_ARGOPEN) {
2751 if (token != TT_ARGCLOSE) {
2753 if (token != TT_ARGCLOSE) {
2754 throwSyntaxError("')' expected after identifier '" + ident + "' in postfix-expression.");
2763 // if (token == TT_SEMICOLON) {
2767 // throwSyntaxError("';' expected after 'print' statement.");
2774 if (token == TT_ARGOPEN) {
2776 if (token == TT_COMMA) {
2780 if (token != TT_ARGCLOSE) {
2781 throwSyntaxError("')' expected after 'list' keyword.");
2784 // if (token == TT_SET) {
2786 // logicalinclusiveorExpression();
2789 throwSyntaxError("'(' expected after 'list' keyword.");
2794 // if (token != TT_SEMICOLON) {
2797 // if (token == TT_SEMICOLON) {
2801 // throwSyntaxError("';' expected after 'exit' expression.");
2808 // if (token != TT_SEMICOLON) {
2811 // if (token == TT_SEMICOLON) {
2815 // throwSyntaxError("';' expected after 'die' expression.");
2822 // if (token == TT_ARGOPEN) {
2824 // if (token == TT_COMMA) {
2827 // expressionList();
2828 // if (token != TT_ARGCLOSE) {
2829 // throwSyntaxError("')' expected after 'list' keyword.");
2832 // if (token == TT_SET) {
2834 // logicalinclusiveorExpression();
2837 // throwSyntaxError("'(' expected after 'list' keyword.");
2841 boolean while_flag = true;
2847 if (token != TT_PARTCLOSE) {
2848 throwSyntaxError("] expected in postfix-expression.");
2852 case TT_DDOT2 : // ::
2855 if (token > TT_KEYWORD) {
2857 setMarker("Avoid using keyword '" + ident + "' as variable name.", rowCount, PHPParser.INFO);
2863 // if (token == TT_ARGOPEN) {
2865 // expressionList();
2866 // if (token != TT_ARGCLOSE) {
2867 // throwSyntaxError(") expected after variable '" + ident + "'.");
2872 case TT_IDENTIFIER :
2879 if (token != TT_LISTCLOSE) {
2880 throwSyntaxError("} expected in postfix-expression.");
2885 throwSyntaxError("Syntax error after '->' token.");
2886 } while (token == TT_PARTOPEN || token == TT_ARGOPEN || token == TT_LISTOPEN) {
2887 if (token == TT_PARTOPEN) {
2890 if (token != TT_PARTCLOSE) {
2891 throwSyntaxError("] expected after '->'.");
2895 if (token == TT_ARGOPEN) {
2898 if (token != TT_ARGCLOSE) {
2899 throwSyntaxError(") expected after '->'.");
2903 if (token == TT_LISTOPEN) {
2906 if (token != TT_LISTCLOSE) {
2907 throwSyntaxError("} expected after '->'.");
2927 private void unaryExpression() throws CoreException {
2937 // '@' '&' '*' '+' '-' '~' '!'
2967 postfixExpression();
2971 private void castExpression() throws CoreException {
2972 // if (token == TT_ARGOPEN) {
2975 // if (token != TT_ARGCLOSE) {
2976 // throwSyntaxError(") expected after cast-expression.");
2983 private void typeName() throws CoreException {
2984 //'string' 'unset' 'array' 'object'
2986 //'real' 'double' 'float'
2989 if (token == TT_IDENTIFIER) {
2991 String str = identifier.toLowerCase();
2993 for (int i = 0; i < PHP_TYPES.length; i++) {
2994 if (PHP_TYPES[i].equals(str)) {
2999 throwSyntaxError("Expected type cast '( <type-name> )'; Got '" + ident + "'.");
3002 private void assignExpression() throws CoreException {
3004 if (token == TT_ASSIGN) { // =
3006 logicalinclusiveorExpression();
3007 } else if (token == TT_DOTASSIGN) { // .=
3009 logicalinclusiveorExpression();
3010 } else if (token == TT_FOREACH) { // =>
3012 logicalinclusiveorExpression();
3013 } else if (token == TT_ADDTO) { // +=
3015 logicalinclusiveorExpression();
3016 } else if (token == TT_SUBTRACTFROM) { // -=
3018 logicalinclusiveorExpression();
3019 } else if (token == TT_TIMESBY) { // *=
3021 logicalinclusiveorExpression();
3022 } else if (token == TT_DIVIDEBY) { // *=
3024 logicalinclusiveorExpression();
3025 } else if (token == TT_MODASSIGN) { // %=
3027 logicalinclusiveorExpression();
3028 } else if (token == TT_ANDASSIGN) { // &=
3030 logicalinclusiveorExpression();
3031 } else if (token == TT_POWASSIGN) { // ^=
3033 logicalinclusiveorExpression();
3034 } else if (token == TT_LSHIFTASSIGN) { // <<=
3036 logicalinclusiveorExpression();
3037 } else if (token == TT_RSHIFTASSIGN) { // >>=
3039 logicalinclusiveorExpression();
3040 } else if (token == TT_TILDEASSIGN) { // ~=
3042 logicalinclusiveorExpression();
3046 private void multiplicativeExpression() throws CoreException {
3049 if (token != TT_MULTIPLY && token != TT_DIV && token != TT_MOD) {
3056 private void concatenationExpression() throws CoreException {
3058 multiplicativeExpression();
3059 if (token != TT_DOT) {
3066 private void additiveExpression() throws CoreException {
3068 concatenationExpression();
3069 if (token != TT_ADD && token != TT_SUBTRACT) {
3076 private void shiftExpression() throws CoreException {
3078 additiveExpression();
3079 if (token != TT_LSHIFT && token != TT_RSHIFT) {
3086 private void relationalExpression() throws CoreException {
3089 if (token != TT_LESS && token != TT_GREATER && token != TT_LESSEQUAL && token != TT_GREATEREQUAL) {
3096 private void identicalExpression() throws CoreException {
3098 relationalExpression();
3099 if (token != TT_EX_EQUAL && token != TT_EX_UNEQUAL) {
3106 private void equalityExpression() throws CoreException {
3108 identicalExpression();
3109 if (token != TT_EQUAL && token != TT_UNEQUAL) {
3116 private void ternaryExpression() throws CoreException {
3117 equalityExpression();
3118 if (token == TT_QUESTIONMARK) {
3121 if (token == TT_DDOT) {
3125 throwSyntaxError("':' expected in ternary operator '? :'.");
3130 private void andExpression() throws CoreException {
3132 ternaryExpression();
3133 if (token != TT_AMPERSAND) {
3140 private void exclusiveorExpression() throws CoreException {
3143 if (token != TT_POW) {
3150 private void inclusiveorExpression() throws CoreException {
3152 exclusiveorExpression();
3153 if (token != TT_LINE) {
3160 private void booleanandExpression() throws CoreException {
3162 inclusiveorExpression();
3163 if (token != TT_AND) {
3170 private void booleanorExpression() throws CoreException {
3172 booleanandExpression();
3173 if (token != TT_OR) {
3180 private void logicalandExpression() throws CoreException {
3182 booleanorExpression();
3183 if (token != TT_and) {
3190 private void logicalexclusiveorExpression() throws CoreException {
3192 logicalandExpression();
3193 if (token != TT_xor) {
3200 private void logicalinclusiveorExpression() throws CoreException {
3202 logicalexclusiveorExpression();
3203 if (token != TT_or) {
3210 // public void assignmentExpression() {
3211 // if (token == TT_VARIABLE) {
3213 // if (token == TT_SET) {
3215 // logicalinclusiveorExpression();
3218 // logicalinclusiveorExpression();
3222 private void variableList() throws CoreException {
3225 if (token == TT_COMMA) {
3233 private void variable() throws CoreException {
3234 if (token == TT_DOLLAROPEN) {
3238 if (token != TT_LISTCLOSE) {
3239 throwSyntaxError("'}' expected after indirect variable token '${'.");
3243 if (token == TT_VARIABLE) {
3245 if (token == TT_PARTOPEN) {
3248 if (token != TT_PARTCLOSE) {
3249 throwSyntaxError("']' expected in variable-list.");
3252 } else if (token == TT_ASSIGN) {
3257 throwSyntaxError("$-variable expected in variable-list.");
3262 private void constant() throws CoreException {
3268 case TT_DOUBLE_NUMBER :
3271 case TT_INT_NUMBER :
3275 throwSyntaxError("Constant expected after '+' presign.");
3281 case TT_DOUBLE_NUMBER :
3284 case TT_INT_NUMBER :
3288 throwSyntaxError("Constant expected after '-' presign.");
3300 case TT_IDENTIFIER :
3303 if (token == TT_ARGOPEN) {
3305 if (token != TT_ARGCLOSE) {
3307 if (token != TT_ARGCLOSE) {
3308 throwSyntaxError("')' expected after identifier '" + ident + "' in postfix-expression.");
3314 case TT_STRING_CONSTANT :
3317 case TT_INTERPOLATED_STRING :
3320 case TT_DOUBLE_NUMBER :
3323 case TT_INT_NUMBER :
3327 throwSyntaxError("Constant expected.");
3332 * Call the php parse command ( php -l -f <filename> )
3333 * and create markers according to the external parser output
3335 public static void phpExternalParse(IFile file) {
3336 //IFile file = (IFile) resource;
3337 IPath path = file.getFullPath();
3338 IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
3339 String filename = file.getLocation().toString();
3341 String[] arguments = { filename };
3342 MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
3343 String command = form.format(arguments);
3345 String parserResult = PHPStartApacheAction.execute(command, "External parser: ");
3348 // parse the buffer to find the errors and warnings
3349 createMarkers(parserResult, file);
3350 } catch (CoreException e) {
3355 * Create markers according to the external parser output
3357 private static void createMarkers(String output, IFile file) throws CoreException {
3358 // delete all markers
3359 file.deleteMarkers(IMarker.PROBLEM, false, 0);
3363 boolean flag = true;
3364 while ((brIndx = output.indexOf("<br />", indx)) != -1) {
3365 // newer php error output (tested with 4.2.3)
3366 scanLine(output, file, indx, brIndx);
3371 while ((brIndx = output.indexOf("<br>", indx)) != -1) {
3372 // older php error output (tested with 4.2.3)
3373 scanLine(output, file, indx, brIndx);
3379 private static void scanLine(String output, IFile file, int indx, int brIndx) throws CoreException {
3381 String outLineNumberString;
3382 StringBuffer lineNumberBuffer = new StringBuffer(10);
3384 current = output.substring(indx, brIndx);
3386 if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) {
3387 int onLine = current.indexOf("on line <b>");
3389 lineNumberBuffer.delete(0, lineNumberBuffer.length());
3390 for (int i = onLine; i < current.length(); i++) {
3391 ch = current.charAt(i);
3392 if ('0' <= ch && '9' >= ch) {
3393 lineNumberBuffer.append(ch);
3397 int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
3399 Hashtable attributes = new Hashtable();
3401 current = current.replaceAll("\n", "");
3402 current = current.replaceAll("<b>", "");
3403 current = current.replaceAll("</b>", "");
3404 MarkerUtilities.setMessage(attributes, current);
3406 if (current.indexOf(PARSE_ERROR_STRING) != -1)
3407 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
3408 else if (current.indexOf(PARSE_WARNING_STRING) != -1)
3409 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
3411 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
3412 MarkerUtilities.setLineNumber(attributes, lineNumber);
3413 MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);