Custum editor: reserved words [message #503472] |
Mon, 14 December 2009 06:33  |
Eclipse User |
|
|
|
Hello,
I created, via a plugin in eclipse 3.5, a custom (multipage)editor for an exotic programming language.
I can't figure out how to create reservedwords that are highligted in my editor. Does anybody know how to do this ?
Thx.
|
|
|
|
|
Re: Custum editor: reserved words [message #503656 is a reply to message #503536] |
Tue, 15 December 2009 03:45   |
Eclipse User |
|
|
|
Kitesurfer a écrit :
> I'd like to do it without an addtional framework. Do you perhaps have a
> working example of a WordRule in a RuleBasedScanner ?
Hi Kitesurfer,
Here is an example of what I have done in my plugin. You'll have to
adapt it a little to make it work in your project. I hope this can help you.
1- In your xxxTextEditor class (that extends TextEditor), initialize the
source viewer configuration, like this :
@Override
protected void initializeEditor()
{
super.initializeEditor();
setSourceViewerConfiguration(new XxxSourceViewerConfiguration(this));
}
2- add xxxSourceViewerConfiguration class that extends
SourceViewerConfiguration to your project.
3- in xxxSourceViewerConfiguration, override getPresentationReconciler
method, and initialize your code scanner in it :
@Override
public IPresentationReconciler getPresentationReconciler(ISourceViewer
sourceViewer)
{
PresentationReconciler reconciler = new PresentationReconciler();
XxxCodeScanner codescanner = new XxxCodeScanner();
DefaultDamagerRepairer dr = new DefaultDamagerRepairer(codescanner);
reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
// ...
}
4- add xxxCodeScanner class that extends RuleBasedScanner to your project
5- in xxxCodeScanner, initialize WordRule, like this :
public xxxCodeScanner()
{
ArrayList<IRule> rules = new ArrayList<IRule>();
rules.add(new WhitespaceRule(new IWhitespaceDetector()
{
@Override
public boolean isWhitespace(char c)
{
return (c == ' ' || c == '\t' || c == '\n' || c == '\r');
}
}));
WordRule wordRule = new WordRule(new IWordDetector()
{
@Override
public boolean isWordPart(char c)
{
return (Character.isLetterOrDigit(c) || c == '_');
}
@Override
public boolean isWordStart(char c)
{
return (Character.isLetter(c) || c == '_');
}
});
Token instructionToken = new Token(...);
for (String keyword : AllYourKeywords)
{
wordRule.addWord(keyword, instructionToken);
}
rules.add(wordRule);
setRules(rules.toArray(new IRule[] {}));
}
Regards
David
|
|
|
|
|
|
|
|
|
Re: Custum editor: reserved words [message #505777 is a reply to message #505448] |
Mon, 04 January 2010 16:59  |
Eclipse User |
|
|
|
Michael Golovanov wrote on Wed, 30 December 2009 13:57 | OK, you are right, this sample has error
I dont debug this sample yet, but find workarond.
In runned sample create new Generic Project and import your *.xxx file to this project. In my case this help - editor opened without critical errors.
PS Can you write more about exotic programming language syntax from first post?
|
Your workaround to "activate" the plugin works ... thanks. Strange that the plugin on an extension only works within a project (import an xxx-file, or link to an xxx-file) and doesn't work when just opening an xxx-file outside a project. Is this normal behaviour in Eclipse ?
The exotic programming language is the "Transaction Application Langauge" on an HP-system. It's looks a bit like C but has somewhat other syntax and definitly other keywords.
|
|
|
Powered by
FUDForum. Page generated in 0.09846 seconds