Skip to main content



      Home
Home » Newcomers » Newcomers » Custum editor: reserved words(How to ?)
Custum editor: reserved words [message #503472] Mon, 14 December 2009 06:33 Go to next message
Eclipse UserFriend
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 #503484 is a reply to message #503472] Mon, 14 December 2009 07:36 Go to previous messageGo to next message
Eclipse UserFriend
Kitesurfer a écrit :
> 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.

Hi Kitesurfer,

Try to take a look at DLTK framework. It's a very nice framework to make
editors plugin.

Otherwise, you can define a WordRule in your RuleBasedScanner.

David
Re: Custum editor: reserved words [message #503536 is a reply to message #503484] Mon, 14 December 2009 11:05 Go to previous messageGo to next message
Eclipse UserFriend
I'd like to do it without an addtional framework. Do you perhaps have a working example of a WordRule in a RuleBasedScanner ?
Re: Custum editor: reserved words [message #503656 is a reply to message #503536] Tue, 15 December 2009 03:45 Go to previous messageGo to next message
Eclipse UserFriend
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 #503685 is a reply to message #503472] Tue, 15 December 2009 05:41 Go to previous messageGo to next message
Eclipse UserFriend
http://www.realsolve.co.uk/site/tech/jface-text.php

This is tutorial about writing enhanced text editor
Re: Custum editor: reserved words [message #504647 is a reply to message #503685] Mon, 21 December 2009 11:22 Go to previous messageGo to next message
Eclipse UserFriend
Michael Golovanov wrote on Tue, 15 December 2009 05:41
http://www.realsolve.co.uk/site/tech/jface-text.php

This is tutorial about writing enhanced text editor


Thanks, this is a great example. It's a challenge to customize it ... so I started removing some stuff (at the end all the scanner classes and all the rules) ... but when I start the plugin (via run as eclipse application) all the functionality is still there ? ... the xml-tags and attributes are still scanned and colored, also for xml-comment.
Is this normal behaviour ? ... or do I have to do more then just delete the classes from the project and solve the errors ?
Re: Custum editor: reserved words [message #505242 is a reply to message #503685] Mon, 28 December 2009 16:09 Go to previous messageGo to next message
Eclipse UserFriend
Michael Golovanov wrote on Tue, 15 December 2009 05:41
http://www.realsolve.co.uk/site/tech/jface-text.php

This is tutorial about writing enhanced text editor


This tutorial/project doesn't work ... when I change the extension from 'xml' to 'xxx' and open a file with extension 'xxx' then I get an error.
Re: Custum editor: reserved words [message #505277 is a reply to message #505242] Tue, 29 December 2009 01:46 Go to previous messageGo to next message
Eclipse UserFriend
>when I change the extension from 'xml' to 'xxx' and open a file with >extension 'xxx' then I get an error
Please write more details about how you do this

Can you show error stack trace?
Re: Custum editor: reserved words [message #505280 is a reply to message #505277] Tue, 29 December 2009 04:25 Go to previous messageGo to next message
Eclipse UserFriend
I downloaded the project (had to do it twice to get it) from http://www.realsolve.co.uk/site/tech/jface-text.php

I imported (import existing project into workspace) the project in Eclipse 3.5 (Build id: 20090920-1017)

I changed the file plugin.xml : in xml-node "extension", "editor" I changed the xml-attribute "extensions" to "xxx" (old value was 'xml')

I save the whole project via "Save All"

I delete the directory "runtime-EclipseApplication" in my workspace-folder.

I right-click on the project and select "Run as", "Eclipse application"

In the new started eclipse I open a file called "plugin.xxx" (which is a copy of plugin.xml).

Then I get an editor-window with only the text "ERROR" (no error stack trace)
Re: Custum editor: reserved words [message #505448 is a reply to message #505280] Wed, 30 December 2009 13:57 Go to previous messageGo to next message
Eclipse UserFriend
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?

[Updated on: Wed, 30 December 2009 09:02] by Moderator

Re: Custum editor: reserved words [message #505777 is a reply to message #505448] Mon, 04 January 2010 16:59 Go to previous message
Eclipse UserFriend
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.
Previous Topic:Issue in installing WST Plugin
Next Topic:org.eclipse.team.ftp
Goto Forum:
  


Current Time: Thu Aug 21 08:02:35 EDT 2025

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

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

Back to the top