Geertjan's Blog

  • March 18, 2007

Schliemann on Schliemann

Geertjan Wielenga
Product Manager
An interesting thing to be aware of is that the NBS file type is itself defined in an NBS file. What does this mean? This means that you can brand the NBS file. Let's say, for example, that we don't like the syntax colors of NBS files. Here's how an NBS file looks by default:

So, let's say that we want the syntax colors to be different. We could, as an end user, just go to the Options window and change the text/x-nbs MIME type's colors. However, let's make the change more permanent. First, find the NBS file that defines NBS files in the "this layer in context" folder. (Expand the "Important Files" node in a module project, then the "XML Layer" node, and then the "this layer in context" node.) And there, within Editors/text/x-nbs, we find our language.nbs file for NBS files:

Pretty cool to see the TOKEN keyword defining tokens, including the TOKEN keyword itself!

Notice also that this NBS file, itself an example of the NBS file it describes, has some colors already. Keywords are blue, comments are grey, and strings are purplish. As pointed out yesterday, there are some tokens that automatically are attributed colors. In fact, if you look inside the file above, you will notice that no colors have been defined at all, so only the three special keywords are colored.

Let's, as an experiment, change the color of tokens in NBS files. Here we assign the color red to the 'keyword' token, thus overriding the color attributed to it by default:

COLOR:keyword: {
foreground_color: "red";

Just paste the above anywhere in the file above. When you save the file, notice that the Projects window shows the node for the file in bold. In fact, all the folders leading down to the file are in bold. This signifies that you have changed a file provided by the NetBeans sources. But, it gets even more interesting, because when you look in your package, you notice that a copy of the language.nbs file that you changed is now available in your module and that appropriate entries have appeared in the layer, so that your copy of the NBS file will override the one found in the NetBeans sources:

This means you're good to go. You have a modified version of the NBS file for NBS files and you have the relevant registration entry in the layer. Install the module and notice that all the keywords are now red:

In this way, you can provide syntax coloring for NBS files.

Another important point is that you can look at the language.nbs file for NBS files and learn from it. The documentation describing the syntax is a bit sporadic right now. What better way to learn about the syntax than in the file that defines it? For example, by looking at that specific file, I learned that each entry in the navigator is an HTML document. So, this is how each entry is constructed in the navigator for NBS files:

NAVIGATOR:token: {
display_name: "<html><b><font color=000099>TOKEN</font></b>: $identifier$</html>";

That's handy info. Better than looking at the half complete NBS files for Groovy and so on, it's probably better to look at the (also half complete, I guess, but probably more reliable) NBS file that defines NBS files. And it might also appeal to one's enjoyment of the "meta" aspect of all of this too!

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.