Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Help! RuleBasedScanner is driving me crazy...
Help! RuleBasedScanner is driving me crazy... [message #289163] Mon, 01 August 2005 01:40 Go to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Help! RuleBasedScanner is driving me crazy... [message #289177 is a reply to message #289168] Mon, 01 August 2005 10:44 Go to previous messageGo to next message
Eclipse UserFriend
Thank you, Sunil. I have two follow-up questions.

Is there a way to get the single-line rule not to break on EOL?

Is there an easy way to get a WordRule to accept things like r2++ and
r34++ as well as r++? (That is, I'm looking for the pattern "r[0-9]*++".
Do I need to override something in the IWordDetector interface to do that,
or can I use the method calls that are already in place?)
Re: Help! RuleBasedScanner is driving me crazy... [message #289183 is a reply to message #289177] Mon, 01 August 2005 12:37 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sunil_kamath.nohotspammail.com

"bburd" <bburd@drew.edu> wrote in message
news:022e15592956f6c19d896b1a47112ebb$1@www.eclipse.org...
> Thank you, Sunil. I have two follow-up questions.
>
> Is there a way to get the single-line rule not to break on EOL?
>
> Is there an easy way to get a WordRule to accept things like r2++ and
> r34++ as well as r++? (That is, I'm looking for the pattern "r[0-9]*++".
> Do I need to override something in the IWordDetector interface to do that,
> or can I use the method calls that are already in place?)
>

The superclass of SingleLineRule is PatternRule which can be configured to
not break on EOL.
However, then it will also accept:

r
++

as a valid input.

WordRules are for known static words. Perhaps you should use WordPattenRule
instead.
It will allow you to look for a startsequence, endSequence as well as use a
IWordDetector to validate the characters in the word.
---
Sunil
Re: Help! RuleBasedScanner is driving me crazy... [message #289187 is a reply to message #289183] Mon, 01 August 2005 13:00 Go to previous message
Eclipse UserFriend
WordPatternRule is just what I needed. Thank you.
Previous Topic:Open Resource in PDE
Next Topic:MultiPageEditor, problem with marker selection and status not visible
Goto Forum:
  


Current Time: Sun May 11 22:32:57 EDT 2025

Powered by FUDForum. Page generated in 0.04251 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top