import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
import net.sourceforge.phpeclipse.phpeditor.PHPString;
import net.sourceforge.phpeclipse.phpeditor.php.PHPKeywords;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
public static final int ERROR = 2;
public static final int WARNING = 1;
public static final int INFO = 0;
+
private IFile fileToParse;
private ArrayList phpList;
Long longNumber;
Double doubleNumber;
- String stringValue;
+ private String stringValue;
+
+ /** Contains the current expression. */
+ private StringBuffer expression;
+
private boolean phpMode;
final static int TT_EOF = 0;
}
}
+ /**
+ * This method will throw the SyntaxError.
+ * It will add the good lines and columns to the Error
+ * @param error the error message
+ * @throws SyntaxError the error raised
+ */
private void throwSyntaxError(String error) {
if (str.length() < chIndx) {
throw new SyntaxError(rowCount, chIndx - columnCount + 1, str.substring(columnCount, eol), error);
}
+ /**
+ * This method will throw the SyntaxError.
+ * It will add the good lines and columns to the Error
+ * @param error the error message
+ * @throws SyntaxError the error raised
+ */
private void throwSyntaxError(String error, int startRow) {
-
throw new SyntaxError(startRow, 0, " ", error);
}
phpMode = true;
phpFound = true;
break;
- } else if (ch2 == 'p') {
+ } else if (ch2 == 'p' || ch2 == 'P') {
ch2 = str.charAt(chIndx++);
- if (ch2 == 'h') {
+ if (ch2 == 'h' || ch2 == 'H') {
ch2 = str.charAt(chIndx++);
- if (ch2 == 'p') {
- phpMode = true;
- phpFound = true;
- break;
- }
- chIndx--;
- }
- chIndx--;
- } else if (ch2 == 'P') {
- ch2 = str.charAt(chIndx++);
- if (ch2 == 'H') {
- ch2 = str.charAt(chIndx++);
- if (ch2 == 'P') {
+ if (ch2 == 'p' || ch2 == 'P') {
phpMode = true;
phpFound = true;
break;
// }
}
-
+ /**
+ * Get an identifier.
+ */
private void getIdentifier() {
- StringBuffer ident = new StringBuffer();
-
- ident.append(ch);
+ // StringBuffer ident = new StringBuffer();
+ int startPosition = chIndx - 1;
+// ident.append(ch);
if (ch == '$') {
getChar();
// attention recursive call:
}
getChar();
+
+ //this will read the buffer until the next character is a forbidden character for identifier
while ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') || (ch == '_')) {
- ident.append(ch);
+ // ident.append(ch);
getChar();
}
- identifier = ident.toString();
- chIndx--;
+ int endPosition = chIndx--;
+ int length = (--endPosition) - startPosition;
+ identifier = str.substring(startPosition, endPosition);
+ // System.out.println(identifier);
+
// determine if this identitfer is a keyword
// @todo improve this in future version
Integer i = (Integer) keywordMap.get(identifier.toLowerCase());
}
}
+ /**
+ * Get a number.
+ * if it's a <code>double</code> the number will be stored in <code>doubleNumber</code> and the token will have the
+ * value {@link PHPParser#TT_DOUBLE_NUMBER}<br />
+ * if it's a <code>double</code> the number will be stored in <code>longNumber</code> and the token will have the
+ * value {@link PHPParser#TT_INT_NUMBER}
+ */
private void getNumber() {
StringBuffer inum = new StringBuffer();
char dFlag = ' ';
return outlineInfo;
}
- private void parseDeclarations(PHPOutlineInfo outlineInfo, PHPClassDeclaration current, boolean goBack) {
+ private void parseDeclarations(PHPOutlineInfo outlineInfo, PHPSegmentWithChildren current, boolean goBack) {
// PHPClassDeclaration current = (PHPClassDeclaration) stack.peek();
- PHPClassDeclaration temp;
+ PHPSegmentWithChildren temp;
int counter = 0;
String oldIdentifier;
IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
}
if (token == TT_IDENTIFIER && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_FUNC)) {
outlineInfo.addVariable(identifier);
- current.add(new PHPFunctionDeclaration(current, identifier, chIndx - identifier.length()));
+ temp = new PHPFunctionDeclaration(current, identifier, chIndx - identifier.length());
+ current.add(temp);
getNextToken();
+ parseDeclarations(outlineInfo, temp, true);
}
} else if (token == TT_class) {
getNextToken();
current.add(temp);
// stack.push(temp);
getNextToken();
+
+ //skip tokens for classname, extends and others until we have the opening '{'
while (token != TT_LISTOPEN && token != TT_EOF && token != TT_UNDEFINED) {
getNextToken();
}
if (counter == 0 && goBack) {
return;
}
+ } else if (token == TT_require || token == TT_require_once || token == TT_include || token == TT_include_once) {
+ expression();
+ outlineInfo.addVariable(identifier);
+ current.add(new PHPReqIncDeclaration(current, identifier, chIndx - identifier.length(),expression.toString()));
+ getNextToken();
} else {
getNextToken();
}
}
private void expression() throws CoreException {
+ //todo: find a better way to get the expression
+ expression = new StringBuffer();
+ for (int i = chIndx;i<str.length();i++) {
+ if (str.charAt(i) == ';') {
+ break;
+ }
+ expression.append(str.charAt(i));
+ }
// if (token == TT_STRING_CONSTANT || token == TT_INTERPOLATED_STRING) {
// getNextToken();
// } else {
}
}
+ /**
+ * It will look for a value (after a '=' for example)
+ * @throws CoreException
+ */
private void constant() throws CoreException {
String ident;
switch (token) {
MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
String command = form.format(arguments);
- String parserResult = PHPStartApacheAction.execute(command, "External parser: ");
+ String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: ");
- try {
+ try {
// parse the buffer to find the errors and warnings
createMarkers(parserResult, file);
} catch (CoreException e) {