chrisichris
chrisichris

Reputation: 220

Is there a way to add very simple code-highlighting to eclipse by just giving a list of different keyword, block start etc?

I want to provide a bit of very simple editor support for a new language which is in development in elcipse. Just basic key-wordhighlight, brace matching maybe block folding.

In most editors (vim, emacs or notpad++) I can acomplish that reltively simple by more or less giving a list of keyword with some simple directives. However eveything I looked at in eclipse needs real parsing an antlr-grammar or directly translating from the compilers.

This is certainly powerful, but just too much work for the language I indent to support,because as said the languag is in develompment changes (and is not that much used). So the work for a full IDE-Editor in eclipse does not realy pay off.

So my question is: What is the simplest way to add syntaxcoloring for keywords to an eclipse editor?

Thanks

Upvotes: 2

Views: 181

Answers (2)

McDowell
McDowell

Reputation: 108899

If you're willing to write your own plug-in, Eclipse has a sample plug-in project called Plug-in with an editor that contains simple, hard-coded syntax highlighting. You could adapt this to read a list of keywords from a file. Exported plugin jars can be dropped into your IDE dropin directory.

To create the sample:

  • File > New > Project...
  • Plug-in Development > Plug-in Project > Next
  • Enter a project name
  • In the Templates page of the wizard, select "Plug-in with an editor"
  • Choose a new file extension for your language prior to selecting finish

You will need to edit XMLPartitionScanner.java to provide your own syntax rules.

public XMLPartitionScanner() {  
  IToken xmlComment = new Token(XML_COMMENT);
  IToken tag = new Token(XML_TAG);

  IPredicateRule[] rules = new IPredicateRule[2];

  rules[0] = new MultiLineRule("<!--", "-->", xmlComment);
  rules[1] = new TagRule(tag);

  setPredicateRules(rules);
}

See IPredicateRule implementations.

Upvotes: 2

Ha.
Ha.

Reputation: 3454

You can try xtext - eclipse plugin for creating DSL languages. But it would not be as simple as a list of keywords.

Upvotes: 0

Related Questions