Rules question [message #165982] |
Thu, 04 December 2003 15:26  |
Eclipse User |
|
|
|
Originally posted by: sacolcor.soartech.com
Hello all...I'm hoping someone can give an Eclipse newcomer a hand.
I'm trying to create a rule for use in syntax highlighting and outlining which
will pass the following construct:
<SP><whitespace><open-brace><whitespace><name><whitespace ><CONTENT><close-brace>
Where:
<SP> := The literal string "SP"
<whitespace> := Any number of whitespace characters
<open-brace> := A single '{' character
<name> := The name of my function (alphanumeric word)
<CONTENT> := Any content, which may include '{' or '}', as long as they all
match up
<close-brace>:= A single '}' character
I've tried to create it using a MultiLineRule (or others of the standard
rules), but there seem to be two shortcomings:
1) There doesn't seem to be a way to express the "Any number of whitespace
characters" concept. The starting string needs to be literally specified.
2) There doesn't seem to be a way to express the idea of finding the correct
closing brace when the content could itself include braces.
I've looked at the included Java editor example, but it only seems to do some
very simple context free highlighting and outlining. The source for the
full-fledged Java editor used in Eclipse, on the other hand, is rather
dauntingly huge.
Does anyone have any suggestions on either how this rule would be created, or
on where I could find a good mid-level example of developing rules and
outliners for Eclipse?
Many thanks,
----Scott
--
Scott A. Colcord Software Engineer
Soar Technology, Inc. sacolcor@soartech.com
|
|
|
Re: Rules question [message #166036 is a reply to message #165982] |
Thu, 04 December 2003 16:11   |
Eclipse User |
|
|
|
I would propose that the org.eclipse.ant.internal.ui.editor.AntEditor is a
mid-level example that might help you out
See the associated classes in the org.eclipse.ant.internal.ui.editor.text
package.
I am not saying it will help with all your problems though as I know we have
an outstanding bug very similar to number 2
(https://bugs.eclipse.org/bugs/show_bug.cgi?id=43409 problems with comments
containing closing "indicators")
So hopefully you will be able to help me out shortly :-)
HTH
Darins
"Scott A. Colcord" <sacolcor@soartech.com> wrote in message
news:3FCF988E.8060703@soartech.com...
> Hello all...I'm hoping someone can give an Eclipse newcomer a hand.
>
> I'm trying to create a rule for use in syntax highlighting and outlining
which
> will pass the following construct:
>
>
<SP><whitespace><open-brace><whitespace><name><whitespace ><CONTENT><close-br
ace>
>
> Where:
> <SP> := The literal string "SP"
> <whitespace> := Any number of whitespace characters
> <open-brace> := A single '{' character
> <name> := The name of my function (alphanumeric word)
> <CONTENT> := Any content, which may include '{' or '}', as long as they
all
> match up
> <close-brace>:= A single '}' character
>
> I've tried to create it using a MultiLineRule (or others of the standard
> rules), but there seem to be two shortcomings:
>
> 1) There doesn't seem to be a way to express the "Any number of whitespace
> characters" concept. The starting string needs to be literally specified.
>
> 2) There doesn't seem to be a way to express the idea of finding the
correct
> closing brace when the content could itself include braces.
>
> I've looked at the included Java editor example, but it only seems to do
some
> very simple context free highlighting and outlining. The source for the
> full-fledged Java editor used in Eclipse, on the other hand, is rather
> dauntingly huge.
>
> Does anyone have any suggestions on either how this rule would be created,
or
> on where I could find a good mid-level example of developing rules and
> outliners for Eclipse?
>
> Many thanks,
>
> ----Scott
>
> --
> Scott A. Colcord Software Engineer
> Soar Technology, Inc. sacolcor@soartech.com
>
|
|
|
Re: Rules question [message #166153 is a reply to message #165982] |
Thu, 04 December 2003 21:18   |
Eclipse User |
|
|
|
Originally posted by: bob.objfac.com
You could write your own IPredicateRule, or even IRule. A very simple
example of how to do this is in JavaPartitionScanner EmptyCommentRule. A
rule can do pretty much anything.
However, rules with inner brackets present some design issues. For example,
such a rule is not resumable.
Bob Foster
"Scott A. Colcord" <sacolcor@soartech.com> wrote in message
news:3FCF988E.8060703@soartech.com...
> Hello all...I'm hoping someone can give an Eclipse newcomer a hand.
>
> I'm trying to create a rule for use in syntax highlighting and outlining
which
> will pass the following construct:
>
>
<SP><whitespace><open-brace><whitespace><name><whitespace ><CONTENT><close-br
ace>
>
> Where:
> <SP> := The literal string "SP"
> <whitespace> := Any number of whitespace characters
> <open-brace> := A single '{' character
> <name> := The name of my function (alphanumeric word)
> <CONTENT> := Any content, which may include '{' or '}', as long as they
all
> match up
> <close-brace>:= A single '}' character
>
> I've tried to create it using a MultiLineRule (or others of the standard
> rules), but there seem to be two shortcomings:
>
> 1) There doesn't seem to be a way to express the "Any number of whitespace
> characters" concept. The starting string needs to be literally specified.
>
> 2) There doesn't seem to be a way to express the idea of finding the
correct
> closing brace when the content could itself include braces.
>
> I've looked at the included Java editor example, but it only seems to do
some
> very simple context free highlighting and outlining. The source for the
> full-fledged Java editor used in Eclipse, on the other hand, is rather
> dauntingly huge.
>
> Does anyone have any suggestions on either how this rule would be created,
or
> on where I could find a good mid-level example of developing rules and
> outliners for Eclipse?
>
> Many thanks,
>
> ----Scott
>
> --
> Scott A. Colcord Software Engineer
> Soar Technology, Inc. sacolcor@soartech.com
>
|
|
|
Re: Rules question [message #235543 is a reply to message #165982] |
Tue, 27 April 2004 16:44  |
Eclipse User |
|
|
|
Originally posted by: ish.soton.ac.uk
I just came across your problem and have written a IPredicateRule rule that
deals with bracket matching, i thought it might help if you are still having
the proplem
forgive the typesetting!
/*
* Created on Apr 27, 2004
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
package ish.ecletex.editors.tex;
import org.eclipse.jface.text.rules.ICharacterScanner;
import org.eclipse.jface.text.rules.IPredicateRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.Token;
/**
* @author ish
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class BracketRule implements IPredicateRule {
public BracketRule(char startBracket,char endBracket,IToken returnToken){
this.fStartChar = startBracket;
this.fEndChar = endBracket;
this.fToken = returnToken;
}
/* (non-Javadoc)
* @see org.eclipse.jface.text.rules.IPredicateRule#getSuccessToken( )
*/
public IToken getSuccessToken() {
// TODO Auto-generated method stub
return fToken;
}
/* (non-Javadoc)
* @see
org.eclipse.jface.text.rules.IPredicateRule#evaluate(org.ecl ipse.jface.text.
rules.ICharacterScanner, boolean)
*/
public IToken evaluate(ICharacterScanner scanner, boolean resume) {
if(resume){
if (endBracketDetected(scanner)){
return fToken;
}else{
return Token.UNDEFINED;
}
}else{
return evaluate(scanner);
}
}
/* (non-Javadoc)
* @see
org.eclipse.jface.text.rules.IRule#evaluate(org.eclipse.jfac e.text.rules.ICh
aracterScanner)
*/
private char fStartChar;
private char fEndChar;
IToken fToken;
public IToken evaluate(ICharacterScanner scanner) {
int c= scanner.read();
if(c == fStartChar){
if (endBracketDetected(scanner))
return fToken;
}
scanner.unread();
return Token.UNDEFINED;
}
private void unread(int count,ICharacterScanner scanner){
for(int i=0;i<count;i++)
scanner.unread();
}
private boolean endBracketDetected(ICharacterScanner scanner){
int c;
int pairs = 0;
int read = 0;
while ((c= scanner.read()) != ICharacterScanner.EOF) {
read++;
if(c == fEndChar){
if(pairs == 0){
return true;
}else{
pairs--;
}
}else if(c == fStartChar){
pairs++;
}
}
unread(read,scanner);
return false;
}
}
"Scott A. Colcord" <sacolcor@soartech.com> wrote in message
news:3FCF988E.8060703@soartech.com...
> Hello all...I'm hoping someone can give an Eclipse newcomer a hand.
>
> I'm trying to create a rule for use in syntax highlighting and outlining
which
> will pass the following construct:
>
>
<SP><whitespace><open-brace><whitespace><name><whitespace ><CONTENT><close-br
ace>
>
> Where:
> <SP> := The literal string "SP"
> <whitespace> := Any number of whitespace characters
> <open-brace> := A single '{' character
> <name> := The name of my function (alphanumeric word)
> <CONTENT> := Any content, which may include '{' or '}', as long as they
all
> match up
> <close-brace>:= A single '}' character
>
> I've tried to create it using a MultiLineRule (or others of the standard
> rules), but there seem to be two shortcomings:
>
> 1) There doesn't seem to be a way to express the "Any number of whitespace
> characters" concept. The starting string needs to be literally specified.
>
> 2) There doesn't seem to be a way to express the idea of finding the
correct
> closing brace when the content could itself include braces.
>
> I've looked at the included Java editor example, but it only seems to do
some
> very simple context free highlighting and outlining. The source for the
> full-fledged Java editor used in Eclipse, on the other hand, is rather
> dauntingly huge.
>
> Does anyone have any suggestions on either how this rule would be created,
or
> on where I could find a good mid-level example of developing rules and
> outliners for Eclipse?
>
> Many thanks,
>
> ----Scott
>
> --
> Scott A. Colcord Software Engineer
> Soar Technology, Inc. sacolcor@soartech.com
>
|
|
|
Powered by
FUDForum. Page generated in 0.05598 seconds