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 {
30 public Scanner scanner;
32 private IFile fileToParse;
33 private ArrayList phpList;
35 private int currentPHPString;
36 private boolean phpEnd;
38 // private static HashMap keywordMap = null;
46 // row counter for syntax errors:
48 // column counter for syntax errors:
53 // // current identifier
59 private String stringValue;
61 /** Contains the current expression. */
62 // private StringBuffer expression;
64 private boolean phpMode;
66 // final static int TokenNameEOF = 0;
67 // final static int TokenNameERROR = 1;
68 // final static int TokenNameHTML = 2;
70 // final static int TokenNameREMAINDER = 30;
71 // final static int TokenNameNOT = 31;
72 // final static int TokenNameDOT = 32;
73 // final static int TokenNameXOR = 33;
74 // final static int TokenNameDIVIDE = 34;
75 // final static int TokenNameMULTIPLY = 35;
76 // final static int TokenNameMINUS = 36;
77 // final static int TokenNamePLUS = 37;
78 // final static int TokenNameEQUAL_EQUAL = 38;
79 // final static int TokenNameNOT_EQUAL = 39;
80 // final static int TokenNameGREATER = 40;
81 // final static int TokenNameGREATER_EQUAL = 41;
82 // final static int TokenNameLESS = 42;
83 // final static int TokenNameLESS_EQUAL = 43;
84 // final static int TokenNameAND_AND = 44;
85 // final static int TokenNameOR_OR = 45;
86 // // final static int TokenNameHASH = 46;
87 // final static int TokenNameCOLON = 47;
88 // final static int TokenNameDOT_EQUAL = 48;
90 // final static int TokenNameEQUAL = 49;
91 // final static int TokenNameMINUS_GREATER = 50; // ->
92 // final static int TokenNameFOREACH = 51;
93 // final static int TokenNameAND = 52;
94 // //final static int TokenNameDOLLARLISTOPEN = 53;
95 // final static int TokenNameTWIDDLE = 54;
96 // final static int TokenNameTWIDDLE_EQUAL = 55;
97 // final static int TokenNameREMAINDER_EQUAL = 56;
98 // final static int TokenNameXOR_EQUAL = 57;
99 // final static int TokenNameRIGHT_SHIFT_EQUAL = 58;
100 // final static int TokenNameLEFT_SHIFT_EQUAL = 59;
101 // final static int TokenNameAND_EQUAL = 60;
102 // final static int TokenNameOR_EQUAL = 61;
103 // final static int TokenNameQUESTION = 62;
104 // final static int TokenNameCOLON_COLON = 63;
105 // final static int TokenNameAT = 63;
106 // // final static int TokenNameHEREDOC = 64;
108 // final static int TokenNameDOLLAROPEN = 127;
109 // final static int TokenNameLPAREN = 128;
110 // final static int TokenNameRPAREN = 129;
111 // final static int TokenNameLBRACE = 130;
112 // final static int TokenNameRBRACE = 131;
113 // final static int TokenNameLBRACKET = 132;
114 // final static int TokenNameRBRACKET = 133;
115 // final static int TokenNameCOMMA = 134;
117 // final static int TokenNameStringLiteral = 136;
118 // final static int TokenNameIdentifier = 138;
119 // // final static int TokenNameDIGIT = 139;
120 // final static int TokenNameSEMICOLON = 140;
121 // // final static int TokenNameSLOT = 141;
122 // // final static int TokenNameSLOTSEQUENCE = 142;
123 // final static int TokenNameMINUS_MINUS = 144;
124 // final static int TokenNamePLUS_PLUS = 145;
125 // final static int TokenNamePLUS_EQUAL = 146;
126 // final static int TokenNameDIVIDE_EQUAL = 147;
127 // final static int TokenNameMINUS_EQUAL = 148;
128 // final static int TokenNameMULTIPLY_EQUAL = 149;
129 // final static int TokenNameVariable = 150;
130 // final static int TokenNameIntegerLiteral = 151;
131 // final static int TokenNameDoubleLiteral = 152;
132 // final static int TokenNameStringInterpolated = 153;
133 // final static int TokenNameStringConstant = 154;
135 // final static int TokenNameLEFT_SHIFT = 155;
136 // final static int TokenNameRIGHT_SHIFT = 156;
137 // final static int TokenNameEQUAL_EQUAL_EQUAL = 157;
138 // final static int TokenNameNOT_EQUAL_EQUAL = 158;
139 // final static int TokenNameOR = 159;
140 // final static int TokenNameAT = 153; // @
145 public void setFileToParse(IFile fileToParse) {
146 this.currentPHPString = 0;
147 this.fileToParse = fileToParse;
150 this.token = TokenNameEOF;
152 this.initializeScanner();
158 *@param sess Description of Parameter
161 public Parser(IFile fileToParse) {
162 // if (keywordMap == null) {
163 // keywordMap = new HashMap();
164 // for (int i = 0; i < PHP_KEYWORS.length; i++) {
165 // keywordMap.put(PHP_KEYWORS[i], new Integer(PHP_KEYWORD_TOKEN[i]));
168 this.currentPHPString = 0;
169 this.fileToParse = fileToParse;
172 this.token = TokenNameEOF;
174 // this.rowCount = 1;
175 // this.columnCount = 0;
179 this.initializeScanner();
182 public void initializeScanner() {
183 this.scanner = new Scanner(false, false, false, false);
186 * Create marker for the parse error
188 private void setMarker(
193 throws CoreException {
194 setMarker(fileToParse, message, charStart, charEnd, errorLevel);
198 * This method will throw the SyntaxError.
199 * It will add the good lines and columns to the Error
200 * @param error the error message
201 * @throws SyntaxError the error raised
203 private void throwSyntaxError(String error) {
205 // if (str.length() < chIndx) {
208 // // read until end-of-line
210 // while (str.length() > eol) {
211 // ch = str.charAt(eol++);
217 // throw new SyntaxError(
219 // chIndx - columnCount + 1,
220 // str.substring(columnCount, eol),
222 throw new SyntaxError(1, 1, "", error);
226 * This method will throw the SyntaxError.
227 * It will add the good lines and columns to the Error
228 * @param error the error message
229 * @throws SyntaxError the error raised
231 private void throwSyntaxError(String error, int startRow) {
232 throw new SyntaxError(startRow, 0, " ", error);
236 * Method Declaration.
240 // private void getChar() {
241 // if (str.length() > chIndx) {
242 // ch = str.charAt(chIndx++);
247 // chIndx = str.length() + 1;
249 // // token = TokenNameEOF;
254 * gets the next token from input
256 private void getNextToken() throws CoreException {
258 token = scanner.getNextToken();
260 int currentEndPosition = scanner.getCurrentTokenEndPosition();
261 int currentStartPosition = scanner.getCurrentTokenStartPosition();
264 currentStartPosition + "," + currentEndPosition + ": ");
265 System.out.println(scanner.toStringAction(token));
267 } catch (InvalidInputException e) {
268 token = TokenNameERROR;
272 // boolean phpFound = false;
279 // while (str.length() > chIndx) {
280 // token = TokenNameERROR;
281 // ch = str.charAt(chIndx++);
287 // ch2 = str.charAt(chIndx++);
289 // ch2 = str.charAt(chIndx++);
290 // if (Character.isWhitespace(ch2)) {
295 // } else if (ch2 == 'p' || ch2 == 'P') {
296 // ch2 = str.charAt(chIndx++);
297 // if (ch2 == 'h' || ch2 == 'H') {
298 // ch2 = str.charAt(chIndx++);
299 // if (ch2 == 'p' || ch2 == 'P') {
317 // while (str.length() > chIndx) {
318 // ch = str.charAt(chIndx++);
319 // token = TokenNameERROR;
322 // columnCount = chIndx;
323 // continue; // while loop
325 // if (str.length() == chIndx) {
328 // if (!Character.isWhitespace(ch)) {
330 // if (str.length() > chIndx) {
331 // if (str.charAt(chIndx) == '{') {
333 // token = TokenNameDOLLAROPEN;
340 // if ((ch >= 'a' && ch <= 'z')
341 // || (ch >= 'A' && ch <= 'Z')
347 // if (ch >= '0' && ch <= '9') {
352 // if (str.length() > chIndx) {
353 // if (str.charAt(chIndx) == '/') {
356 // // read comment until end of line:
357 // while ((str.length() > chIndx)
358 // && (ch != '\n')) {
359 // ch = str.charAt(chIndx++);
361 // ch2 = str.charAt(chIndx);
364 // token = TokenNameHTML;
375 // } else if (str.charAt(chIndx) == '*') {
377 // // multi line comment:
378 // while (str.length() > chIndx) {
379 // if (str.charAt(chIndx) == '*'
380 // && (str.length() > (chIndx + 1))
381 // && str.charAt(chIndx + 1) == '/') {
385 // ch = str.charAt(chIndx++);
388 // columnCount = chIndx;
394 // } else if (ch == '#') {
395 // // read comment until end of line:
396 // while ((str.length() > chIndx) && (ch != '\n')) {
397 // ch = str.charAt(chIndx++);
399 // ch2 = str.charAt(chIndx);
402 // token = TokenNameHTML;
413 // } else if (ch == '"') {
416 // TokenNameStringInterpolated,
417 // "Open string character '\"' at end of file.");
419 // } else if (ch == '\'') {
422 // TokenNameStringConstant,
423 // "Open string character \"'\" at end of file.");
425 // } else if (ch == '`') {
428 // TokenNameStringConstant,
429 // "Open string character \"`\" at end of file.");
431 // "Other string delimiters prefered (found \"`\").",
440 // token = TokenNameLPAREN;
444 // token = TokenNameRPAREN;
448 // token = TokenNameLBRACE;
452 // token = TokenNameRBRACE;
456 // token = TokenNameLBRACKET;
460 // token = TokenNameRBRACKET;
464 // token = TokenNameCOMMA;
468 // token = TokenNameQUESTION;
469 // if (str.length() > chIndx) {
470 // if (str.charAt(chIndx) == '>') {
472 // token = TokenNameHTML;
482 // token = TokenNameAT;
485 // token = TokenNameTWIDDLE;
486 // if (str.length() > chIndx) {
487 // if (str.charAt(chIndx) == '=') {
489 // token = TokenNameTWIDDLE_EQUAL;
496 // token = TokenNameDOT;
497 // if (str.length() > chIndx) {
498 // if (str.charAt(chIndx) == '=') {
500 // token = TokenNameDOT_EQUAL;
508 // token = TokenNameStringLiteral;
512 // token = TokenNameREMAINDER;
513 // if (str.length() > chIndx) {
514 // if (str.charAt(chIndx) == '=') {
516 // token = TokenNameREMAINDER_EQUAL;
523 // token = TokenNameSEMICOLON;
527 // token = TokenNameXOR;
528 // if (str.length() > chIndx) {
529 // if (str.charAt(chIndx) == '=') {
531 // token = TokenNameXOR_EQUAL;
538 // token = TokenNameDIVIDE;
540 // if (str.length() > chIndx) {
541 // if (str.charAt(chIndx) == '=') {
543 // token = TokenNameDIVIDE_EQUAL;
551 // token = TokenNameMULTIPLY;
552 // if (str.length() > chIndx) {
553 // if (str.charAt(chIndx) == '*') {
555 // token = TokenNameXOR;
559 // if (str.charAt(chIndx) == '=') {
561 // token = TokenNameMULTIPLY_EQUAL;
569 // token = TokenNamePLUS;
570 // if (str.length() > chIndx) {
571 // if (str.charAt(chIndx) == '+') {
573 // token = TokenNamePLUS_PLUS;
577 // if (str.charAt(chIndx) == '=') {
579 // token = TokenNamePLUS_EQUAL;
586 // token = TokenNameMINUS;
587 // if (str.length() > chIndx) {
588 // if (str.charAt(chIndx) == '-') {
590 // token = TokenNameMINUS_MINUS;
594 // if (str.charAt(chIndx) == '=') {
596 // token = TokenNameMINUS_EQUAL;
600 // if (str.charAt(chIndx) == '>') {
602 // token = TokenNameMINUS_GREATER;
610 // token = TokenNameEQUAL;
612 // if (str.length() > chIndx) {
613 // ch = str.charAt(chIndx);
617 // token = TokenNameEQUAL_EQUAL;
618 // if (str.length() > chIndx) {
619 // ch = str.charAt(chIndx);
624 // TokenNameEQUAL_EQUAL_EQUAL;
631 // token = TokenNameEQUAL_GREATER;
639 // token = TokenNameNOT;
641 // if (str.length() > chIndx) {
642 // if (str.charAt(chIndx) == '=') {
644 // token = TokenNameNOT_EQUAL;
645 // if (str.length() > chIndx) {
646 // ch = str.charAt(chIndx);
651 // TokenNameNOT_EQUAL_EQUAL;
660 // token = TokenNameGREATER;
662 // if (str.length() > chIndx) {
663 // if (str.charAt(chIndx) == '=') {
665 // token = TokenNameGREATER_EQUAL;
668 // if (str.charAt(chIndx) == '>') {
670 // token = TokenNameRIGHT_SHIFT;
671 // if (str.length() > chIndx) {
672 // if (str.charAt(chIndx) == '=') {
675 // TokenNameRIGHT_SHIFT_EQUAL;
685 // token = TokenNameLESS;
687 // if (str.length() > chIndx) {
688 // if (str.charAt(chIndx) == '=') {
690 // token = TokenNameLESS_EQUAL;
694 // if (str.charAt(chIndx) == '<') {
696 // token = TokenNameLEFT_SHIFT;
697 // if (str.charAt(chIndx) == '<') {
699 // int startRow = rowCount;
700 // if (str.length() > chIndx) {
702 // ch = str.charAt(++chIndx);
703 // if ((ch >= 'a' && ch <= 'z')
704 // || (ch >= 'A' && ch <= 'Z')
709 // TokenNameStringConstant;
710 // while (str.length()
726 // .equals(identifier)) {
738 // "Open heredoc syntax after operator '<<<'.",
740 // } else if (str.charAt(chIndx) == '=') {
742 // token = TokenNameLEFT_SHIFT_EQUAL;
752 // token = TokenNameOR;
754 // if (str.length() > chIndx) {
755 // if (str.charAt(chIndx) == '|') {
757 // token = TokenNameOR_OR;
760 // if (str.charAt(chIndx) == '=') {
762 // token = TokenNameOR_EQUAL;
769 // token = TokenNameAND;
770 // if (str.length() > chIndx) {
771 // if (str.charAt(chIndx) == '&') {
773 // token = TokenNameAND_AND;
776 // if (str.charAt(chIndx) == '=') {
778 // token = TokenNameAND_EQUAL;
786 // token = TokenNameCOLON;
787 // if (str.length() > chIndx) {
788 // if (str.charAt(chIndx) == ':') {
790 // token = TokenNameCOLON_COLON;
795 // // token = TokenNameHASH;
799 // // token = TokenNameAT;
804 // "unexpected character: '" + ch + "'");
807 // if (token == TokenNameERROR) {
808 // throwSyntaxError("token not found");
815 // } catch (StringIndexOutOfBoundsException e) {
816 // // catched from charAt
819 // chIndx = str.length() + 1;
821 // token = TokenNameEOF;
824 // // if (phpList != null) {
825 // // if (currentPHPString < phpList.size()) {
826 // // token = TokenNameUNDEFINED;
827 // // temp = (PHPString) phpList.get(currentPHPString++);
828 // // this.str = temp.getPHPString();
829 // // this.token = TokenNameEOF;
830 // // this.chIndx = 0;
831 // // this.rowCount = temp.getLineNumber();
832 // // this.columnCount = 0;
833 // // getNextToken();
836 // // token = TokenNameUNDEFINED;
843 // * Get an identifier.
845 // private void getIdentifier() {
846 // // StringBuffer ident = new StringBuffer();
847 // int startPosition = chIndx - 1;
848 // // ident.append(ch);
851 // // attention recursive call:
853 // token = TokenNameVariable;
856 // token = TokenNameIdentifier;
861 // //this will read the buffer until the next character is a forbidden character for identifier
862 // while ((ch >= 'a' && ch <= 'z')
863 // || (ch >= 'A' && ch <= 'Z')
864 // || (ch >= '0' && ch <= '9')
866 // // ident.append(ch);
869 // int endPosition = chIndx--;
870 // int length = (--endPosition) - startPosition;
872 // identifier = str.substring(startPosition, endPosition);
873 // // System.out.println(identifier);
875 // // determine if this identitfer is a keyword
876 // // @todo improve this in future version
877 // Integer i = (Integer) keywordMap.get(identifier.toLowerCase());
879 // token = i.intValue();
885 * if it's a <code>double</code> the number will be stored in <code>doubleNumber</code> and the token will have the
886 * value {@link Parser#TokenNameDOUBLE_NUMBER}<br />
887 * if it's a <code>double</code> the number will be stored in <code>longNumber</code> and the token will have the
888 * value {@link Parser#TokenNameINT_NUMBER}
890 // private void getNumber() {
891 // StringBuffer inum = new StringBuffer();
893 // int numFormat = 10;
895 // // save first digit
896 // char firstCh = ch;
900 // // determine number conversions:
901 // if (firstCh == '0') {
930 // if (numFormat == 16) {
931 // while ((ch >= '0' && ch <= '9')
932 // || (ch >= 'a' && ch <= 'f')
933 // || (ch >= 'A' && ch <= 'F')) {
938 // while ((ch >= '0' && ch <= '9')
942 // if ((ch == '.') || (ch == 'E') || (ch == 'e')) {
943 // if (ch == '.' && dFlag != ' ') {
946 // if ((dFlag == 'E') || (dFlag == 'e')) {
952 // if ((ch == '-') || (ch == '+')) {
965 // if (dFlag != ' ') {
966 // doubleNumber = new Double(inum.toString());
967 // token = TokenNameDoubleLiteral;
970 // longNumber = Long.valueOf(inum.toString(), numFormat);
971 // token = TokenNameIntegerLiteral;
975 // } catch (Throwable e) {
976 // throwSyntaxError("Number format error: " + inum.toString());
982 // * @param openChar the opening char ('\'', '"', '`')
983 // * @param typeString the type of string {@link #TokenNameSTRING_CONSTANT},{@link #TokenNameINTERPOLATED_STRING}
984 // * @param errorMsg the error message in case of parse error in the string
986 // private void getString(
987 // final char openChar,
988 // final int typeString,
989 // final String errorMsg) {
990 // StringBuffer sBuffer = new StringBuffer();
991 // boolean openString = true;
992 // int startRow = rowCount;
993 // while (str.length() > chIndx) {
994 // ch = str.charAt(chIndx++);
996 // sBuffer.append(ch);
997 // if (str.length() > chIndx) {
998 // ch = str.charAt(chIndx++);
999 // sBuffer.append(ch);
1001 // } else if (ch == openChar) {
1002 // openString = false;
1004 // } else if (ch == '\n') {
1006 // columnCount = chIndx;
1008 // sBuffer.append(ch);
1011 // if (openString) {
1012 // if (typeString == TokenNameStringConstant) {
1013 // throwSyntaxError(errorMsg, startRow);
1015 // throwSyntaxError(errorMsg);
1018 // token = typeString;
1019 // stringValue = sBuffer.toString();
1022 // public void htmlParserTester(String input) {
1023 // int lineNumber = 1;
1024 // int startLineNumber = 1;
1025 // int startIndex = 0;
1028 // boolean phpMode = false;
1029 // boolean phpFound = false;
1031 // phpList = new ArrayList();
1032 // currentPHPString = 0;
1036 // while (i < input.length()) {
1037 // ch = input.charAt(i++);
1038 // if (ch == '\n') {
1041 // if ((!phpMode) && ch == '<') {
1042 // ch2 = input.charAt(i++);
1043 // if (ch2 == '?') {
1044 // ch2 = input.charAt(i++);
1045 // if (Character.isWhitespace(ch2)) {
1050 // startLineNumber = lineNumber;
1052 // } else if (ch2 == 'p') {
1053 // ch2 = input.charAt(i++);
1054 // if (ch2 == 'h') {
1055 // ch2 = input.charAt(i++);
1056 // if (ch2 == 'p') {
1060 // startLineNumber = lineNumber;
1066 // } else if (ch2 == 'P') {
1067 // ch2 = input.charAt(i++);
1068 // if (ch2 == 'H') {
1069 // ch2 = input.charAt(i++);
1070 // if (ch2 == 'P') {
1074 // startLineNumber = lineNumber;
1087 // if (ch == '/' && i < input.length()) {
1088 // ch2 = input.charAt(i++);
1089 // if (ch2 == '/') {
1090 // while (i < input.length()) {
1091 // ch = input.charAt(i++);
1092 // if (ch == '?' && i < input.length()) {
1093 // ch2 = input.charAt(i++);
1094 // if (ch2 == '>') {
1102 // startLineNumber));
1106 // } else if (ch == '\n') {
1112 // } else if (ch2 == '*') {
1113 // // multi-line comment
1114 // while (i < input.length()) {
1115 // ch = input.charAt(i++);
1116 // if (ch == '\n') {
1118 // } else if (ch == '*' && i < input.length()) {
1119 // ch2 = input.charAt(i++);
1120 // if (ch2 == '/') {
1130 // } else if (ch == '#') {
1131 // while (i < input.length()) {
1132 // ch = input.charAt(i++);
1133 // if (ch == '?' && i < input.length()) {
1134 // ch2 = input.charAt(i++);
1135 // if (ch2 == '>') {
1140 // input.substring(startIndex, i - 2),
1141 // startLineNumber));
1145 // } else if (ch == '\n') {
1151 // } else if (ch == '"') {
1153 // while (i < input.length()) {
1154 // ch = input.charAt(i++);
1155 // if (ch == '\n') {
1158 // ch == '\\' && i < input.length()) { // escape
1160 // } else if (ch == '"') {
1165 // } else if (ch == '\'') {
1167 // while (i < input.length()) {
1168 // ch = input.charAt(i++);
1169 // if (ch == '\n') {
1172 // ch == '\\' && i < input.length()) { // escape
1174 // } else if (ch == '\'') {
1181 // if (ch == '?' && i < input.length()) {
1182 // ch2 = input.charAt(i++);
1183 // if (ch2 == '>') {
1188 // input.substring(startIndex, i - 2),
1189 // startLineNumber));
1199 // "No PHP source code found.",
1205 // "Open PHP tag at end of file.",
1210 // input.substring(startIndex, i - 2),
1211 // startLineNumber));
1213 // // for (int j=0;j<phpList.size();j++) {
1214 // // String temp = ((PHPString)phpList.get(j)).getPHPString();
1215 // // int startIndx = temp.length()-10;
1216 // // if (startIndx<0) {
1217 // // startIndx = 0;
1219 // // System.out.println(temp.substring(startIndx)+"?>");
1221 // phpParserTester(null, 1);
1222 // // PHPString temp;
1223 // // for(int j=0;j<phpList.size();j++) {
1224 // // temp = (PHPString) phpList.get(j);
1225 // // parser.start(temp.getPHPString(), temp.getLineNumber());
1228 // } catch (CoreException e) {
1232 public void phpParserTester(String s, int rowCount) throws CoreException {
1235 if (phpList.size() != 0) {
1236 this.str = ((PHPString) phpList.get(currentPHPString++)).getPHPString();
1239 this.token = TokenNameEOF;
1241 // this.rowCount = rowCount;
1242 // this.columnCount = 0;
1243 this.phpEnd = false;
1244 this.phpMode = true;
1245 scanner.setSource(s.toCharArray());
1246 scanner.setPHPMode(true);
1250 if (token != TokenNameEOF && token != TokenNameERROR) {
1253 if (token != TokenNameEOF) {
1254 if (token == TokenNameERROR) {
1256 "Scanner error (Found unknown token: "
1257 + scanner.toStringAction(token)
1260 if (token == TokenNameRPAREN) {
1261 throwSyntaxError("Too many closing ')'; end-of-file not reached.");
1263 if (token == TokenNameRBRACE) {
1264 throwSyntaxError("Too many closing '}'; end-of-file not reached.");
1266 if (token == TokenNameRBRACKET) {
1267 throwSyntaxError("Too many closing ']'; end-of-file not reached.");
1270 if (token == TokenNameLPAREN) {
1271 throwSyntaxError("Read character '('; end-of-file not reached.");
1273 if (token == TokenNameLBRACE) {
1274 throwSyntaxError("Read character '{'; end-of-file not reached.");
1276 if (token == TokenNameLBRACKET) {
1277 throwSyntaxError("Read character '['; end-of-file not reached.");
1280 throwSyntaxError("End-of-file not reached.");
1283 } catch (SyntaxError err) {
1287 // setMarker(err.getMessage(), err.getLine(), ERROR);
1290 scanner.getCurrentTokenStartPosition(),
1291 scanner.getCurrentTokenEndPosition(),
1294 // if an error occured,
1295 // try to find keywords 'class' or 'function'
1296 // to parse the rest of the string
1297 while (token != TokenNameEOF && token != TokenNameERROR) {
1298 if (token == TokenNameclass || token == TokenNamefunction) {
1303 if (token == TokenNameEOF || token == TokenNameERROR) {
1312 * Parses a string with php tags
1313 * i.e. '<body> <?php phpinfo() ?> </body>'
1315 public void parse(String s) throws CoreException {
1317 this.token = TokenNameEOF;
1319 // this.rowCount = 1;
1320 // this.columnCount = 0;
1321 this.phpEnd = false;
1322 this.phpMode = false;
1323 /* scanner initialization */
1324 scanner.setSource(s.toCharArray());
1325 scanner.setPHPMode(false);
1329 if (token != TokenNameEOF && token != TokenNameERROR) {
1332 if (token != TokenNameEOF) {
1333 if (token == TokenNameERROR) {
1335 "Scanner error (Found unknown token: "
1336 + scanner.toStringAction(token)
1339 if (token == TokenNameRPAREN) {
1340 throwSyntaxError("Too many closing ')'; end-of-file not reached.");
1342 if (token == TokenNameRBRACE) {
1343 throwSyntaxError("Too many closing '}'; end-of-file not reached.");
1345 if (token == TokenNameRBRACKET) {
1346 throwSyntaxError("Too many closing ']'; end-of-file not reached.");
1349 if (token == TokenNameLPAREN) {
1350 throwSyntaxError("Read character '('; end-of-file not reached.");
1352 if (token == TokenNameLBRACE) {
1353 throwSyntaxError("Read character '{'; end-of-file not reached.");
1355 if (token == TokenNameLBRACKET) {
1356 throwSyntaxError("Read character '['; end-of-file not reached.");
1359 throwSyntaxError("End-of-file not reached.");
1362 } catch (SyntaxError sytaxErr1) {
1363 // setMarker(sytaxErr1.getMessage(), sytaxErr1.getLine(), ERROR);
1365 sytaxErr1.getMessage(),
1366 scanner.getCurrentTokenStartPosition(),
1367 scanner.getCurrentTokenEndPosition(),
1370 // if an error occured,
1371 // try to find keywords 'class' or 'function'
1372 // to parse the rest of the string
1373 while (token != TokenNameEOF && token != TokenNameERROR) {
1374 if (token == TokenNameclass || token == TokenNamefunction) {
1379 if (token == TokenNameEOF || token == TokenNameERROR) {
1382 } catch (SyntaxError sytaxErr2) {
1383 // setMarker(sytaxErr2.getMessage(), sytaxErr2.getLine(), ERROR);
1385 sytaxErr2.getMessage(),
1386 scanner.getCurrentTokenStartPosition(),
1387 scanner.getCurrentTokenEndPosition(),
1396 public PHPOutlineInfo parseInfo(Object parent, String s) {
1397 PHPOutlineInfo outlineInfo = new PHPOutlineInfo(parent);
1398 // Stack stack = new Stack();
1399 // stack.push(outlineInfo.getDeclarations());
1402 this.token = TokenNameEOF;
1404 // this.rowCount = 1;
1405 // this.columnCount = 0;
1406 this.phpEnd = false;
1407 this.phpMode = false;
1408 scanner.setSource(s.toCharArray());
1409 scanner.setPHPMode(false);
1413 parseDeclarations(outlineInfo, outlineInfo.getDeclarations(), false);
1414 } catch (CoreException e) {
1419 private void parseDeclarations(
1420 PHPOutlineInfo outlineInfo,
1421 PHPSegmentWithChildren current,
1424 // PHPClassDeclaration current = (PHPClassDeclaration) stack.peek();
1425 PHPSegmentWithChildren temp;
1428 IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
1430 while (token != TokenNameEOF && token != TokenNameERROR) {
1431 if (token == TokenNameVariable) {
1432 ident = scanner.getCurrentIdentifierSource();
1433 outlineInfo.addVariable(new String(ident));
1435 } else if (token == TokenNamevar) {
1437 if (token == TokenNameVariable
1438 && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_VAR)) {
1439 ident = scanner.getCurrentIdentifierSource();
1440 String variableName = new String(ident);
1441 outlineInfo.addVariable(variableName);
1443 if (token != TokenNameSEMICOLON) {
1446 ident = scanner.getCurrentTokenSource();
1447 if (token > TokenNameKEYWORD) {
1448 current.add(new PHPVarDeclaration(current, variableName,
1449 // chIndx - ident.length,
1450 scanner.getCurrentTokenStartPosition(), new String(ident)));
1453 case TokenNameVariable :
1454 current.add(new PHPVarDeclaration(current, variableName,
1455 // chIndx - ident.length,
1456 scanner.getCurrentTokenStartPosition(), new String(ident)));
1458 case TokenNameIdentifier :
1459 current.add(new PHPVarDeclaration(current, variableName,
1460 // chIndx - ident.length,
1461 scanner.getCurrentTokenStartPosition(), new String(ident)));
1463 case TokenNameDoubleLiteral :
1465 .add(new PHPVarDeclaration(
1467 variableName + doubleNumber,
1468 // chIndx - ident.length,
1469 scanner.getCurrentTokenStartPosition(), new String(ident)));
1471 case TokenNameIntegerLiteral :
1472 current.add(new PHPVarDeclaration(current, variableName,
1473 // chIndx - ident.length,
1474 scanner.getCurrentTokenStartPosition(), new String(ident)));
1476 case TokenNameStringInterpolated :
1477 case TokenNameStringLiteral :
1478 current.add(new PHPVarDeclaration(current, variableName,
1479 // chIndx - ident.length,
1480 scanner.getCurrentTokenStartPosition(), new String(ident)));
1482 case TokenNameStringConstant :
1483 current.add(new PHPVarDeclaration(current, variableName,
1484 // chIndx - ident.length,
1485 scanner.getCurrentTokenStartPosition(), new String(ident)));
1488 current.add(new PHPVarDeclaration(current, variableName,
1489 // chIndx - ident.length
1490 scanner.getCurrentTokenStartPosition()));
1496 ident = scanner.getCurrentIdentifierSource();
1498 current.add(new PHPVarDeclaration(current, variableName,
1499 // chIndx - ident.length
1500 scanner.getCurrentTokenStartPosition()));
1503 } else if (token == TokenNamefunction) {
1505 if (token == TokenNameAND) {
1508 if (token == TokenNameIdentifier
1509 && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_FUNC)) {
1510 ident = scanner.getCurrentIdentifierSource();
1511 outlineInfo.addVariable(new String(ident));
1512 temp = new PHPFunctionDeclaration(current, new String(ident),
1513 // chIndx - ident.length
1514 scanner.getCurrentTokenStartPosition());
1517 parseDeclarations(outlineInfo, temp, true);
1519 } else if (token == TokenNameclass) {
1521 if (token == TokenNameIdentifier
1522 && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_CLASS)) {
1523 ident = scanner.getCurrentIdentifierSource();
1524 outlineInfo.addVariable(new String(ident));
1525 temp = new PHPClassDeclaration(current, new String(ident),
1526 // chIndx - ident.len
1527 scanner.getCurrentTokenStartPosition());
1529 // stack.push(temp);
1532 //skip tokens for classname, extends and others until we have the opening '{'
1533 while (token != TokenNameLBRACE
1534 && token != TokenNameEOF
1535 && token != TokenNameERROR) {
1538 parseDeclarations(outlineInfo, temp, true);
1541 } else if (token == TokenNameLBRACE) {
1544 } else if (token == TokenNameRBRACE) {
1547 if (counter == 0 && goBack) {
1551 token == TokenNamerequire
1552 || token == TokenNamerequire_once
1553 || token == TokenNameinclude
1554 || token == TokenNameinclude_once) {
1555 ident = scanner.getCurrentTokenSource();
1558 int startPosition = scanner.getCurrentTokenStartPosition();
1560 char[] expr = scanner.getCurrentTokenSource(startPosition);
1561 outlineInfo.addVariable(new String(ident));
1562 current.add(new PHPReqIncDeclaration(current, new String(ident),
1563 // chIndx - ident.length,
1564 startPosition, new String(expr)));
1570 } catch (CoreException e) {
1571 } catch (SyntaxError sytaxErr) {
1573 // setMarker(sytaxErr.getMessage(), sytaxErr.getLine(), ERROR);
1575 sytaxErr.getMessage(),
1576 scanner.getCurrentTokenStartPosition(),
1577 scanner.getCurrentTokenEndPosition(),
1579 } catch (CoreException e) {
1584 private void statementList() throws CoreException {
1587 if ((token == TokenNameRBRACE)
1588 || (token == TokenNamecase)
1589 || (token == TokenNamedefault)
1590 || (token == TokenNameelseif)
1591 || (token == TokenNameendif)
1592 || (token == TokenNameendfor)
1593 || (token == TokenNameendforeach)
1594 || (token == TokenNameendwhile)
1595 || (token == TokenNameendswitch)
1596 || (token == TokenNameEOF)
1597 || (token == TokenNameERROR)) {
1603 private void compoundStatement() throws CoreException {
1604 // '{' [statement-list] '}'
1605 if (token == TokenNameLBRACE) {
1608 throwSyntaxError("'{' expected in compound-statement.");
1610 if (token != TokenNameRBRACE) {
1613 if (token == TokenNameRBRACE) {
1616 throwSyntaxError("'}' expected in compound-statement.");
1620 private void statement() throws CoreException {
1621 // if (token > TokenNameKEYWORD && token != TokenNamelist && token != TokenNamenew) {
1622 // char[] ident = scanner.getCurrentIdentifierSource();
1623 // String keyword = new String(ident);
1624 if (token == TokenNameinclude || token == TokenNameinclude_once) {
1627 if (token == TokenNameSEMICOLON) {
1630 if (token != TokenNameStopPHP) {
1631 throwSyntaxError("';' character after 'include' or 'include_once' expected.");
1636 } else if (token == TokenNamerequire || token == TokenNamerequire_once) {
1640 if (token == TokenNameSEMICOLON) {
1643 if (token != TokenNameStopPHP) {
1644 throwSyntaxError("';' character after 'require' or 'require_once' expected.");
1649 } else if (token == TokenNameif) {
1651 if (token == TokenNameLPAREN) {
1654 throwSyntaxError("'(' expected after 'if' keyword.");
1657 if (token == TokenNameRPAREN) {
1660 throwSyntaxError("')' expected after 'if' condition.");
1665 } else if (token == TokenNameswitch) {
1667 if (token == TokenNameLPAREN) {
1670 throwSyntaxError("'(' expected after 'switch' keyword.");
1673 if (token == TokenNameRPAREN) {
1676 throwSyntaxError("')' expected after 'switch' condition.");
1680 } else if (token == TokenNamefor) {
1682 if (token == TokenNameLPAREN) {
1685 throwSyntaxError("'(' expected after 'for' keyword.");
1687 if (token == TokenNameSEMICOLON) {
1691 if (token == TokenNameSEMICOLON) {
1694 throwSyntaxError("';' expected after 'for'.");
1697 if (token == TokenNameSEMICOLON) {
1701 if (token == TokenNameSEMICOLON) {
1704 throwSyntaxError("';' expected after 'for'.");
1707 if (token == TokenNameRPAREN) {
1711 if (token == TokenNameRPAREN) {
1714 throwSyntaxError("')' expected after 'for'.");
1719 } else if (token == TokenNamewhile) {
1721 if (token == TokenNameLPAREN) {
1724 throwSyntaxError("'(' expected after 'while' keyword.");
1727 if (token == TokenNameRPAREN) {
1730 throwSyntaxError("')' expected after 'while' condition.");
1734 } else if (token == TokenNamedo) {
1736 if (token == TokenNameLBRACE) {
1739 throwSyntaxError("'{' expected after 'do' keyword.");
1741 if (token != TokenNameRBRACE) {
1744 if (token == TokenNameRBRACE) {
1747 throwSyntaxError("'}' expected after 'do' keyword.");
1749 if (token == TokenNamewhile) {
1751 if (token == TokenNameLPAREN) {
1754 throwSyntaxError("'(' expected after 'while' keyword.");
1757 if (token == TokenNameRPAREN) {
1760 throwSyntaxError("')' expected after 'while' condition.");
1763 throwSyntaxError("'while' expected after 'do' keyword.");
1765 if (token == TokenNameSEMICOLON) {
1768 if (token != TokenNameStopPHP) {
1769 throwSyntaxError("';' expected after do-while statement.");
1774 } else if (token == TokenNameforeach) {
1776 if (token == TokenNameLPAREN) {
1779 throwSyntaxError("'(' expected after 'foreach' keyword.");
1782 if (token == TokenNameas) {
1785 throwSyntaxError("'as' expected after 'foreach' exxpression.");
1788 if (token == TokenNameEQUAL_GREATER) {
1792 if (token == TokenNameRPAREN) {
1795 throwSyntaxError("')' expected after 'foreach' expression.");
1801 token == TokenNamecontinue
1802 || token == TokenNamebreak
1803 || token == TokenNamereturn) {
1805 if (token != TokenNameSEMICOLON) {
1808 if (token == TokenNameSEMICOLON) {
1811 if (token != TokenNameStopPHP) {
1812 throwSyntaxError("';' expected after 'continue', 'break' or 'return'.");
1818 } else if (token == TokenNameecho) {
1821 if (token == TokenNameSEMICOLON) {
1824 if (token != TokenNameStopPHP) {
1825 throwSyntaxError("';' expected after 'echo' statement.");
1830 // } else if (token == TokenNameprint) {
1833 // if (token == TokenNameSEMICOLON) {
1836 // if (token != TokenNameStopPHP) {
1837 // throwSyntaxError("';' expected after 'print' statement.");
1843 } else if (token == TokenNameglobal || token == TokenNamestatic) {
1846 if (token == TokenNameSEMICOLON) {
1849 if (token != TokenNameStopPHP) {
1850 throwSyntaxError("';' expected after 'global' or 'static' statement.");
1856 // } else if (token == TokenNameunset) {
1858 // if (token == TokenNameARGOPEN) {
1861 // throwSyntaxError("'(' expected after 'unset' keyword.");
1864 // if (token == TokenNameARGCLOSE) {
1867 // throwSyntaxError("')' expected after 'unset' statement.");
1869 // if (token == TokenNameSEMICOLON) {
1872 // if (token != TokenNameStopPHP) {
1873 // throwSyntaxError("';' expected after 'unset' statement.");
1879 // } else if (token == TokenNameexit || token == TokenNamedie) {
1881 // if (token != TokenNameSEMICOLON) {
1884 // if (token == TokenNameSEMICOLON) {
1887 // if (token != TokenNameStopPHP) {
1888 // throwSyntaxError("';' expected after 'exit' or 'die' statement.");
1894 } else if (token == TokenNamedefine) {
1896 if (token == TokenNameLPAREN) {
1899 throwSyntaxError("'(' expected after 'define' keyword.");
1902 if (token == TokenNameCOMMA) {
1905 throwSyntaxError("',' expected after first 'define' constant.");
1908 if (token == TokenNameCOMMA) {
1912 if (token == TokenNameRPAREN) {
1915 throwSyntaxError("')' expected after 'define' statement.");
1917 if (token == TokenNameSEMICOLON) {
1920 if (token != TokenNameStopPHP) {
1921 throwSyntaxError("';' expected after 'define' statement.");
1926 } else if (token == TokenNamefunction) {
1928 functionDefinition();
1930 } else if (token == TokenNameclass) {
1936 // throwSyntaxError("Unexpected keyword '" + keyword + "'");
1937 } else if (token == TokenNameLBRACE) {
1938 // compoundStatement
1940 if (token != TokenNameRBRACE) {
1943 if (token == TokenNameRBRACE) {
1947 throwSyntaxError("'}' expected.");
1950 if (token != TokenNameSEMICOLON) {
1953 if (token == TokenNameSEMICOLON) {
1957 if (token != TokenNameStopPHP && token != TokenNameEOF) {
1959 "';' expected after expression (Found token: "
1960 + scanner.toStringAction(token)
1968 private void classDeclarator() throws CoreException {
1970 //identifier 'extends' identifier
1971 if (token == TokenNameIdentifier) {
1973 if (token == TokenNameextends) {
1975 if (token == TokenNameIdentifier) {
1978 throwSyntaxError("Class name expected after keyword 'extends'.");
1982 if (token > TokenNameKEYWORD) {
1984 "Don't use keyword for class declaration [" + token + "].");
1986 throwSyntaxError("Class name expected after keyword 'class'.");
1990 private void classBody() throws CoreException {
1991 //'{' [class-element-list] '}'
1992 if (token == TokenNameLBRACE) {
1994 if (token != TokenNameRBRACE) {
1997 if (token == TokenNameRBRACE) {
2000 throwSyntaxError("'}' expected at end of class body.");
2003 throwSyntaxError("'{' expected at start of class body.");
2007 private void classElementList() throws CoreException {
2010 } while (token == TokenNamefunction || token == TokenNamevar);
2013 private void classElement() throws CoreException {
2015 //function-definition
2016 if (token == TokenNamefunction) {
2018 functionDefinition();
2019 } else if (token == TokenNamevar) {
2023 throwSyntaxError("'function' or 'var' expected.");
2027 private void classProperty() throws CoreException {
2028 //'var' variable ';'
2029 //'var' variable '=' constant ';'
2031 if (token == TokenNameVariable) {
2033 if (token == TokenNameEQUAL) {
2038 throwSyntaxError("Variable expected after keyword 'var'.");
2040 if (token != TokenNameCOMMA) {
2045 if (token == TokenNameSEMICOLON) {
2048 throwSyntaxError("';' expected after variable declaration.");
2052 private void functionDefinition() throws CoreException {
2053 functionDeclarator();
2054 compoundStatement();
2057 private void functionDeclarator() throws CoreException {
2058 //identifier '(' [parameter-list] ')'
2059 if (token == TokenNameAND) {
2062 if (token == TokenNameIdentifier) {
2064 if (token == TokenNameLPAREN) {
2067 throwSyntaxError("'(' expected in function declaration.");
2069 if (token != TokenNameRPAREN) {
2072 if (token != TokenNameRPAREN) {
2073 throwSyntaxError("')' expected in function declaration.");
2078 if (token > TokenNameKEYWORD) {
2080 "Don't use keyword for function declaration [" + token + "].");
2082 throwSyntaxError("Function name expected after keyword 'function'.");
2086 private void parameterList() throws CoreException {
2087 //parameter-declaration
2088 //parameter-list ',' parameter-declaration
2090 parameterDeclaration();
2091 if (token != TokenNameCOMMA) {
2098 private void parameterDeclaration() throws CoreException {
2100 //variable-reference
2101 if (token == TokenNameAND) {
2103 if (token == TokenNameVariable) {
2106 throwSyntaxError("Variable expected after reference operator '&'.");
2109 //variable '=' constant
2110 if (token == TokenNameVariable) {
2112 if (token == TokenNameEQUAL) {
2120 private void labeledStatementList() throws CoreException {
2121 if (token != TokenNamecase && token != TokenNamedefault) {
2122 throwSyntaxError("'case' or 'default' expected.");
2125 if (token == TokenNamecase) {
2128 if (token == TokenNameCOLON) {
2130 if (token == TokenNamecase
2131 || token == TokenNamedefault) { // empty case statement ?
2135 } else if (token == TokenNameSEMICOLON) {
2137 // "':' expected after 'case' keyword (Found token: "
2138 // + scanner.toStringAction(token)
2143 "':' expected after 'case' keyword (Found token: "
2144 + scanner.toStringAction(token)
2146 scanner.getCurrentTokenStartPosition(),
2147 scanner.getCurrentTokenEndPosition(),
2150 if (token == TokenNamecase) { // empty case statement ?
2156 "':' character after 'case' constant expected (Found token: "
2157 + scanner.toStringAction(token)
2160 } else { // TokenNamedefault
2162 if (token == TokenNameCOLON) {
2166 throwSyntaxError("':' character after 'default' expected.");
2169 } while (token == TokenNamecase || token == TokenNamedefault);
2172 // public void labeledStatement() {
2173 // if (token == TokenNamecase) {
2176 // if (token == TokenNameDDOT) {
2180 // throwSyntaxError("':' character after 'case' constant expected.");
2183 // } else if (token == TokenNamedefault) {
2185 // if (token == TokenNameDDOT) {
2189 // throwSyntaxError("':' character after 'default' expected.");
2195 // public void expressionStatement() {
2198 // private void inclusionStatement() {
2201 // public void compoundStatement() {
2204 // public void selectionStatement() {
2207 // public void iterationStatement() {
2210 // public void jumpStatement() {
2213 // public void outputStatement() {
2216 // public void scopeStatement() {
2219 // public void flowStatement() {
2222 // public void definitionStatement() {
2225 private void ifStatement() throws CoreException {
2226 // ':' statement-list [elseif-list] [else-colon-statement] 'endif' ';'
2227 if (token == TokenNameCOLON) {
2231 case TokenNameelse :
2233 if (token == TokenNameCOLON) {
2237 if (token == TokenNameif) { //'else if'
2239 elseifStatementList();
2241 throwSyntaxError("':' expected after 'else'.");
2245 case TokenNameelseif :
2247 elseifStatementList();
2251 if (token != TokenNameendif) {
2252 throwSyntaxError("'endif' expected.");
2255 if (token != TokenNameSEMICOLON) {
2256 throwSyntaxError("';' expected after if-statement.");
2260 // statement [else-statement]
2262 if (token == TokenNameelseif) {
2264 if (token == TokenNameLPAREN) {
2267 throwSyntaxError("'(' expected after 'elseif' keyword.");
2270 if (token == TokenNameRPAREN) {
2273 throwSyntaxError("')' expected after 'elseif' condition.");
2276 } else if (token == TokenNameelse) {
2283 private void elseifStatementList() throws CoreException {
2287 case TokenNameelse :
2289 if (token == TokenNameCOLON) {
2294 if (token == TokenNameif) { //'else if'
2297 throwSyntaxError("':' expected after 'else'.");
2301 case TokenNameelseif :
2310 private void elseifStatement() throws CoreException {
2311 if (token == TokenNameLPAREN) {
2314 if (token != TokenNameLPAREN) {
2315 throwSyntaxError("')' expected in else-if-statement.");
2318 if (token != TokenNameCOLON) {
2319 throwSyntaxError("':' expected in else-if-statement.");
2326 private void switchStatement() throws CoreException {
2327 if (token == TokenNameCOLON) {
2328 // ':' [labeled-statement-list] 'endswitch' ';'
2330 labeledStatementList();
2331 if (token != TokenNameendswitch) {
2332 throwSyntaxError("'endswitch' expected.");
2335 if (token != TokenNameSEMICOLON) {
2336 throwSyntaxError("';' expected after switch-statement.");
2340 // '{' [labeled-statement-list] '}'
2341 if (token != TokenNameLBRACE) {
2342 throwSyntaxError("'{' expected in switch statement.");
2345 if (token != TokenNameRBRACE) {
2346 labeledStatementList();
2348 if (token != TokenNameRBRACE) {
2349 throwSyntaxError("'}' expected in switch statement.");
2356 private void forStatement() throws CoreException {
2357 if (token == TokenNameCOLON) {
2360 if (token != TokenNameendfor) {
2361 throwSyntaxError("'endfor' expected.");
2364 if (token != TokenNameSEMICOLON) {
2365 throwSyntaxError("';' expected after for-statement.");
2373 private void whileStatement() throws CoreException {
2374 // ':' statement-list 'endwhile' ';'
2375 if (token == TokenNameCOLON) {
2378 if (token != TokenNameendwhile) {
2379 throwSyntaxError("'endwhile' expected.");
2382 if (token != TokenNameSEMICOLON) {
2383 throwSyntaxError("';' expected after while-statement.");
2391 private void foreachStatement() throws CoreException {
2392 if (token == TokenNameCOLON) {
2395 if (token != TokenNameendforeach) {
2396 throwSyntaxError("'endforeach' expected.");
2399 if (token != TokenNameSEMICOLON) {
2400 throwSyntaxError("';' expected after foreach-statement.");
2408 private void exitStatus() throws CoreException {
2409 if (token == TokenNameLPAREN) {
2412 throwSyntaxError("'(' expected in 'exit-status'.");
2414 if (token != TokenNameRPAREN) {
2417 if (token == TokenNameRPAREN) {
2420 throwSyntaxError("')' expected after 'exit-status'.");
2424 private void expressionList() throws CoreException {
2427 if (token == TokenNameCOMMA) {
2435 private void expression() throws CoreException {
2436 //todo: find a better way to get the expression
2437 // expression = new StringBuffer();
2438 // for (int i = chIndx; i < str.length(); i++) {
2439 // if (str.charAt(i) == ';') {
2442 // expression.append(str.charAt(i));
2445 // if (token == TokenNameSTRING_CONSTANT || token == TokenNameINTERPOLATED_STRING) {
2448 logicalinclusiveorExpression();
2449 // while (token != TokenNameSEMICOLON) {
2455 private void postfixExpression() throws CoreException {
2458 boolean castFlag = false;
2464 case TokenNamenull :
2467 case TokenNamefalse :
2470 case TokenNametrue :
2473 case TokenNameStringConstant :
2476 case TokenNameHEREDOC :
2477 case TokenNameStringInterpolated :
2478 case TokenNameStringLiteral :
2481 case TokenNameLPAREN :
2483 if (token == TokenNameIdentifier) {
2484 // check if identifier is a type:
2485 // ident = identifier;
2486 ident = scanner.getCurrentIdentifierSource();
2487 String str = new String(ident).toLowerCase();
2488 for (int i = 0; i < PHP_TYPES.length; i++) {
2489 if (PHP_TYPES[i].equals(str)) {
2496 if (token != TokenNameRPAREN) {
2497 throwSyntaxError(") expected after cast-type '" + str + "'.");
2507 if (token != TokenNameRPAREN) {
2508 throwSyntaxError(") expected in postfix-expression.");
2512 case TokenNameDoubleLiteral :
2515 case TokenNameIntegerLiteral :
2518 case TokenNameDOLLAR_LBRACE :
2521 if (token != TokenNameRBRACE) {
2522 throwSyntaxError("'}' expected after indirect variable token '${'.");
2526 case TokenNameVariable :
2527 ident = scanner.getCurrentIdentifierSource();
2529 if (token == TokenNameLBRACE) {
2532 if (token != TokenNameRBRACE) {
2534 "'}' expected after variable '"
2536 + "' in variable-expression.");
2539 } else if (token == TokenNameLPAREN) {
2541 if (token != TokenNameRPAREN) {
2543 if (token != TokenNameRPAREN) {
2545 "')' expected after variable '"
2547 + "' in postfix-expression.");
2553 case TokenNameIdentifier :
2554 ident = scanner.getCurrentIdentifierSource();
2556 if (token == TokenNameLPAREN) {
2558 if (token != TokenNameRPAREN) {
2560 if (token != TokenNameRPAREN) {
2562 "')' expected after identifier '"
2564 + "' in postfix-expression."
2566 + scanner.toStringAction(token)
2573 case TokenNameprint :
2576 // if (token == TokenNameSEMICOLON) {
2579 // if (token != TokenNameStopPHP) {
2580 // throwSyntaxError("';' expected after 'print' statement.");
2585 case TokenNamelist :
2587 if (token == TokenNameLPAREN) {
2589 if (token == TokenNameCOMMA) {
2593 if (token != TokenNameRPAREN) {
2594 throwSyntaxError("')' expected after 'list' keyword.");
2597 // if (token == TokenNameSET) {
2599 // logicalinclusiveorExpression();
2602 throwSyntaxError("'(' expected after 'list' keyword.");
2605 // case TokenNameexit :
2607 // if (token != TokenNameSEMICOLON) {
2610 // if (token == TokenNameSEMICOLON) {
2613 // if (token != TokenNameStopPHP) {
2614 // throwSyntaxError("';' expected after 'exit' expression.");
2619 // case TokenNamedie :
2621 // if (token != TokenNameSEMICOLON) {
2624 // if (token == TokenNameSEMICOLON) {
2627 // if (token != TokenNameStopPHP) {
2628 // throwSyntaxError("';' expected after 'die' expression.");
2633 // case TokenNamearray :
2635 // if (token == TokenNameARGOPEN) {
2637 // if (token == TokenNameCOMMA) {
2640 // expressionList();
2641 // if (token != TokenNameARGCLOSE) {
2642 // throwSyntaxError("')' expected after 'list' keyword.");
2645 // if (token == TokenNameSET) {
2647 // logicalinclusiveorExpression();
2650 // throwSyntaxError("'(' expected after 'list' keyword.");
2654 boolean while_flag = true;
2657 case TokenNameLBRACKET :
2660 if (token != TokenNameRBRACKET) {
2661 throwSyntaxError("] expected in postfix-expression.");
2665 case TokenNameCOLON_COLON : // ::
2666 case TokenNameMINUS_GREATER : // ->
2668 if (token > TokenNameKEYWORD) {
2669 ident = scanner.getCurrentIdentifierSource();
2671 // "Avoid using keyword '"
2672 // + new String(ident)
2673 // + "' as variable name.",
2677 "Avoid using keyword '"
2679 + "' as variable name.",
2680 scanner.getCurrentTokenStartPosition(),
2681 scanner.getCurrentTokenEndPosition(),
2685 case TokenNameVariable :
2686 ident = scanner.getCurrentIdentifierSource();
2688 // if (token == TokenNameARGOPEN) {
2690 // expressionList();
2691 // if (token != TokenNameARGCLOSE) {
2692 // throwSyntaxError(") expected after variable '" + ident + "'.");
2697 case TokenNameIdentifier :
2698 //ident = scanner.getCurrentIdentifierSource();
2701 case TokenNameLBRACE :
2704 if (token != TokenNameRBRACE) {
2705 throwSyntaxError("} expected in postfix-expression.");
2710 throwSyntaxError("Syntax error after '->' token.");
2712 token == TokenNameLBRACKET
2713 || token == TokenNameLPAREN
2714 || token == TokenNameLBRACE) {
2715 if (token == TokenNameLBRACKET) {
2718 if (token != TokenNameRBRACKET) {
2719 throwSyntaxError("] expected after '->'.");
2723 if (token == TokenNameLPAREN) {
2726 if (token != TokenNameRPAREN) {
2727 throwSyntaxError(") expected after '->'.");
2731 if (token == TokenNameLBRACE) {
2734 if (token != TokenNameRBRACE) {
2735 throwSyntaxError("} expected after '->'.");
2741 case TokenNamePLUS_PLUS :
2744 case TokenNameMINUS_MINUS :
2755 private void unaryExpression() throws CoreException {
2757 case TokenNamePLUS_PLUS :
2761 case TokenNameMINUS_MINUS :
2765 // '@' '&' '*' '+' '-' '~' '!'
2774 case TokenNameMULTIPLY :
2778 case TokenNamePLUS :
2782 case TokenNameMINUS :
2786 case TokenNameTWIDDLE :
2795 postfixExpression();
2799 private void castExpression() throws CoreException {
2800 // if (token == TokenNameARGOPEN) {
2803 // if (token != TokenNameARGCLOSE) {
2804 // throwSyntaxError(") expected after cast-expression.");
2811 // private void typeName() throws CoreException {
2812 // //'string' 'unset' 'array' 'object'
2813 // //'bool' 'boolean'
2814 // //'real' 'double' 'float'
2815 // //'int' 'integer'
2816 // String identifier = "";
2817 // if (token == TokenNameIdentifier) {
2818 // char[] ident = scanner.getCurrentIdentifierSource();
2819 // identifier = new String(ident);
2820 // String str = identifier.toLowerCase();
2822 // for (int i = 0; i < PHP_TYPES.length; i++) {
2823 // if (PHP_TYPES[i].equals(str)) {
2828 // throwSyntaxError(
2829 // "Expected type cast '( <type-name> )'; Got '" + identifier + "'.");
2832 private void assignExpression() throws CoreException {
2834 if (token == TokenNameEQUAL) { // =
2836 logicalinclusiveorExpression();
2837 } else if (token == TokenNameDOT_EQUAL) { // .=
2839 logicalinclusiveorExpression();
2840 } else if (token == TokenNameEQUAL_GREATER) { // =>
2842 logicalinclusiveorExpression();
2843 } else if (token == TokenNamePLUS_EQUAL) { // +=
2845 logicalinclusiveorExpression();
2846 } else if (token == TokenNameMINUS_EQUAL) { // -=
2848 logicalinclusiveorExpression();
2849 } else if (token == TokenNameMULTIPLY_EQUAL) { // *=
2851 logicalinclusiveorExpression();
2852 } else if (token == TokenNameDIVIDE_EQUAL) { // *=
2854 logicalinclusiveorExpression();
2855 } else if (token == TokenNameREMAINDER_EQUAL) { // %=
2857 logicalinclusiveorExpression();
2858 } else if (token == TokenNameAND_EQUAL) { // &=
2860 logicalinclusiveorExpression();
2861 } else if (token == TokenNameOR_EQUAL) { // |=
2863 logicalinclusiveorExpression();
2864 } else if (token == TokenNameXOR_EQUAL) { // ^=
2866 logicalinclusiveorExpression();
2867 } else if (token == TokenNameLEFT_SHIFT_EQUAL) { // <<=
2869 logicalinclusiveorExpression();
2870 } else if (token == TokenNameRIGHT_SHIFT_EQUAL) { // >>=
2872 logicalinclusiveorExpression();
2873 } else if (token == TokenNameTWIDDLE_EQUAL) { // ~=
2875 logicalinclusiveorExpression();
2879 private void multiplicativeExpression() throws CoreException {
2882 if (token != TokenNameMULTIPLY
2883 && token != TokenNameDIVIDE
2884 && token != TokenNameREMAINDER) {
2891 private void concatenationExpression() throws CoreException {
2893 multiplicativeExpression();
2894 if (token != TokenNameDOT) {
2901 private void additiveExpression() throws CoreException {
2903 concatenationExpression();
2904 if (token != TokenNamePLUS && token != TokenNameMINUS) {
2911 private void shiftExpression() throws CoreException {
2913 additiveExpression();
2914 if (token != TokenNameLEFT_SHIFT && token != TokenNameRIGHT_SHIFT) {
2921 private void relationalExpression() throws CoreException {
2924 if (token != TokenNameLESS
2925 && token != TokenNameGREATER
2926 && token != TokenNameLESS_EQUAL
2927 && token != TokenNameGREATER_EQUAL) {
2934 private void identicalExpression() throws CoreException {
2936 relationalExpression();
2937 if (token != TokenNameEQUAL_EQUAL_EQUAL
2938 && token != TokenNameNOT_EQUAL_EQUAL) {
2945 private void equalityExpression() throws CoreException {
2947 identicalExpression();
2948 if (token != TokenNameEQUAL_EQUAL && token != TokenNameNOT_EQUAL) {
2955 private void ternaryExpression() throws CoreException {
2956 equalityExpression();
2957 if (token == TokenNameQUESTION) {
2960 if (token == TokenNameCOLON) {
2964 throwSyntaxError("':' expected in ternary operator '? :'.");
2969 private void andExpression() throws CoreException {
2971 ternaryExpression();
2972 if (token != TokenNameAND) {
2979 private void exclusiveorExpression() throws CoreException {
2982 if (token != TokenNameXOR) {
2989 private void inclusiveorExpression() throws CoreException {
2991 exclusiveorExpression();
2992 if (token != TokenNameOR) {
2999 private void booleanandExpression() throws CoreException {
3001 inclusiveorExpression();
3002 if (token != TokenNameAND_AND) {
3009 private void booleanorExpression() throws CoreException {
3011 booleanandExpression();
3012 if (token != TokenNameOR_OR) {
3019 private void logicalandExpression() throws CoreException {
3021 booleanorExpression();
3022 if (token != TokenNameAND) {
3029 private void logicalexclusiveorExpression() throws CoreException {
3031 logicalandExpression();
3032 if (token != TokenNameXOR) {
3039 private void logicalinclusiveorExpression() throws CoreException {
3041 logicalexclusiveorExpression();
3042 if (token != TokenNameOR) {
3049 // public void assignmentExpression() {
3050 // if (token == TokenNameVARIABLE) {
3052 // if (token == TokenNameSET) {
3054 // logicalinclusiveorExpression();
3057 // logicalinclusiveorExpression();
3061 private void variableList() throws CoreException {
3064 if (token == TokenNameCOMMA) {
3072 private void variable() throws CoreException {
3073 if (token == TokenNameDOLLAR_LBRACE) {
3077 if (token != TokenNameRBRACE) {
3078 throwSyntaxError("'}' expected after indirect variable token '${'.");
3082 if (token == TokenNameVariable) {
3084 if (token == TokenNameLBRACKET) {
3087 if (token != TokenNameRBRACKET) {
3088 throwSyntaxError("']' expected in variable-list.");
3091 } else if (token == TokenNameEQUAL) {
3096 throwSyntaxError("$-variable expected in variable-list.");
3102 * It will look for a value (after a '=' for example)
3103 * @throws CoreException
3105 private void constant() throws CoreException {
3108 case TokenNamePLUS :
3111 case TokenNameDoubleLiteral :
3114 case TokenNameIntegerLiteral :
3118 throwSyntaxError("Constant expected after '+' presign.");
3121 case TokenNameMINUS :
3124 case TokenNameDoubleLiteral :
3127 case TokenNameIntegerLiteral :
3131 throwSyntaxError("Constant expected after '-' presign.");
3134 case TokenNamenull :
3137 case TokenNamefalse :
3140 case TokenNametrue :
3143 case TokenNameIdentifier :
3144 // ident = identifier;
3145 char[] ident = scanner.getCurrentIdentifierSource();
3147 if (token == TokenNameLPAREN) {
3149 if (token != TokenNameRPAREN) {
3151 if (token != TokenNameRPAREN) {
3153 "')' expected after identifier '"
3155 + "' in postfix-expression.");
3161 case TokenNameStringLiteral :
3164 case TokenNameStringConstant :
3167 case TokenNameStringInterpolated :
3170 case TokenNameDoubleLiteral :
3173 case TokenNameIntegerLiteral :
3177 throwSyntaxError("Constant expected.");