*/
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();
do {
fBuffer.append((char) c);
c = scanner.read();
- } while (c != scanner.EOF && fDetector.isWordPart((char) c));
+ } while (c != ICharacterScanner.EOF && fDetector.isWordPart((char) c));
scanner.unread();
if (isVariable) {
}
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();
- 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(PHPColorProvider.VARIABLE)));
+ 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))));
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.
// Add word rule for keywords, types, and constants.
PHPWordRule wordRule = new PHPWordRule(new PHPWordDetector(), other);
- for (int i = 0; i < PHPKeywords.PHP_KEYWORS.length; i++)
+// //choochter-->
+// for (int i = 0; i < PHPKeywords.PHP_KEYWORS.length; i++)
+// wordRule.addWord(PHPKeywords.PHP_KEYWORS[i], keyword);
+//
+// /*Read in the keywords from the XML file*/
+// PHPSyntaxRdr syntaxRdr = new PHPSyntaxRdr();
+// syntaxRdr.readFromFile(
+// "C:\\eclipse\\workspace\\net.sourceforge.phpeclipse\\src\\net\\sourceforge\\phpeclipse\\phpeditor"
+// + java.io.File.separator
+// + "syntax.xml");
+// {
+// Vector Vbuffer = syntaxRdr.getKeywords();
+// String VString = null;
+// //Read keywords
+// while ((Vbuffer != null) && (!Vbuffer.isEmpty() && ((VString = (String) Vbuffer.remove(0)) != null))) {
+// wordRule.addWord(VString, keyword);
+// }
+// //Read functions - to be tested
+// Vbuffer = syntaxRdr.getFunctions();
+// while ((Vbuffer != null) && (!Vbuffer.isEmpty() && ((VString = (String) Vbuffer.remove(0)) != null))) {
+// wordRule.addWord(VString, functionName);
+// }
+// }
+//
+// //for (int i = 0; i < PHPFunctionNames.FUNCTION_NAMES.length; i++)
+// // wordRule.addWord(PHPFunctionNames.FUNCTION_NAMES[i], functionName);
+// //<--choochter
+ for (int i = 0; i < PHPKeywords.PHP_KEYWORS.length; i++) {
wordRule.addWord(PHPKeywords.PHP_KEYWORS[i], keyword);
- for (int i = 0; i < PHPFunctionNames.FUNCTION_NAMES.length; i++)
+ }
+ for (int i = 0; i < PHPFunctionNames.FUNCTION_NAMES.length; i++) {
wordRule.addWord(PHPFunctionNames.FUNCTION_NAMES[i], functionName);
- for (int i = 0; i < fgConstants.length; i++)
- wordRule.addWord(fgConstants[i], functionName);
+ }
+ for (int i = 0; i < fgConstants.length; i++) {
+ wordRule.addWord(fgConstants[i], keyword);
+ }
rules.add(wordRule);
IRule[] result = new IRule[rules.size()];
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))));
+
+ }
}