Help! RuleBasedScanner is driving me crazy... [message #289163] |
Mon, 01 August 2005 01:40  |
Eclipse User |
|
|
|
I took the Editor plugin that's offered in Ecipse's New Plug-in Project
wizard, and I made ONLY ONE CHANGE to it...
public class XMLScanner extends RuleBasedScanner {
public XMLScanner(ColorManager manager) {
IToken procInstr =
new Token(
new TextAttribute(
manager.getColor(IXMLColorConstants.PROC_INSTR)));
// IRule[] rules = new IRule[2];
// //Add rule for processing instructions
// rules[0] = new SingleLineRule("<?", "?>", procInstr);
// // Add generic whitespace rule.
// rules[1] = new WhitespaceRule(new XMLWhitespaceDetector());
IToken comment =
new Token(
new TextAttribute(
manager.getColor(IXMLColorConstants.XML_COMMENT)));
IRule[] rules = new IRule[3];
rules[0] = new SingleLineRule("r", "++", procInstr);
rules[1] = new SingleLineRule("r", "--", comment);
rules[2] = new WhitespaceRule(new XMLWhitespaceDetector());
setRules(rules);
}
}
As far as I can see, this puts everything inside the following document
into the default partition...
while r != 0
r1++
end
r--
r2++
The document has the .xml extension, but it's not really an XML document.
(It has no tags, no processing instructions, etc.) Even so, my new
SingleLineRules should color the r++ lines one color, color the r-- lines
another color, and leave the while and end lines to the default color.
Unfortunately, this doesn't happen. (Everything from 'r' onward on any
line gets painted in the procInstr color.)
Can someone please tell me why (or tell me something about it to get me
past the roadblock). Any thoughts on the subject will be considered
helpful (and much appreciated). Thanks.
|
|
|
Re: Help! RuleBasedScanner is driving me crazy... [message #289168 is a reply to message #289163] |
Mon, 01 August 2005 08:50   |
Eclipse User |
|
|
|
Originally posted by: sunil_kamath.nohotspammail.com
"bburd" <bburd@drew.edu> wrote in message
news:02b7e798fc761f214f761b112ee47f52$1@www.eclipse.org...
>I took the Editor plugin that's offered in Ecipse's New Plug-in Project
>wizard, and I made ONLY ONE CHANGE to it...
>
>
> IRule[] rules = new IRule[3];
> rules[0] = new SingleLineRule("r", "++", procInstr);
> rules[1] = new SingleLineRule("r", "--", comment);
> rules[2] = new WhitespaceRule(new XMLWhitespaceDetector());
> setRules(rules);
> }
> }
>
> The document has the .xml extension, but it's not really an XML document.
> (It has no tags, no processing instructions, etc.) Even so, my new
> SingleLineRules should color the r++ lines one color, color the r-- lines
> another color, and leave the while and end lines to the default color.
> Unfortunately, this doesn't happen. (Everything from 'r' onward on any
> line gets painted in the procInstr color.)
> Can someone please tell me why (or tell me something about it to get me
> past the roadblock). Any thoughts on the subject will be considered
> helpful (and much appreciated). Thanks.
>
A SingleLineRule breaks on EOL even if the ending pattern is not detected.
If you know for sure that you are looking for exactly r++ and r--, use
WordRule instead.
---
Sunil
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04251 seconds