• Post Reply Bookmark Topic Watch Topic
  • New Topic

TextEditor scanners seem to be toppling over one another  RSS feed

Barry Burd
Ranch Hand
Posts: 133
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I' trying to create an editor in which the following code appears in various colors:

while r != 0

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());

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);

And in the XMLConfiguration class...

protected XMLTagScanner getXMLTagScanner() {
if (tagScanner == null) {
tagScanner = new XMLTagScanner(colorManager);
new Token(
new TextAttribute(
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(
reconciler.setDamager(ndr, XMLPartitionScanner.XML_COMMENT);
reconciler.setRepairer(ndr, XMLPartitionScanner.XML_COMMENT);

return reconciler;
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!