From 1dca3bc4c68e2b9f8d4a54ac48165dfffbe35b23 Mon Sep 17 00:00:00 2001 From: khartlage Date: Sun, 4 Jul 2004 16:06:59 +0000 Subject: [PATCH] improved syntax highlighting (php tag/return keyword/brackets and operators) improved preferences --- .../ui/preferences/JavaEditorPreferencePage.java | 40 ++++++++++++-- .../ui/preferences/PHPEditorPreferencePage.java | 2 +- .../folding/DefaultJavaFoldingPreferenceBlock.java | 4 +- .../sourceforge/phpdt/ui/PreferenceConstants.java | 12 ++-- .../phpeclipse/IPreferenceConstants.java | 2 +- .../phpeclipse/phpeditor/php/PHPCodeScanner.java | 56 ++++++++++++++------ 6 files changed, 84 insertions(+), 32 deletions(-) diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/JavaEditorPreferencePage.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/JavaEditorPreferencePage.java index c25ed26..99e8fa1 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/JavaEditorPreferencePage.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/JavaEditorPreferencePage.java @@ -131,7 +131,7 @@ public class JavaEditorPreferencePage extends PreferencePage PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_COLOR}, //$NON-NLS-1$ {PreferencesMessages.getString("PHPEditorPreferencePage.tags"), - PreferenceConstants.EDITOR_JAVA_TAG_COLOR}, + PreferenceConstants.EDITOR_PHP_TAG_COLOR}, //$NON-NLS-1$ {PreferencesMessages.getString("PHPEditorPreferencePage.keywords"), PreferenceConstants.EDITOR_JAVA_KEYWORD_COLOR}, @@ -369,12 +369,42 @@ public class JavaEditorPreferencePage extends PreferencePage overlayKeys.add(new OverlayPreferenceStore.OverlayKey( OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_JAVA_KEYWORD_BOLD)); - overlayKeys - .add(new OverlayPreferenceStore.OverlayKey( + + overlayKeys.add(new OverlayPreferenceStore.OverlayKey( + OverlayPreferenceStore.STRING, + PreferenceConstants.EDITOR_PHP_TAG_COLOR)); + overlayKeys.add(new OverlayPreferenceStore.OverlayKey( + OverlayPreferenceStore.BOOLEAN, + PreferenceConstants.EDITOR_PHP_TAG_BOLD)); + overlayKeys.add(new OverlayPreferenceStore.OverlayKey( + OverlayPreferenceStore.STRING, + PreferenceConstants.EDITOR_PHP_FUNCTIONNAME_COLOR)); + overlayKeys.add(new OverlayPreferenceStore.OverlayKey( + OverlayPreferenceStore.BOOLEAN, + PreferenceConstants.EDITOR_PHP_FUNCTIONNAME_BOLD)); + overlayKeys.add(new OverlayPreferenceStore.OverlayKey( + OverlayPreferenceStore.STRING, + PreferenceConstants.EDITOR_PHP_VARIABLE_COLOR)); + overlayKeys.add(new OverlayPreferenceStore.OverlayKey( + OverlayPreferenceStore.BOOLEAN, + PreferenceConstants.EDITOR_PHP_VARIABLE_BOLD)); + overlayKeys.add(new OverlayPreferenceStore.OverlayKey( + OverlayPreferenceStore.STRING, + PreferenceConstants.EDITOR_PHP_CONSTANT_COLOR)); + overlayKeys.add(new OverlayPreferenceStore.OverlayKey( + OverlayPreferenceStore.BOOLEAN, + PreferenceConstants.EDITOR_PHP_CONSTANT_BOLD)); + overlayKeys.add(new OverlayPreferenceStore.OverlayKey( + OverlayPreferenceStore.STRING, + PreferenceConstants.EDITOR_PHP_TYPE_COLOR)); + overlayKeys.add(new OverlayPreferenceStore.OverlayKey( + OverlayPreferenceStore.BOOLEAN, + PreferenceConstants.EDITOR_PHP_TYPE_BOLD)); + + overlayKeys.add(new OverlayPreferenceStore.OverlayKey( OverlayPreferenceStore.STRING, PreferenceConstants.EDITOR_STRING_COLOR)); - overlayKeys - .add(new OverlayPreferenceStore.OverlayKey( + overlayKeys.add(new OverlayPreferenceStore.OverlayKey( OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_STRING_BOLD)); overlayKeys.add(new OverlayPreferenceStore.OverlayKey( diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/PHPEditorPreferencePage.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/PHPEditorPreferencePage.java index d0e75ad..6500ee1 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/PHPEditorPreferencePage.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/PHPEditorPreferencePage.java @@ -321,7 +321,7 @@ public class PHPEditorPreferencePage extends PreferencePage PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_COLOR}, //$NON-NLS-1$ {PHPUIMessages.getString("PHPEditorPreferencePage.tags"), - PreferenceConstants.EDITOR_JAVA_TAG_COLOR}, + PreferenceConstants.EDITOR_PHP_TAG_COLOR}, //$NON-NLS-1$ {PHPUIMessages.getString("PHPEditorPreferencePage.keywords"), PreferenceConstants.EDITOR_JAVA_KEYWORD_COLOR}, diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/folding/DefaultJavaFoldingPreferenceBlock.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/folding/DefaultJavaFoldingPreferenceBlock.java index 7613683..411b38b 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/folding/DefaultJavaFoldingPreferenceBlock.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/folding/DefaultJavaFoldingPreferenceBlock.java @@ -63,7 +63,7 @@ public class DefaultJavaFoldingPreferenceBlock implements IJavaFoldingPreference private OverlayKey[] createKeys() { ArrayList overlayKeys= new ArrayList(); - overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_FOLDING_JAVADOC)); +// overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_FOLDING_JAVADOC)); // overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_FOLDING_INNERTYPES)); overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_FOLDING_METHODS)); // overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_FOLDING_IMPORTS)); @@ -87,7 +87,7 @@ public class DefaultJavaFoldingPreferenceBlock implements IJavaFoldingPreference Label label= new Label(inner, SWT.LEFT); label.setText(FoldingMessages.getString("DefaultJavaFoldingPreferenceBlock.title")); //$NON-NLS-1$ - addCheckBox(inner, FoldingMessages.getString("DefaultJavaFoldingPreferenceBlock.comments"), PreferenceConstants.EDITOR_FOLDING_JAVADOC, 0); //$NON-NLS-1$ +// addCheckBox(inner, FoldingMessages.getString("DefaultJavaFoldingPreferenceBlock.comments"), PreferenceConstants.EDITOR_FOLDING_JAVADOC, 0); //$NON-NLS-1$ // addCheckBox(inner, FoldingMessages.getString("DefaultJavaFoldingPreferenceBlock.innerTypes"), PreferenceConstants.EDITOR_FOLDING_INNERTYPES, 0); //$NON-NLS-1$ addCheckBox(inner, FoldingMessages.getString("DefaultJavaFoldingPreferenceBlock.methods"), PreferenceConstants.EDITOR_FOLDING_METHODS, 0); //$NON-NLS-1$ // addCheckBox(inner, FoldingMessages.getString("DefaultJavaFoldingPreferenceBlock.imports"), PreferenceConstants.EDITOR_FOLDING_IMPORTS, 0); //$NON-NLS-1$ diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/PreferenceConstants.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/PreferenceConstants.java index b023981..e9a271f 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/PreferenceConstants.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/PreferenceConstants.java @@ -1088,7 +1088,7 @@ public final static String EDITOR_TEXT_FONT= "net.sourceforge.phpdt.ui.editors.t * @see org.eclipse.jface.resource.StringConverter * @see org.eclipse.jface.preference.PreferenceConverter */ - public final static String EDITOR_JAVA_TAG_COLOR = IPreferenceConstants.PHP_TAG; + public final static String EDITOR_PHP_TAG_COLOR = IPreferenceConstants.PHP_TAG; /** * A named preference that controls whether php start and stop tags are rendered in bold. @@ -1096,7 +1096,7 @@ public final static String EDITOR_TEXT_FONT= "net.sourceforge.phpdt.ui.editors.t * Value is of type Boolean. *

*/ - public final static String EDITOR_JAVA_TAG_BOLD = IPreferenceConstants.PHP_TAG + EDITOR_BOLD_SUFFIX; + public final static String EDITOR_PHP_TAG_BOLD = IPreferenceConstants.PHP_TAG + EDITOR_BOLD_SUFFIX; /** * A named preference that holds the color used to render php keywords. @@ -2304,8 +2304,8 @@ public final static String EDITOR_TEXT_FONT= "net.sourceforge.phpdt.ui.editors.t PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_COLOR, new RGB(63, 127, 95)); store.setDefault(PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_BOLD, false); - PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_JAVA_TAG_COLOR, new RGB(255, 0, 128)); - store.setDefault(PreferenceConstants.EDITOR_JAVA_TAG_BOLD, true); + PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_PHP_TAG_COLOR, new RGB(255, 0, 128)); + store.setDefault(PreferenceConstants.EDITOR_PHP_TAG_BOLD, true); PreferenceConverter.setDefault(store, PreferenceConstants.EDITOR_JAVA_KEYWORD_COLOR, new RGB(127, 0, 85)); store.setDefault(PreferenceConstants.EDITOR_JAVA_KEYWORD_BOLD, true); @@ -2409,11 +2409,11 @@ public final static String EDITOR_TEXT_FONT= "net.sourceforge.phpdt.ui.editors.t // folding store.setDefault(PreferenceConstants.EDITOR_FOLDING_ENABLED, true); - store.setDefault(PreferenceConstants.EDITOR_FOLDING_PROVIDER, "org.eclipse.jdt.ui.text.defaultFoldingProvider"); //$NON-NLS-1$ + store.setDefault(PreferenceConstants.EDITOR_FOLDING_PROVIDER, "net.sourceforge.phpdt.ui.text.defaultFoldingProvider"); //$NON-NLS-1$ store.setDefault(PreferenceConstants.EDITOR_FOLDING_JAVADOC, false); store.setDefault(PreferenceConstants.EDITOR_FOLDING_INNERTYPES, true); store.setDefault(PreferenceConstants.EDITOR_FOLDING_METHODS, false); - store.setDefault(PreferenceConstants.EDITOR_FOLDING_IMPORTS, true); + store.setDefault(PreferenceConstants.EDITOR_FOLDING_IMPORTS, false); // do more complicated stuff // NewJavaProjectPreferencePage.initDefaults(store); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/IPreferenceConstants.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/IPreferenceConstants.java index a4c52bb..66ceacd 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/IPreferenceConstants.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/IPreferenceConstants.java @@ -61,7 +61,7 @@ public interface IPreferenceConstants { * (value "__php_operator"). * @since 3.0 */ - public static final String PHP_OPERATOR= "__php_operator"; //$NON-NLS-1$ + public static final String PHP_OPERATOR = "__php_operator"; //$NON-NLS-1$ /** * A named preference that holds the color used to render operators and brackets. *

diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCodeScanner.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCodeScanner.java index b227ae2..1b74a75 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCodeScanner.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCodeScanner.java @@ -83,6 +83,22 @@ public class PHPCodeScanner extends AbstractJavaScanner { int character= scanner.read(); if (isOperator((char) character)) { + int lastCharacter = character; + character= scanner.read(); + if (!isOperator((char) character)) { + scanner.unread(); + return fToken; + } + if (lastCharacter=='<' && character=='?') { + scanner.unread(); + scanner.unread(); + return Token.UNDEFINED; + } + if (lastCharacter=='?' && character=='>') { + scanner.unread(); + scanner.unread(); + return Token.UNDEFINED; + } do { character= scanner.read(); } while (isOperator((char) character)); @@ -113,32 +129,41 @@ public class PHPCodeScanner extends AbstractJavaScanner { c = scanner.read(); if (c != '?') { scanner.unread(); + scanner.unread(); + return Token.UNDEFINED; } else { c = scanner.read(); if (c != 'p') { scanner.unread(); + return getToken(IPreferenceConstants.PHP_TAG); } else { c = scanner.read(); if (c != 'h') { scanner.unread(); + scanner.unread(); + return getToken(IPreferenceConstants.PHP_TAG); } else { c = scanner.read(); if (c != 'p') { scanner.unread(); + scanner.unread(); + scanner.unread(); + return getToken(IPreferenceConstants.PHP_TAG); } else { return getToken(IPreferenceConstants.PHP_TAG); } } } } - } if (c == '?') { - c = scanner.read(); + c = scanner.read(); if (c == '>') { return getToken(IPreferenceConstants.PHP_TAG); - } + } scanner.unread(); + scanner.unread(); + return Token.UNDEFINED; } if (fDetector.isWordStart((char) c)) { if (c == '$') { @@ -361,10 +386,6 @@ public class PHPCodeScanner extends AbstractJavaScanner { rules.add(new MultiLineRule("\"", "\"", token, '\\')); //$NON-NLS-2$ //$NON-NLS-1$ rules.add(new MultiLineRule("`", "`", token, '\\')); //$NON-NLS-2$ //$NON-NLS-1$ rules.add(new MultiLineRule("'", "'", token, '\\')); //$NON-NLS-2$ //$NON-NLS-1$ - -// Add rule for operators and brackets - token= getToken(IPreferenceConstants.PHP_OPERATOR); - rules.add(new OperatorRule(token)); token = getToken(IPreferenceConstants.PHP_MULTILINE_COMMENT); rules.add(new MultiLineRule("/*", "*/", token)); //$NON-NLS-2$ //$NON-NLS-1$ @@ -373,7 +394,6 @@ public class PHPCodeScanner extends AbstractJavaScanner { // Add word rule for keywords, types, and constants. token = getToken(IPreferenceConstants.PHP_DEFAULT); PHPWordRule wordRule = new PHPWordRule(new PHPWordDetector(), token); - CombinedWordRule combinedWordRule= new CombinedWordRule(new PHPWordDetector(), token); Token keyword = getToken(IPreferenceConstants.PHP_KEYWORD); Token functionName = getToken(IPreferenceConstants.PHP_FUNCTIONNAME); @@ -391,9 +411,9 @@ public class PHPCodeScanner extends AbstractJavaScanner { elbuffer = (PHPElement) buffer.get(i); if (elbuffer instanceof PHPKeyword) { name = ((PHPKeyword) elbuffer).getName(); -// if (!name.equals("return")) { + if (!name.equals("return")) { wordRule.addWord(name, keyword); -// } + } } else if (elbuffer instanceof PHPFunction) { wordRule.addWord(((PHPFunction) elbuffer).getName(), functionName); } else if (elbuffer instanceof PHPType) { @@ -402,15 +422,17 @@ public class PHPCodeScanner extends AbstractJavaScanner { wordRule.addWord(elbuffer.getName(), constant); } } + +// Add word rule for keyword 'return'. + token= getToken(IPreferenceConstants.PHP_KEYWORD_RETURN); + wordRule.addWord("return", token); + +// Add rule for operators and brackets (at the end !) + token= getToken(IPreferenceConstants.PHP_OPERATOR); + rules.add(new OperatorRule(token)); + rules.add(wordRule); -// Add word rule for keyword 'return'. -// CombinedWordRule.WordMatcher returnWordRule= new CombinedWordRule.WordMatcher(); -// token= getToken(IPreferenceConstants.PHP_KEYWORD_RETURN); -// returnWordRule.addWord("return", token); //$NON-NLS-1$ -// combinedWordRule.addWordMatcher(returnWordRule); -// rules.add(combinedWordRule); -// return rules; } } -- 1.7.1