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.phpdt.internal.compiler.parser;
13 import java.util.ArrayList;
14 import java.util.Hashtable;
16 import net.sourceforge.phpdt.core.compiler.*;
17 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
18 import net.sourceforge.phpeclipse.phpeditor.PHPString;
20 import org.eclipse.core.resources.IFile;
21 import org.eclipse.core.resources.IMarker;
22 import org.eclipse.core.runtime.CoreException;
23 import org.eclipse.jface.preference.IPreferenceStore;
24 import org.eclipse.ui.texteditor.MarkerUtilities;
25 import test.PHPParserSuperclass;
27 public class Parser extends PHPParserSuperclass implements ITerminalSymbols {
29 public static final int ERROR = 2;
30 public static final int WARNING = 1;
31 public static final int INFO = 0;
34 public Scanner scanner;
36 private IFile fileToParse;
37 private ArrayList phpList;
39 private int currentPHPString;
40 private boolean phpEnd;
42 // private static HashMap keywordMap = null;
50 // row counter for syntax errors:
52 // column counter for syntax errors:
57 // // current identifier
63 private String stringValue;
65 /** Contains the current expression. */
66 // private StringBuffer expression;
68 private boolean phpMode;
70 // final static int TokenNameEOF = 0;
71 // final static int TokenNameERROR = 1;
72 // final static int TokenNameHTML = 2;
74 // final static int TokenNameREMAINDER = 30;
75 // final static int TokenNameNOT = 31;
76 // final static int TokenNameDOT = 32;
77 // final static int TokenNameXOR = 33;
78 // final static int TokenNameDIVIDE = 34;
79 // final static int TokenNameMULTIPLY = 35;
80 // final static int TokenNameMINUS = 36;
81 // final static int TokenNamePLUS = 37;
82 // final static int TokenNameEQUAL_EQUAL = 38;
83 // final static int TokenNameNOT_EQUAL = 39;
84 // final static int TokenNameGREATER = 40;
85 // final static int TokenNameGREATER_EQUAL = 41;
86 // final static int TokenNameLESS = 42;
87 // final static int TokenNameLESS_EQUAL = 43;
88 // final static int TokenNameAND_AND = 44;
89 // final static int TokenNameOR_OR = 45;
90 // // final static int TokenNameHASH = 46;
91 // final static int TokenNameCOLON = 47;
92 // final static int TokenNameDOT_EQUAL = 48;
94 // final static int TokenNameEQUAL = 49;
95 // final static int TokenNameMINUS_GREATER = 50; // ->
96 // final static int TokenNameFOREACH = 51;
97 // final static int TokenNameAND = 52;
98 // //final static int TokenNameDOLLARLISTOPEN = 53;
99 // final static int TokenNameTWIDDLE = 54;
100 // final static int TokenNameTWIDDLE_EQUAL = 55;
101 // final static int TokenNameREMAINDER_EQUAL = 56;
102 // final static int TokenNameXOR_EQUAL = 57;
103 // final static int TokenNameRIGHT_SHIFT_EQUAL = 58;
104 // final static int TokenNameLEFT_SHIFT_EQUAL = 59;
105 // final static int TokenNameAND_EQUAL = 60;
106 // final static int TokenNameOR_EQUAL = 61;
107 // final static int TokenNameQUESTION = 62;
108 // final static int TokenNameCOLON_COLON = 63;
109 // final static int TokenNameAT = 63;
110 // // final static int TokenNameHEREDOC = 64;
112 // final static int TokenNameDOLLAROPEN = 127;
113 // final static int TokenNameLPAREN = 128;
114 // final static int TokenNameRPAREN = 129;
115 // final static int TokenNameLBRACE = 130;
116 // final static int TokenNameRBRACE = 131;
117 // final static int TokenNameLBRACKET = 132;
118 // final static int TokenNameRBRACKET = 133;
119 // final static int TokenNameCOMMA = 134;
121 // final static int TokenNameStringLiteral = 136;
122 // final static int TokenNameIdentifier = 138;
123 // // final static int TokenNameDIGIT = 139;
124 // final static int TokenNameSEMICOLON = 140;
125 // // final static int TokenNameSLOT = 141;
126 // // final static int TokenNameSLOTSEQUENCE = 142;
127 // final static int TokenNameMINUS_MINUS = 144;
128 // final static int TokenNamePLUS_PLUS = 145;
129 // final static int TokenNamePLUS_EQUAL = 146;
130 // final static int TokenNameDIVIDE_EQUAL = 147;
131 // final static int TokenNameMINUS_EQUAL = 148;
132 // final static int TokenNameMULTIPLY_EQUAL = 149;
133 // final static int TokenNameVariable = 150;
134 // final static int TokenNameIntegerLiteral = 151;
135 // final static int TokenNameDoubleLiteral = 152;
136 // final static int TokenNameStringInterpolated = 153;
137 // final static int TokenNameStringConstant = 154;
139 // final static int TokenNameLEFT_SHIFT = 155;
140 // final static int TokenNameRIGHT_SHIFT = 156;
141 // final static int TokenNameEQUAL_EQUAL_EQUAL = 157;
142 // final static int TokenNameNOT_EQUAL_EQUAL = 158;
143 // final static int TokenNameOR = 159;
144 // final static int TokenNameAT = 153; // @
149 public void setFileToParse(IFile fileToParse) {
150 this.currentPHPString = 0;
151 this.fileToParse = fileToParse;
154 this.token = TokenNameEOF;
156 this.initializeScanner();
162 *@param sess Description of Parameter
165 public Parser(IFile fileToParse) {
166 // if (keywordMap == null) {
167 // keywordMap = new HashMap();
168 // for (int i = 0; i < PHP_KEYWORS.length; i++) {
169 // keywordMap.put(PHP_KEYWORS[i], new Integer(PHP_KEYWORD_TOKEN[i]));
172 this.currentPHPString = 0;
173 this.fileToParse = fileToParse;
176 this.token = TokenNameEOF;
178 // this.rowCount = 1;
179 // this.columnCount = 0;
183 this.initializeScanner();
186 public void initializeScanner() {
187 this.scanner = new Scanner(false, false, false, false);
190 * Create marker for the parse error
192 private void setMarker(
197 throws CoreException {
198 setMarker(fileToParse, message, charStart, charEnd, errorLevel);
201 public static void setMarker(
207 throws CoreException {
209 Hashtable attributes = new Hashtable();
210 MarkerUtilities.setMessage(attributes, message);
211 switch (errorLevel) {
213 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
218 new Integer(IMarker.SEVERITY_WARNING));
221 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
224 MarkerUtilities.setCharStart(attributes, charStart);
225 MarkerUtilities.setCharEnd(attributes, charEnd);
226 // setLineNumber(attributes, lineNumber);
227 MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
232 * This method will throw the SyntaxError.
233 * It will add the good lines and columns to the Error
234 * @param error the error message
235 * @throws SyntaxError the error raised
237 private void throwSyntaxError(String error) {
239 // if (str.length() < chIndx) {
242 // // read until end-of-line
244 // while (str.length() > eol) {
245 // ch = str.charAt(eol++);
251 // throw new SyntaxError(
253 // chIndx - columnCount + 1,
254 // str.substring(columnCount, eol),
256 throw new SyntaxError(1, 1, "", error);
260 * This method will throw the SyntaxError.
261 * It will add the good lines and columns to the Error
262 * @param error the error message
263 * @throws SyntaxError the error raised
265 private void throwSyntaxError(String error, int startRow) {
266 throw new SyntaxError(startRow, 0, " ", error);
270 * Method Declaration.
274 // private void getChar() {
275 // if (str.length() > chIndx) {
276 // ch = str.charAt(chIndx++);
281 // chIndx = str.length() + 1;
283 // // token = TokenNameEOF;
288 * gets the next token from input
290 private void getNextToken() throws CoreException {
292 token = scanner.getNextToken();
294 int currentEndPosition = scanner.getCurrentTokenEndPosition();
295 int currentStartPosition = scanner.getCurrentTokenStartPosition();
298 currentStartPosition + "," + currentEndPosition + ": ");
299 System.out.println(scanner.toStringAction(token));
301 } catch (InvalidInputException e) {
302 token = TokenNameERROR;
306 // boolean phpFound = false;
313 // while (str.length() > chIndx) {
314 // token = TokenNameERROR;
315 // ch = str.charAt(chIndx++);
321 // ch2 = str.charAt(chIndx++);
323 // ch2 = str.charAt(chIndx++);
324 // if (Character.isWhitespace(ch2)) {
329 // } else if (ch2 == 'p' || ch2 == 'P') {
330 // ch2 = str.charAt(chIndx++);
331 // if (ch2 == 'h' || ch2 == 'H') {
332 // ch2 = str.charAt(chIndx++);
333 // if (ch2 == 'p' || ch2 == 'P') {
351 // while (str.length() > chIndx) {
352 // ch = str.charAt(chIndx++);
353 // token = TokenNameERROR;
356 // columnCount = chIndx;
357 // continue; // while loop
359 // if (str.length() == chIndx) {
362 // if (!Character.isWhitespace(ch)) {
364 // if (str.length() > chIndx) {
365 // if (str.charAt(chIndx) == '{') {
367 // token = TokenNameDOLLAROPEN;
374 // if ((ch >= 'a' && ch <= 'z')
375 // || (ch >= 'A' && ch <= 'Z')
381 // if (ch >= '0' && ch <= '9') {
386 // if (str.length() > chIndx) {
387 // if (str.charAt(chIndx) == '/') {
390 // // read comment until end of line:
391 // while ((str.length() > chIndx)
392 // && (ch != '\n')) {
393 // ch = str.charAt(chIndx++);
395 // ch2 = str.charAt(chIndx);
398 // token = TokenNameHTML;
409 // } else if (str.charAt(chIndx) == '*') {
411 // // multi line comment:
412 // while (str.length() > chIndx) {
413 // if (str.charAt(chIndx) == '*'
414 // && (str.length() > (chIndx + 1))
415 // && str.charAt(chIndx + 1) == '/') {
419 // ch = str.charAt(chIndx++);
422 // columnCount = chIndx;
428 // } else if (ch == '#') {
429 // // read comment until end of line:
430 // while ((str.length() > chIndx) && (ch != '\n')) {
431 // ch = str.charAt(chIndx++);
433 // ch2 = str.charAt(chIndx);
436 // token = TokenNameHTML;
447 // } else if (ch == '"') {
450 // TokenNameStringInterpolated,
451 // "Open string character '\"' at end of file.");
453 // } else if (ch == '\'') {
456 // TokenNameStringConstant,
457 // "Open string character \"'\" at end of file.");
459 // } else if (ch == '`') {
462 // TokenNameStringConstant,
463 // "Open string character \"`\" at end of file.");
465 // "Other string delimiters prefered (found \"`\").",
474 // token = TokenNameLPAREN;
478 // token = TokenNameRPAREN;
482 // token = TokenNameLBRACE;
486 // token = TokenNameRBRACE;
490 // token = TokenNameLBRACKET;
494 // token = TokenNameRBRACKET;
498 // token = TokenNameCOMMA;
502 // token = TokenNameQUESTION;
503 // if (str.length() > chIndx) {
504 // if (str.charAt(chIndx) == '>') {
506 // token = TokenNameHTML;
516 // token = TokenNameAT;
519 // token = TokenNameTWIDDLE;
520 // if (str.length() > chIndx) {
521 // if (str.charAt(chIndx) == '=') {
523 // token = TokenNameTWIDDLE_EQUAL;
530 // token = TokenNameDOT;
531 // if (str.length() > chIndx) {
532 // if (str.charAt(chIndx) == '=') {
534 // token = TokenNameDOT_EQUAL;
542 // token = TokenNameStringLiteral;
546 // token = TokenNameREMAINDER;
547 // if (str.length() > chIndx) {
548 // if (str.charAt(chIndx) == '=') {
550 // token = TokenNameREMAINDER_EQUAL;
557 // token = TokenNameSEMICOLON;
561 // token = TokenNameXOR;
562 // if (str.length() > chIndx) {
563 // if (str.charAt(chIndx) == '=') {
565 // token = TokenNameXOR_EQUAL;
572 // token = TokenNameDIVIDE;
574 // if (str.length() > chIndx) {
575 // if (str.charAt(chIndx) == '=') {
577 // token = TokenNameDIVIDE_EQUAL;
585 // token = TokenNameMULTIPLY;
586 // if (str.length() > chIndx) {
587 // if (str.charAt(chIndx) == '*') {
589 // token = TokenNameXOR;
593 // if (str.charAt(chIndx) == '=') {
595 // token = TokenNameMULTIPLY_EQUAL;
603 // token = TokenNamePLUS;
604 // if (str.length() > chIndx) {
605 // if (str.charAt(chIndx) == '+') {
607 // token = TokenNamePLUS_PLUS;
611 // if (str.charAt(chIndx) == '=') {
613 // token = TokenNamePLUS_EQUAL;
620 // token = TokenNameMINUS;
621 // if (str.length() > chIndx) {
622 // if (str.charAt(chIndx) == '-') {
624 // token = TokenNameMINUS_MINUS;
628 // if (str.charAt(chIndx) == '=') {
630 // token = TokenNameMINUS_EQUAL;
634 // if (str.charAt(chIndx) == '>') {
636 // token = TokenNameMINUS_GREATER;
644 // token = TokenNameEQUAL;
646 // if (str.length() > chIndx) {
647 // ch = str.charAt(chIndx);
651 // token = TokenNameEQUAL_EQUAL;
652 // if (str.length() > chIndx) {
653 // ch = str.charAt(chIndx);
658 // TokenNameEQUAL_EQUAL_EQUAL;
665 // token = TokenNameEQUAL_GREATER;
673 // token = TokenNameNOT;
675 // if (str.length() > chIndx) {
676 // if (str.charAt(chIndx) == '=') {
678 // token = TokenNameNOT_EQUAL;
679 // if (str.length() > chIndx) {
680 // ch = str.charAt(chIndx);
685 // TokenNameNOT_EQUAL_EQUAL;
694 // token = TokenNameGREATER;
696 // if (str.length() > chIndx) {
697 // if (str.charAt(chIndx) == '=') {
699 // token = TokenNameGREATER_EQUAL;
702 // if (str.charAt(chIndx) == '>') {
704 // token = TokenNameRIGHT_SHIFT;
705 // if (str.length() > chIndx) {
706 // if (str.charAt(chIndx) == '=') {
709 // TokenNameRIGHT_SHIFT_EQUAL;
719 // token = TokenNameLESS;
721 // if (str.length() > chIndx) {
722 // if (str.charAt(chIndx) == '=') {
724 // token = TokenNameLESS_EQUAL;
728 // if (str.charAt(chIndx) == '<') {
730 // token = TokenNameLEFT_SHIFT;
731 // if (str.charAt(chIndx) == '<') {
733 // int startRow = rowCount;
734 // if (str.length() > chIndx) {
736 // ch = str.charAt(++chIndx);
737 // if ((ch >= 'a' && ch <= 'z')
738 // || (ch >= 'A' && ch <= 'Z')
743 // TokenNameStringConstant;
744 // while (str.length()
760 // .equals(identifier)) {
772 // "Open heredoc syntax after operator '<<<'.",
774 // } else if (str.charAt(chIndx) == '=') {
776 // token = TokenNameLEFT_SHIFT_EQUAL;
786 // token = TokenNameOR;
788 // if (str.length() > chIndx) {
789 // if (str.charAt(chIndx) == '|') {
791 // token = TokenNameOR_OR;
794 // if (str.charAt(chIndx) == '=') {
796 // token = TokenNameOR_EQUAL;
803 // token = TokenNameAND;
804 // if (str.length() > chIndx) {
805 // if (str.charAt(chIndx) == '&') {
807 // token = TokenNameAND_AND;
810 // if (str.charAt(chIndx) == '=') {
812 // token = TokenNameAND_EQUAL;
820 // token = TokenNameCOLON;
821 // if (str.length() > chIndx) {
822 // if (str.charAt(chIndx) == ':') {
824 // token = TokenNameCOLON_COLON;
829 // // token = TokenNameHASH;
833 // // token = TokenNameAT;
838 // "unexpected character: '" + ch + "'");
841 // if (token == TokenNameERROR) {
842 // throwSyntaxError("token not found");
849 // } catch (StringIndexOutOfBoundsException e) {
850 // // catched from charAt
853 // chIndx = str.length() + 1;
855 // token = TokenNameEOF;
858 // // if (phpList != null) {
859 // // if (currentPHPString < phpList.size()) {
860 // // token = TokenNameUNDEFINED;
861 // // temp = (PHPString) phpList.get(currentPHPString++);
862 // // this.str = temp.getPHPString();
863 // // this.token = TokenNameEOF;
864 // // this.chIndx = 0;
865 // // this.rowCount = temp.getLineNumber();
866 // // this.columnCount = 0;
867 // // getNextToken();
870 // // token = TokenNameUNDEFINED;
877 // * Get an identifier.
879 // private void getIdentifier() {
880 // // StringBuffer ident = new StringBuffer();
881 // int startPosition = chIndx - 1;
882 // // ident.append(ch);
885 // // attention recursive call:
887 // token = TokenNameVariable;
890 // token = TokenNameIdentifier;
895 // //this will read the buffer until the next character is a forbidden character for identifier
896 // while ((ch >= 'a' && ch <= 'z')
897 // || (ch >= 'A' && ch <= 'Z')
898 // || (ch >= '0' && ch <= '9')
900 // // ident.append(ch);
903 // int endPosition = chIndx--;
904 // int length = (--endPosition) - startPosition;
906 // identifier = str.substring(startPosition, endPosition);
907 // // System.out.println(identifier);
909 // // determine if this identitfer is a keyword
910 // // @todo improve this in future version
911 // Integer i = (Integer) keywordMap.get(identifier.toLowerCase());
913 // token = i.intValue();
919 * if it's a <code>double</code> the number will be stored in <code>doubleNumber</code> and the token will have the
920 * value {@link Parser#TokenNameDOUBLE_NUMBER}<br />
921 * if it's a <code>double</code> the number will be stored in <code>longNumber</code> and the token will have the
922 * value {@link Parser#TokenNameINT_NUMBER}
924 // private void getNumber() {
925 // StringBuffer inum = new StringBuffer();
927 // int numFormat = 10;
929 // // save first digit
930 // char firstCh = ch;
934 // // determine number conversions:
935 // if (firstCh == '0') {
964 // if (numFormat == 16) {
965 // while ((ch >= '0' && ch <= '9')
966 // || (ch >= 'a' && ch <= 'f')
967 // || (ch >= 'A' && ch <= 'F')) {
972 // while ((ch >= '0' && ch <= '9')
976 // if ((ch == '.') || (ch == 'E') || (ch == 'e')) {
977 // if (ch == '.' && dFlag != ' ') {
980 // if ((dFlag == 'E') || (dFlag == 'e')) {
986 // if ((ch == '-') || (ch == '+')) {
999 // if (dFlag != ' ') {
1000 // doubleNumber = new Double(inum.toString());
1001 // token = TokenNameDoubleLiteral;
1004 // longNumber = Long.valueOf(inum.toString(), numFormat);
1005 // token = TokenNameIntegerLiteral;
1009 // } catch (Throwable e) {
1010 // throwSyntaxError("Number format error: " + inum.toString());
1016 // * @param openChar the opening char ('\'', '"', '`')
1017 // * @param typeString the type of string {@link #TokenNameSTRING_CONSTANT},{@link #TokenNameINTERPOLATED_STRING}
1018 // * @param errorMsg the error message in case of parse error in the string
1020 // private void getString(
1021 // final char openChar,
1022 // final int typeString,
1023 // final String errorMsg) {
1024 // StringBuffer sBuffer = new StringBuffer();
1025 // boolean openString = true;
1026 // int startRow = rowCount;
1027 // while (str.length() > chIndx) {
1028 // ch = str.charAt(chIndx++);
1029 // if (ch == '\\') {
1030 // sBuffer.append(ch);
1031 // if (str.length() > chIndx) {
1032 // ch = str.charAt(chIndx++);
1033 // sBuffer.append(ch);
1035 // } else if (ch == openChar) {
1036 // openString = false;
1038 // } else if (ch == '\n') {
1040 // columnCount = chIndx;
1042 // sBuffer.append(ch);
1045 // if (openString) {
1046 // if (typeString == TokenNameStringConstant) {
1047 // throwSyntaxError(errorMsg, startRow);
1049 // throwSyntaxError(errorMsg);
1052 // token = typeString;
1053 // stringValue = sBuffer.toString();
1056 // public void htmlParserTester(String input) {
1057 // int lineNumber = 1;
1058 // int startLineNumber = 1;
1059 // int startIndex = 0;
1062 // boolean phpMode = false;
1063 // boolean phpFound = false;
1065 // phpList = new ArrayList();
1066 // currentPHPString = 0;
1070 // while (i < input.length()) {
1071 // ch = input.charAt(i++);
1072 // if (ch == '\n') {
1075 // if ((!phpMode) && ch == '<') {
1076 // ch2 = input.charAt(i++);
1077 // if (ch2 == '?') {
1078 // ch2 = input.charAt(i++);
1079 // if (Character.isWhitespace(ch2)) {
1084 // startLineNumber = lineNumber;
1086 // } else if (ch2 == 'p') {
1087 // ch2 = input.charAt(i++);
1088 // if (ch2 == 'h') {
1089 // ch2 = input.charAt(i++);
1090 // if (ch2 == 'p') {
1094 // startLineNumber = lineNumber;
1100 // } else if (ch2 == 'P') {
1101 // ch2 = input.charAt(i++);
1102 // if (ch2 == 'H') {
1103 // ch2 = input.charAt(i++);
1104 // if (ch2 == 'P') {
1108 // startLineNumber = lineNumber;
1121 // if (ch == '/' && i < input.length()) {
1122 // ch2 = input.charAt(i++);
1123 // if (ch2 == '/') {
1124 // while (i < input.length()) {
1125 // ch = input.charAt(i++);
1126 // if (ch == '?' && i < input.length()) {
1127 // ch2 = input.charAt(i++);
1128 // if (ch2 == '>') {
1136 // startLineNumber));
1140 // } else if (ch == '\n') {
1146 // } else if (ch2 == '*') {
1147 // // multi-line comment
1148 // while (i < input.length()) {
1149 // ch = input.charAt(i++);
1150 // if (ch == '\n') {
1152 // } else if (ch == '*' && i < input.length()) {
1153 // ch2 = input.charAt(i++);
1154 // if (ch2 == '/') {
1164 // } else if (ch == '#') {
1165 // while (i < input.length()) {
1166 // ch = input.charAt(i++);
1167 // if (ch == '?' && i < input.length()) {
1168 // ch2 = input.charAt(i++);
1169 // if (ch2 == '>') {
1174 // input.substring(startIndex, i - 2),
1175 // startLineNumber));
1179 // } else if (ch == '\n') {
1185 // } else if (ch == '"') {
1187 // while (i < input.length()) {
1188 // ch = input.charAt(i++);
1189 // if (ch == '\n') {
1192 // ch == '\\' && i < input.length()) { // escape
1194 // } else if (ch == '"') {
1199 // } else if (ch == '\'') {
1201 // while (i < input.length()) {
1202 // ch = input.charAt(i++);
1203 // if (ch == '\n') {
1206 // ch == '\\' && i < input.length()) { // escape
1208 // } else if (ch == '\'') {
1215 // if (ch == '?' && i < input.length()) {
1216 // ch2 = input.charAt(i++);
1217 // if (ch2 == '>') {
1222 // input.substring(startIndex, i - 2),
1223 // startLineNumber));
1233 // "No PHP source code found.",
1239 // "Open PHP tag at end of file.",
1244 // input.substring(startIndex, i - 2),
1245 // startLineNumber));
1247 // // for (int j=0;j<phpList.size();j++) {
1248 // // String temp = ((PHPString)phpList.get(j)).getPHPString();
1249 // // int startIndx = temp.length()-10;
1250 // // if (startIndx<0) {
1251 // // startIndx = 0;
1253 // // System.out.println(temp.substring(startIndx)+"?>");
1255 // phpParserTester(null, 1);
1256 // // PHPString temp;
1257 // // for(int j=0;j<phpList.size();j++) {
1258 // // temp = (PHPString) phpList.get(j);
1259 // // parser.start(temp.getPHPString(), temp.getLineNumber());
1262 // } catch (CoreException e) {
1266 public void phpParserTester(String s, int rowCount) throws CoreException {
1269 if (phpList.size() != 0) {
1270 this.str = ((PHPString) phpList.get(currentPHPString++)).getPHPString();
1273 this.token = TokenNameEOF;
1275 // this.rowCount = rowCount;
1276 // this.columnCount = 0;
1277 this.phpEnd = false;
1278 this.phpMode = true;
1279 scanner.setSource(s.toCharArray());
1280 scanner.setPHPMode(true);
1284 if (token != TokenNameEOF && token != TokenNameERROR) {
1287 if (token != TokenNameEOF) {
1288 if (token == TokenNameERROR) {
1290 "Scanner error (Found unknown token: "
1291 + scanner.toStringAction(token)
1294 if (token == TokenNameRPAREN) {
1295 throwSyntaxError("Too many closing ')'; end-of-file not reached.");
1297 if (token == TokenNameRBRACE) {
1298 throwSyntaxError("Too many closing '}'; end-of-file not reached.");
1300 if (token == TokenNameRBRACKET) {
1301 throwSyntaxError("Too many closing ']'; end-of-file not reached.");
1304 if (token == TokenNameLPAREN) {
1305 throwSyntaxError("Read character '('; end-of-file not reached.");
1307 if (token == TokenNameLBRACE) {
1308 throwSyntaxError("Read character '{'; end-of-file not reached.");
1310 if (token == TokenNameLBRACKET) {
1311 throwSyntaxError("Read character '['; end-of-file not reached.");
1314 throwSyntaxError("End-of-file not reached.");
1317 } catch (SyntaxError err) {
1321 // setMarker(err.getMessage(), err.getLine(), ERROR);
1324 scanner.getCurrentTokenStartPosition(),
1325 scanner.getCurrentTokenEndPosition(),
1328 // if an error occured,
1329 // try to find keywords 'class' or 'function'
1330 // to parse the rest of the string
1331 while (token != TokenNameEOF && token != TokenNameERROR) {
1332 if (token == TokenNameclass || token == TokenNamefunction) {
1337 if (token == TokenNameEOF || token == TokenNameERROR) {
1346 * Parses a string with php tags
1347 * i.e. '<body> <?php phpinfo() ?> </body>'
1349 public void parse(String s) throws CoreException {
1351 this.token = TokenNameEOF;
1353 // this.rowCount = 1;
1354 // this.columnCount = 0;
1355 this.phpEnd = false;
1356 this.phpMode = false;
1357 /* scanner initialization */
1358 scanner.setSource(s.toCharArray());
1359 scanner.setPHPMode(false);
1363 if (token != TokenNameEOF && token != TokenNameERROR) {
1366 if (token != TokenNameEOF) {
1367 if (token == TokenNameERROR) {
1369 "Scanner error (Found unknown token: "
1370 + scanner.toStringAction(token)
1373 if (token == TokenNameRPAREN) {
1374 throwSyntaxError("Too many closing ')'; end-of-file not reached.");
1376 if (token == TokenNameRBRACE) {
1377 throwSyntaxError("Too many closing '}'; end-of-file not reached.");
1379 if (token == TokenNameRBRACKET) {
1380 throwSyntaxError("Too many closing ']'; end-of-file not reached.");
1383 if (token == TokenNameLPAREN) {
1384 throwSyntaxError("Read character '('; end-of-file not reached.");
1386 if (token == TokenNameLBRACE) {
1387 throwSyntaxError("Read character '{'; end-of-file not reached.");
1389 if (token == TokenNameLBRACKET) {
1390 throwSyntaxError("Read character '['; end-of-file not reached.");
1393 throwSyntaxError("End-of-file not reached.");
1396 } catch (SyntaxError sytaxErr1) {
1397 // setMarker(sytaxErr1.getMessage(), sytaxErr1.getLine(), ERROR);
1399 sytaxErr1.getMessage(),
1400 scanner.getCurrentTokenStartPosition(),
1401 scanner.getCurrentTokenEndPosition(),
1404 // if an error occured,
1405 // try to find keywords 'class' or 'function'
1406 // to parse the rest of the string
1407 while (token != TokenNameEOF && token != TokenNameERROR) {
1408 if (token == TokenNameclass || token == TokenNamefunction) {
1413 if (token == TokenNameEOF || token == TokenNameERROR) {
1416 } catch (SyntaxError sytaxErr2) {
1417 // setMarker(sytaxErr2.getMessage(), sytaxErr2.getLine(), ERROR);
1419 sytaxErr2.getMessage(),
1420 scanner.getCurrentTokenStartPosition(),
1421 scanner.getCurrentTokenEndPosition(),
1430 public PHPOutlineInfo parseInfo(Object parent, String s) {
1431 PHPOutlineInfo outlineInfo = new PHPOutlineInfo(parent);
1432 // Stack stack = new Stack();
1433 // stack.push(outlineInfo.getDeclarations());
1436 this.token = TokenNameEOF;
1438 // this.rowCount = 1;
1439 // this.columnCount = 0;
1440 this.phpEnd = false;
1441 this.phpMode = false;
1442 scanner.setSource(s.toCharArray());
1443 scanner.setPHPMode(false);
1447 parseDeclarations(outlineInfo, outlineInfo.getDeclarations(), false);
1448 } catch (CoreException e) {
1453 private void parseDeclarations(
1454 PHPOutlineInfo outlineInfo,
1455 PHPSegmentWithChildren current,
1458 // PHPClassDeclaration current = (PHPClassDeclaration) stack.peek();
1459 PHPSegmentWithChildren temp;
1462 IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
1464 while (token != TokenNameEOF && token != TokenNameERROR) {
1465 if (token == TokenNameVariable) {
1466 ident = scanner.getCurrentIdentifierSource();
1467 outlineInfo.addVariable(new String(ident));
1469 } else if (token == TokenNamevar) {
1471 if (token == TokenNameVariable
1472 && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_VAR)) {
1473 ident = scanner.getCurrentIdentifierSource();
1474 String variableName = new String(ident);
1475 outlineInfo.addVariable(variableName);
1477 if (token != TokenNameSEMICOLON) {
1480 ident = scanner.getCurrentTokenSource();
1481 if (token > TokenNameKEYWORD) {
1482 current.add(new PHPVarDeclaration(current, variableName,
1483 // chIndx - ident.length,
1484 scanner.getCurrentTokenStartPosition(), new String(ident)));
1487 case TokenNameVariable :
1488 current.add(new PHPVarDeclaration(current, variableName,
1489 // chIndx - ident.length,
1490 scanner.getCurrentTokenStartPosition(), new String(ident)));
1492 case TokenNameIdentifier :
1493 current.add(new PHPVarDeclaration(current, variableName,
1494 // chIndx - ident.length,
1495 scanner.getCurrentTokenStartPosition(), new String(ident)));
1497 case TokenNameDoubleLiteral :
1499 .add(new PHPVarDeclaration(
1501 variableName + doubleNumber,
1502 // chIndx - ident.length,
1503 scanner.getCurrentTokenStartPosition(), new String(ident)));
1505 case TokenNameIntegerLiteral :
1506 current.add(new PHPVarDeclaration(current, variableName,
1507 // chIndx - ident.length,
1508 scanner.getCurrentTokenStartPosition(), new String(ident)));
1510 case TokenNameStringInterpolated :
1511 case TokenNameStringLiteral :
1512 current.add(new PHPVarDeclaration(current, variableName,
1513 // chIndx - ident.length,
1514 scanner.getCurrentTokenStartPosition(), new String(ident)));
1516 case TokenNameStringConstant :
1517 current.add(new PHPVarDeclaration(current, variableName,
1518 // chIndx - ident.length,
1519 scanner.getCurrentTokenStartPosition(), new String(ident)));
1522 current.add(new PHPVarDeclaration(current, variableName,
1523 // chIndx - ident.length
1524 scanner.getCurrentTokenStartPosition()));
1530 ident = scanner.getCurrentIdentifierSource();
1532 current.add(new PHPVarDeclaration(current, variableName,
1533 // chIndx - ident.length
1534 scanner.getCurrentTokenStartPosition()));
1537 } else if (token == TokenNamefunction) {
1539 if (token == TokenNameAND) {
1542 if (token == TokenNameIdentifier
1543 && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_FUNC)) {
1544 ident = scanner.getCurrentIdentifierSource();
1545 outlineInfo.addVariable(new String(ident));
1546 temp = new PHPFunctionDeclaration(current, new String(ident),
1547 // chIndx - ident.length
1548 scanner.getCurrentTokenStartPosition());
1551 parseDeclarations(outlineInfo, temp, true);
1553 } else if (token == TokenNameclass) {
1555 if (token == TokenNameIdentifier
1556 && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_CLASS)) {
1557 ident = scanner.getCurrentIdentifierSource();
1558 outlineInfo.addVariable(new String(ident));
1559 temp = new PHPClassDeclaration(current, new String(ident),
1560 // chIndx - ident.len
1561 scanner.getCurrentTokenStartPosition());
1563 // stack.push(temp);
1566 //skip tokens for classname, extends and others until we have the opening '{'
1567 while (token != TokenNameLBRACE
1568 && token != TokenNameEOF
1569 && token != TokenNameERROR) {
1572 parseDeclarations(outlineInfo, temp, true);
1575 } else if (token == TokenNameLBRACE) {
1578 } else if (token == TokenNameRBRACE) {
1581 if (counter == 0 && goBack) {
1585 token == TokenNamerequire
1586 || token == TokenNamerequire_once
1587 || token == TokenNameinclude
1588 || token == TokenNameinclude_once) {
1589 ident = scanner.getCurrentTokenSource();
1592 int startPosition = scanner.getCurrentTokenStartPosition();
1594 char[] expr = scanner.getCurrentTokenSource(startPosition);
1595 outlineInfo.addVariable(new String(ident));
1596 current.add(new PHPReqIncDeclaration(current, new String(ident),
1597 // chIndx - ident.length,
1598 startPosition, new String(expr)));
1604 } catch (CoreException e) {
1605 } catch (SyntaxError sytaxErr) {
1607 // setMarker(sytaxErr.getMessage(), sytaxErr.getLine(), ERROR);
1609 sytaxErr.getMessage(),
1610 scanner.getCurrentTokenStartPosition(),
1611 scanner.getCurrentTokenEndPosition(),
1613 } catch (CoreException e) {
1618 private void statementList() throws CoreException {
1621 if ((token == TokenNameRBRACE)
1622 || (token == TokenNamecase)
1623 || (token == TokenNamedefault)
1624 || (token == TokenNameelseif)
1625 || (token == TokenNameendif)
1626 || (token == TokenNameendfor)
1627 || (token == TokenNameendforeach)
1628 || (token == TokenNameendwhile)
1629 || (token == TokenNameendswitch)
1630 || (token == TokenNameEOF)
1631 || (token == TokenNameERROR)) {
1637 private void compoundStatement() throws CoreException {
1638 // '{' [statement-list] '}'
1639 if (token == TokenNameLBRACE) {
1642 throwSyntaxError("'{' expected in compound-statement.");
1644 if (token != TokenNameRBRACE) {
1647 if (token == TokenNameRBRACE) {
1650 throwSyntaxError("'}' expected in compound-statement.");
1654 private void statement() throws CoreException {
1655 // if (token > TokenNameKEYWORD && token != TokenNamelist && token != TokenNamenew) {
1656 // char[] ident = scanner.getCurrentIdentifierSource();
1657 // String keyword = new String(ident);
1658 if (token == TokenNameinclude || token == TokenNameinclude_once) {
1661 if (token == TokenNameSEMICOLON) {
1664 if (token != TokenNameStopPHP) {
1665 throwSyntaxError("';' character after 'include' or 'include_once' expected.");
1670 } else if (token == TokenNamerequire || token == TokenNamerequire_once) {
1674 if (token == TokenNameSEMICOLON) {
1677 if (token != TokenNameStopPHP) {
1678 throwSyntaxError("';' character after 'require' or 'require_once' expected.");
1683 } else if (token == TokenNameif) {
1685 if (token == TokenNameLPAREN) {
1688 throwSyntaxError("'(' expected after 'if' keyword.");
1691 if (token == TokenNameRPAREN) {
1694 throwSyntaxError("')' expected after 'if' condition.");
1699 } else if (token == TokenNameswitch) {
1701 if (token == TokenNameLPAREN) {
1704 throwSyntaxError("'(' expected after 'switch' keyword.");
1707 if (token == TokenNameRPAREN) {
1710 throwSyntaxError("')' expected after 'switch' condition.");
1714 } else if (token == TokenNamefor) {
1716 if (token == TokenNameLPAREN) {
1719 throwSyntaxError("'(' expected after 'for' keyword.");
1721 if (token == TokenNameSEMICOLON) {
1725 if (token == TokenNameSEMICOLON) {
1728 throwSyntaxError("';' expected after 'for'.");
1731 if (token == TokenNameSEMICOLON) {
1735 if (token == TokenNameSEMICOLON) {
1738 throwSyntaxError("';' expected after 'for'.");
1741 if (token == TokenNameRPAREN) {
1745 if (token == TokenNameRPAREN) {
1748 throwSyntaxError("')' expected after 'for'.");
1753 } else if (token == TokenNamewhile) {
1755 if (token == TokenNameLPAREN) {
1758 throwSyntaxError("'(' expected after 'while' keyword.");
1761 if (token == TokenNameRPAREN) {
1764 throwSyntaxError("')' expected after 'while' condition.");
1768 } else if (token == TokenNamedo) {
1770 if (token == TokenNameLBRACE) {
1773 throwSyntaxError("'{' expected after 'do' keyword.");
1775 if (token != TokenNameRBRACE) {
1778 if (token == TokenNameRBRACE) {
1781 throwSyntaxError("'}' expected after 'do' keyword.");
1783 if (token == TokenNamewhile) {
1785 if (token == TokenNameLPAREN) {
1788 throwSyntaxError("'(' expected after 'while' keyword.");
1791 if (token == TokenNameRPAREN) {
1794 throwSyntaxError("')' expected after 'while' condition.");
1797 throwSyntaxError("'while' expected after 'do' keyword.");
1799 if (token == TokenNameSEMICOLON) {
1802 if (token != TokenNameStopPHP) {
1803 throwSyntaxError("';' expected after do-while statement.");
1808 } else if (token == TokenNameforeach) {
1810 if (token == TokenNameLPAREN) {
1813 throwSyntaxError("'(' expected after 'foreach' keyword.");
1816 if (token == TokenNameas) {
1819 throwSyntaxError("'as' expected after 'foreach' exxpression.");
1822 if (token == TokenNameEQUAL_GREATER) {
1826 if (token == TokenNameRPAREN) {
1829 throwSyntaxError("')' expected after 'foreach' expression.");
1835 token == TokenNamecontinue
1836 || token == TokenNamebreak
1837 || token == TokenNamereturn) {
1839 if (token != TokenNameSEMICOLON) {
1842 if (token == TokenNameSEMICOLON) {
1845 if (token != TokenNameStopPHP) {
1846 throwSyntaxError("';' expected after 'continue', 'break' or 'return'.");
1852 } else if (token == TokenNameecho) {
1855 if (token == TokenNameSEMICOLON) {
1858 if (token != TokenNameStopPHP) {
1859 throwSyntaxError("';' expected after 'echo' statement.");
1864 // } else if (token == TokenNameprint) {
1867 // if (token == TokenNameSEMICOLON) {
1870 // if (token != TokenNameStopPHP) {
1871 // throwSyntaxError("';' expected after 'print' statement.");
1877 } else if (token == TokenNameglobal || token == TokenNamestatic) {
1880 if (token == TokenNameSEMICOLON) {
1883 if (token != TokenNameStopPHP) {
1884 throwSyntaxError("';' expected after 'global' or 'static' statement.");
1890 // } else if (token == TokenNameunset) {
1892 // if (token == TokenNameARGOPEN) {
1895 // throwSyntaxError("'(' expected after 'unset' keyword.");
1898 // if (token == TokenNameARGCLOSE) {
1901 // throwSyntaxError("')' expected after 'unset' statement.");
1903 // if (token == TokenNameSEMICOLON) {
1906 // if (token != TokenNameStopPHP) {
1907 // throwSyntaxError("';' expected after 'unset' statement.");
1913 // } else if (token == TokenNameexit || token == TokenNamedie) {
1915 // if (token != TokenNameSEMICOLON) {
1918 // if (token == TokenNameSEMICOLON) {
1921 // if (token != TokenNameStopPHP) {
1922 // throwSyntaxError("';' expected after 'exit' or 'die' statement.");
1928 } else if (token == TokenNamedefine) {
1930 if (token == TokenNameLPAREN) {
1933 throwSyntaxError("'(' expected after 'define' keyword.");
1936 if (token == TokenNameCOMMA) {
1939 throwSyntaxError("',' expected after first 'define' constant.");
1942 if (token == TokenNameCOMMA) {
1946 if (token == TokenNameRPAREN) {
1949 throwSyntaxError("')' expected after 'define' statement.");
1951 if (token == TokenNameSEMICOLON) {
1954 if (token != TokenNameStopPHP) {
1955 throwSyntaxError("';' expected after 'define' statement.");
1960 } else if (token == TokenNamefunction) {
1962 functionDefinition();
1964 } else if (token == TokenNameclass) {
1970 // throwSyntaxError("Unexpected keyword '" + keyword + "'");
1971 } else if (token == TokenNameLBRACE) {
1972 // compoundStatement
1974 if (token != TokenNameRBRACE) {
1977 if (token == TokenNameRBRACE) {
1981 throwSyntaxError("'}' expected.");
1984 if (token != TokenNameSEMICOLON) {
1987 if (token == TokenNameSEMICOLON) {
1991 if (token != TokenNameStopPHP && token != TokenNameEOF) {
1993 "';' expected after expression (Found token: "
1994 + scanner.toStringAction(token)
2002 private void classDeclarator() throws CoreException {
2004 //identifier 'extends' identifier
2005 if (token == TokenNameIdentifier) {
2007 if (token == TokenNameextends) {
2009 if (token == TokenNameIdentifier) {
2012 throwSyntaxError("Class name expected after keyword 'extends'.");
2016 throwSyntaxError("Class name expected after keyword 'class'.");
2020 private void classBody() throws CoreException {
2021 //'{' [class-element-list] '}'
2022 if (token == TokenNameLBRACE) {
2024 if (token != TokenNameRBRACE) {
2027 if (token == TokenNameRBRACE) {
2030 throwSyntaxError("'}' expected at end of class body.");
2033 throwSyntaxError("'{' expected at start of class body.");
2037 private void classElementList() throws CoreException {
2040 } while (token == TokenNamefunction || token == TokenNamevar);
2043 private void classElement() throws CoreException {
2045 //function-definition
2046 if (token == TokenNamefunction) {
2048 functionDefinition();
2049 } else if (token == TokenNamevar) {
2053 throwSyntaxError("'function' or 'var' expected.");
2057 private void classProperty() throws CoreException {
2058 //'var' variable ';'
2059 //'var' variable '=' constant ';'
2061 if (token == TokenNameVariable) {
2063 if (token == TokenNameEQUAL) {
2068 throwSyntaxError("Variable expected after keyword 'var'.");
2070 if (token != TokenNameCOMMA) {
2075 if (token == TokenNameSEMICOLON) {
2078 throwSyntaxError("';' expected after variable declaration.");
2082 private void functionDefinition() throws CoreException {
2083 functionDeclarator();
2084 compoundStatement();
2087 private void functionDeclarator() throws CoreException {
2088 //identifier '(' [parameter-list] ')'
2089 if (token == TokenNameAND) {
2092 if (token == TokenNameIdentifier) {
2094 if (token == TokenNameLPAREN) {
2097 throwSyntaxError("'(' expected in function declaration.");
2099 if (token != TokenNameRPAREN) {
2102 if (token != TokenNameRPAREN) {
2103 throwSyntaxError("')' expected in function declaration.");
2110 private void parameterList() throws CoreException {
2111 //parameter-declaration
2112 //parameter-list ',' parameter-declaration
2114 parameterDeclaration();
2115 if (token != TokenNameCOMMA) {
2122 private void parameterDeclaration() throws CoreException {
2124 //variable-reference
2125 if (token == TokenNameAND) {
2127 if (token == TokenNameVariable) {
2130 throwSyntaxError("Variable expected after reference operator '&'.");
2133 //variable '=' constant
2134 if (token == TokenNameVariable) {
2136 if (token == TokenNameEQUAL) {
2144 private void labeledStatementList() throws CoreException {
2145 if (token != TokenNamecase && token != TokenNamedefault) {
2146 throwSyntaxError("'case' or 'default' expected.");
2149 if (token == TokenNamecase) {
2152 if (token == TokenNameCOLON) {
2154 if (token == TokenNamecase
2155 || token == TokenNamedefault) { // empty case statement ?
2159 } else if (token == TokenNameSEMICOLON) {
2161 // "':' expected after 'case' keyword (Found token: "
2162 // + scanner.toStringAction(token)
2167 "':' expected after 'case' keyword (Found token: "
2168 + scanner.toStringAction(token)
2170 scanner.getCurrentTokenStartPosition(),
2171 scanner.getCurrentTokenEndPosition(),
2174 if (token == TokenNamecase) { // empty case statement ?
2180 "':' character after 'case' constant expected (Found token: "
2181 + scanner.toStringAction(token)
2184 } else { // TokenNamedefault
2186 if (token == TokenNameCOLON) {
2190 throwSyntaxError("':' character after 'default' expected.");
2193 } while (token == TokenNamecase || token == TokenNamedefault);
2196 // public void labeledStatement() {
2197 // if (token == TokenNamecase) {
2200 // if (token == TokenNameDDOT) {
2204 // throwSyntaxError("':' character after 'case' constant expected.");
2207 // } else if (token == TokenNamedefault) {
2209 // if (token == TokenNameDDOT) {
2213 // throwSyntaxError("':' character after 'default' expected.");
2219 // public void expressionStatement() {
2222 // private void inclusionStatement() {
2225 // public void compoundStatement() {
2228 // public void selectionStatement() {
2231 // public void iterationStatement() {
2234 // public void jumpStatement() {
2237 // public void outputStatement() {
2240 // public void scopeStatement() {
2243 // public void flowStatement() {
2246 // public void definitionStatement() {
2249 private void ifStatement() throws CoreException {
2250 // ':' statement-list [elseif-list] [else-colon-statement] 'endif' ';'
2251 if (token == TokenNameCOLON) {
2255 case TokenNameelse :
2257 if (token == TokenNameCOLON) {
2261 if (token == TokenNameif) { //'else if'
2263 elseifStatementList();
2265 throwSyntaxError("':' expected after 'else'.");
2269 case TokenNameelseif :
2271 elseifStatementList();
2275 if (token != TokenNameendif) {
2276 throwSyntaxError("'endif' expected.");
2279 if (token != TokenNameSEMICOLON) {
2280 throwSyntaxError("';' expected after if-statement.");
2284 // statement [else-statement]
2286 if (token == TokenNameelseif) {
2288 if (token == TokenNameLPAREN) {
2291 throwSyntaxError("'(' expected after 'elseif' keyword.");
2294 if (token == TokenNameRPAREN) {
2297 throwSyntaxError("')' expected after 'elseif' condition.");
2300 } else if (token == TokenNameelse) {
2307 private void elseifStatementList() throws CoreException {
2311 case TokenNameelse :
2313 if (token == TokenNameCOLON) {
2318 if (token == TokenNameif) { //'else if'
2321 throwSyntaxError("':' expected after 'else'.");
2325 case TokenNameelseif :
2334 private void elseifStatement() throws CoreException {
2335 if (token == TokenNameLPAREN) {
2338 if (token != TokenNameLPAREN) {
2339 throwSyntaxError("')' expected in else-if-statement.");
2342 if (token != TokenNameCOLON) {
2343 throwSyntaxError("':' expected in else-if-statement.");
2350 private void switchStatement() throws CoreException {
2351 if (token == TokenNameCOLON) {
2352 // ':' [labeled-statement-list] 'endswitch' ';'
2354 labeledStatementList();
2355 if (token != TokenNameendswitch) {
2356 throwSyntaxError("'endswitch' expected.");
2359 if (token != TokenNameSEMICOLON) {
2360 throwSyntaxError("';' expected after switch-statement.");
2364 // '{' [labeled-statement-list] '}'
2365 if (token != TokenNameLBRACE) {
2366 throwSyntaxError("'{' expected in switch statement.");
2369 if (token != TokenNameRBRACE) {
2370 labeledStatementList();
2372 if (token != TokenNameRBRACE) {
2373 throwSyntaxError("'}' expected in switch statement.");
2380 private void forStatement() throws CoreException {
2381 if (token == TokenNameCOLON) {
2384 if (token != TokenNameendfor) {
2385 throwSyntaxError("'endfor' expected.");
2388 if (token != TokenNameSEMICOLON) {
2389 throwSyntaxError("';' expected after for-statement.");
2397 private void whileStatement() throws CoreException {
2398 // ':' statement-list 'endwhile' ';'
2399 if (token == TokenNameCOLON) {
2402 if (token != TokenNameendwhile) {
2403 throwSyntaxError("'endwhile' expected.");
2406 if (token != TokenNameSEMICOLON) {
2407 throwSyntaxError("';' expected after while-statement.");
2415 private void foreachStatement() throws CoreException {
2416 if (token == TokenNameCOLON) {
2419 if (token != TokenNameendforeach) {
2420 throwSyntaxError("'endforeach' expected.");
2423 if (token != TokenNameSEMICOLON) {
2424 throwSyntaxError("';' expected after foreach-statement.");
2432 private void exitStatus() throws CoreException {
2433 if (token == TokenNameLPAREN) {
2436 throwSyntaxError("'(' expected in 'exit-status'.");
2438 if (token != TokenNameRPAREN) {
2441 if (token == TokenNameRPAREN) {
2444 throwSyntaxError("')' expected after 'exit-status'.");
2448 private void expressionList() throws CoreException {
2451 if (token == TokenNameCOMMA) {
2459 private void expression() throws CoreException {
2460 //todo: find a better way to get the expression
2461 // expression = new StringBuffer();
2462 // for (int i = chIndx; i < str.length(); i++) {
2463 // if (str.charAt(i) == ';') {
2466 // expression.append(str.charAt(i));
2469 // if (token == TokenNameSTRING_CONSTANT || token == TokenNameINTERPOLATED_STRING) {
2472 logicalinclusiveorExpression();
2473 // while (token != TokenNameSEMICOLON) {
2479 private void postfixExpression() throws CoreException {
2482 boolean castFlag = false;
2488 case TokenNamenull :
2491 case TokenNamefalse :
2494 case TokenNametrue :
2497 case TokenNameStringConstant :
2500 case TokenNameHEREDOC :
2501 case TokenNameStringInterpolated :
2502 case TokenNameStringLiteral :
2505 case TokenNameLPAREN :
2507 if (token == TokenNameIdentifier) {
2508 // check if identifier is a type:
2509 // ident = identifier;
2510 ident = scanner.getCurrentIdentifierSource();
2511 String str = new String(ident).toLowerCase();
2512 for (int i = 0; i < PHP_TYPES.length; i++) {
2513 if (PHP_TYPES[i].equals(str)) {
2520 if (token != TokenNameRPAREN) {
2521 throwSyntaxError(") expected after cast-type '" + str + "'.");
2531 if (token != TokenNameRPAREN) {
2532 throwSyntaxError(") expected in postfix-expression.");
2536 case TokenNameDoubleLiteral :
2539 case TokenNameIntegerLiteral :
2542 case TokenNameDOLLAR_LBRACE :
2545 if (token != TokenNameRBRACE) {
2546 throwSyntaxError("'}' expected after indirect variable token '${'.");
2550 case TokenNameVariable :
2551 ident = scanner.getCurrentIdentifierSource();
2553 if (token == TokenNameLBRACE) {
2556 if (token != TokenNameRBRACE) {
2558 "'}' expected after variable '"
2560 + "' in variable-expression.");
2563 } else if (token == TokenNameLPAREN) {
2565 if (token != TokenNameRPAREN) {
2567 if (token != TokenNameRPAREN) {
2569 "')' expected after variable '"
2571 + "' in postfix-expression.");
2577 case TokenNameIdentifier :
2578 ident = scanner.getCurrentIdentifierSource();
2580 if (token == TokenNameLPAREN) {
2582 if (token != TokenNameRPAREN) {
2584 if (token != TokenNameRPAREN) {
2586 "')' expected after identifier '"
2588 + "' in postfix-expression."
2590 + scanner.toStringAction(token)
2597 case TokenNameprint :
2600 // if (token == TokenNameSEMICOLON) {
2603 // if (token != TokenNameStopPHP) {
2604 // throwSyntaxError("';' expected after 'print' statement.");
2609 case TokenNamelist :
2611 if (token == TokenNameLPAREN) {
2613 if (token == TokenNameCOMMA) {
2617 if (token != TokenNameRPAREN) {
2618 throwSyntaxError("')' expected after 'list' keyword.");
2621 // if (token == TokenNameSET) {
2623 // logicalinclusiveorExpression();
2626 throwSyntaxError("'(' expected after 'list' keyword.");
2629 // case TokenNameexit :
2631 // if (token != TokenNameSEMICOLON) {
2634 // if (token == TokenNameSEMICOLON) {
2637 // if (token != TokenNameStopPHP) {
2638 // throwSyntaxError("';' expected after 'exit' expression.");
2643 // case TokenNamedie :
2645 // if (token != TokenNameSEMICOLON) {
2648 // if (token == TokenNameSEMICOLON) {
2651 // if (token != TokenNameStopPHP) {
2652 // throwSyntaxError("';' expected after 'die' expression.");
2657 // case TokenNamearray :
2659 // if (token == TokenNameARGOPEN) {
2661 // if (token == TokenNameCOMMA) {
2664 // expressionList();
2665 // if (token != TokenNameARGCLOSE) {
2666 // throwSyntaxError("')' expected after 'list' keyword.");
2669 // if (token == TokenNameSET) {
2671 // logicalinclusiveorExpression();
2674 // throwSyntaxError("'(' expected after 'list' keyword.");
2678 boolean while_flag = true;
2681 case TokenNameLBRACKET :
2684 if (token != TokenNameRBRACKET) {
2685 throwSyntaxError("] expected in postfix-expression.");
2689 case TokenNameCOLON_COLON : // ::
2690 case TokenNameMINUS_GREATER : // ->
2692 if (token > TokenNameKEYWORD) {
2693 ident = scanner.getCurrentIdentifierSource();
2695 // "Avoid using keyword '"
2696 // + new String(ident)
2697 // + "' as variable name.",
2701 "Avoid using keyword '"
2703 + "' as variable name.",
2704 scanner.getCurrentTokenStartPosition(),
2705 scanner.getCurrentTokenEndPosition(),
2709 case TokenNameVariable :
2710 ident = scanner.getCurrentIdentifierSource();
2712 // if (token == TokenNameARGOPEN) {
2714 // expressionList();
2715 // if (token != TokenNameARGCLOSE) {
2716 // throwSyntaxError(") expected after variable '" + ident + "'.");
2721 case TokenNameIdentifier :
2722 //ident = scanner.getCurrentIdentifierSource();
2725 case TokenNameLBRACE :
2728 if (token != TokenNameRBRACE) {
2729 throwSyntaxError("} expected in postfix-expression.");
2734 throwSyntaxError("Syntax error after '->' token.");
2736 token == TokenNameLBRACKET
2737 || token == TokenNameLPAREN
2738 || token == TokenNameLBRACE) {
2739 if (token == TokenNameLBRACKET) {
2742 if (token != TokenNameRBRACKET) {
2743 throwSyntaxError("] expected after '->'.");
2747 if (token == TokenNameLPAREN) {
2750 if (token != TokenNameRPAREN) {
2751 throwSyntaxError(") expected after '->'.");
2755 if (token == TokenNameLBRACE) {
2758 if (token != TokenNameRBRACE) {
2759 throwSyntaxError("} expected after '->'.");
2765 case TokenNamePLUS_PLUS :
2768 case TokenNameMINUS_MINUS :
2779 private void unaryExpression() throws CoreException {
2781 case TokenNamePLUS_PLUS :
2785 case TokenNameMINUS_MINUS :
2789 // '@' '&' '*' '+' '-' '~' '!'
2798 case TokenNameMULTIPLY :
2802 case TokenNamePLUS :
2806 case TokenNameMINUS :
2810 case TokenNameTWIDDLE :
2819 postfixExpression();
2823 private void castExpression() throws CoreException {
2824 // if (token == TokenNameARGOPEN) {
2827 // if (token != TokenNameARGCLOSE) {
2828 // throwSyntaxError(") expected after cast-expression.");
2835 // private void typeName() throws CoreException {
2836 // //'string' 'unset' 'array' 'object'
2837 // //'bool' 'boolean'
2838 // //'real' 'double' 'float'
2839 // //'int' 'integer'
2840 // String identifier = "";
2841 // if (token == TokenNameIdentifier) {
2842 // char[] ident = scanner.getCurrentIdentifierSource();
2843 // identifier = new String(ident);
2844 // String str = identifier.toLowerCase();
2846 // for (int i = 0; i < PHP_TYPES.length; i++) {
2847 // if (PHP_TYPES[i].equals(str)) {
2852 // throwSyntaxError(
2853 // "Expected type cast '( <type-name> )'; Got '" + identifier + "'.");
2856 private void assignExpression() throws CoreException {
2858 if (token == TokenNameEQUAL) { // =
2860 logicalinclusiveorExpression();
2861 } else if (token == TokenNameDOT_EQUAL) { // .=
2863 logicalinclusiveorExpression();
2864 } else if (token == TokenNameEQUAL_GREATER) { // =>
2866 logicalinclusiveorExpression();
2867 } else if (token == TokenNamePLUS_EQUAL) { // +=
2869 logicalinclusiveorExpression();
2870 } else if (token == TokenNameMINUS_EQUAL) { // -=
2872 logicalinclusiveorExpression();
2873 } else if (token == TokenNameMULTIPLY_EQUAL) { // *=
2875 logicalinclusiveorExpression();
2876 } else if (token == TokenNameDIVIDE_EQUAL) { // *=
2878 logicalinclusiveorExpression();
2879 } else if (token == TokenNameREMAINDER_EQUAL) { // %=
2881 logicalinclusiveorExpression();
2882 } else if (token == TokenNameAND_EQUAL) { // &=
2884 logicalinclusiveorExpression();
2885 } else if (token == TokenNameOR_EQUAL) { // |=
2887 logicalinclusiveorExpression();
2888 } else if (token == TokenNameXOR_EQUAL) { // ^=
2890 logicalinclusiveorExpression();
2891 } else if (token == TokenNameLEFT_SHIFT_EQUAL) { // <<=
2893 logicalinclusiveorExpression();
2894 } else if (token == TokenNameRIGHT_SHIFT_EQUAL) { // >>=
2896 logicalinclusiveorExpression();
2897 } else if (token == TokenNameTWIDDLE_EQUAL) { // ~=
2899 logicalinclusiveorExpression();
2903 private void multiplicativeExpression() throws CoreException {
2906 if (token != TokenNameMULTIPLY
2907 && token != TokenNameDIVIDE
2908 && token != TokenNameREMAINDER) {
2915 private void concatenationExpression() throws CoreException {
2917 multiplicativeExpression();
2918 if (token != TokenNameDOT) {
2925 private void additiveExpression() throws CoreException {
2927 concatenationExpression();
2928 if (token != TokenNamePLUS && token != TokenNameMINUS) {
2935 private void shiftExpression() throws CoreException {
2937 additiveExpression();
2938 if (token != TokenNameLEFT_SHIFT && token != TokenNameRIGHT_SHIFT) {
2945 private void relationalExpression() throws CoreException {
2948 if (token != TokenNameLESS
2949 && token != TokenNameGREATER
2950 && token != TokenNameLESS_EQUAL
2951 && token != TokenNameGREATER_EQUAL) {
2958 private void identicalExpression() throws CoreException {
2960 relationalExpression();
2961 if (token != TokenNameEQUAL_EQUAL_EQUAL
2962 && token != TokenNameNOT_EQUAL_EQUAL) {
2969 private void equalityExpression() throws CoreException {
2971 identicalExpression();
2972 if (token != TokenNameEQUAL_EQUAL && token != TokenNameNOT_EQUAL) {
2979 private void ternaryExpression() throws CoreException {
2980 equalityExpression();
2981 if (token == TokenNameQUESTION) {
2984 if (token == TokenNameCOLON) {
2988 throwSyntaxError("':' expected in ternary operator '? :'.");
2993 private void andExpression() throws CoreException {
2995 ternaryExpression();
2996 if (token != TokenNameAND) {
3003 private void exclusiveorExpression() throws CoreException {
3006 if (token != TokenNameXOR) {
3013 private void inclusiveorExpression() throws CoreException {
3015 exclusiveorExpression();
3016 if (token != TokenNameOR) {
3023 private void booleanandExpression() throws CoreException {
3025 inclusiveorExpression();
3026 if (token != TokenNameAND_AND) {
3033 private void booleanorExpression() throws CoreException {
3035 booleanandExpression();
3036 if (token != TokenNameOR_OR) {
3043 private void logicalandExpression() throws CoreException {
3045 booleanorExpression();
3046 if (token != TokenNameAND) {
3053 private void logicalexclusiveorExpression() throws CoreException {
3055 logicalandExpression();
3056 if (token != TokenNameXOR) {
3063 private void logicalinclusiveorExpression() throws CoreException {
3065 logicalexclusiveorExpression();
3066 if (token != TokenNameOR) {
3073 // public void assignmentExpression() {
3074 // if (token == TokenNameVARIABLE) {
3076 // if (token == TokenNameSET) {
3078 // logicalinclusiveorExpression();
3081 // logicalinclusiveorExpression();
3085 private void variableList() throws CoreException {
3088 if (token == TokenNameCOMMA) {
3096 private void variable() throws CoreException {
3097 if (token == TokenNameDOLLAR_LBRACE) {
3101 if (token != TokenNameRBRACE) {
3102 throwSyntaxError("'}' expected after indirect variable token '${'.");
3106 if (token == TokenNameVariable) {
3108 if (token == TokenNameLBRACKET) {
3111 if (token != TokenNameRBRACKET) {
3112 throwSyntaxError("']' expected in variable-list.");
3115 } else if (token == TokenNameEQUAL) {
3120 throwSyntaxError("$-variable expected in variable-list.");
3126 * It will look for a value (after a '=' for example)
3127 * @throws CoreException
3129 private void constant() throws CoreException {
3132 case TokenNamePLUS :
3135 case TokenNameDoubleLiteral :
3138 case TokenNameIntegerLiteral :
3142 throwSyntaxError("Constant expected after '+' presign.");
3145 case TokenNameMINUS :
3148 case TokenNameDoubleLiteral :
3151 case TokenNameIntegerLiteral :
3155 throwSyntaxError("Constant expected after '-' presign.");
3158 case TokenNamenull :
3161 case TokenNamefalse :
3164 case TokenNametrue :
3167 case TokenNameIdentifier :
3168 // ident = identifier;
3169 char[] ident = scanner.getCurrentIdentifierSource();
3171 if (token == TokenNameLPAREN) {
3173 if (token != TokenNameRPAREN) {
3175 if (token != TokenNameRPAREN) {
3177 "')' expected after identifier '"
3179 + "' in postfix-expression.");
3185 case TokenNameStringLiteral :
3188 case TokenNameStringConstant :
3191 case TokenNameStringInterpolated :
3194 case TokenNameDoubleLiteral :
3197 case TokenNameIntegerLiteral :
3201 throwSyntaxError("Constant expected.");