|
From: Christopher W. <caw...@us...> - 2006-01-27 16:28:07
|
Update of /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28338/src/org/rubypeople/rdt/internal/ui/text/ruby Modified Files: RubyCodeScanner.java Added Files: GlobalDetector.java InstanceVariableDetector.java IdentifierDetector.java Log Message: Add support for coloring global variables and instance/class variables uniquely --- NEW FILE: IdentifierDetector.java --- package org.rubypeople.rdt.internal.ui.text.ruby; import org.eclipse.jface.text.rules.IWordDetector; public class IdentifierDetector implements IWordDetector { public boolean isWordStart(char c) { if (c == '_') return true; return Character.isLetter(c); } public boolean isWordPart(char c) { if (c == '_') return true; if (Character.isWhitespace(c)) return false; if (Character.isDigit(c)) return true; return Character.isLetter(c); } } --- NEW FILE: GlobalDetector.java --- package org.rubypeople.rdt.internal.ui.text.ruby; public class GlobalDetector extends IdentifierDetector { public boolean isWordStart(char c) { return c == '$'; } } --- NEW FILE: InstanceVariableDetector.java --- package org.rubypeople.rdt.internal.ui.text.ruby; public class InstanceVariableDetector extends IdentifierDetector { public boolean isWordStart(char c) { return c == '@'; } } Index: RubyCodeScanner.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyCodeScanner.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** RubyCodeScanner.java 2 Dec 2005 16:18:11 -0000 1.9 --- RubyCodeScanner.java 27 Jan 2006 16:27:56 -0000 1.10 *************** *** 16,75 **** public class RubyCodeScanner extends AbstractRubyScanner { ! protected String[] keywords; ! private static String[] fgTokenProperties = { ! IRubyColorConstants.RUBY_KEYWORD, IRubyColorConstants.RUBY_DEFAULT, ! IRubyColorConstants.RUBY_FIXNUM, IRubyColorConstants.RUBY_CHARACTER, ! IRubyColorConstants.RUBY_SYMBOL ! // TODO Add Ability to set colors for return and operators ! // IRubyColorConstants.RUBY_METHOD_NAME, ! // IRubyColorConstants.RUBY_KEYWORD_RETURN, ! // IRubyColorConstants.RUBY_OPERATOR ! }; ! /** ! * Creates a Ruby code scanner ! * ! * @param manager ! * the color manager ! * @param store ! * the preference store ! */ ! public RubyCodeScanner(IColorManager manager, IPreferenceStore store) { ! super(manager, store); ! initialize(); ! } ! /* ! * @see AbstractRubyScanner#getTokenProperties() ! */ ! protected String[] getTokenProperties() { ! return fgTokenProperties; ! } ! protected List createRules() { ! List rules = new ArrayList(); ! rules.add(new CharacterRule( ! getToken(IRubyColorConstants.RUBY_CHARACTER))); ! IToken fixnumToken = getToken(IRubyColorConstants.RUBY_FIXNUM); ! rules.add(new NumberRule(fixnumToken)); ! ! rules.add(new SymbolRule( ! getToken(IRubyColorConstants.RUBY_SYMBOL))); ! IWordDetector wordDetector = new RubyWordDetector(); ! IToken defToken = getToken(IRubyColorConstants.RUBY_DEFAULT); ! setDefaultReturnToken(defToken); ! WordRule wordRule = new WordRule(wordDetector, defToken); ! rules.add(wordRule); ! IToken token = getToken(IRubyColorConstants.RUBY_KEYWORD); ! String[] keywords = RubyTextTools.getKeyWords(); ! for (int keyWordIndex = 0; keyWordIndex < keywords.length; keyWordIndex++) ! wordRule.addWord(keywords[keyWordIndex], token); ! return rules; ! } } \ No newline at end of file --- 16,82 ---- public class RubyCodeScanner extends AbstractRubyScanner { ! protected String[] keywords; ! private static String[] fgTokenProperties = { IRubyColorConstants.RUBY_KEYWORD, ! IRubyColorConstants.RUBY_DEFAULT, IRubyColorConstants.RUBY_FIXNUM, ! IRubyColorConstants.RUBY_CHARACTER, IRubyColorConstants.RUBY_SYMBOL, ! IRubyColorConstants.RUBY_INSTANCE_VARIABLE, IRubyColorConstants.RUBY_GLOBAL ! // TODO Add Ability to set colors for return and operators ! // IRubyColorConstants.RUBY_METHOD_NAME, ! // IRubyColorConstants.RUBY_KEYWORD_RETURN, ! // IRubyColorConstants.RUBY_OPERATOR ! }; ! /** ! * Creates a Ruby code scanner ! * ! * @param manager ! * the color manager ! * @param store ! * the preference store ! */ ! public RubyCodeScanner(IColorManager manager, IPreferenceStore store) { ! super(manager, store); ! initialize(); ! } ! /* ! * @see AbstractRubyScanner#getTokenProperties() ! */ ! protected String[] getTokenProperties() { ! return fgTokenProperties; ! } ! protected List createRules() { ! List rules = new ArrayList(); ! rules.add(new CharacterRule(getToken(IRubyColorConstants.RUBY_CHARACTER))); ! IToken fixnumToken = getToken(IRubyColorConstants.RUBY_FIXNUM); ! rules.add(new NumberRule(fixnumToken)); ! rules.add(new SymbolRule(getToken(IRubyColorConstants.RUBY_SYMBOL))); ! //rules.add(new ClassVariableRule(getToken(IRubyColorConstants.RUBY_CLASS_VARIABLE))); ! IToken defToken = getToken(IRubyColorConstants.RUBY_DEFAULT); ! setDefaultReturnToken(getToken(IRubyColorConstants.RUBY_DEFAULT)); ! ! IWordDetector instanceVarDetector = new InstanceVariableDetector(); ! WordRule instanceVarRule = new WordRule(instanceVarDetector, getToken(IRubyColorConstants.RUBY_INSTANCE_VARIABLE)); ! rules.add(instanceVarRule); ! ! WordRule gloablRule = new WordRule(new GlobalDetector(), getToken(IRubyColorConstants.RUBY_GLOBAL)); ! rules.add(gloablRule); ! ! IWordDetector wordDetector = new RubyWordDetector(); ! WordRule wordRule = new WordRule(wordDetector, defToken); ! IToken token = getToken(IRubyColorConstants.RUBY_KEYWORD); ! String[] keywords = RubyTextTools.getKeyWords(); ! for (int keyWordIndex = 0; keyWordIndex < keywords.length; keyWordIndex++) ! wordRule.addWord(keywords[keyWordIndex], token); ! rules.add(wordRule); ! ! return rules; ! } } \ No newline at end of file |