From: kpouer Date: Thu, 27 Feb 2003 21:57:45 +0000 (+0000) Subject: now It extends PHPParserSuperclass X-Git-Url: http://secure.phpeclipse.com now It extends PHPParserSuperclass --- diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java index e31d80b..e3bea19 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java @@ -10,28 +10,23 @@ Contributors: **********************************************************************/ package net.sourceforge.phpdt.internal.compiler.parser; -import java.text.MessageFormat; import java.util.ArrayList; import java.util.Hashtable; import net.sourceforge.phpdt.core.compiler.*; import net.sourceforge.phpdt.internal.compiler.parser.*; import net.sourceforge.phpeclipse.PHPeclipsePlugin; -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; -import org.eclipse.core.runtime.IPath; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.ui.texteditor.MarkerUtilities; +import test.PHPParserSuperclass; -public class Parser extends PHPKeywords implements ITerminalSymbols { - // strings for external parser call - private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$ - private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$ +public class Parser extends PHPParserSuperclass implements PHPKeywords, ITerminalSymbols { public static final int ERROR = 2; public static final int WARNING = 1; @@ -150,6 +145,19 @@ public class Parser extends PHPKeywords implements ITerminalSymbols { // final static int TokenNameNOT_EQUAL_EQUAL = 158; // final static int TokenNameOR = 159; // final static int TokenNameAT = 153; // @ + + public Parser() { + } + + public void setFileToParse(IFile fileToParse) { + this.currentPHPString = 0; + this.fileToParse = fileToParse; + this.phpList = null; + this.str = ""; + this.token = TokenNameEOF; + this.phpEnd = false; + this.initializeScanner(); + } /** * Class Constructor. * @@ -3189,97 +3197,4 @@ public class Parser extends PHPKeywords implements ITerminalSymbols { } } - /** - * Call the php parse command ( php -l -f <filename> ) - * and create markers according to the external parser output - */ - public static void phpExternalParse(IFile file) { - //IFile file = (IFile) resource; - IPath path = file.getFullPath(); - IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore(); - String filename = file.getLocation().toString(); - - String[] arguments = { filename }; - MessageFormat form = - new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF)); - String command = form.format(arguments); - - String parserResult = - PHPStartApacheAction.getParserOutput(command, "External parser: "); - - try { - // parse the buffer to find the errors and warnings - createMarkers(parserResult, file); - } catch (CoreException e) { - } - } - - /** - * Create markers according to the external parser output - */ - private static void createMarkers(String output, IFile file) - throws CoreException { - // delete all markers - file.deleteMarkers(IMarker.PROBLEM, false, 0); - - int indx = 0; - int brIndx = 0; - boolean flag = true; - while ((brIndx = output.indexOf("
", indx)) != -1) { - // newer php error output (tested with 4.2.3) - scanLine(output, file, indx, brIndx); - indx = brIndx + 6; - flag = false; - } - if (flag) { - while ((brIndx = output.indexOf("
", indx)) != -1) { - // older php error output (tested with 4.2.3) - scanLine(output, file, indx, brIndx); - indx = brIndx + 4; - } - } - } - - private static void scanLine(String output, IFile file, int indx, int brIndx) - throws CoreException { - String current; - String outLineNumberString; - StringBuffer lineNumberBuffer = new StringBuffer(10); - char ch; - current = output.substring(indx, brIndx); - - if (current.indexOf(PARSE_WARNING_STRING) != -1 - || current.indexOf(PARSE_ERROR_STRING) != -1) { - int onLine = current.indexOf("on line "); - if (onLine != -1) { - lineNumberBuffer.delete(0, lineNumberBuffer.length()); - for (int i = onLine; i < current.length(); i++) { - ch = current.charAt(i); - if ('0' <= ch && '9' >= ch) { - lineNumberBuffer.append(ch); - } - } - - int lineNumber = Integer.parseInt(lineNumberBuffer.toString()); - - Hashtable attributes = new Hashtable(); - - current = current.replaceAll("\n", ""); - current = current.replaceAll("", ""); - current = current.replaceAll("", ""); - MarkerUtilities.setMessage(attributes, current); - - if (current.indexOf(PARSE_ERROR_STRING) != -1) - attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR)); - else if (current.indexOf(PARSE_WARNING_STRING) != -1) - attributes.put( - IMarker.SEVERITY, - new Integer(IMarker.SEVERITY_WARNING)); - else - attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO)); - MarkerUtilities.setLineNumber(attributes, lineNumber); - MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM); - } - } - } } \ No newline at end of file