import java.util.ArrayList;
import java.util.List;
+import net.sourceforge.phpdt.internal.ui.text.AbstractJavaScanner;
+import net.sourceforge.phpdt.internal.ui.text.JavaColorManager;
+import net.sourceforge.phpdt.ui.text.IColorManager;
+import net.sourceforge.phpeclipse.IPreferenceConstants;
import net.sourceforge.phpeclipse.phpeditor.util.HTMLWordDetector;
import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
import net.sourceforge.phpeclipse.phpeditor.util.PHPWhitespaceDetector;
-import org.eclipse.jface.text.BadLocationException;
+
+import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.rules.ICharacterScanner;
import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.IWordDetector;
-import org.eclipse.jface.text.rules.RuleBasedScanner;
import org.eclipse.jface.text.rules.SingleLineRule;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.rules.WhitespaceRule;
import org.eclipse.jface.text.rules.WordRule;
/**
- * A Java code scanner.
+ * A HTML code scanner.
*/
-public class HTMLCodeScanner extends RuleBasedScanner {
-
- private static String[] fgKeywords = {
- };
-
- private static String[] fgTypes = {
- };
-
- private IToken keyword;
-
+public class HTMLCodeScanner extends AbstractJavaScanner {
+
+// private static String[] fgKeywords = {
+// };
+//
+// private static String[] fgTypes = {
+// };
+
+// private IToken keyword;
+ private static String[] fgTokenProperties =
+ {
+ IPreferenceConstants.PHP_MULTILINE_COMMENT,
+ IPreferenceConstants.PHP_SINGLELINE_COMMENT,
+ IPreferenceConstants.PHP_TAG,
+ IPreferenceConstants.PHP_KEYWORD,
+ IPreferenceConstants.PHP_FUNCTIONNAME,
+ IPreferenceConstants.PHP_VARIABLE,
+ IPreferenceConstants.PHP_STRING,
+ IPreferenceConstants.PHP_TYPE,
+ IPreferenceConstants.PHP_CONSTANT,
+ IPreferenceConstants.PHP_DEFAULT,
+ IPreferenceConstants.PHP_OPERATOR,
+ IPreferenceConstants.PHP_KEYWORD_RETURN};
+ /*
+ * @see AbstractJavaScanner#getTokenProperties()
+ */
+ protected String[] getTokenProperties() {
+ return fgTokenProperties;
+ }
private class HTMLWordRule extends WordRule {
private StringBuffer fBuffer = new StringBuffer();
if (c == '/' && (fBuffer.length() > 2) ) {
break;
}
- } while (c != scanner.EOF && fDetector.isWordPart((char) c));
+ } while (c != ICharacterScanner.EOF && fDetector.isWordPart((char) c));
scanner.unread();
if (tagBegin) {
- return keyword;
+ return getToken(IPreferenceConstants.PHP_KEYWORD);
}
IToken token = (IToken) fWords.get(fBuffer.toString());
if (token != null)
/**
* Creates a Java code scanner
*/
- public HTMLCodeScanner(PHPColorProvider provider) {
+ public HTMLCodeScanner(IColorManager manager, IPreferenceStore store) {
+ super(manager, store);
+ initialize();
+ }
- keyword = new Token(new TextAttribute(provider.getColor(PHPColorProvider.KEYWORD)));
- IToken type = new Token(new TextAttribute(provider.getColor(PHPColorProvider.TYPE)));
- IToken string = new Token(new TextAttribute(provider.getColor(PHPColorProvider.STRING)));
- IToken comment = new Token(new TextAttribute(provider.getColor(PHPColorProvider.SINGLE_LINE_COMMENT)));
- IToken multi_comment = new Token(new TextAttribute(provider.getColor(PHPColorProvider.MULTI_LINE_COMMENT)));
- IToken other = new Token(new TextAttribute(provider.getColor(PHPColorProvider.DEFAULT)));
+ /*
+ * @see AbstractJavaScanner#createRules()
+ */
+ protected List createRules() {
+ List rules = new ArrayList();
- //variable = new Token(new TextAttribute(provider.getColor(PHPColorProvider.VARIABLE)));
+// keyword = new Token(new TextAttribute(provider.getColor(PHPColorProvider.KEYWORD)));
+// IToken type = new Token(new TextAttribute(provider.getColor(PHPColorProvider.FUNCTION_NAME)));
+// IToken string = new Token(new TextAttribute(provider.getColor(PHPColorProvider.STRING)));
+// IToken comment = new Token(new TextAttribute(provider.getColor(PHPColorProvider.SINGLE_LINE_COMMENT)));
+// IToken multi_comment = new Token(new TextAttribute(provider.getColor(PHPColorProvider.MULTI_LINE_COMMENT)));
+// IToken other = new Token(new TextAttribute(provider.getColor(PHPColorProvider.DEFAULT)));
- List rules = new ArrayList();
+ //variable = new Token(new TextAttribute(provider.getColor(PHPColorProvider.VARIABLE)));
- // Add rule for single line comments.
- //rules.add(new EndOfLineRule("//", comment)); //$NON-NLS-1$
- //rules.add(new EndOfLineRule("#", comment));
-
- // Add rule for strings and character constants.
- rules.add(new SingleLineRule("\"", "\"", string)); //$NON-NLS-2$ //$NON-NLS-1$
- // rules.add(new SingleLineRule("'", "'", string, '\\')); //$NON-NLS-2$ //$NON-NLS-1$
-
- // rules.add(new SingleLineRule("//", "//", php_comment));
- // rules.add(new MultiLineRule("/*", "*/", multi_comment));
-
- // Add generic whitespace rule.
- rules.add(new WhitespaceRule(new PHPWhitespaceDetector()));
-
- // Add word rule for keywords, types, and constants.
- HTMLWordRule wordRule = new HTMLWordRule(new HTMLWordDetector(), other);
- for (int i = 0; i < fgKeywords.length; i++)
- wordRule.addWord(fgKeywords[i], keyword);
- for (int i = 0; i < fgTypes.length; i++)
- wordRule.addWord(fgTypes[i], type);
- // for (int i = 0; i < fgConstants.length; i++)
- // wordRule.addWord(fgConstants[i], type);
- rules.add(wordRule);
-
- IRule[] result = new IRule[rules.size()];
- rules.toArray(result);
- setRules(result);
- }
+ // Add rule for single line comments.
+ //rules.add(new EndOfLineRule("//", comment)); //$NON-NLS-1$
+ //rules.add(new EndOfLineRule("#", comment));
+
+ // Add rule for strings and character constants.
+ rules.add(new SingleLineRule("\"", "\"", getToken(IPreferenceConstants.PHP_STRING))); //$NON-NLS-2$ //$NON-NLS-1$
+ // rules.add(new SingleLineRule("'", "'", string, '\\')); //$NON-NLS-2$ //$NON-NLS-1$
+
+ // rules.add(new SingleLineRule("//", "//", php_comment));
+ // rules.add(new MultiLineRule("/*", "*/", multi_comment));
+
+ // Add generic whitespace rule.
+ rules.add(new WhitespaceRule(new PHPWhitespaceDetector()));
+
+ // Add word rule for keywords, types, and constants.
+ HTMLWordRule wordRule = new HTMLWordRule(new HTMLWordDetector(), getToken(IPreferenceConstants.PHP_DEFAULT));
+// for (int i = 0; i < fgKeywords.length; i++)
+// wordRule.addWord(fgKeywords[i], keyword);
+// for (int i = 0; i < fgTypes.length; i++)
+// wordRule.addWord(fgTypes[i], type);
+ rules.add(wordRule);
+
+ setDefaultReturnToken(getToken(IPreferenceConstants.PHP_DEFAULT));
+return rules;
+ }
}