import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
+import java.util.Stack;
import net.sourceforge.phpeclipse.PHPeclipsePlugin;
import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
}
public static void setMarker(IFile file, String message, int lineNumber, int errorLevel) throws CoreException {
-
- Hashtable attributes = new Hashtable();
- MarkerUtilities.setMessage(attributes, message);
- switch (errorLevel) {
- case ERROR :
- attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
- break;
- case WARNING :
- attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
- break;
- case INFO :
- attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
- break;
+ if (file != null) {
+ Hashtable attributes = new Hashtable();
+ MarkerUtilities.setMessage(attributes, message);
+ switch (errorLevel) {
+ case ERROR :
+ attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
+ break;
+ case WARNING :
+ attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
+ break;
+ case INFO :
+ attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
+ break;
+ }
+ MarkerUtilities.setLineNumber(attributes, lineNumber);
+ MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
}
- MarkerUtilities.setLineNumber(attributes, lineNumber);
- MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
}
private void throwSyntaxError(String error) {
if (openString) {
throwSyntaxError("Open string character \"`\" at end of file.", startRow);
}
- setMarker("Other string delimiters prefered (found \"`\").", rowCount, PHPParser.INFO);
token = TT_STRING_CONSTANT;
return;
}
ident.append(ch);
if (ch == '$') {
+ getChar();
+ // attention recursive call:
+ getIdentifier();
token = TT_VARIABLE;
+ return;
} else {
token = TT_IDENTIFIER;
}
+
getChar();
while ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') || (ch == '_')) {
ident.append(ch);
identifier = ident.toString();
chIndx--;
+ // determine if this identitfer is a keyword
+ // @todo improve this in future version
Integer i = (Integer) keywordMap.get(identifier.toLowerCase());
if (i != null) {
token = i.intValue();
}
/**
- * Parses a string with php tAGS
+ * Parses a string with php tags
* i.e. '<body> <?php phpinfo() ?> </body>'
*/
public void parse(String s) throws CoreException {
while (true);
}
+ public PHPOutlineInfo parseInfo(Object parent, String s) {
+ PHPOutlineInfo outlineInfo = new PHPOutlineInfo(parent);
+ // Stack stack = new Stack();
+ // stack.push(outlineInfo.getDeclarations());
+
+ this.str = s;
+ this.token = TT_EOF;
+ this.chIndx = 0;
+ this.rowCount = 1;
+ this.columnCount = 0;
+ this.phpEnd = false;
+ this.phpMode = false;
+
+ try {
+ getNextToken();
+ parseDeclarations(outlineInfo, outlineInfo.getDeclarations(), false);
+ } catch (CoreException e) {
+ }
+ return outlineInfo;
+ }
+
+ private void parseDeclarations(PHPOutlineInfo outlineInfo, PHPClassDeclaration current, boolean goBack) {
+ // PHPClassDeclaration current = (PHPClassDeclaration) stack.peek();
+ PHPClassDeclaration temp;
+ int counter = 0;
+
+ try {
+ while (token != TT_EOF && token != TT_UNDEFINED) {
+ if (token == TT_VARIABLE) {
+ outlineInfo.addVariable(identifier);
+ getNextToken();
+ } else if (token == TT_function) {
+ getNextToken();
+ if (token == TT_AMPERSAND) {
+ getNextToken();
+ }
+ if (token == TT_IDENTIFIER) {
+ outlineInfo.addVariable(identifier);
+ current.add(new PHPFunctionDeclaration(current, identifier, chIndx - identifier.length()));
+ getNextToken();
+ }
+ } else if (token == TT_class) {
+ getNextToken();
+ if (token == TT_IDENTIFIER) {
+ outlineInfo.addVariable(identifier);
+ temp = new PHPClassDeclaration(current, identifier, chIndx - identifier.length());
+ current.add(temp);
+ // stack.push(temp);
+ getNextToken();
+ while (token != TT_LISTOPEN && token != TT_EOF && token != TT_UNDEFINED) {
+ getNextToken();
+ }
+ parseDeclarations(outlineInfo, temp, true);
+ // stack.pop();
+ }
+ } else if (token == TT_LISTOPEN) {
+ getNextToken();
+ counter++;
+ } else if (token == TT_LISTCLOSE) {
+ getNextToken();
+ --counter;
+ if (counter == 0 && goBack) {
+ return;
+ }
+ } else {
+ getNextToken();
+ }
+ }
+ } catch (CoreException e) {
+ }
+ }
+
private void statementList() throws CoreException {
do {
statement();