Posted By:
Barry_Burd
Posted On:
Saturday, July 30, 2005 01:52 PM
I' trying to create an editor in which the following code appears in various colors: while r != 0 r-- end r++ The r-- line appears in one color; the r++ line appears in another color, and the while r != 0/end lines appear in a third color. I've tried the following combination of scanners, with no success. (All three of r++, r--, and r !=0 show up in the same color, with the words while/end showing up in another color.) Can anybody help? public class XMLTagScanner extends RuleBasedScanner { public XMLTagScanner(ColorManager manager) { IToken incr = new Token( new TextAttribute(manager.getColor(IXMLColorConstants.STRING)));
More>>
I' trying to create an editor in which the following code appears in various colors:
while r != 0
r--
end
r++
The r-- line appears in one color; the r++ line appears in another color, and the while r != 0/end lines appear in a third color.
I've tried the following combination of scanners, with no success. (All three of r++, r--, and r !=0 show up in the same color, with the words while/end showing up in another color.)
Can anybody help?
public class XMLTagScanner extends RuleBasedScanner {
public XMLTagScanner(ColorManager manager) {
IToken incr =
new Token(
new TextAttribute(manager.getColor(IXMLColorConstants.STRING)));
IToken decr =
new Token(
new TextAttribute(manager.getColor(IXMLColorConstants.TAG)));
IRule[] rules = new IRule[3];
rules[0] = new SingleLineRule("r", "++", incr);
rules[1] = new SingleLineRule("r", "--", decr);
rules[2] = new WhitespaceRule(new XMLWhitespaceDetector());
setRules(rules);
}
}
public class XMLPartitionScanner extends RuleBasedPartitionScanner {
public final static String XML_DEFAULT = "__xml_default";
public final static String XML_COMMENT = "__xml_comment";
public final static String INCR_DECR = "__xml_tag";
public XMLPartitionScanner() {
IToken xmlComment = new Token(XML_COMMENT);
IToken incr_decr = new Token(INCR_DECR);
IPredicateRule[] rules = new IPredicateRule[2];
rules[0] = new SingleLineRule("r", "++", incr_decr);
rules[1] = new SingleLineRule("r", "--", incr_decr);
setPredicateRules(rules);
}
}
And in the XMLConfiguration class...
protected XMLTagScanner getXMLTagScanner() {
if (tagScanner == null) {
tagScanner = new XMLTagScanner(colorManager);
tagScanner.setDefaultReturnToken(
new Token(
new TextAttribute(
colorManager.getColor(IXMLColorConstants.TAG))));
}
return tagScanner;
}
public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
PresentationReconciler reconciler = new PresentationReconciler();
DefaultDamagerRepairer dr =
new DefaultDamagerRepairer(getXMLTagScanner());
reconciler.setDamager(dr, XMLPartitionScanner.INCR_DECR);
reconciler.setRepairer(dr, XMLPartitionScanner.INCR_DECR);
dr = new DefaultDamagerRepairer(getXMLScanner());
reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
NonRuleBasedDamagerRepairer ndr =
new NonRuleBasedDamagerRepairer(
new TextAttribute(
colorManager.getColor(IXMLColorConstants.XML_COMMENT)));
reconciler.setDamager(ndr, XMLPartitionScanner.XML_COMMENT);
reconciler.setRepairer(ndr, XMLPartitionScanner.XML_COMMENT);
return reconciler;
}
<<Less