Sunday, April 6, 2008

New Language Support in NetBeans 6x

Few days ago I happened to come across Project Schliemann , I already had interest for providing VHDL Language support in NetBeans. Prior to Project Schliemann I was struggling to set up syntax highlighting support, code Folding & parser. Again I had to go thru lots of Netbeans APIs like Nodes APIs, File System APIs etc. It was a heck for me atleast! Days went on and I kept wondering when I'll kickstart my work. Then suddenly as though god had answered my prayers Project Schliemann came to my rescue. Thanks to the team of Project Schliemann.

I think I needn't explain what project Schliemann is about.
Schliemann project implements Generic Language Framework for NetBeans IDE. Schliemann engine allows one to describe some programming language and define how to integrate it to the NetBeans. Each programming language is defined in one nbs (NetBeans Schliemann) file. New declarative language has been created for that purpose.

As normal, In the first step you should describe the language - lexical part (define tokens using regular expressions) and syntax (grammar rules). In the second step you can define how to visualize this language in NetBeans. You can define colors for tokens (syntax coloring) or folding (based on grammar rules). You can define what parts of this language should be displayed in the navigator, and how to indent this language plus many other features.

Here I go with my findings,
- NetBeans is bundled with GLF support and shipped. It must not be difficult for users to extend the IDE to support their favorite language. Start with a new Netbeans module project:

Define the code name base and Display name on the next page:

New project is created when the finish button is pressed.

Now a new language support is to be added so right click on the project root node, then choose Language support (or Other-->Module Development-->Language Support)

Select the mime type as shown below:

After this you should see a language.nbs file in the editor window. It creates syntax definitons, grammars, color highlighting etc etc for an artificial language. It can be modified according to the
need of language description. This module can be directly built and installed now.

However if one wishes to see the changes made to his nbs file in the output file ( Example.vhd in my case) immediately, the following steps must be followed.

1. Open Advanced Options Dialog first (Tools--> Options action and Advanced Options button).

2. Select IDE Configuration/System / Object Types / Generic Languages Framework Objects node in Advanced Options Dialog.

3. Open "GLF Files" property for editing & press "..." button. A dialog box appears where the corresponding mime type can be selected for editing.

4. Select the mimeType ("text/vhd" in my case) there and press "Edit" button.

Now onwards, all the changes made in the nbs file will be reflected on the actual file type opened!
Lexical Structure of the Language can be defined in the way one wants! Here are few regular expression constructs-
'a' character a
"abc" string abc - syntax is the same like in Java (\t, \n, ...)
"ab"i case-insensitive string, i.e. ab, Ab, aB or AB
['a' 'b' 'c'] charater a, b, or c (simple class)
[^'a' 'b' 'c'] any character except a, b, or c (negation)
['a'-'z' 'A'-'Z'] a through z or A through Z, inclusive (range)
. any character
'a'? character a once or not at all
'a'+ character a one or more time
'a'* character a zero or more time
XY X followed by Y
X/Y Either X or Y
(X) X, as a capturing group

TOKEN:identifier: ( ['a'-'z' 'A'-'Z'] ['a'-'z' 'A'-'Z' '0'-'9']*)
Here is the list of Tokens( To be modified later) I declared:

A statement can be skipped by using the SKIP keyword as shown,
SKIP: comment

Note that the comment has to be declared as a token prior to the usage of it with this keyword.

Grammar has to be defined for the language, here is a pic of my grammar definition

Coloring can be done in an easy fashion:
Supported properties:

  • color_name: Name of color. elementName is used for name of color if its not specified.
  • default_coloring: Defines parent coloring (operator, keyword, identifier, whitespace, number, char, string, comment).
  • foreground_color: Foreground color (for example "white", "FF00FF").
  • background_color: Background color.
  • underline_color: Underlined color.
  • wave_underline_color: Wave underlined color.
  • strike_through_color: Strike through color.
  • font_name: Name of font.
  • font_type: Font type (like "bold" or "italics-bold").

Code Folding is also made easy. Any grammar rule can be code folded.


foldDefinition = "FOLD" ":" identifier [ ":" parameters ( "\"" text "\"" ) | methodCall ]

Where identifier is name of some grammar rule.


FOLD:additiveExpression:"$multiplicativeExpression$ + $additiveExpression$"

If some part of code is folded, there is some text written in place of it. There are three ways how to specify this text.

  1. If you do not specify the text, default text ("...") is used.
  2. You can specify text directly. And you can use some expressions inside this text.
  3. Text can be obtained from some method call.
Here is my code which is an example for it.

Here is a screen shot of sample vhdl file in Netbeans. It looks very cool for me!!

I'm exploring more and more. There are many more things included in this brilliant project. I wish to come up with it in future. It has made life so easy for coders like me :)


Vikram said...

Hi, I would like to talk to you about a possible project on netbeans. If you are interested pls contact me at vkr101 at gmail.


Anonymous said...

Great Post

Anonymous said...

Who knows where to download XRumer 5.0 Palladium?
Help, please. All recommend this program to effectively advertise on the Internet, this is the best program!

Anonymous said...


can i use this in netbeans 6.9 ?