Long longNumber;
Double doubleNumber;
+
+ String stringValue;
private boolean phpMode;
final static int TT_EOF = 0;
}
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;
}
if (ch2 == '?') {
ch2 = str.charAt(chIndx++);
if (Character.isWhitespace(ch2)) {
- // php start
+ // php start
phpMode = true;
phpFound = true;
break;
continue;
} else if (ch == '"') {
- // read string until end
- boolean openString = true;
- while (str.length() > chIndx) {
- ch = str.charAt(chIndx++);
- if (ch == '\\') {
- if (str.length() > chIndx) {
- ch = str.charAt(chIndx++);
- }
- } else if (ch == '"') {
- openString = false;
- break;
- } else if (ch == '\n') {
- rowCount++;
- columnCount = chIndx;
- }
- }
- if (openString) {
- throwSyntaxError("Open string character '\"' at end of file.");
- }
- token = TT_INTERPOLATED_STRING;
+ getString('"',TT_INTERPOLATED_STRING,"Open string character '\"' at end of file.");
return;
} else if (ch == '\'') {
- // read string until end
- boolean openString = true;
- int startRow = rowCount;
- while (str.length() > chIndx) {
- ch = str.charAt(chIndx++);
- if (ch == '\\') {
- if (str.length() > chIndx) {
- ch = str.charAt(chIndx++);
- }
- } else if (ch == '\'') {
- openString = false;
- break;
- } else if (ch == '\n') {
- rowCount++;
- columnCount = chIndx;
- }
- }
- if (openString) {
- throwSyntaxError("Open string character \"'\" at end of file.", startRow);
- }
- token = TT_STRING_CONSTANT;
+ getString('\'',TT_STRING_CONSTANT,"Open string character \"'\" at end of file.");
return;
} else if (ch == '`') {
- // read string until end
- boolean openString = true;
- int startRow = rowCount;
- while (str.length() > chIndx) {
- ch = str.charAt(chIndx++);
- if (ch == '\\') {
- if (str.length() > chIndx) {
- ch = str.charAt(chIndx++);
- }
- } else if (ch == '`') {
- openString = false;
- break;
- } else if (ch == '\n') {
- rowCount++;
- columnCount = chIndx;
- }
- }
- if (openString) {
- throwSyntaxError("Open string character \"`\" at end of file.", startRow);
- }
+ getString('`',TT_STRING_CONSTANT,"Open string character \"`\" at end of file.");
setMarker("Other string delimiters prefered (found \"`\").", rowCount, PHPParser.INFO);
- token = TT_STRING_CONSTANT;
return;
}
// }
}
+
private void getIdentifier() {
StringBuffer ident = new StringBuffer();
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();
}
}
+ /**
+ * Get a String.
+ * @param openChar the opening char ('\'', '"', '`')
+ * @param typeString the type of string {@link #TT_STRING_CONSTANT},{@link #TT_INTERPOLATED_STRING}
+ * @param errorMsg the error message in case of parse error in the string
+ */
+ private void getString(final char openChar, final int typeString, final String errorMsg) {
+ StringBuffer sBuffer = new StringBuffer();
+ boolean openString = true;
+ int startRow = rowCount;
+ while (str.length() > chIndx) {
+ ch = str.charAt(chIndx++);
+ if (ch == '\\') {
+ sBuffer.append(ch);
+ if (str.length() > chIndx) {
+ ch = str.charAt(chIndx++);
+ sBuffer.append(ch);
+ }
+ } else if (ch == openChar) {
+ openString = false;
+ break;
+ } else if (ch == '\n') {
+ rowCount++;
+ columnCount = chIndx;
+ } else {
+ sBuffer.append(ch);
+ }
+ }
+ if (openString) {
+ if (typeString == TT_STRING_CONSTANT) {
+ throwSyntaxError(errorMsg, startRow);
+ } else {
+ throwSyntaxError(errorMsg);
+ }
+ }
+ token = typeString;
+ stringValue = sBuffer.toString();
+ }
+
public void htmlParserTester(String input) {
int lineNumber = 1;
int startLineNumber = 1;
if (ch2 == '?') {
ch2 = input.charAt(i++);
if (Character.isWhitespace(ch2)) {
- // php start
+ // php start
phpMode = true;
phpFound = true;
startIndex = i;
// String temp = ((PHPString)phpList.get(j)).getPHPString();
// int startIndx = temp.length()-10;
// if (startIndx<0) {
- // startIndx = 0;
+ // startIndx = 0;
// }
// System.out.println(temp.substring(startIndx)+"?>");
// }
// for(int j=0;j<phpList.size();j++) {
// temp = (PHPString) phpList.get(j);
// parser.start(temp.getPHPString(), temp.getLineNumber());
- // }
+ // }
}
} catch (CoreException e) {
}
} else {
setMarker(err.getMessage(), err.getLine(), ERROR);
}
- // if an error occured,
+ // if an error occured,
// try to find keywords 'class' or 'function'
// to parse the rest of the string
while (token != TT_EOF && token != TT_UNDEFINED) {
}
/**
- * 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 {
} catch (SyntaxError sytaxErr1) {
setMarker(sytaxErr1.getMessage(), sytaxErr1.getLine(), ERROR);
try {
- // if an error occured,
+ // if an error occured,
// try to find keywords 'class' or 'function'
// to parse the rest of the string
while (token != TT_EOF && token != TT_UNDEFINED) {
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;
+ String oldIdentifier;
+ IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
+ try {
+ while (token != TT_EOF && token != TT_UNDEFINED) {
+ if (token == TT_VARIABLE) {
+ outlineInfo.addVariable(identifier);
+ getNextToken();
+ } else if (token == TT_var) {
+ getNextToken();
+ if (token == TT_VARIABLE && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_VAR)) {
+ getNextToken();
+ outlineInfo.addVariable(identifier);
+ if (token != TT_SEMICOLON) {
+ oldIdentifier = identifier;
+ getNextToken();
+ switch (token) {
+ case TT_VARIABLE : current.add(new PHPVarDeclaration(current, oldIdentifier, chIndx - identifier.length(),identifier));
+ break;
+ case TT_IDENTIFIER : current.add(new PHPVarDeclaration(current, oldIdentifier, chIndx - identifier.length(),identifier));
+ break;
+ case TT_DOUBLE_NUMBER : current.add(new PHPVarDeclaration(current, oldIdentifier + doubleNumber, chIndx - identifier.length(),doubleNumber.toString()));
+ break;
+ case TT_INT_NUMBER : current.add(new PHPVarDeclaration(current, oldIdentifier, chIndx - identifier.length(),longNumber.toString()));
+ break;
+ case TT_INTERPOLATED_STRING : current.add(new PHPVarDeclaration(current, oldIdentifier, chIndx - identifier.length(),stringValue));
+ break;
+ case TT_STRING_CONSTANT : current.add(new PHPVarDeclaration(current, oldIdentifier, chIndx - identifier.length(),stringValue));
+ break;
+ default : current.add(new PHPVarDeclaration(current, oldIdentifier, chIndx - identifier.length()));
+ break;
+ }
+ } else {
+ current.add(new PHPVarDeclaration(current, identifier, chIndx - identifier.length()));
+ }
+ }
+ } else if (token == TT_function) {
+ getNextToken();
+ if (token == TT_AMPERSAND) {
+ getNextToken();
+ }
+ if (token == TT_IDENTIFIER && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_FUNC)) {
+ outlineInfo.addVariable(identifier);
+ current.add(new PHPFunctionDeclaration(current, identifier, chIndx - identifier.length()));
+ getNextToken();
+ }
+ } else if (token == TT_class) {
+ getNextToken();
+ if (token == TT_IDENTIFIER && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_CLASS)) {
+ 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) {
+ } catch (SyntaxError sytaxErr) {
+ try {
+ setMarker(sytaxErr.getMessage(), sytaxErr.getLine(), ERROR);
+ } catch (CoreException e) {
+ }
+ }
+ }
+
private void statementList() throws CoreException {
do {
statement();
} else {
throwSyntaxError("':' character after 'case' constant expected.");
}
- } else { // TT_default
+ } else { // TT_default
getNextToken();
if (token == TT_DDOT) {
getNextToken();
getNextToken();
unaryExpression();
break;
- // '@' '&' '*' '+' '-' '~' '!'
+ // '@' '&' '*' '+' '-' '~' '!'
case TT_AT :
getNextToken();
castExpression();