Permalink
Browse files

Cleaned up the code. Known bugs: highhlight types in the middle of wo…

…rds (e.g. TestObject), etc.
  • Loading branch information...
1 parent 1bc6aac commit cc6f5e76dc204eb927cb929fd8e550f98012c4c8 @fasterthanlime committed Jul 8, 2009
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -13,8 +13,7 @@
public class OocConfiguration extends SourceViewerConfiguration {
private DoubleClickStrategy doubleClickStrategy;
- private OocTagScanner tagScanner;
- private OocScanner scanner;
+ private Scanner scanner;
private ColorManager colorManager;
public OocConfiguration(ColorManager colorManager) {
@@ -25,9 +24,10 @@ public OocConfiguration(ColorManager colorManager) {
public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
return new String[] {
IDocument.DEFAULT_CONTENT_TYPE,
- PartitionScanner.COMMENT,
- PartitionScanner.XML_TAG,
- PartitionScanner.KEYWORD,
+ Scanner.KEYWORD,
+ Scanner.STRING,
+ Scanner.COMMENT,
+ Scanner.TYPE,
};
}
@@ -40,62 +40,52 @@ public ITextDoubleClickStrategy getDoubleClickStrategy(
return doubleClickStrategy;
}
- protected OocScanner getOocScanner() {
+ protected Scanner getScanner() {
if (scanner == null) {
- scanner = new OocScanner(colorManager);
+ scanner = new Scanner();
scanner.setDefaultReturnToken(
new Token(
new TextAttribute(
colorManager.getColor(ColorConstants.DEFAULT))));
}
return scanner;
}
- protected OocTagScanner getOocTagScanner() {
- if (tagScanner == null) {
- tagScanner = new OocTagScanner(colorManager);
- tagScanner.setDefaultReturnToken(
- new Token(
- new TextAttribute(
- colorManager.getColor(ColorConstants.TAG))));
- }
- return tagScanner;
- }
@Override
public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
PresentationReconciler reconciler = new PresentationReconciler();
- DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getOocScanner());
+ DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getScanner());
reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
NonRuleBasedDamagerRepairer ndr =
new NonRuleBasedDamagerRepairer(
new TextAttribute(
colorManager.getColor(ColorConstants.COMMENT)));
- reconciler.setDamager(ndr, PartitionScanner.COMMENT);
- reconciler.setRepairer(ndr, PartitionScanner.COMMENT);
+ reconciler.setDamager(ndr, Scanner.COMMENT);
+ reconciler.setRepairer(ndr, Scanner.COMMENT);
ndr =
new NonRuleBasedDamagerRepairer(
new TextAttribute(
colorManager.getColor(ColorConstants.KEYWORD), null, SWT.BOLD));
- reconciler.setDamager(ndr, PartitionScanner.KEYWORD);
- reconciler.setRepairer(ndr, PartitionScanner.KEYWORD);
+ reconciler.setDamager(ndr, Scanner.KEYWORD);
+ reconciler.setRepairer(ndr, Scanner.KEYWORD);
ndr =
new NonRuleBasedDamagerRepairer(
new TextAttribute(
colorManager.getColor(ColorConstants.STRING)));
- reconciler.setDamager(ndr, PartitionScanner.STRING);
- reconciler.setRepairer(ndr, PartitionScanner.STRING);
+ reconciler.setDamager(ndr, Scanner.STRING);
+ reconciler.setRepairer(ndr, Scanner.STRING);
ndr =
new NonRuleBasedDamagerRepairer(
new TextAttribute(
colorManager.getColor(ColorConstants.TYPE), null, SWT.BOLD));
- reconciler.setDamager(ndr, PartitionScanner.TYPE);
- reconciler.setRepairer(ndr, PartitionScanner.TYPE);
+ reconciler.setDamager(ndr, Scanner.TYPE);
+ reconciler.setRepairer(ndr, Scanner.TYPE);
return reconciler;
}
@@ -15,12 +15,12 @@ protected IDocument createDocument(Object element) throws CoreException {
if (document != null) {
IDocumentPartitioner partitioner =
new FastPartitioner(
- new PartitionScanner(),
+ new Scanner(),
new String[] {
- PartitionScanner.KEYWORD,
- PartitionScanner.STRING,
- PartitionScanner.COMMENT,
- PartitionScanner.XML_TAG,
+ Scanner.KEYWORD,
+ Scanner.STRING,
+ Scanner.COMMENT,
+ Scanner.TYPE,
});
partitioner.connect(document);
document.setDocumentPartitioner(partitioner);
@@ -8,9 +8,10 @@
import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;
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;
-public class PartitionScanner extends RuleBasedPartitionScanner {
+public class Scanner extends RuleBasedPartitionScanner {
private final static String[] KEYWORDS = new String[] {
"class", "cover", "func", "abstract",
@@ -19,7 +20,7 @@
"continue", "fallthrough", "implement",
"override", "if", "else", "for", "while",
"do", "switch", "case", "version",
- "return",
+ "return", "ctype", "typedef",
};
private final static String[] TYPES = new String[] {
@@ -29,37 +30,34 @@
};
public final static String KEYWORD = "__keyword";
- public final static String TYPE = "__builtin_type";
+ public final static String TYPE = "__type";
public final static String COMMENT = "__comment";
- public final static String STRING = "__string_literal";
- public final static String XML_TAG = "__xml_tag";
+ public final static String STRING = "__string";
- public PartitionScanner() {
+ public Scanner() {
IToken comment = new Token(COMMENT);
IToken stringLiteral = new Token(STRING);
- //IToken tag = new Token(XML_TAG);
IToken keyword = new Token(KEYWORD);
- WordPredicateRule keywordRule = new WordPredicateRule(keyword);
+ WordPredicateRule wordRule = new WordPredicateRule(keyword);
for(String kw: KEYWORDS) {
- keywordRule.addWord(kw, keyword);
+ wordRule.addWord(kw, keyword);
}
IToken type = new Token(TYPE);
- WordPredicateRule typeRule = new WordPredicateRule(type);
for(String ty: TYPES) {
- typeRule.addWord(ty, type);
+ wordRule.addWord(ty, type);
}
setPredicateRules(new IPredicateRule[] {
- keywordRule,
- typeRule,
+ wordRule,
new SingleLineRule("//", null, comment),
+ new MultiLineRule("/**", "*/", comment),
new MultiLineRule("/*", "*/", comment),
new SingleLineRule("\"", "\"", stringLiteral, '\\'),
new SingleLineRule("'", "'", stringLiteral, '\\'),
- //new TagRule(tag),
+ new WhitespacePredicateRule(new Token("__whitespace")),
});
}
@@ -75,24 +73,40 @@ public WordPredicateRule(IToken successToken) {
public boolean isWordStart(char c) {
return Character.isJavaIdentifierStart(c);
}
+
public boolean isWordPart(char c) {
return Character.isJavaIdentifierPart(c);
}
});
- fSuccessToken= successToken;
+ fSuccessToken = successToken;
addWord("/**/", fSuccessToken); //$NON-NLS-1$
}
- /*
- * @see org.eclipse.jface.text.rules.IPredicateRule#evaluate(ICharacterScanner, boolean)
- */
public IToken evaluate(ICharacterScanner scanner, boolean resume) {
return super.evaluate(scanner);
}
- /*
- * @see org.eclipse.jface.text.rules.IPredicateRule#getSuccessToken()
- */
+ public IToken getSuccessToken() {
+ return fSuccessToken;
+ }
+ }
+
+ /**
+ *
+ */
+ static class WhitespacePredicateRule extends WhitespaceRule implements IPredicateRule {
+
+ private IToken fSuccessToken;
+
+ public WhitespacePredicateRule(IToken successToken) {
+ super(new WhitespaceDetector());
+ fSuccessToken = successToken;
+ }
+
+ public IToken evaluate(ICharacterScanner scanner, boolean resume) {
+ return super.evaluate(scanner);
+ }
+
public IToken getSuccessToken() {
return fSuccessToken;
}

0 comments on commit cc6f5e7

Please sign in to comment.