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;
import net.sourceforge.phpeclipse.phpeditor.PHPString;
-import net.sourceforge.phpeclipse.phpeditor.PHPParserAction;
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;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.action.IAction;
import org.eclipse.ui.texteditor.MarkerUtilities;
public class PHPParser extends PHPKeywords {
Long longNumber;
Double doubleNumber;
+
+ String stringValue;
private boolean phpMode;
final static int TT_EOF = 0;
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();
}
}
+ /**
+ * 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;
// 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) {
} else if (token == TT_var) {
getNextToken();
if (token == TT_VARIABLE && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_VAR)) {
- outlineInfo.addVariable(identifier);
- current.add(new PHPVarDeclaration(current, identifier, chIndx - identifier.length()));
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();
}
}
} catch (CoreException e) {
+ } catch (SyntaxError sytaxErr) {
+ try {
+ setMarker(sytaxErr.getMessage(), sytaxErr.getLine(), ERROR);
+ } catch (CoreException e) {
+ }
}
}