|
From: <caw...@us...> - 2007-03-14 14:58:12
|
Revision: 2163
http://svn.sourceforge.net/rubyeclipse/?rev=2163&view=rev
Author: cawilliams
Date: 2007-03-14 07:58:09 -0700 (Wed, 14 Mar 2007)
Log Message:
-----------
Merge over changes from syntax branch r2078:HEAD into trunk
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyPlugin.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/IRubyColorConstants.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/RubyPartitionScanner.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubyTextTools.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/AbstractRubyTokenScanner.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyTokenScanner.java
Removed Paths:
-------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/HereDocPatternRule.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/PercentSyntaxRule.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/CharacterRule.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyCodeScanner.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyNumberRule.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/SingleCharacterPrefixRule.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/SingleTokenRubyCodeScanner.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/SymbolRule.java
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyPlugin.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyPlugin.java 2007-03-14 13:54:14 UTC (rev 2162)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyPlugin.java 2007-03-14 14:58:09 UTC (rev 2163)
@@ -286,7 +286,11 @@
store.setDefault(RUBY_DEFAULT + PreferenceConstants.EDITOR_ITALIC_SUFFIX, false);
PreferenceConverter.setDefault(store, RUBY_KEYWORD, new RGB(164, 53, 122));
store.setDefault(RUBY_KEYWORD + PreferenceConstants.EDITOR_BOLD_SUFFIX, true);
- store.setDefault(RUBY_KEYWORD + PreferenceConstants.EDITOR_ITALIC_SUFFIX, false);
+ store.setDefault(RUBY_KEYWORD + PreferenceConstants.EDITOR_ITALIC_SUFFIX, false);
+ PreferenceConverter.setDefault(store, RUBY_ERROR, new RGB(255, 255, 255));
+ store.setDefault(RUBY_ERROR + PreferenceConstants.EDITOR_BOLD_SUFFIX, true);
+ store.setDefault(RUBY_ERROR + PreferenceConstants.EDITOR_ITALIC_SUFFIX, false);
+ PreferenceConverter.setDefault(store, RUBY_ERROR + PreferenceConstants.EDITOR_BG_SUFFIX, new RGB(255, 0, 0));
PreferenceConverter.setDefault(store, RUBY_STRING, new RGB(42, 0, 255));
store.setDefault(RUBY_STRING + PreferenceConstants.EDITOR_BOLD_SUFFIX, false);
store.setDefault(RUBY_STRING + PreferenceConstants.EDITOR_ITALIC_SUFFIX, false);
Deleted: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/HereDocPatternRule.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/HereDocPatternRule.java 2007-03-14 13:54:14 UTC (rev 2162)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/HereDocPatternRule.java 2007-03-14 14:58:09 UTC (rev 2163)
@@ -1,96 +0,0 @@
-package org.rubypeople.rdt.internal.ui.text;
-
-import org.eclipse.jface.text.rules.ICharacterScanner;
-import org.eclipse.jface.text.rules.IToken;
-import org.eclipse.jface.text.rules.PatternRule;
-
-public class HereDocPatternRule extends PatternRule {
-
- public HereDocPatternRule(IToken token) {
- // TODO: escape char OK?
- // FIXME We need to only handle exact cases, not <<=
-
- // Correct cases:
- // (http://www.zenspider.com/Languages/Ruby/QuickRef.html#8)
- // <<identifier - interpolated, goes until identifier
- // <<"identifier" - same thing
- // <<'identifier' - no interpolation
- // <<-identifier - you can indent the identifier by using "-" in front
- super("<<", "", token, (char) -1, false, false);
- }
-
- protected boolean endSequenceDetected(ICharacterScanner scanner) {
- char firstChar = (char) scanner.read();
-
- if (Character.isWhitespace(firstChar)) { return false; }
-
- boolean indentedKeyword = false;
- if (firstChar == '-') {
- indentedKeyword = true;
- firstChar = (char) scanner.read();
- }
- boolean isQuoted = false;
- char quote = ' ';
- if (firstChar == '\'' || firstChar == '"') {
- isQuoted = true;
- quote = firstChar;
- firstChar = (char) scanner.read();
- }
- String keyword = readKeyword(scanner, firstChar);
- if (keyword.length() == 0) { return false; }
- if (isQuoted && !(keyword.charAt(keyword.length() - 1) == quote)) { return false; }
- if (isQuoted) {
- fEndSequence = removeEndQuote(keyword).toCharArray();
- } else {
- fEndSequence = keyword.toCharArray();
- }
- boolean result = super.endSequenceDetected(scanner);
- if (!result) { return false; }
-
- if(indentedKeyword) {
- rewindToBeginOfLine(scanner);
- char lastChar;
- do {
- lastChar = (char) scanner.read();
- }
- while(Character.isWhitespace(lastChar));
-
- String newKeyword = readKeyword(scanner, lastChar);
-
- if(isQuoted)
- return removeEndQuote(keyword).equals(newKeyword);
- else
- return keyword.equals(newKeyword);
-
- } else {
- return scanner.getColumn() == fEndSequence.length;
- }
- }
-
- private String removeEndQuote(String keyword) {
- return keyword.substring(0, keyword.length() - 1);
- }
-
- private void rewindToBeginOfLine(ICharacterScanner scanner) {
- char readChar = 0;
- while (readChar != '\n') {
- scanner.unread();
- scanner.unread();
- readChar = (char) scanner.read();
- }
- }
-
- private String readKeyword(ICharacterScanner scanner, char firstChar) {
- String keyword = "";
- char c = firstChar;
- do {
- if ((byte) c == ICharacterScanner.EOF || Character.isWhitespace(c)) {
- break;
- }
- keyword += c;
- c = (char) scanner.read();
- } while (true);
- return keyword;
- }
-
-}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/IRubyColorConstants.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/IRubyColorConstants.java 2007-03-14 13:54:14 UTC (rev 2162)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/IRubyColorConstants.java 2007-03-14 14:58:09 UTC (rev 2163)
@@ -4,6 +4,7 @@
public static final String RUBY_COLOR_PREFIX = "color_ruby_";
public static final String RUBY_DEFAULT = RUBY_COLOR_PREFIX + "default";
public static final String RUBY_KEYWORD = RUBY_COLOR_PREFIX + "keyword";
+ public static final String RUBY_ERROR = RUBY_COLOR_PREFIX + "error";
public static final String RUBY_STRING = RUBY_COLOR_PREFIX + "string";
public static final String RUBY_REGEXP = RUBY_COLOR_PREFIX + "regexp";
public static final String RUBY_COMMAND = RUBY_COLOR_PREFIX + "command";
Deleted: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/PercentSyntaxRule.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/PercentSyntaxRule.java 2007-03-14 13:54:14 UTC (rev 2162)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/PercentSyntaxRule.java 2007-03-14 14:58:09 UTC (rev 2163)
@@ -1,127 +0,0 @@
-package org.rubypeople.rdt.internal.ui.text;
-
-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.Token;
-
-public class PercentSyntaxRule implements IRule {
-
- public IToken evaluate(ICharacterScanner scanner) {
- int c = scanner.read();
- if (((char) c) == '%') {
- c = scanner.read(); // get next char
- switch ((char) c) {
- case 'r': // regular expression
- return detectToken(scanner, IRubyPartitions.RUBY_REGEX);
- case 'x': // commands
- return detectToken(scanner, IRubyPartitions.RUBY_COMMAND);
- case 'q':
- case 'Q': // strings
- return detectToken(scanner, IRubyPartitions.RUBY_STRING);
- case 'w':
- case 'W': // Array of strings
- scanner.unread();
- scanner.unread();
- // FIXME Mark the individual elements as strings
- return Token.UNDEFINED;
- default: // special case of string (no letter following percent)
- scanner.unread();
- return detectToken(scanner, IRubyPartitions.RUBY_STRING);
- }
- }
- scanner.unread();
- return Token.UNDEFINED;
- }
-
- private IToken detectToken(ICharacterScanner scanner, String tokenType) {
- int c = scanner.read(); // get delimeter
- int lastChar = c;
- char endChar = getMatchingBracket((char) c);
- // Read until EOF, End character or EOL
- while (true) {
- c = scanner.read();
- // FIXME This is a big hack. Expression substitution actually needs to be returned as normal ruby code (and repartitioned)
- if ((char) c == '#') { // Try to handle expression substitution
- int d = scanner.read();
- if ((char) d == '{') {
- // read until '}'
- do {
- d = scanner.read();
- if (d == ICharacterScanner.EOF) {
- return new Token(tokenType);
- }
- } while ((char) d != '}');
- continue;
- } else if ((char) d == '@' || (char) d == '$') {
- // read until whitespace
- do {
- d = scanner.read();
- } while ((char) d != ' ');
- continue;
- } else {// not expression subst.
- scanner.unread();
- }
- }
-
- // TODO Stop at EOL,char[][] originalDelimiters=
- // scanner.getLegalLineDelimiters();
- if (c == ICharacterScanner.EOF)
- break; // we're done
- if ((char) c == endChar && ((char) lastChar != '\\'))
- break; // we found matching bracket
- lastChar = c;
- }
- return new Token(tokenType);
- }
-
- /**
- * Returns whether the next characters to be read by the character scanner
- * are an exact match with the given sequence. No escape characters are
- * allowed within the sequence. If specified the sequence is considered to
- * be found when reading the EOF character.
- *
- * @param scanner
- * the character scanner to be used
- * @param sequence
- * the sequence to be detected
- * @param eofAllowed
- * indicated whether EOF terminates the pattern
- * @return <code>true</code> if the given sequence has been detected
- */
- protected boolean sequenceDetected(ICharacterScanner scanner,
- char[] sequence, boolean eofAllowed) {
- for (int i = 1; i < sequence.length; i++) {
- int c = scanner.read();
- if (c == ICharacterScanner.EOF && eofAllowed) {
- return true;
- } else if (c != sequence[i]) {
- // Non-matching character detected, rewind the scanner back to
- // the start.
- // Do not unread the first character.
- scanner.unread();
- for (int j = i - 1; j > 0; j--)
- scanner.unread();
- return false;
- }
- }
-
- return true;
- }
-
- private char getMatchingBracket(char c) {
- switch (c) {
- case '(':
- return ')';
- case '{':
- return '}';
- case '[':
- return ']';
- case '<':
- return '>';
- default:
- return c;
- }
- }
-
-}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/RubyPartitionScanner.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/RubyPartitionScanner.java 2007-03-14 13:54:14 UTC (rev 2162)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/RubyPartitionScanner.java 2007-03-14 14:58:09 UTC (rev 2163)
@@ -10,11 +10,7 @@
import org.eclipse.jface.text.rules.IPredicateRule;
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.PatternRule;
-import org.eclipse.jface.text.rules.SingleLineRule;
import org.eclipse.jface.text.rules.Token;
-import org.eclipse.jface.text.rules.WordPatternRule;
public class RubyPartitionScanner extends BufferedRuleBasedScanner implements
IPartitionTokenScanner {
@@ -25,16 +21,11 @@
/** The offset of the partition inside which to resume. */
protected int fPartitionOffset;
- public final static String RUBY_STRING = IRubyPartitions.RUBY_STRING;
public final static String RUBY_MULTI_LINE_COMMENT = IRubyPartitions.RUBY_MULTI_LINE_COMMENT;
- public static final String RUBY_SINGLE_LINE_COMMENT = IRubyPartitions.RUBY_SINGLE_LINE_COMMENT;
- public static final String RUBY_REGULAR_EXPRESSION = IRubyPartitions.RUBY_REGEX;
- public static final String RUBY_COMMAND = IRubyPartitions.RUBY_COMMAND;
- public static final String HERE_DOC = "partition_scanner_here_doc";
- public static final String[] LEGAL_CONTENT_TYPES = { RUBY_STRING,
- RUBY_MULTI_LINE_COMMENT, RUBY_SINGLE_LINE_COMMENT,
- RUBY_REGULAR_EXPRESSION, RUBY_COMMAND };
+ public static final String[] LEGAL_CONTENT_TYPES = {
+ RUBY_MULTI_LINE_COMMENT
+ };
public RubyPartitionScanner() {
super();
@@ -42,79 +33,10 @@
}
protected void initialize() {
- IToken string = new Token(RUBY_STRING);
IToken multiLineComment = new Token(RUBY_MULTI_LINE_COMMENT);
- IToken singleLineComment = new Token(RUBY_SINGLE_LINE_COMMENT);
- IToken regexp = new Token(RUBY_REGULAR_EXPRESSION);
- IToken command = new Token(RUBY_COMMAND);
- IToken hereDoc = new Token(RUBY_STRING);
List rules = new ArrayList();
-
- // TODO Fix this to be able to recognize variable substitution inside
- // strings (and therefore have quotes inside them which don't end the
- // partition)
-
- // Strings
- rules.add(new PatternRule("\"", "\"", string, '\\', false, false));
- rules.add(new PatternRule("'", "'", string, '\\', false, false));
-
- // Regular expressions
- // TODO Work with options: 's', 'u', 'e', 'n', 'x', 'm', 'o', 'i'
- rules.add(new SingleLineRule("/", "/", regexp, '\\'));
-
- // Commands
- rules.add(new SingleLineRule("`", "`", command, '\\'));
-
- // Catch all the wacky Percent Syntax (Strings/commands/regexps)
- rules.add(new PercentSyntaxRule());
-
- // Single line comments
- // ?# evaluates to the ascii value of #
- rules.add(new WordPatternRule(new NumberSignDetector(), "?", "#",
- Token.UNDEFINED));
- // ugly hacks to make ?" and ?' recognized as characters
- rules.add(new WordPatternRule(new IWordDetector() {
-
- public boolean isWordPart(char c) {
- return c == '"';
- }
-
- public boolean isWordStart(char c) {
- return c == '?';
- }
-
- }, "?", "\"", Token.UNDEFINED));
- rules.add(new WordPatternRule(new IWordDetector() {
-
- public boolean isWordPart(char c) {
- return c == '\'';
- }
-
- public boolean isWordStart(char c) {
- return c == '?';
- }
-
- }, "?", "'", Token.UNDEFINED));
- rules.add(new WordPatternRule(new IWordDetector() {
-
- public boolean isWordPart(char c) {
- return c == '/';
- }
-
- public boolean isWordStart(char c) {
- return c == '?';
- }
-
- }, "?", "/", Token.UNDEFINED));
-
- rules.add(new EndOfLineRule("#", singleLineComment));
rules.add(new DocumentationCommentRule(multiLineComment));
- rules.add(new HereDocPatternRule(hereDoc));
-
- // FIXME Create Hyrbid of RuleBasedPartitionScanner which allows IRule
- // or IPredicateRule and will only evaluate IPredicateRules if success
- // token matches content type
IRule[] result = new IRule[rules.size()];
rules.toArray(result);
setRules(result);
Copied: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/AbstractRubyTokenScanner.java (from rev 2162, branches/syntax/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/AbstractRubyTokenScanner.java)
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/AbstractRubyTokenScanner.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/AbstractRubyTokenScanner.java 2007-03-14 14:58:09 UTC (rev 2163)
@@ -0,0 +1,296 @@
+package org.rubypeople.rdt.internal.ui.text.ruby;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.jface.resource.StringConverter;
+import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.rules.ITokenScanner;
+import org.eclipse.jface.text.rules.Token;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Display;
+import org.rubypeople.rdt.ui.PreferenceConstants;
+import org.rubypeople.rdt.ui.text.IColorManager;
+import org.rubypeople.rdt.ui.text.IColorManagerExtension;
+
+public abstract class AbstractRubyTokenScanner implements ITokenScanner {
+
+ private String[] fPropertyNamesColor;
+ private String[] fPropertyNamesBgColor;
+ private String[] fPropertyNamesBold;
+ private String[] fPropertyNamesItalic;
+ private String[] fPropertyNamesStrikethrough;
+ private String[] fPropertyNamesUnderline;
+ private IColorManager fColorManager;
+ private IPreferenceStore fPreferenceStore;
+ private boolean fNeedsLazyColorLoading;
+ private Map fTokenMap = new HashMap();
+
+ /**
+ * Creates an abstract Ruby scanner.
+ */
+ public AbstractRubyTokenScanner(IColorManager manager, IPreferenceStore store) {
+ super();
+ fColorManager = manager;
+ fPreferenceStore = store;
+ }
+
+ /**
+ * Returns the preference store.
+ *
+ * @return the preference store.
+ *
+ * @since 3.0
+ */
+ protected IPreferenceStore getPreferenceStore() {
+ return fPreferenceStore;
+ }
+
+ /**
+ * Returns an array of preference keys which define the tokens used in the
+ * rules of this scanner.
+ * <p>
+ * The preference key is used access the color in the preference store and
+ * in the color manager.
+ * </p>
+ * <p>
+ * Preference key +{@link PreferenceConstants#EDITOR_BOLD_SUFFIX}is used
+ * to retrieve whether the token is rendered in bold.
+ * </p>
+ * <p>
+ * Preference key +{@link PreferenceConstants#EDITOR_ITALIC_SUFFIX}is used
+ * to retrieve whether the token is rendered in italic.
+ * </p>
+ */
+ abstract protected String[] getTokenProperties();
+
+ public final void initialize() {
+ fPropertyNamesColor = getTokenProperties();
+ int length = fPropertyNamesColor.length;
+ fPropertyNamesBgColor = new String[length];
+ fPropertyNamesBold = new String[length];
+ fPropertyNamesItalic = new String[length];
+ fPropertyNamesStrikethrough = new String[length];
+ fPropertyNamesUnderline = new String[length];
+
+ for (int i= 0; i < length; i++) {
+ fPropertyNamesBgColor[i]= getBGKey(fPropertyNamesColor[i]);
+ fPropertyNamesBold[i]= getBoldKey(fPropertyNamesColor[i]);
+ fPropertyNamesItalic[i]= getItalicKey(fPropertyNamesColor[i]);
+ fPropertyNamesStrikethrough[i]= getStrikethroughKey(fPropertyNamesColor[i]);
+ fPropertyNamesUnderline[i]= getUnderlineKey(fPropertyNamesColor[i]);
+ }
+
+ fNeedsLazyColorLoading = Display.getCurrent() == null;
+ for (int i = 0; i < length; i++) {
+ if (fNeedsLazyColorLoading)
+ addTokenWithProxyAttribute(fPropertyNamesColor[i], fPropertyNamesBgColor[i], fPropertyNamesBold[i], fPropertyNamesItalic[i], fPropertyNamesStrikethrough[i], fPropertyNamesUnderline[i]);
+ else
+ addToken(fPropertyNamesColor[i], fPropertyNamesBgColor[i], fPropertyNamesBold[i], fPropertyNamesItalic[i], fPropertyNamesStrikethrough[i], fPropertyNamesUnderline[i]);
+ }
+ }
+
+ protected String getBoldKey(String colorKey) {
+ return colorKey + PreferenceConstants.EDITOR_BOLD_SUFFIX;
+ }
+
+ protected String getBGKey(String colorKey) {
+ return colorKey + PreferenceConstants.EDITOR_BG_SUFFIX;
+ }
+
+ protected String getItalicKey(String colorKey) {
+ return colorKey + PreferenceConstants.EDITOR_ITALIC_SUFFIX;
+ }
+
+ protected String getStrikethroughKey(String colorKey) {
+ return colorKey + PreferenceConstants.EDITOR_STRIKETHROUGH_SUFFIX;
+ }
+
+ protected String getUnderlineKey(String colorKey) {
+ return colorKey + PreferenceConstants.EDITOR_UNDERLINE_SUFFIX;
+ }
+
+ private void addTokenWithProxyAttribute(String colorKey, String bgColorKey, String boldKey, String italicKey, String strikethroughKey, String underlineKey) {
+ fTokenMap.put(colorKey, new Token(createTextAttribute(null, null, boldKey, italicKey, strikethroughKey, underlineKey)));
+ }
+
+ private void resolveProxyAttributes() {
+ if (fNeedsLazyColorLoading && Display.getCurrent() != null) {
+ for (int i = 0; i < fPropertyNamesColor.length; i++) {
+ addToken(fPropertyNamesColor[i], fPropertyNamesBgColor[i], fPropertyNamesBold[i], fPropertyNamesItalic[i], fPropertyNamesStrikethrough[i], fPropertyNamesUnderline[i]);
+ }
+ fNeedsLazyColorLoading = false;
+ }
+ }
+
+ private void addToken(String colorKey, String bgColorKey, String boldKey, String italicKey, String strikethroughKey, String underlineKey) {
+ bindColor(colorKey);
+ bindColor(bgColorKey);
+
+ if (!fNeedsLazyColorLoading)
+ fTokenMap.put(colorKey, new Token(createTextAttribute(colorKey, bgColorKey, boldKey, italicKey, strikethroughKey, underlineKey)));
+ else {
+ Token token = ((Token) fTokenMap.get(colorKey));
+ if (token != null) token.setData(createTextAttribute(colorKey, bgColorKey, boldKey, italicKey, strikethroughKey, underlineKey));
+ }
+ }
+
+ private void bindColor(String colorKey) {
+ if (fColorManager != null && colorKey != null && fColorManager.getColor(colorKey) == null) {
+ RGB rgb = PreferenceConverter.getColor(fPreferenceStore, colorKey);
+ if (rgb == PreferenceConverter.COLOR_DEFAULT_DEFAULT) return;
+
+ if (fColorManager instanceof IColorManagerExtension) {
+ IColorManagerExtension ext = (IColorManagerExtension) fColorManager;
+ ext.unbindColor(colorKey);
+ ext.bindColor(colorKey, rgb);
+ }
+ }
+ }
+
+ protected Token getToken(String key) {
+ if (fNeedsLazyColorLoading) resolveProxyAttributes();
+ return (Token) fTokenMap.get(key);
+ }
+
+ /**
+ * Create a text attribute based on the given color, bold and italic
+ * preference keys.
+ *
+ * @param colorKey
+ * the color preference key
+ * @param colorKey
+ * the color preference key
+ * @param boldKey
+ * the bold preference key
+ * @param italicKey
+ * the italic preference key
+ * @param strikethroughKey
+ * the strikethrough preference key
+ * @param underlineKey
+ * the underline preference key
+ * @return the created text attribute
+ * @since 0.9.0
+ */
+ private TextAttribute createTextAttribute(String colorKey, String bgColorKey, String boldKey, String italicKey, String strikethroughKey, String underlineKey) {
+ Color color= null;
+ if (colorKey != null)
+ color= fColorManager.getColor(colorKey);
+
+ Color bgColor= null;
+ if (bgColorKey != null)
+ bgColor= fColorManager.getColor(bgColorKey);
+
+ int style= fPreferenceStore.getBoolean(boldKey) ? SWT.BOLD : SWT.NORMAL;
+ if (fPreferenceStore.getBoolean(italicKey))
+ style |= SWT.ITALIC;
+
+ if (fPreferenceStore.getBoolean(strikethroughKey))
+ style |= TextAttribute.STRIKETHROUGH;
+
+ if (fPreferenceStore.getBoolean(underlineKey))
+ style |= TextAttribute.UNDERLINE;
+
+ return new TextAttribute(color, bgColor, style);
+ }
+
+ public boolean affectsBehavior(PropertyChangeEvent event) {
+ return indexOf(event.getProperty()) >= 0;
+ }
+
+ public void adaptToPreferenceChange(PropertyChangeEvent event) {
+ // New
+ String p = event.getProperty();
+ int index = indexOf(p);
+ Token token = getToken(fPropertyNamesColor[index]);
+ if (fPropertyNamesColor[index].equals(p))
+ adaptToColorChange(token, event);
+ if (fPropertyNamesBgColor[index].equals(p))
+ adaptToBgColorChange(token, event);
+ else if (fPropertyNamesBold[index].equals(p))
+ adaptToStyleChange(token, event, SWT.BOLD);
+ else if (fPropertyNamesItalic[index].equals(p))
+ adaptToStyleChange(token, event, SWT.ITALIC);
+ else if (fPropertyNamesStrikethrough[index].equals(p))
+ adaptToStyleChange(token, event, TextAttribute.STRIKETHROUGH);
+ else if (fPropertyNamesUnderline[index].equals(p))
+ adaptToStyleChange(token, event, TextAttribute.UNDERLINE);
+ }
+
+ private void adaptToStyleChange(Token token, PropertyChangeEvent event, int styleAttribute) {
+ boolean eventValue = false;
+ Object value = event.getNewValue();
+ if (value instanceof Boolean)
+ eventValue = ((Boolean) value).booleanValue();
+ else if (IPreferenceStore.TRUE.equals(value)) eventValue = true;
+
+ Object data = token.getData();
+ if (data instanceof TextAttribute) {
+ TextAttribute oldAttr = (TextAttribute) data;
+ boolean activeValue = (oldAttr.getStyle() & styleAttribute) == styleAttribute;
+ if (activeValue != eventValue) token.setData(new TextAttribute(oldAttr.getForeground(), oldAttr.getBackground(), eventValue ? oldAttr.getStyle() | styleAttribute : oldAttr.getStyle() & ~styleAttribute));
+ }
+ }
+
+ private void adaptToColorChange(Token token, PropertyChangeEvent event) {
+ adaptToSomeColorChange(token, event, true);
+ }
+
+ private void adaptToBgColorChange(Token token, PropertyChangeEvent event) {
+ adaptToSomeColorChange(token, event, false);
+ }
+
+ private void adaptToSomeColorChange(Token token, PropertyChangeEvent event, boolean isForeground) {
+ RGB rgb = null;
+
+ Object value = event.getNewValue();
+ if (value instanceof RGB)
+ rgb = (RGB) value;
+ else if (value instanceof String) rgb = StringConverter.asRGB((String) value);
+
+ if (rgb != null) {
+
+ String property = event.getProperty();
+ Color color = fColorManager.getColor(property);
+
+ if ((color == null || !rgb.equals(color.getRGB())) && fColorManager instanceof IColorManagerExtension) {
+ IColorManagerExtension ext = (IColorManagerExtension) fColorManager;
+
+ ext.unbindColor(property);
+ ext.bindColor(property, rgb);
+
+ color = fColorManager.getColor(property);
+ }
+
+ Object data = token.getData();
+ if (data instanceof TextAttribute) {
+ TextAttribute oldAttr = (TextAttribute) data;
+ Color foreGround;
+ Color backGround;
+ if (!isForeground) {
+ foreGround = oldAttr.getForeground();
+ backGround = color;
+ } else {
+ foreGround = color;
+ backGround = oldAttr.getBackground();
+ }
+ token.setData(new TextAttribute(foreGround, backGround, oldAttr.getStyle()));
+ }
+ }
+ }
+
+ private int indexOf(String property) {
+ if (property != null) {
+ int length = fPropertyNamesColor.length;
+ for (int i = 0; i < length; i++) {
+ if (property.equals(fPropertyNamesColor[i]) || property.equals(fPropertyNamesBgColor[i]) || property.equals(fPropertyNamesBold[i]) || property.equals(fPropertyNamesItalic[i]) || property.equals(fPropertyNamesStrikethrough[i]) || property.equals(fPropertyNamesUnderline[i])) return i;
+ }
+ }
+ return -1;
+ }
+}
Deleted: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/CharacterRule.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/CharacterRule.java 2007-03-14 13:54:14 UTC (rev 2162)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/CharacterRule.java 2007-03-14 14:58:09 UTC (rev 2163)
@@ -1,20 +0,0 @@
-package org.rubypeople.rdt.internal.ui.text.ruby;
-
-import org.eclipse.jface.text.rules.IToken;
-
-public class CharacterRule extends SingleCharacterPrefixRule {
-
- private static final char PREFIX = '?';
- private static final int WORD_LENGTH = 2;
-
- /**
- * Creates a rule which will return the specified token when a character
- * sequence is detected.
- *
- * @param token
- * the token to be returned
- */
- public CharacterRule(IToken token) {
- super(PREFIX, token, WORD_LENGTH, 2);
- }
-}
Deleted: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyCodeScanner.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyCodeScanner.java 2007-03-14 13:54:14 UTC (rev 2162)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyCodeScanner.java 2007-03-14 14:58:09 UTC (rev 2163)
@@ -1,81 +0,0 @@
-package org.rubypeople.rdt.internal.ui.text.ruby;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.text.rules.IToken;
-import org.eclipse.jface.text.rules.IWordDetector;
-import org.eclipse.jface.text.rules.WordRule;
-import org.rubypeople.rdt.internal.ui.text.IRubyColorConstants;
-import org.rubypeople.rdt.internal.ui.text.RubyWordDetector;
-import org.rubypeople.rdt.ui.text.IColorManager;
-import org.rubypeople.rdt.ui.text.RubyTextTools;
-
-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 RubyNumberRule(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
Deleted: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyNumberRule.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyNumberRule.java 2007-03-14 13:54:14 UTC (rev 2162)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyNumberRule.java 2007-03-14 14:58:09 UTC (rev 2163)
@@ -1,48 +0,0 @@
-package org.rubypeople.rdt.internal.ui.text.ruby;
-
-import org.eclipse.jface.text.rules.ICharacterScanner;
-import org.eclipse.jface.text.rules.IToken;
-import org.eclipse.jface.text.rules.NumberRule;
-import org.eclipse.jface.text.rules.Token;
-
-public class RubyNumberRule extends NumberRule {
-
- public RubyNumberRule(IToken token){
- super(token);
- }
-
- /*
- * @see IRule#evaluate(ICharacterScanner)
- */
- public IToken evaluate(ICharacterScanner scanner) {
- int c= scanner.read();
- if (Character.isDigit((char)c)) {
- scanner.unread();
- scanner.unread();
- c = scanner.read();
- if ( Character.isLetter((char)c) || ((char)c) == '_'){
- do {
- c= scanner.read();
- } while (Character.isDigit((char) c));
- scanner.unread();
- return Token.UNDEFINED;
- }
- c = scanner.read();
- if (fColumn == UNDEFINED || (fColumn == scanner.getColumn() - 1)) {
- do {
- c= scanner.read();
- } while (Character.isDigit((char) c));
- if ( Character.isLetter((char)c) || ((char)c) == '_' ){
- scanner.unread();
- return Token.UNDEFINED;
- }
- scanner.unread();
- return fToken;
- }
- }
-
- scanner.unread();
- return Token.UNDEFINED;
- }
-
-}
Copied: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyTokenScanner.java (from rev 2162, branches/syntax/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyTokenScanner.java)
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyTokenScanner.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyTokenScanner.java 2007-03-14 14:58:09 UTC (rev 2163)
@@ -0,0 +1,209 @@
+package org.rubypeople.rdt.internal.ui.text.ruby;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.List;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.Token;
+import org.jruby.ast.CommentNode;
+import org.jruby.lexer.yacc.LexState;
+import org.jruby.lexer.yacc.LexerSource;
+import org.jruby.lexer.yacc.RubyYaccLexer;
+import org.jruby.lexer.yacc.SyntaxException;
+import org.jruby.parser.ParserSupport;
+import org.jruby.parser.RubyParserConfiguration;
+import org.jruby.parser.RubyParserResult;
+import org.jruby.parser.Tokens;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
+import org.rubypeople.rdt.internal.ui.text.IRubyColorConstants;
+import org.rubypeople.rdt.ui.text.IColorManager;
+
+public class RubyTokenScanner extends AbstractRubyTokenScanner {
+
+ 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, IRubyColorConstants.RUBY_STRING,
+ IRubyColorConstants.RUBY_REGEXP, IRubyColorConstants.RUBY_ERROR, IRubyColorConstants.RUBY_SINGLE_LINE_COMMENT
+ // TODO Add Ability to set colors for return and operators
+ // IRubyColorConstants.RUBY_METHOD_NAME,
+ // IRubyColorConstants.RUBY_KEYWORD_RETURN,
+ // IRubyColorConstants.RUBY_OPERATOR
+ };
+
+ private RubyYaccLexer lexer;
+ private LexerSource lexerSource;
+ private ParserSupport parserSupport;
+ private int tokenLength;
+ private int oldOffset;
+ private boolean isInRegexp;
+ private boolean isInString;
+ private RubyParserResult result;
+ private int origOffset;
+ private int origLength;
+ private String contents;
+
+ private IToken fSavedToken = null;
+ private int fSavedLength = -1;
+ private int fSavedOffset = -1;
+
+ private boolean lastWasComment;
+
+ public RubyTokenScanner(IColorManager manager, IPreferenceStore store) {
+ super(manager, store);
+ lexer = new RubyYaccLexer();
+ parserSupport = new ParserSupport();
+ parserSupport.setConfiguration(new RubyParserConfiguration());
+ result = new RubyParserResult();
+ parserSupport.setResult(result);
+ lexer.setParserSupport(parserSupport);
+ initialize();
+ }
+
+ public int getTokenLength() {
+ if (lastWasComment) {
+ lastWasComment = false;
+ return tokenLength;
+ }
+ if (fSavedLength != -1) {
+ int length = fSavedLength;
+ fSavedLength = -1;
+ return length;
+ }
+ return tokenLength;
+ }
+
+ public int getTokenOffset() {
+ if (lastWasComment) {
+ return oldOffset;
+ }
+ if (fSavedOffset != -1) {
+ int offset = fSavedOffset;
+ fSavedOffset = -1;
+ return offset;
+ }
+ return oldOffset;
+ }
+
+ public IToken nextToken() {
+ if (fSavedToken != null) {
+ IToken returnToken = fSavedToken;
+ fSavedToken = null;
+ return returnToken;
+ }
+ oldOffset = getOffset();
+ tokenLength = 0;
+ IToken returnValue = getToken(IRubyColorConstants.RUBY_DEFAULT);
+ boolean isEOF = false;
+ try {
+ isEOF = !lexer.advance();
+ if (isEOF) {
+ returnValue = Token.EOF;
+ } else {
+ returnValue = token(lexer.token());
+ }
+ List comments = result.getCommentNodes();
+ if (comments != null && !comments.isEmpty()) {
+ CommentNode comment = (CommentNode) comments.remove(comments.size() - 1); // Grab last comment
+ tokenLength = comment.getContent().length() + 1;
+ fSavedToken = returnValue;
+ fSavedOffset = comment.getPosition().getEndOffset();
+ fSavedLength = lexerSource.getOffset() - fSavedOffset;
+ lastWasComment = true;
+ return getToken(IRubyColorConstants.RUBY_SINGLE_LINE_COMMENT);
+ }
+ } catch (SyntaxException se) {
+ if (lexerSource.getOffset() - origLength == 0)
+ return Token.EOF; // return eof if we hit a problem found at
+ // end of parsing
+ else
+ tokenLength = getOffset() - oldOffset;
+ return getToken(IRubyColorConstants.RUBY_ERROR);
+ } catch (IOException e) {
+ RubyPlugin.log(e);
+ }
+ if (!isEOF)
+ tokenLength = getOffset() - oldOffset;
+ return returnValue;
+ }
+
+ private int getOffset() {
+ return lexerSource.getOffset() + origOffset;
+ }
+
+ @Override
+ protected Token getToken(String key) {
+ if (isInRegexp)
+ return super.getToken(IRubyColorConstants.RUBY_REGEXP);
+ if (isInString)
+ return super.getToken(IRubyColorConstants.RUBY_STRING);
+ return super.getToken(key);
+ }
+
+ private IToken token(int i) {
+ if (i >= 257 && i <= 303)
+ return getToken(IRubyColorConstants.RUBY_KEYWORD);
+ switch (i) {
+ case Tokens.tSYMBEG:
+ return getToken(IRubyColorConstants.RUBY_SYMBOL);
+ case Tokens.tGVAR:
+ return getToken(IRubyColorConstants.RUBY_GLOBAL);
+ case Tokens.tIVAR:
+ case Tokens.tCVAR: // FIXME Allow for unique coloring of class variables...
+ return getToken(IRubyColorConstants.RUBY_INSTANCE_VARIABLE);
+ case Tokens.tFLOAT:
+ case Tokens.tINTEGER:
+ // A character is marked as an integer, lets check for that special case...
+ if ((((oldOffset - origOffset) + 1) < contents.length()) && (contents.charAt((oldOffset - origOffset) + 1) == '?'))
+ return getToken(IRubyColorConstants.RUBY_CHARACTER);
+ return getToken(IRubyColorConstants.RUBY_FIXNUM);
+ case Tokens.tSTRING_CONTENT:
+ return getToken(IRubyColorConstants.RUBY_STRING);
+ case Tokens.tSTRING_BEG:
+ isInString = true;
+ return getToken(IRubyColorConstants.RUBY_STRING);
+ case Tokens.tSTRING_END:
+ isInString = false;
+ return getToken(IRubyColorConstants.RUBY_STRING);
+ case Tokens.tREGEXP_BEG:
+ isInRegexp = true;
+ return getToken(IRubyColorConstants.RUBY_REGEXP);
+ case Tokens.tREGEXP_END:
+ isInRegexp = false;
+ return getToken(IRubyColorConstants.RUBY_REGEXP);
+ default:
+ return getToken(IRubyColorConstants.RUBY_DEFAULT);
+ }
+ }
+
+ public void setRange(IDocument document, int offset, int length) {
+ lexer.reset();
+ lexer.setState(LexState.EXPR_BEG);
+ parserSupport.initTopLocalVariables();
+ if (offset == 0) {
+ isInRegexp = false;
+ isInString = false;
+ }
+ try {
+ contents = document.get(offset, length);
+ lexerSource = new LexerSource("filename", new StringReader(contents));
+ lexer.setSource(lexerSource);
+ } catch (BadLocationException e) {
+ RubyPlugin.log(e);
+ }
+ origOffset = offset;
+ origLength = length;
+ }
+
+ /*
+ * @see AbstractRubyScanner#getTokenProperties()
+ */
+ protected String[] getTokenProperties() {
+ return fgTokenProperties;
+ }
+}
Deleted: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/SingleCharacterPrefixRule.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/SingleCharacterPrefixRule.java 2007-03-14 13:54:14 UTC (rev 2162)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/SingleCharacterPrefixRule.java 2007-03-14 14:58:09 UTC (rev 2163)
@@ -1,94 +0,0 @@
-package org.rubypeople.rdt.internal.ui.text.ruby;
-
-import org.eclipse.jface.text.Assert;
-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.Token;
-
-/**
- * This is a base class for recognizing tokens where a single character prefix
- * can determine if the word is of a particular token type. The token ends at
- * EOF, EOL or whitespace.
- *
- * @author cawilliams
- *
- */
-public class SingleCharacterPrefixRule implements IRule {
-
- protected char fPrefix;
- protected IToken fToken;
- protected int fMinLength;
- protected int fMaxLength;
- private StringBuffer fWord;
-
- public SingleCharacterPrefixRule(char prefix, IToken token, int minLength, int maxLength) {
- fPrefix = prefix;
- Assert.isNotNull(token);
- fToken = token;
- Assert.isLegal(minLength >= 1);
- fMinLength = minLength;
- Assert.isLegal(maxLength >= 1);
- fMaxLength = maxLength;
- }
-
- public IToken evaluate(ICharacterScanner scanner) {
- int c = scanner.read();
- int length = 1;
- fWord = new StringBuffer();
- if (((char) c) == fPrefix) {
- fWord.append(((char) c));
- // Now read until we hit EOF, EOL or whitespace
- while (true) {
- c = scanner.read();
- if (!isValidCharacter(c, length)) {
- if (!isValidEndCharacter(c, length))
- scanner.unread();
- else {
- fWord.append(((char) c));
- length++;
- }
- if (!lengthInRange(length) || !wordValid(fWord.toString())) return Token.UNDEFINED;
- return fToken;
- }
- fWord.append(((char) c));
- length++;
- }
- }
-
- scanner.unread();
- return Token.UNDEFINED;
- }
-
- protected boolean wordValid(String word) {
- return true;
- }
-
- protected boolean isValidEndCharacter(int c, int length) {
- return false;
- }
-
- /**
- * Determine if the current character is valid for the rule. Return false if
- * the character is not a part of the token. This is not applied to the
- * single character prefix.
- *
- * @param c
- * @param index
- * @return
- */
- protected boolean isValidCharacter(int c, int index) {
- return c != ICharacterScanner.EOF && !Character.isWhitespace((char) c);
- }
-
- /**
- * Determine if the length of the token is valid.
- *
- * @param length
- * @return
- */
- protected boolean lengthInRange(int length) {
- return (length >= fMinLength) && (length <= fMaxLength);
- }
-
-}
Deleted: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/SingleTokenRubyCodeScanner.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/SingleTokenRubyCodeScanner.java 2007-03-14 13:54:14 UTC (rev 2162)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/SingleTokenRubyCodeScanner.java 2007-03-14 14:58:09 UTC (rev 2163)
@@ -1,33 +0,0 @@
-package org.rubypeople.rdt.internal.ui.text.ruby;
-
-import java.util.List;
-
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.rubypeople.rdt.ui.text.IColorManager;
-
-public class SingleTokenRubyCodeScanner extends AbstractRubyScanner {
-
- private String[] fProperty;
-
- public SingleTokenRubyCodeScanner(IColorManager manager, IPreferenceStore store, String property) {
- super(manager, store);
- fProperty = new String[] { property};
- initialize();
- }
-
- /*
- * @see AbstractRubyScanner#getTokenProperties()
- */
- protected String[] getTokenProperties() {
- return fProperty;
- }
-
- /*
- * @see AbstractRubyScanner#createRules()
- */
- protected List createRules() {
- setDefaultReturnToken(getToken(fProperty[0]));
- return null;
- }
-
-}
Deleted: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/SymbolRule.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/SymbolRule.java 2007-03-14 13:54:14 UTC (rev 2162)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/SymbolRule.java 2007-03-14 14:58:09 UTC (rev 2163)
@@ -1,36 +0,0 @@
-package org.rubypeople.rdt.internal.ui.text.ruby;
-
-import org.eclipse.jface.text.rules.IToken;
-
-/**
- * A rule which will return the given Token for Ruby symbols.
- *
- * @author cawilliams
- *
- */
-public class SymbolRule extends SingleCharacterPrefixRule {
-
- private static final char PREFIX = ':';
-
- public SymbolRule(IToken token) {
- super(PREFIX, token, 2, Integer.MAX_VALUE);
- }
-
- protected boolean isValidCharacter(int c, int index) {
- if (!super.isValidCharacter(c, index))
- return false;
-
- // Symbols can only contain word characters (a-zA-Z0-9_)
- // TODO which special method names contain brackets?
- return Character.isLetterOrDigit((char) c) || c == '_';
- }
-
- protected boolean isValidEndCharacter(int c, int length) {
- return c == '?' || c == '!';
- }
-
- protected boolean wordValid(String word) {
- return !Character.isDigit(word.charAt(1));
- }
-
-}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java 2007-03-14 13:54:14 UTC (rev 2162)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java 2007-03-14 14:58:09 UTC (rev 2163)
@@ -57,11 +57,11 @@
import org.rubypeople.rdt.internal.ui.text.comment.RubyCommentAutoIndentStrategy;
import org.rubypeople.rdt.internal.ui.text.hyperlinks.RubyHyperLinkDetector;
import org.rubypeople.rdt.internal.ui.text.ruby.AbstractRubyScanner;
-import org.rubypeople.rdt.internal.ui.text.ruby.RubyCodeScanner;
+import org.rubypeople.rdt.internal.ui.text.ruby.AbstractRubyTokenScanner;
import org.rubypeople.rdt.internal.ui.text.ruby.RubyCompletionProcessor;
import org.rubypeople.rdt.internal.ui.text.ruby.RubyFormattingStrategy;
import org.rubypeople.rdt.internal.ui.text.ruby.RubyReconcilingStrategy;
-import org.rubypeople.rdt.internal.ui.text.ruby.SingleTokenRubyCodeScanner;
+import org.rubypeople.rdt.internal.ui.text.ruby.RubyTokenScanner;
import org.rubypeople.rdt.internal.ui.text.ruby.hover.RubyCodeTextHover;
public class RubySourceViewerConfiguration extends
@@ -85,11 +85,9 @@
*/
private IColorManager fColorManager;
- protected AbstractRubyScanner fCodeScanner;
+ protected AbstractRubyTokenScanner fCodeScanner;
- protected AbstractRubyScanner fMultilineCommentScanner, fSinglelineCommentScanner, fStringScanner;
- private SingleTokenRubyCodeScanner fRegexpScanner;
- private SingleTokenRubyCodeScanner fCommandScanner;
+ protected AbstractRubyScanner fMultilineCommentScanner;
private RubyDoubleClickSelector fRubyDoubleClickSelector;
private RubyCompletionProcessor fRubyCp;
@@ -180,11 +178,7 @@
*/
public boolean affectsTextPresentation(PropertyChangeEvent event) {
return fCodeScanner.affectsBehavior(event)
- || fMultilineCommentScanner.affectsBehavior(event)
- || fSinglelineCommentScanner.affectsBehavior(event)
- || fStringScanner.affectsBehavior(event)
- || fRegexpScanner.affectsBehavior(event)
- || fCommandScanner.affectsBehavior(event);
+ || fMultilineCommentScanner.affectsBehavior(event);
}
/**
@@ -207,14 +201,6 @@
fCodeScanner.adaptToPreferenceChange(event);
if (fMultilineCommentScanner.affectsBehavior(event))
fMultilineCommentScanner.adaptToPreferenceChange(event);
- if (fSinglelineCommentScanner.affectsBehavior(event))
- fSinglelineCommentScanner.adaptToPreferenceChange(event);
- if (fStringScanner.affectsBehavior(event))
- fStringScanner.adaptToPreferenceChange(event);
- if (fRegexpScanner.affectsBehavior(event))
- fRegexpScanner.adaptToPreferenceChange(event);
- if (fCommandScanner.affectsBehavior(event))
- fCommandScanner.adaptToPreferenceChange(event);
}
/**
@@ -247,17 +233,9 @@
*/
private void initializeScanners() {
Assert.isTrue(isNewSetup());
- fCodeScanner = new RubyCodeScanner(getColorManager(), fPreferenceStore);
+ fCodeScanner = new RubyTokenScanner(getColorManager(), fPreferenceStore);
fMultilineCommentScanner = new RubyCommentScanner(getColorManager(),
fPreferenceStore, IRubyColorConstants.RUBY_MULTI_LINE_COMMENT);
- fSinglelineCommentScanner = new RubyCommentScanner(getColorManager(),
- fPreferenceStore, IRubyColorConstants.RUBY_SINGLE_LINE_COMMENT);
- fStringScanner = new SingleTokenRubyCodeScanner(getColorManager(),
- fPreferenceStore, IRubyColorConstants.RUBY_STRING);
- fRegexpScanner = new SingleTokenRubyCodeScanner(getColorManager(),
- fPreferenceStore, IRubyColorConstants.RUBY_REGEXP);
- fCommandScanner = new SingleTokenRubyCodeScanner(getColorManager(),
- fPreferenceStore, IRubyColorConstants.RUBY_COMMAND);
}
/**
@@ -288,37 +266,13 @@
reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
- dr = new DefaultDamagerRepairer(getSinglelineCommentScanner());
- reconciler
- .setDamager(dr, RubyPartitionScanner.RUBY_SINGLE_LINE_COMMENT);
- reconciler.setRepairer(dr,
- RubyPartitionScanner.RUBY_SINGLE_LINE_COMMENT);
-
dr = new DefaultDamagerRepairer(getMultilineCommentScanner());
reconciler.setDamager(dr, RubyPartitionScanner.RUBY_MULTI_LINE_COMMENT);
reconciler
.setRepairer(dr, RubyPartitionScanner.RUBY_MULTI_LINE_COMMENT);
-
- dr = new DefaultDamagerRepairer(getStringScanner());
- reconciler.setDamager(dr, RubyPartitionScanner.RUBY_STRING);
- reconciler.setRepairer(dr, RubyPartitionScanner.RUBY_STRING);
-
- dr = new DefaultDamagerRepairer(getRegexpScanner());
- reconciler.setDamager(dr, RubyPartitionScanner.RUBY_REGULAR_EXPRESSION);
- reconciler
- .setRepairer(dr, RubyPartitionScanner.RUBY_REGULAR_EXPRESSION);
-
- dr = new DefaultDamagerRepairer(getCommandScanner());
- reconciler.setDamager(dr, RubyPartitionScanner.RUBY_COMMAND);
- reconciler.setRepairer(dr, RubyPartitionScanner.RUBY_COMMAND);
-
return reconciler;
}
- private ITokenScanner getCommandScanner() {
- return fCommandScanner;
- }
-
protected ITokenScanner getCodeScanner() {
return fCodeScanner;
}
@@ -327,23 +281,9 @@
return fMultilineCommentScanner;
}
- protected ITokenScanner getSinglelineCommentScanner() {
- return fSinglelineCommentScanner;
- }
-
- protected ITokenScanner getStringScanner() {
- return fStringScanner;
- }
-
- protected ITokenScanner getRegexpScanner() {
- return fRegexpScanner;
- }
-
public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
return new String[] { IDocument.DEFAULT_CONTENT_TYPE,
- RubyPartitionScanner.RUBY_MULTI_LINE_COMMENT,
- RubyPartitionScanner.RUBY_STRING,
- RubyPartitionScanner.RUBY_SINGLE_LINE_COMMENT };
+ RubyPartitionScanner.RUBY_MULTI_LINE_COMMENT };
}
/*
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubyTextTools.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubyTextTools.java 2007-03-14 13:54:14 UTC (rev 2162)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubyTextTools.java 2007-03-14 14:58:09 UTC (rev 2163)
@@ -21,8 +21,8 @@
import org.rubypeople.rdt.internal.ui.text.RubyCommentScanner;
import org.rubypeople.rdt.internal.ui.text.RubyPartitionScanner;
import org.rubypeople.rdt.internal.ui.text.ruby.AbstractRubyScanner;
-import org.rubypeople.rdt.internal.ui.text.ruby.RubyCodeScanner;
-import org.rubypeople.rdt.internal.ui.text.ruby.SingleTokenRubyCodeScanner;
+import org.rubypeople.rdt.internal.ui.text.ruby.AbstractRubyTokenScanner;
+import org.rubypeople.rdt.internal.ui.text.ruby.RubyTokenScanner;
public class RubyTextTools {
@@ -45,15 +45,12 @@
protected static String[] keywords;
protected RubyColorManager fColorManager;
protected RubyPartitionScanner partitionScanner;
- protected AbstractRubyScanner fCodeScanner;
- protected AbstractRubyScanner fMultilineCommentScanner, fSinglelineCommentScanner,
- stringScanner;
+ protected AbstractRubyTokenScanner fCodeScanner;
+ protected AbstractRubyScanner fMultilineCommentScanner, fSinglelineCommentScanner;
private IPreferenceStore fPreferenceStore;
private Preferences fCorePreferenceStore;
/** The preference change listener */
private PreferenceListener fPreferenceListener = new PreferenceListener();
- private SingleTokenRubyCodeScanner fRegexpScanner;
- private SingleTokenRubyCodeScanner fCommandScanner;
/**
* Creates a new Ruby text tools collection.
@@ -108,17 +105,11 @@
fColorManager = new RubyColorManager(autoDisposeOnDisplayDispose);
partitionScanner = new RubyPartitionScanner();
- fCodeScanner = new RubyCodeScanner(fColorManager, store);
+ fCodeScanner = new RubyTokenScanner(fColorManager, store);
fMultilineCommentScanner = new RubyCommentScanner(fColorManager, store, coreStore,
IRubyColorConstants.RUBY_MULTI_LINE_COMMENT);
fSinglelineCommentScanner = new RubyCommentScanner(fColorManager, store, coreStore,
IRubyColorConstants.RUBY_SINGLE_LINE_COMMENT);
- stringScanner = new SingleTokenRubyCodeScanner(fColorManager, store,
- IRubyColorConstants.RUBY_STRING);
- fRegexpScanner = new SingleTokenRubyCodeScanner(fColorManager, store,
- IRubyColorConstants.RUBY_REGEXP);
- fCommandScanner = new SingleTokenRubyCodeScanner(fColorManager, store,
- IRubyColorConstants.RUBY_COMMAND);
fPreferenceStore = store;
fPreferenceStore.addPropertyChangeListener(fPreferenceListener);
@@ -142,10 +133,7 @@
if (fMultilineCommentScanner.affectsBehavior(event))
fMultilineCommentScanner.adaptToPreferenceChange(event);
if (fSinglelineCommentScanner.affectsBehavior(event))
- fSinglelineCommentScanner.adaptToPreferenceChange(event);
- if (stringScanner.affectsBehavior(event)) stringScanner.adaptToPreferenceChange(event);
- if (fRegexpScanner.affectsBehavior(event)) fRegexpScanner.adaptToPreferenceChange(event);
- if (fCommandScanner.affectsBehavior(event)) fCommandScanner.adaptToPreferenceChange(event);
+ fSinglelineCommentScanner.adaptToPreferenceChange(event);
}
public IDocumentPartitioner createDocumentPartitioner() {
@@ -161,7 +149,7 @@
* @deprecated As of 0.8.0, replaced by
* {@link RubySourceViewerConfiguration#getCodeScanner()}
*/
- public AbstractRubyScanner getCodeScanner() {
+ public AbstractRubyTokenScanner getCodeScanner() {
return fCodeScanner;
}
@@ -181,14 +169,6 @@
return fSinglelineCommentScanner;
}
- /**
- * @deprecated As of 0.8.0, replaced by
- * {@link RubySourceViewerConfiguration#getStringScanner()}
- */
- public ITokenScanner getStringScanner() {
- return stringScanner;
- }
-
public IPreferenceStore getPreferenceStore() {
return RubyPlugin.getDefault().getPreferenceStore();
}
@@ -212,9 +192,7 @@
public boolean affectsTextPresentation(PropertyChangeEvent event) {
return fCodeScanner.affectsBehavior(event)
|| fMultilineCommentScanner.affectsBehavior(event)
- || fSinglelineCommentScanner.affectsBehavior(event)
- || stringScanner.affectsBehavior(event) || fRegexpScanner.affectsBehavior(event)
- || fCommandScanner.affectsBehavior(event);
+ || fSinglelineCommentScanner.affectsBehavior(event);
}
/**
@@ -246,9 +224,6 @@
fCodeScanner = null;
fMultilineCommentScanner = null;
fSinglelineCommentScanner = null;
- stringScanner = null;
- fRegexpScanner = null;
- fCommandScanner = null;
// fJavaDocScanner= null;
partitionScanner = null;
@@ -271,22 +246,6 @@
}
/**
- * @deprecated As of 0.8.0, replaced by
- * {@link RubySourceViewerConfiguration#getRegexpScanner()}
- */
- public ITokenScanner getRegexpScanner() {
- return fRegexpScanner;
- }
-
- /**
- * @deprecated As of 0.8.0, replaced by
- * {@link RubySourceViewerConfiguration#getCommandScanner()}
- */
- public ITokenScanner getCommandScanner() {
- return fCommandScanner;
- }
-
- /**
* Returns the color manager which is used to manage any Ruby-specific
* colors needed for such things like syntax highlighting.
* <p>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|