* Test the PHP Parser with different PHP snippets
*/
public void testPHPParser() {
+ checkHTML("<?php print \"Hello world\" ?>");
checkHTML("<?php phpinfo(); ?>");
checkHTML("<?php phpinfo()?>");
checkHTML("<?php phpinfo(); ?> foo <?php phpinfo(); ?>");
checkHTML(" <?php //this is a line comment ?>");
+ checkPHP("echo \"Test\", \"me\";");
+ checkPHP("print (\"Test me\");");
+ checkPHP("$s = <<<HEREDOC \n dskjfhskj\n \n\nHEREDOC;");
+ checkPHP("$a == 0 ? print \"true\" : print \"false\";");
checkPHP("if(!$result = mysql_query($sql)) return(array());");
checkPHP("class test { function &fetchRow($result, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null) \n{ \n } \n }");
checkPHP("call_user_method_array($function_name[1], ${$objectname}, $arguments);");
public static final String SHOW_OUTPUT_IN_CONSOLE = "_sho_output_in_console";
public static final String EXTERNAL_PARSER_PREF = "_external_parser";
+ public static final String PHP_PARSER_DEFAULT = "_php_parser_default";
+ public static final String PHP_INTERNAL_PARSER = "_php_internal_parser";
+ public static final String PHP_EXTERNAL_PARSER = "_php_external_parser";
+ public static final String PHP_PARSE_ON_SAVE = "_php_parse_on_save";
+
public static final String PHP_MULTILINE_COMMENT = "_php_multilineComment";
public static final String PHP_SINGLELINE_COMMENT = "_php_singlelineComment";
public static final String PHP_KEYWORD = "_php_keyword";
import org.eclipse.jface.preference.DirectoryFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.RadioGroupFieldEditor;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
StringFieldEditor externalParser =
new StringFieldEditor(PHPeclipsePlugin.EXTERNAL_PARSER_PREF, "&External Parser command:", 60, getFieldEditorParent());
+
+ RadioGroupFieldEditor chooseParser = new RadioGroupFieldEditor(
+ IPreferenceConstants.PHP_PARSER_DEFAULT,
+ "Choose PHP parser",
+ 1,
+ new String[][] {
+ {"Internal parser",
+ IPreferenceConstants.PHP_INTERNAL_PARSER
+ },
+ {"External parser",
+ IPreferenceConstants.PHP_EXTERNAL_PARSER
+ }
+ },
+ this.getFieldEditorParent());
+
+ BooleanFieldEditor parseOnSave =
+ new BooleanFieldEditor(PHPeclipsePlugin.PHP_PARSE_ON_SAVE, "&Parse automatically on save", getFieldEditorParent());
+
+
+
addField(localhost);
addField(documentRoot);
addField(useExternalBrowser);
addField(restartApache);
addField(externalParser);
+
+ addField(chooseParser);
+ addField(parseOnSave);
}
/**
**********************************************************************/
package net.sourceforge.phpeclipse;
-import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.ColorFieldEditor;
-import org.eclipse.jface.preference.DirectoryFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.preference.StringFieldEditor;
+import org.eclipse.jface.preference.RadioGroupFieldEditor;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
* The main plugin class to be used in the desktop.
*/
public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceConstants {
-// public static final String LOCALHOST_PREF = "_localhost";
-// public static final String DOCUMENTROOT_PREF = "_documentroot";
-// public static final String USE_EXTERNAL_BROWSER_PREF = "_use_external_browser";
-// public static final String EXTERNAL_BROWSER_PREF = "_external_browser";
-// public static final String MYSQL_PREF = "_my_sql";
-// public static final String APACHE_START_PREF = "_apache_start";
-// public static final String APACHE_STOP_PREF = "_apache_stop";
-// public static final String APACHE_RESTART_PREF = "_apache_restart";
-// public static final String SHOW_OUTPUT_IN_CONSOLE = "_sho_output_in_console";
-// public static final String EXTERNAL_PARSER_PREF = "_external_parser";
-
+ // public static final String LOCALHOST_PREF = "_localhost";
+ // public static final String DOCUMENTROOT_PREF = "_documentroot";
+ // public static final String USE_EXTERNAL_BROWSER_PREF = "_use_external_browser";
+ // public static final String EXTERNAL_BROWSER_PREF = "_external_browser";
+ // public static final String MYSQL_PREF = "_my_sql";
+ // public static final String APACHE_START_PREF = "_apache_start";
+ // public static final String APACHE_STOP_PREF = "_apache_stop";
+ // public static final String APACHE_RESTART_PREF = "_apache_restart";
+ // public static final String SHOW_OUTPUT_IN_CONSOLE = "_sho_output_in_console";
+ // public static final String EXTERNAL_PARSER_PREF = "_external_parser";
+
/**
* The id of the PHP plugin (value <code>"net.sourceforge.phpeclipse"</code>).
- */
- public static final String ID_PLUGIN= "net.sourceforge.phpeclipse"; //$NON-NLS-1$
-
- //The shared instance.
- private static PHPeclipsePlugin plugin;
- //Resource bundle.
- private ResourceBundle resourceBundle;
-
+ */
+ public static final String ID_PLUGIN = "net.sourceforge.phpeclipse"; //$NON-NLS-1$
+
+ //The shared instance.
+ private static PHPeclipsePlugin plugin;
+ //Resource bundle.
+ private ResourceBundle resourceBundle;
+
private PHPDocumentProvider fCompilationUnitDocumentProvider;
- /**
- * The Java virtual machine that we are running on.
- */
- private static int jvm;
-
- /** MRJ 2.0 */
- private static final int MRJ_2_0 = 0;
-
- /** MRJ 2.1 or later */
- private static final int MRJ_2_1 = 1;
-
- /** Java on Mac OS X 10.0 (MRJ 3.0) */
- private static final int MRJ_3_0 = 3;
-
- /** MRJ 3.1 */
- private static final int MRJ_3_1 = 4;
-
- /** Windows NT */
- private static final int WINDOWS_NT = 5;
-
- /** Windows 9x */
- private static final int WINDOWS_9x = 6;
-
- /** JVM constant for any other platform */
- private static final int OTHER = -1;
- /**
- * The constructor.
- */
- public PHPeclipsePlugin(IPluginDescriptor descriptor) {
- super(descriptor);
- plugin = this;
- setJVM();
- try {
- resourceBundle = ResourceBundle.getBundle("net.sourceforge.PHPeclipsePluginResources");
- } catch (MissingResourceException x) {
- resourceBundle = null;
- }
- }
+ /**
+ * The Java virtual machine that we are running on.
+ */
+ private static int jvm;
+
+ /** MRJ 2.0 */
+ private static final int MRJ_2_0 = 0;
+
+ /** MRJ 2.1 or later */
+ private static final int MRJ_2_1 = 1;
+
+ /** Java on Mac OS X 10.0 (MRJ 3.0) */
+ private static final int MRJ_3_0 = 3;
+
+ /** MRJ 3.1 */
+ private static final int MRJ_3_1 = 4;
+
+ /** Windows NT */
+ private static final int WINDOWS_NT = 5;
+
+ /** Windows 9x */
+ private static final int WINDOWS_9x = 6;
+
+ /** JVM constant for any other platform */
+ private static final int OTHER = -1;
+ /**
+ * The constructor.
+ */
+ public PHPeclipsePlugin(IPluginDescriptor descriptor) {
+ super(descriptor);
+ plugin = this;
+ setJVM();
+ try {
+ resourceBundle = ResourceBundle.getBundle("net.sourceforge.PHPeclipsePluginResources");
+ } catch (MissingResourceException x) {
+ resourceBundle = null;
+ }
+ }
// @TODO: refactor this into a better method name !
public PHPDocumentProvider getCompilationUnitDocumentProvider() {
if (fCompilationUnitDocumentProvider == null)
- fCompilationUnitDocumentProvider= new PHPDocumentProvider();
+ fCompilationUnitDocumentProvider = new PHPDocumentProvider();
return fCompilationUnitDocumentProvider;
}
-
- public static void setJVM() {
- String osName = System.getProperty("os.name");
-
- if (osName.startsWith("Mac OS")) {
- String mrjVersion = System.getProperty("mrj.version");
- String majorMRJVersion = mrjVersion.substring(0, 3);
- jvm = OTHER;
- try {
-
- double version = Double.valueOf(majorMRJVersion).doubleValue();
-
- if (version == 2) {
- jvm = MRJ_2_0;
- } else if (version >= 2.1 && version < 3) {
- jvm = MRJ_2_1;
- } else if (version == 3.0) {
- jvm = MRJ_3_0;
- } else if (version >= 3.1) {
- jvm = MRJ_3_1;
- }
-
- } catch (NumberFormatException nfe) {
-
- }
-
- } else if (osName.startsWith("Windows")) {
- if (osName.indexOf("9") != -1) {
- jvm = WINDOWS_9x;
- } else {
- jvm = WINDOWS_NT;
- }
- }
- }
- public static int getJVM() {
- return jvm;
- }
- /**
- * Returns the shared instance.
- */
- public static PHPeclipsePlugin getDefault() {
- return plugin;
- }
-
- /**
- * Returns the workspace instance.
- */
- public static IWorkspace getWorkspace() {
- return ResourcesPlugin.getWorkspace();
- }
-
+
+ public static void setJVM() {
+ String osName = System.getProperty("os.name");
+
+ if (osName.startsWith("Mac OS")) {
+ String mrjVersion = System.getProperty("mrj.version");
+ String majorMRJVersion = mrjVersion.substring(0, 3);
+ jvm = OTHER;
+ try {
+
+ double version = Double.valueOf(majorMRJVersion).doubleValue();
+
+ if (version == 2) {
+ jvm = MRJ_2_0;
+ } else if (version >= 2.1 && version < 3) {
+ jvm = MRJ_2_1;
+ } else if (version == 3.0) {
+ jvm = MRJ_3_0;
+ } else if (version >= 3.1) {
+ jvm = MRJ_3_1;
+ }
+
+ } catch (NumberFormatException nfe) {
+
+ }
+
+ } else if (osName.startsWith("Windows")) {
+ if (osName.indexOf("9") != -1) {
+ jvm = WINDOWS_9x;
+ } else {
+ jvm = WINDOWS_NT;
+ }
+ }
+ }
+ public static int getJVM() {
+ return jvm;
+ }
+ /**
+ * Returns the shared instance.
+ */
+ public static PHPeclipsePlugin getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Returns the workspace instance.
+ */
+ public static IWorkspace getWorkspace() {
+ return ResourcesPlugin.getWorkspace();
+ }
+
public static IWorkbenchPage getActivePage() {
return getDefault().getActivePage();
}
-
+
public static IWorkbenchWindow getActiveWorkbenchWindow() {
return getDefault().getWorkbench().getActiveWorkbenchWindow();
}
-
+
public static Shell getActiveWorkbenchShell() {
return getActiveWorkbenchWindow().getShell();
}
-
+
public static String getPluginId() {
return getDefault().getDescriptor().getUniqueIdentifier();
}
public static void log(IStatus status) {
getDefault().getLog().log(status);
}
-
-// public static void logErrorMessage(String message) {
-// log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null));
-// }
-//
-// public static void logErrorStatus(String message, IStatus status) {
-// if (status == null) {
-// logErrorMessage(message);
-// return;
-// }
-// MultiStatus multi= new MultiStatus(getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null);
-// multi.add(status);
-// log(multi);
-// }
-//
-// public static void log(Throwable e) {
-// log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, JavaUIMessages.getString("JavaPlugin.internal_error"), e)); //$NON-NLS-1$
-// }
-
+
+ // public static void logErrorMessage(String message) {
+ // log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null));
+ // }
+ //
+ // public static void logErrorStatus(String message, IStatus status) {
+ // if (status == null) {
+ // logErrorMessage(message);
+ // return;
+ // }
+ // MultiStatus multi= new MultiStatus(getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null);
+ // multi.add(status);
+ // log(multi);
+ // }
+ //
+ // public static void log(Throwable e) {
+ // log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, JavaUIMessages.getString("JavaPlugin.internal_error"), e)); //$NON-NLS-1$
+ // }
+
public static boolean isDebug() {
return getDefault().isDebugging();
}
-
+
static IPath getInstallLocation() {
return new Path(getDefault().getDescriptor().getInstallURL().getFile());
}
- /**
- * Returns the string from the plugin's resource bundle,
- * or 'key' if not found.
- */
- public static String getResourceString(String key) {
- ResourceBundle bundle = PHPeclipsePlugin.getDefault().getResourceBundle();
- try {
- return bundle.getString(key);
- } catch (MissingResourceException e) {
- return key;
- }
- }
-
- /**
- * Returns the plugin's resource bundle,
- */
- public ResourceBundle getResourceBundle() {
- return resourceBundle;
- }
-
- protected void initializeDefaultPreferences(IPreferenceStore store) {
- // windows preferences:
- store.setDefault(LOCALHOST_PREF, "http://localhost");
-
- store.setDefault(USE_EXTERNAL_BROWSER_PREF, "false");
+ /**
+ * Returns the string from the plugin's resource bundle,
+ * or 'key' if not found.
+ */
+ public static String getResourceString(String key) {
+ ResourceBundle bundle = PHPeclipsePlugin.getDefault().getResourceBundle();
+ try {
+ return bundle.getString(key);
+ } catch (MissingResourceException e) {
+ return key;
+ }
+ }
+
+ /**
+ * Returns the plugin's resource bundle,
+ */
+ public ResourceBundle getResourceBundle() {
+ return resourceBundle;
+ }
+
+ protected void initializeDefaultPreferences(IPreferenceStore store) {
+ // windows preferences:
+ store.setDefault(LOCALHOST_PREF, "http://localhost");
+
+ store.setDefault(USE_EXTERNAL_BROWSER_PREF, "false");
store.setDefault(SHOW_OUTPUT_IN_CONSOLE, "true");
- if (jvm == WINDOWS_9x) {
- store.setDefault(EXTERNAL_BROWSER_PREF, "command.com /c start iexplore {0}");
- } else if (jvm == WINDOWS_NT) {
- store.setDefault(EXTERNAL_BROWSER_PREF, "rundll32 url.dll,FileProtocolHandler {0}");
- } else {
- store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
- }
- if ((jvm == WINDOWS_9x) || (jvm == WINDOWS_NT)) {
+ if (jvm == WINDOWS_9x) {
+ store.setDefault(EXTERNAL_BROWSER_PREF, "command.com /c start iexplore {0}");
+ } else if (jvm == WINDOWS_NT) {
+ store.setDefault(EXTERNAL_BROWSER_PREF, "rundll32 url.dll,FileProtocolHandler {0}");
+ } else {
+ store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
+ }
+ if ((jvm == WINDOWS_9x) || (jvm == WINDOWS_NT)) {
store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}");
store.setDefault(DOCUMENTROOT_PREF, "c:\\eclipse\\workspace");
- store.setDefault(MYSQL_PREF, "c:\\apache\\mysql\\bin\\mysqld.exe --standalone");
- store.setDefault(APACHE_START_PREF, "c:\\apache\\apache.exe -c \"DocumentRoot \"{0}\"\"");
- store.setDefault(APACHE_STOP_PREF, "c:\\apache\\apache.exe -k shutdown");
- store.setDefault(APACHE_RESTART_PREF, "c:\\apache\\apache.exe -k restart");
- } else {
+ store.setDefault(MYSQL_PREF, "c:\\apache\\mysql\\bin\\mysqld.exe --standalone");
+ store.setDefault(APACHE_START_PREF, "c:\\apache\\apache.exe -c \"DocumentRoot \"{0}\"\"");
+ store.setDefault(APACHE_STOP_PREF, "c:\\apache\\apache.exe -k shutdown");
+ store.setDefault(APACHE_RESTART_PREF, "c:\\apache\\apache.exe -k restart");
+ } else {
store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f {0}");
store.setDefault(DOCUMENTROOT_PREF, "/eclipse/workspace");
- store.setDefault(MYSQL_PREF, "/apache/mysql/bin/mysqld --standalone");
- store.setDefault(APACHE_START_PREF, "/apache/apache -c \"DocumentRoot \"{0}\"\"");
- store.setDefault(APACHE_STOP_PREF, "/apache/apache.exe -k shutdown");
- store.setDefault(APACHE_RESTART_PREF, "/apache/apache -k restart");
-
- }
+ store.setDefault(MYSQL_PREF, "/apache/mysql/bin/mysqld --standalone");
+ store.setDefault(APACHE_START_PREF, "/apache/apache -c \"DocumentRoot \"{0}\"\"");
+ store.setDefault(APACHE_STOP_PREF, "/apache/apache.exe -k shutdown");
+ store.setDefault(APACHE_RESTART_PREF, "/apache/apache -k restart");
+
+ }
+
+ store.setDefault(PHP_PARSER_DEFAULT, "true");
+ store.setDefault(PHP_INTERNAL_PARSER, "true");
+ store.setDefault(PHP_EXTERNAL_PARSER, "false");
+ store.setDefault(PHP_PARSE_ON_SAVE, "true");
// php syntax highlighting
PreferenceConverter.setDefault(store, PHP_MULTILINE_COMMENT, PHPColorProvider.MULTI_LINE_COMMENT);
PreferenceConverter.setDefault(store, PHP_SINGLELINE_COMMENT, PHPColorProvider.SINGLE_LINE_COMMENT);
PreferenceConverter.setDefault(store, PHP_STRING, PHPColorProvider.STRING);
PreferenceConverter.setDefault(store, PHP_DEFAULT, PHPColorProvider.DEFAULT);
- }
+ }
}
\ No newline at end of file
**********************************************************************/
package net.sourceforge.phpeclipse.actions;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Hashtable;
import java.util.Iterator;
-import java.util.StringTokenizer;
-import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+import net.sourceforge.phpeclipse.phpeditor.PHPParser;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.texteditor.MarkerUtilities;
public class PHPExternalParserAction implements IObjectActionDelegate {
- private static final String PARSE_ERROR = "Parse error"; //$NON-NLS-1$
- private static final String WARNING = "Warning"; //$NON-NLS-1$
private IWorkbenchPart workbenchPart;
/**
StructuredSelection selection = null;
selection = (StructuredSelection) selectionProvider.getSelection();
- IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
-
- Shell shell = null;
+ //Shell shell = null;
Iterator iterator = null;
iterator = selection.iterator();
while (iterator.hasNext()) {
case IResource.FILE :
// single file:
IFile file = (IFile) resource;
- IPath path = file.getFullPath();
-
- 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.execute(command, "External parser: ");
-
- try {
- // parse the buffer to find the errors and warnings
- createMarkers(parserResult, file);
- } catch (CoreException e) {
- }
-
+ PHPParser.phpExternalParse(file);
}
}
}
public void selectionChanged(IAction action, ISelection selection) {
}
- /**
- * Create markers according to the compiler output
- */
- protected 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("<br />", 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("<br>", indx)) != -1) {
- // older php error output (tested with 4.2.3)
- scanLine(output, file, indx, brIndx);
- indx = brIndx + 4;
- }
- }
- }
- private 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(WARNING) != -1 || current.indexOf(PARSE_ERROR) != -1) {
- int onLine = current.indexOf("on line <b>");
- 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);
- }
- }
-
- // String line = current.substring(current.indexOf(fullPath) + fullPath.length(), current.length());
- // String errorsLocation = line.substring(1, line.indexOf(":") - 1); //$NON-NLS-1$
- // String message = line.substring(line.indexOf(":") + 2, line.length() - 1); //$NON-NLS-1$
-
- int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
-
- Hashtable attributes = new Hashtable();
-
- current = current.replaceAll("\n", "");
- current = current.replaceAll("<b>", "");
- current = current.replaceAll("</b>", "");
- MarkerUtilities.setMessage(attributes, current);
-
- if (current.indexOf(PARSE_ERROR) != -1)
- attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
- else if (current.indexOf(WARNING) != -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);
- }
- }
- }
}
import net.sourceforge.phpeclipse.phpeditor.php.PHPPartitionScanner;
/**
- * The JavaDocumentProvider provides the IDocuments used by java editors.
+ * The PHPDocumentProvider provides the IDocuments used by java editors.
*/
public class PHPDocumentProvider extends FileDocumentProvider {
IBM Corporation - Initial implementation
Klaus Hartlage - www.eclipseproject.de
**********************************************************************/
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+import net.sourceforge.phpeclipse.phpeditor.php.PHPCodeScanner;
import net.sourceforge.phpeclipse.phpeditor.php.PHPWordExtractor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.help.IHelp;
import org.eclipse.help.IHelpResource;
+import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.MenuManager;
-import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.texteditor.DefaultRangeIndicator;
import org.eclipse.ui.texteditor.TextOperationAction;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
-import org.eclipse.jface.action.IAction;
/**
* Java specific text editor.
*/
super.dispose();
}
- /** The <code>JavaEditor</code> implementation of this
+ /** The <code>PHPEditor</code> implementation of this
* <code>AbstractTextEditor</code> method performs any extra
- * revert behavior required by the java editor.
+ * revert behavior required by the php editor.
*/
public void doRevertToSaved() {
super.doRevertToSaved();
fOutlinePage.update();
}
- /** The <code>JavaEditor</code> implementation of this
+ /** The <code>PHPEditor</code> implementation of this
* <code>AbstractTextEditor</code> method performs any extra
- * save behavior required by the java editor.
+ * save behavior required by the php editor.
*/
public void doSave(IProgressMonitor monitor) {
super.doSave(monitor);
// compile or not, according to the user preferences
- IAction a = PHPParserAction.getInstance();
- if (a != null)
- a.run();
+ IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
+ if (store.getBoolean(PHPeclipsePlugin.PHP_PARSE_ON_SAVE)) {
+ IAction a = PHPParserAction.getInstance();
+ if (a != null)
+ a.run();
+ }
if (fOutlinePage != null)
fOutlinePage.update();
}
- /** The <code>JavaEditor</code> implementation of this
+ /** The <code>PHPEditor</code> implementation of this
* <code>AbstractTextEditor</code> method performs any extra
- * save as behavior required by the java editor.
+ * save as behavior required by the php editor.
*/
public void doSaveAs() {
super.doSaveAs();
fOutlinePage.update();
}
- /** The <code>JavaEditor</code> implementation of this
+ /** The <code>PHPEditor</code> implementation of this
* <code>AbstractTextEditor</code> method performs sets the
* input of the outline page after AbstractTextEditor has set input.
*/
setRangeIndicator(new DefaultRangeIndicator());
setEditorContextMenuId("#PHPEditorContext"); //$NON-NLS-1$
setRulerContextMenuId("#PHPRulerContext"); //$NON-NLS-1$
+ // setDocumentProvider(PHPeclipsePlugin.getCompilationUnitDocumentProvider());
+
+ PHPeclipsePlugin.getDefault().getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event) {
+ PHPCodeScanner scanner = PHPEditorEnvironment.getPHPCodeScanner();
+ if (scanner != null) {
+ scanner.updateToken(PHPEditorEnvironment.getPHPColorProvider());
+ }
+ if (getSourceViewer() != null) {
+ getSourceViewer().invalidateTextPresentation();
+ }
+ }
+ });
}
}
/**
* Returns the singleton scanner.
*/
- public static RuleBasedScanner getPHPCodeScanner() {
+ public static PHPCodeScanner getPHPCodeScanner() {
return fgCodeScanner;
}
- public static RuleBasedScanner getHTMLCodeScanner() {
+ public static HTMLCodeScanner getHTMLCodeScanner() {
return fgHTMLCodeScanner;
}
/**
* Returns the singleton color provider.
*/
- public static PHPColorProvider getJavaColorProvider() {
+ public static PHPColorProvider getPHPColorProvider() {
return fgColorProvider;
}
**********************************************************************/
package net.sourceforge.phpeclipse.phpeditor;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
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;
public class PHPParser extends PHPKeywords {
+ // 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 static final int ERROR = 2;
public static final int WARNING = 1;
final static int TT_QUESTIONMARK = 61;
final static int TT_DDOT2 = 62;
final static int TT_AT = 63;
+ // final static int TT_HEREDOC = 64;
final static int TT_DOLLAROPEN = 127;
final static int TT_ARGOPEN = 128;
throw new SyntaxError(rowCount, chIndx - columnCount + 1, str.substring(columnCount, eol), error);
}
+ private void throwSyntaxError(String error, int startRow) {
+
+ throw new SyntaxError(startRow, 0, " ", error);
+ }
+
/**
* Method Declaration.
*
} else if (ch == '\'') {
// read string until end
boolean openString = true;
+ int startRow = rowCount;
while (str.length() > chIndx) {
ch = str.charAt(chIndx++);
if (ch == '\\') {
}
}
if (openString) {
- throwSyntaxError("Open string character \"'\" at end of file.");
+ throwSyntaxError("Open string character \"'\" at end of file.", startRow);
}
token = TT_STRING_CONSTANT;
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 (openString) {
- throwSyntaxError("Open string character \"`\" at end of file.");
+ throwSyntaxError("Open string character \"`\" at end of file.", startRow);
}
setMarker("Other string delimiters prefered (found \"`\").", rowCount, PHPParser.INFO);
token = TT_STRING_CONSTANT;
if (str.charAt(chIndx) == '<') {
chIndx++;
token = TT_LSHIFT;
- if (str.length() > chIndx) {
- if (str.charAt(chIndx) == '=') {
- chIndx++;
- token = TT_LSHIFTASSIGN;
- break;
+ if (str.charAt(chIndx) == '<') {
+ // heredoc
+ int startRow = rowCount;
+ if (str.length() > chIndx) {
+
+ ch = str.charAt(++chIndx);
+ if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch == '_')) {
+ chIndx++;
+ getIdentifier();
+ token = TT_STRING_CONSTANT;
+ while (str.length() > chIndx) {
+ ch = str.charAt(chIndx++);
+ if (ch == '\n') {
+ if (str.length() >= chIndx + identifier.length()) {
+ if (str.substring(chIndx, chIndx + identifier.length()).equals(identifier)) {
+ chIndx += identifier.length();
+ return;
+ }
+ }
+ }
+ }
+ }
}
+ throwSyntaxError("Open heredoc syntax after operator '<<<'.", startRow);
+ } else if (str.charAt(chIndx) == '=') {
+ chIndx++;
+ token = TT_LSHIFTASSIGN;
+ break;
}
break;
}
}
}
return;
- } else if (token == TT_print) {
- getNextToken();
- expression();
- if (token == TT_SEMICOLON) {
- getNextToken();
- } else {
- if (!phpEnd) {
- throwSyntaxError("';' expected after 'print' statement.");
- }
- }
- return;
+ // } else if (token == TT_print) {
+ // getNextToken();
+ // expression();
+ // if (token == TT_SEMICOLON) {
+ // getNextToken();
+ // } else {
+ // if (!phpEnd) {
+ // throwSyntaxError("';' expected after 'print' statement.");
+ // }
+ // }
+ // return;
} else if (token == TT_global || token == TT_static) {
getNextToken();
getNextToken();
}
break;
+ case TT_print :
+ getNextToken();
+ expression();
+ // if (token == TT_SEMICOLON) {
+ // getNextToken();
+ // } else {
+ // if (!phpEnd) {
+ // throwSyntaxError("';' expected after 'print' statement.");
+ // }
+ // }
+ break;
case TT_list :
getNextToken();
if (token == TT_ARGOPEN) {
throwSyntaxError("Constant expected.");
}
}
+
+ /**
+ * 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.execute(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("<br />", 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("<br>", 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 <b>");
+ 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("<b>", "");
+ current = current.replaceAll("</b>", "");
+ 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
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Hashtable;
import java.util.List;
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.Position;
+import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.texteditor.ITextEditor;
-import org.eclipse.ui.texteditor.MarkerUtilities;
import org.eclipse.ui.texteditor.TextEditorAction;
/**
*/
public class PHPParserAction extends TextEditorAction {
- // public static final String EXE = "exe"; //$NON-NLS-1$
- // public static final String WINEXE = "winexe"; //$NON-NLS-1$
- // public static final String LIBRARY = "library"; //$NON-NLS-1$
- // public static final String MODULE = "module"; //$NON-NLS-1$
-
- // private static final String ERROR = "error"; //$NON-NLS-1$
- // private static final String WARNING = "warning"; //$NON-NLS-1$
-
private static PHPParserAction instance = new PHPParserAction();
protected IFile fileToParse;
// should throw an exception
return;
}
- // first delete all the previous markers
- fileToParse.deleteMarkers(IMarker.PROBLEM, false, 0);
- //IDocument document = getTextEditor().getDocumentProvider().getDocument(null);
- //String text = document.get();
-
- // String text =
- // parse(document);
- try {
- InputStream iStream = fileToParse.getContents();
- // int c = iStream.read();
- parse(iStream);
- iStream.close();
- } catch (IOException e) {
+ IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
+ if (store.getBoolean(PHPeclipsePlugin.PHP_PARSER_DEFAULT)) {
+ // first delete all the previous markers
+ fileToParse.deleteMarkers(IMarker.PROBLEM, false, 0);
+
+ try {
+ InputStream iStream = fileToParse.getContents();
+ // int c = iStream.read();
+ parse(iStream);
+ iStream.close();
+ } catch (IOException e) {
+ }
+ } else {
+ PHPParser.phpExternalParse(fileToParse);
}
- // String message = "Test error";
- // int lineNumber = 1;
- //
- // // create marker for the error
- //
- // setMarker(message, lineNumber, fileToParse);
} catch (CoreException e) {
}
/**
* Create marker for the parse error
*/
-// protected void setMarker(String message, int lineNumber) throws CoreException {
-//
-// Hashtable attributes = new Hashtable();
-// MarkerUtilities.setMessage(attributes, message);
-// if (message.startsWith(ERROR))
-// attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
-// else if (message.startsWith(WARNING))
-// 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(fileToParse, attributes, IMarker.PROBLEM);
-// }
+ // protected void setMarker(String message, int lineNumber) throws CoreException {
+ //
+ // Hashtable attributes = new Hashtable();
+ // MarkerUtilities.setMessage(attributes, message);
+ // if (message.startsWith(ERROR))
+ // attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
+ // else if (message.startsWith(WARNING))
+ // 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(fileToParse, attributes, IMarker.PROBLEM);
+ // }
// private String getIdentifier(InputStream iStream, int c) {
// // int i = 0;
return;
}
String input = buf.toString();
-
- PHPParser parser = new PHPParser(fileToParse);
- parser.htmlParse(input);
+
+ PHPParser parser = new PHPParser(fileToParse);
+ parser.htmlParse(input);
}
}
\ No newline at end of file
assistant.setAutoActivationDelay(500);
assistant.setProposalPopupOrientation(assistant.PROPOSAL_OVERLAY);
assistant.setContextInformationPopupOrientation(assistant.CONTEXT_INFO_ABOVE);
- assistant.setContextInformationPopupBackground(PHPEditorEnvironment.getJavaColorProvider().getColor(new RGB(150, 150, 0)));
+ assistant.setContextInformationPopupBackground(PHPEditorEnvironment.getPHPColorProvider().getColor(new RGB(150, 150, 0)));
return assistant;
}
*/
public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
- PHPColorProvider provider = PHPEditorEnvironment.getJavaColorProvider();
+ PHPColorProvider provider = PHPEditorEnvironment.getPHPColorProvider();
PresentationReconciler reconciler = new PresentationReconciler();
DefaultDamagerRepairer dr= new DefaultDamagerRepairer(PHPEditorEnvironment.getHTMLCodeScanner());
*/
public class PHPCodeScanner extends RuleBasedScanner implements IPreferenceConstants {
- private IToken variable;
+ private static Token variable;
+ private static Token keyword;
+ private static Token functionName;
+ private static Token string;
+ private static Token comment;
+ private static Token multi_comment;
+ private static Token other;
private class PHPWordRule extends WordRule {
private StringBuffer fBuffer = new StringBuffer();
}
private static String[] fgConstants = { "__LINE__", "__FILE__", "true", "false", "null", "object", "array" };
- private TextAttribute fComment;
- private TextAttribute fKeyword;
- private TextAttribute fType;
- private TextAttribute fString;
+ // private static TextAttribute fSingleLine;
+ // private static TextAttribute fMultiLine;
+ // private static TextAttribute fKeyword;
+ // private static TextAttribute fFunctionName;
+ // private static TextAttribute fString;
+ // private static TextAttribute fVariable;
private PHPColorProvider fColorProvider;
/**
- * Creates a Java code scanner
+ * Creates a PHP code scanner
*/
public PHPCodeScanner(PHPColorProvider provider) {
- final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
+ final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
- IToken keyword = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PHP_KEYWORD))));
- IToken functionName = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PHP_FUNCTIONNAME))));
- IToken string = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PHP_STRING))));
- IToken comment = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PHP_SINGLELINE_COMMENT))));
- IToken multi_comment =
- new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PHP_MULTILINE_COMMENT))));
- IToken other = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PHP_DEFAULT))));
+ variable = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PHP_VARIABLE))));
+ keyword = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PHP_KEYWORD))));
+ functionName = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PHP_FUNCTIONNAME))));
+ string = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PHP_STRING))));
+ comment = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PHP_SINGLELINE_COMMENT))));
+ multi_comment = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PHP_MULTILINE_COMMENT))));
+ other = new Token(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PHP_DEFAULT))));
- variable = new Token(new TextAttribute(provider.getColor(PHPColorProvider.VARIABLE)));
List rules = new ArrayList();
// Add rule for single line comments.
rules.add(new EndOfLineRule("//", comment)); //$NON-NLS-1$
- // EndOfLineRule endOfLine = new EndOfLineRule("#", comment);
- // endOfLine.setColumnConstraint(0);
rules.add(new EndOfLineRule("#", comment));
// Add rule for strings and character constants.
rules.toArray(result);
setRules(result);
}
+
+ public void updateToken(PHPColorProvider provider) {
+ final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
+
+ variable.setData(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PHP_VARIABLE))));
+ keyword.setData(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PHP_KEYWORD))));
+ functionName.setData(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PHP_FUNCTIONNAME))));
+ string.setData(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PHP_STRING))));
+ comment.setData(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PHP_SINGLELINE_COMMENT))));
+ multi_comment.setData(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PHP_MULTILINE_COMMENT))));
+ other.setData(new TextAttribute(provider.getColor(PreferenceConverter.getColor(store, PHP_DEFAULT))));
+
+ }
}
// "empty",
// "array",
// "isset",
- "echo", "var", "as", "print",
+ "echo", "var", "as",
+ "print",
// "unset",
// "exit", "die",
"and", "or", "xor", "list",
// TT_empty,
// TT_array,
// TT_isset,
- TT_echo, TT_var, TT_as, TT_print,
+ TT_echo, TT_var, TT_as,
+ TT_print,
// TT_unset,
- //TT_exit, TT_die,
+ // TT_exit, TT_die,
TT_and, TT_or, TT_xor, TT_list,
TT_null, TT_false, TT_true };
}