<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> | |
<html> | |
<head> | |
<META NAME="keywords" CONTENT="netbeans,magazine,Schliemann,Integration,Scripting Languages,IDE,editor"> | |
<META NAME="description" CONTENT="NetBeans Magazine: Schliemann - Easy Integration of Scripting Languages in NetBeans IDE 6.0"> | |
<head> | |
<meta http-equiv=Content-Type content="text/html; charset=windows-1252"> | |
<title>Schliemann - Easy Integration of Scripting Languages in NetBeans IDE 6.0</title> | |
<style> | |
<!-- | |
p.Noparagraphstyle, li.Noparagraphstyle, div.Noparagraphstyle | |
{line-height:120%; | |
text-autospace:none; | |
font-size:12.0pt; | |
font-family:Times; | |
color:black;} | |
p.NB-Corpo, li.NB-Corpo, div.NB-Corpo | |
{text-align:left; | |
text-indent:5.65pt; | |
line-height:16.0pt; | |
text-autospace:none; | |
font-size:9.0pt; | |
font-family:Verdana; | |
color:black;} | |
p.NB-Interttulo, li.NB-Interttulo, div.NB-Interttulo | |
{line-height:120%; | |
page-break-after:avoid; | |
text-autospace:none; | |
font-size:13.0pt; | |
font-family:Verdana; | |
color:#B5216F; | |
font-weight:bold;} | |
p.NB-Cdigointerno, li.NB-Cdigointerno, div.NB-Cdigointerno | |
{line-height:10.0pt; | |
text-autospace:none; | |
font-size:8.0pt; | |
font-family:VerdanaBT-RomanCondensed; | |
color:black;} | |
p.NB-Legendaimagem, li.NB-Legendaimagem, div.NB-Legendaimagem | |
{line-height:12.0pt; | |
tab-stops:14.15pt; | |
text-autospace:none; | |
font-size:10.0pt; | |
font-family:"Verdana"; | |
color:black; | |
letter-spacing:.05pt;} | |
span.NB-NegritoTcnico | |
{font-family:VerdanaBT-BoldCondensed; | |
color:black; | |
letter-spacing:.05pt; | |
font-weight:bold; | |
vertical-align:baseline;} | |
span.NB-Legendanegrito | |
{font-weight:bold;} | |
div.NB-Cdigointerno1 {line-height:10.0pt; | |
text-autospace:none; | |
font-size:8.0pt; | |
font-family:VerdanaBT-RomanCondensed; | |
color:black;} | |
div.NB-Corpo1 {text-align:left; | |
text-indent:5.65pt; | |
line-height:16.0pt; | |
text-autospace:none; | |
font-size:9.0pt; | |
font-family:Verdana; | |
color:black;} | |
div.NB-Interttulo1 {line-height:120%; | |
page-break-after:avoid; | |
text-autospace:none; | |
font-size:13.0pt; | |
font-family:Verdana; | |
color:#B5216F; | |
font-weight:bold;} | |
li.NB-Cdigointerno1 {line-height:10.0pt; | |
text-autospace:none; | |
font-size:8.0pt; | |
font-family:VerdanaBT-RomanCondensed; | |
color:black;} | |
li.NB-Corpo1 {text-align:left; | |
text-indent:5.65pt; | |
line-height:16.0pt; | |
text-autospace:none; | |
font-size:9.0pt; | |
font-family:Verdana; | |
color:black;} | |
li.NB-Interttulo1 {line-height:120%; | |
page-break-after:avoid; | |
text-autospace:none; | |
font-size:13.0pt; | |
font-family:Verdana; | |
color:#B5216F; | |
font-weight:bold;} | |
p.NB-Cdigointerno1 {line-height:10.0pt; | |
text-autospace:none; | |
font-size:8.0pt; | |
font-family:VerdanaBT-RomanCondensed; | |
color:black;} | |
p.NB-Corpo1 {text-align:left; | |
text-indent:5.65pt; | |
line-height:16.0pt; | |
text-autospace:none; | |
font-size:9.0pt; | |
font-family:Verdana; | |
color:black;} | |
p.NB-Interttulo1 {line-height:120%; | |
page-break-after:avoid; | |
text-autospace:none; | |
font-size:13.0pt; | |
font-family:Verdana; | |
color:#B5216F; | |
font-weight:bold;} | |
span.NB-NegritoTcnico1 {font-family:VerdanaBT-BoldCondensed; | |
color:black; | |
letter-spacing:.05pt; | |
font-weight:bold; | |
vertical-align:baseline;} | |
p.NB-Corpo22 {text-align:left; | |
text-indent:5.65pt; | |
line-height:16.0pt; | |
text-autospace:none; | |
font-size:9.0pt; | |
font-family:"Verdana"; | |
color:black; | |
letter-spacing:-.05pt;} | |
p.NB-Corpo221 {text-align:left; | |
text-indent:5.65pt; | |
line-height:16.0pt; | |
text-autospace:none; | |
font-size:9.0pt; | |
font-family:"Verdana"; | |
color:black; | |
letter-spacing:-.05pt;} | |
p.NB-Corpo2211 {text-align:left; | |
text-indent:5.65pt; | |
line-height:16.0pt; | |
text-autospace:none; | |
font-size:9.0pt; | |
font-family:"Verdana"; | |
color:black; | |
letter-spacing:-.05pt;} | |
p.NB-Corpo2212 {text-align:left; | |
text-indent:5.65pt; | |
line-height:16.0pt; | |
text-autospace:none; | |
font-size:9.0pt; | |
font-family:"Verdana"; | |
color:black; | |
letter-spacing:-.05pt;} | |
p.NB-Corpo22121 {text-align:left; | |
text-indent:5.65pt; | |
line-height:16.0pt; | |
text-autospace:none; | |
font-size:9.0pt; | |
font-family:"Verdana"; | |
color:black; | |
letter-spacing:-.05pt;} | |
p.NB-Corpo221211 {text-align:left; | |
text-indent:5.65pt; | |
line-height:16.0pt; | |
text-autospace:none; | |
font-size:9.0pt; | |
font-family:"Verdana"; | |
color:black; | |
letter-spacing:-.05pt;} | |
p.NB-Corpo221212 {text-align:left; | |
text-indent:5.65pt; | |
line-height:16.0pt; | |
text-autospace:none; | |
font-size:9.0pt; | |
font-family:"Verdana"; | |
color:black; | |
letter-spacing:-.05pt;} | |
p.NB-Corpo11 {text-align:left; | |
text-indent:5.65pt; | |
line-height:16.0pt; | |
text-autospace:none; | |
font-size:9.0pt; | |
font-family:Verdana; | |
color:black;} | |
.NB-Listagenstitulos {font-family: Verdana, Arial, Helvetica, sans-serif; | |
color: #FFFFFF; | |
font-size: 14px;} | |
.style2 {font-family: "Courier New", Courier, monospace; font-size: 12px; color: #000000;} | |
.style4 {font-size: 11px; | |
font-weight: bold;} | |
p.NB-Corpo1111 {text-align:left; | |
text-indent:5.65pt; | |
line-height:16.0pt; | |
text-autospace:none; | |
font-size:9.0pt; | |
font-family:"Verdana"; | |
color:black;} | |
.style5 {font-family: "Courier New", Courier, monospace; | |
font-size: 9pt;} | |
--> | |
</style> | |
</head> | |
<body bgcolor="#FFFFFF" lang=PT-BR> | |
<table width="770" border="0" cellspacing="0" cellpadding="0"> | |
<tr> | |
<td height="200"><img src="/images_www/magazine/schliemann/top_schliemann_web.jpg" width="770" height="200"></td> | |
</tr> | |
<tr> | |
<td><p class=NB-Corpo11><strong><font size=1 color=black | |
face=Verdana><span lang=EN-US style='font-size:9.0pt;text-effect:outline'><br> | |
Integrating syntax coloring, code completion, and other editor features into the IDE used to be a lot of work. Not anymore! This article describes how a 19th century explorer called Heinrich Schliemann is inspiring the IDE to become fluent in many languages.</span></font></strong></p> | |
<br></td> | |
</tr> | |
<tr> | |
<td><p class=NB-Corpo1><font size=1 color=black | |
face=Verdana><span lang=EN-US style='font-size:9.0pt;text-effect:outline'>Traditionally, | |
when creating editor support for a new programming language in the IDE, a vast | |
variety of NetBeans APIs must be implemented. By “editor support”, we typically | |
mean syntax coloring, code completion, and the source navigation features | |
provided by the IDE’s Navigator. Other examples include code indentation and | |
brace matching. Out of the box, the NetBeans IDE provides this kind of support | |
for several languages and technologies, such as Java (of course), JSP, and | |
HTML. </span></font></p> | |
<p class=NB-Corpo1><font size=1 color=black face=Verdana><span lang=EN-US | |
style='font-size:9.0pt;text-effect:outline'>There are many NetBeans APIs that | |
one needs to implement to provide editor support for a programming language. | |
This is unfortunate for two reasons. Firstly, the domain knowledge that a language | |
programmer typically brings to the table is the language itself, not the | |
versatile knowledge of the NetBeans APIs required to provide the necessary | |
features. Secondly, the underlying infrastructure for editor support is the | |
same for all languages. For example, the only difference between the Navigator | |
for Java and the Navigator for HTML is the actual code, not the container. For | |
these reasons, the language programmer should only need to provide the </span></font><i><font | |
face=Verdana-Oblique><span lang=EN-US style='font-family:Verdana; | |
font-style:italic'>content</span></font></i><span | |
lang=EN-US style='text-effect:outline'> of the language in the form of </span><i><font | |
face=Verdana-Oblique><span lang=EN-US style='font-family:Verdana; | |
font-style:italic'>tokens </span></font></i><span lang=EN-US style='text-effect:outline'>that are | |
communicated in regular expressions. Nothing more than that should be needed. </span></p> | |
<p class=NB-Corpo1><font size=1 color=black face=Verdana><span lang=EN-US | |
style='font-size:9.0pt;text-effect:outline'>Given the tokens and an indication | |
of where they should be used, the NetBeans Platform should be able to figure | |
out how to hook the tokens to the support features. Not only would this | |
approach simplify the process of integrating a new language into the IDE, but | |
it would leverage the </span></font><i><font face=Verdana-Oblique><span | |
lang=EN-US style='font-family:Verdana;font-style:italic'>current </span></font></i><em><font face=Verdana-Oblique><span lang=EN-US style='font-family:Verdana; '>knowledge</span></font></em><span | |
lang=EN-US> of the language programmer – rather | |
than requiring a steep learning curve of acquiring new knowledge before coding | |
can even begin.</span></p> | |
<p class=NB-Interttulo1><b><font size=4 color="#b5216f" face=Verdana><span | |
lang=EN-US style='font-size:13.0pt;line-height:120%'>Enter Schliemann</span></font></b></p> | |
<p class=NB-Corpo1><font size=1 color=black face=Verdana><span lang=EN-US | |
style='font-size:9.0pt'>This, in sum, is what the new Schliemann project (</span></font><i><font | |
face=Verdana-Oblique><span lang=EN-US style='font-family:Verdana; | |
font-style:italic'>languages. | |
netbeans.org</span></font></i><font size=2><span lang=EN-US style='font-size: | |
10.0pt'>) </span></font><span lang=EN-US>is all about. And why is it called | |
Schliemann? Heinrich Schliemann was a 19th century explorer who had a gift for | |
languages. He traveled the world while keeping a diary in the language of the | |
country he happened to be in. In the spirit of Schliemann, the 6.0 release of | |
the NetBeans Platform envisages the IDE as being Schliemannesque, able to pick | |
up languages very quickly and then being able to communicate in them fluently. </span></p> | |
<p class=NB-Corpo1><font size=1 color=black face=Verdana><span lang=EN-US | |
style='font-size:9.0pt'>The project is especially pitched towards </span></font><i><font | |
face=Verdana-Oblique><span lang=EN-US style='font-family:Verdana; | |
font-style:italic'>scripting</span></font></i><span | |
lang=EN-US> languages, because the Schliemann project does not provide | |
compilation support, which is not required by scripting languages­ – and | |
because scripting languages, in particular, are increasingly in vogue today.</span><i><font | |
face=Verdana-Oblique><span lang=EN-US style='font-family:Verdana; | |
font-style:italic'> </span></font></i><span | |
lang=EN-US>In this article, we will explore the main facets of the Schliemann | |
project and touch on some contrasts with the traditional NetBeans API approach | |
to providing the editor features it supports.</span></p> | |
<p class=NB-Interttulo1><b><font size=4 color="#b5216f" face=Verdana><span | |
lang=EN-US style='font-size:13.0pt;line-height:120%'>Everything in a single | |
file!</span></font></b></p> | |
<p class=NB-Corpo1><font size=1 color=black face=Verdana><span lang=EN-US | |
style='font-size:9.0pt'>A central contrast between the traditional API approach | |
and the Schliemann approach is that the latter lets you specify all editor | |
features declaratively in one single file. This file has the </span></font><i><font | |
face=Verdana-Oblique><span lang=EN-US style='font-family:Verdana; | |
font-style:italic'>.NBS </span></font></i><span | |
lang=EN-US>file extension, which stands for NetBeans Scripting. To get a quick | |
flavor of some typical content of an NBS file, let’s examine a code snippet – | |
see </span><b><font face=Verdana><span lang=EN-US style='font-family: | |
Verdana;font-weight:bold'>Listing | |
1</span></font></b><span lang=EN-US>. </span></p> | |
<table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#B5216F"> | |
<tr> | |
<td bgcolor="#B5216F"><p class="NB-Listagenstitulos"><strong>Listing 1.</strong> NBS file snippet.</p></td> | |
</tr> | |
<tr> | |
<td><blockquote> | |
<p class="style2"><br> | |
#<br> | |
# NBS Template<br> | |
#</p> | |
<p class="style2"># definition of tokens<br> | |
TOKEN:keyword:( “while” | “if” | “else”)<br> | |
TOKEN:operator:( “{“ | “}” | “(“ | “)” )<br> | |
TOKEN:identifier:( [“a”-”z”] [“a”-”z” “0”-”9”]* )<br> | |
TOKEN:whitespace:( [“ “ “\t” “\n” “\r”]+ )</p> | |
<p class="style2"># parser should ignore whitespaces<br> | |
SKIP:whitespace</p> | |
<p class="style2"># definition of grammar<br> | |
S = (Statement)*;<br> | |
Statement = WhileStatement | IfStatement | ExpressionStatement;<br> | |
WhileStatement = “while” “(“ ConditionalExpression “)” Block;<br> | |
IfStatement = “if” “(“ ConditionalExpression “)” Block;<br> | |
Block = “{“ (Statement)* “}”;<br> | |
ConditionalExpression = <identifier>;<br> | |
ExpressionStatement = <identifier>;</p> | |
<p class="style2"># code folding<br> | |
FOLD:Block</p> | |
<p class="style2"># navigator support<br> | |
NAVIGATOR:WhileStatement:”{$ConditionalExpression}”</p> | |
<p class="style2"># brace completion<br> | |
COMPLETE “{:}”<br> | |
COMPLETE “(:)”</p> | |
<p class="style2"># indentation support<br> | |
INDENT “{:}”<br> | |
INDENT “(:)”<br> | |
INDENT “\\s*(((if|while)\\s*\\(|else\\s*|else\\s+if\\s*\\(|for\\s*\\(.*\\))[^{;]*)”b</p> | |
<br> | |
</blockquote></td> | |
</tr> | |
</table> | |
<p class=NB-Corpo1><font size=1 color=black face=Verdana><span lang=EN-US | |
style='font-size:9.0pt'>This template is what you are given when you use the | |
new Generic Languages Framework wizard, which is part of NetBeans IDE 6.0. It | |
gives you a single NBS file with sample content, which begins with the | |
definition of four tokens. These tokens are named “keyword”, “operator”, | |
“identifier” and “whitespace”. Within brackets, in the same line as the name of | |
the tokens, a regular expression is used to define them. </span></font></p> | |
<p class=NB-Corpo1><font size=1 color=black face=Verdana><span lang=EN-US | |
style='font-size:9.0pt'>Right away, one can see the power of this new approach | |
to language support provision: a regular expression language, rather than Java, | |
is used to define tokens. As a result, programmers outside the Java ecosystem | |
can integrate their programming languages into the NetBeans IDE. Not needing to | |
know Java, at least for the simpler integrations of languages, is a central | |
benefit of the Schliemann project. </span></font></p> | |
<p class=NB-Corpo1><font size=1 color=black face=Verdana><span lang=EN-US | |
style='font-size:9.0pt'>Once tokens are defined, one can already begin | |
assigning features. For example, this single statement would fill the Navigator | |
with the values provided by the “keyword” token:</span></font><font size=1 color=black | |
face=VerdanaBT-RomanCondensed><span lang=EN-US style='font-size:8.0pt'> </span></font></p> | |
<p class="style5">NAVIGATOR:keyword<font size=1 color=black | |
face=VerdanaBT-RomanCondensed><span lang=EN-US style='font-size:8.0pt'> </span></font></p> | |
<p class=NB-Corpo1><font size=1 color=black face=Verdana><span lang=EN-US | |
style='font-size:9.0pt'>Readers who are familiar with the NetBeans Navigator | |
API can only be amazed at this drastic simplification! However, normally you | |
would like more robust support for a language and to provide a </span></font><i><font | |
face=Verdana-Oblique><span lang=EN-US style='font-family:Verdana; | |
font-style:italic'>grammar</span></font></i><span | |
lang=EN-US> in addition to tokens. The grammar that the Schliemann approach | |
requires is also highly simplified. It is comparable to JavaCC or AntLR. | |
Ideally, one would wish that the grammar provided by JavaCC and AntLR could be | |
directly integrated into NetBeans IDE. Unfortunately, however, these grammars | |
are not tailored to usage within an IDE. For this reason, a conversion process | |
needs to take place, from AntLR or JavaCC (or from a similar approach) to the | |
Schliemann NBS format. </span></p> | |
<p class=NB-Corpo1><font size=1 color=black face=Verdana><span lang=EN-US | |
style='font-size:9.0pt'>Early experiments have shown that both a manual and an | |
automatic solution for this process is feasible. However, this aspect of the | |
Schliemann project is definitely the area where most work needs to be done. A | |
unified, simple approach to integrating grammars provided by AntLR, JavaCC, and | |
the like, is needed in order for the Schliemann project to reach its full | |
potential.</span></font></p> | |
<p class=NB-Corpo1><font size=1 color=black face=Verdana><span lang=EN-US | |
style='font-size:9.0pt'>In the NBS code shown before, you can see, in addition | |
to the tokens, that the grammar forms the basis of both the Navigator | |
implementation and the code folding implementation. In the case of code | |
folding, the </span></font><span class=NB-NegritoTcnico1><b><font size=2 | |
color=black face=VerdanaBT-BoldCondensed><span lang=EN-US style='font-size: | |
10.0pt'>Block</span></font></b></span><span lang=EN-US> grammar definition | |
determines each code fold, while the Navigator is populated by values | |
conforming to the </span><span class=NB-NegritoTcnico1><b><font size=2 | |
color=black face=VerdanaBT-BoldCondensed><span lang=EN-US style='font-size: | |
10.0pt'>WhileStatement</span></font></b></span><span lang=EN-US> definition.</span></p> | |
<p class=NB-Corpo1><font size=1 color=black face=Verdana><span lang=EN-US | |
style='font-size:9.0pt'>Finally, notice that the code also shows how brace | |
completion and indentation is defined, all within the same single file, and | |
that one can fine-tune further by specifying that white space should be skipped | |
by the parser.</span></font></p> | |
<p class=NB-Corpo1><font size=1 color=black face=Verdana><span lang=EN-US | |
style='font-size:9.0pt'>Hence, when the NBS file in </span></font><b><font | |
face=Verdana><span lang=EN-US style='font-family:Verdana; | |
font-weight:bold'>Listing 1</span></font></b><span | |
lang=EN-US> is associated with a MIME type, documents corresponding to the MIME | |
type immediately have the following features:</span></p> | |
<ul> | |
<li class="NB-Corpo1"> Syntax coloring</li> | |
<li class="NB-Corpo1" lang=EN-US>Navigator</li> | |
<li class="NB-Corpo1" lang=EN-US>Code folding</li> | |
<li class="NB-Corpo1" lang=EN-US>Brace matching</li> | |
<li class="NB-Corpo1" lang=EN-US>Indentation</li> | |
</ul> | |
<p class=NB-Corpo1><font size=1 color=black face=Verdana><span lang=EN-US | |
style='font-size:9.0pt'> </span></font><font size=1 color=black face=Verdana><span lang=EN-US | |
style='font-size:9.0pt'>In similar ways, a wide range of other language-support | |
features can be created, including code completion, which is frequently very | |
high up on the list of features that language programmers want to provide | |
support for.</span></font></p> | |
<p class=NB-Interttulo1><b><font size=4 color="#b5216f" face=Verdana><span | |
lang=EN-US style='font-size:13.0pt;line-height:120%'>Getting started</span></font></b></p> | |
<p class=NB-Corpo1><font size=1 color=black face=Verdana><span lang=EN-US | |
style='font-size:9.0pt'>Now that we have a general flavor of the Schliemann | |
approach, let’s put it into practice and create an NBS file for Java Manifests. | |
Manifests, as you know, are constructed from key/value pairs. In the IDE, there | |
is no language support for Manifests, not even syntax coloring. Let’s provide | |
that... and a lot more besides. </span></font></p> | |
<p class=NB-Corpo1><font size=1 color=black face=Verdana><span lang=EN-US | |
style='font-size:9.0pt'>We begin as one always does when creating a plug-in for | |
the IDE: by creating a new module project (see </span></font><b><font | |
face=Verdana><span lang=EN-US style='font-family:Verdana; | |
font-weight:bold'>Figure 1</span></font></b><span | |
lang=EN-US>). Next, in the New Project wizard, name the project | |
“ManifestEditorFeatures” and specify | |
“org.netbeans.modules.manifesteditorfeatures” as the Code Name Base. At the end | |
of the wizard, after having clicked </span><i><font face=Verdana-Oblique><span | |
lang=EN-US style='font-family:Verdana;font-style:italic'>Finish</span></font></i><span lang=EN-US>, you’ll see that | |
the IDE has created a basic source structure, as it does for every NetBeans | |
module (see </span><b><font face=Verdana><span lang=EN-US | |
style='font-family:Verdana;font-weight:bold'>Figure 2</span></font></b><span lang=EN-US>).</span></p> | |
<table width="100%" border="0" cellspacing="0" cellpadding="0"> | |
<tr> | |
<td><img src="/images_www/magazine/schliemann/images/image001.png" width="685" height="367"></td> | |
</tr> | |
<tr> | |
<td><p class=NB-Corpo22><strong>Figure 1.</strong> Creating a new module project.<br> | |
</p></td> | |
</tr> | |
</table> | |
<table width="100%" border="0" cellspacing="0" cellpadding="0"> | |
<tr> | |
<td><img src="/images_www/magazine/schliemann/images/image003.png" width="347" height="313"></td> | |
</tr> | |
<tr> | |
<td><p class=NB-Corpo221><strong>Figure 2.</strong> Result of the New Projects window: Plugin Source Structure.<br> | |
<br> | |
</p></td> | |
</tr> | |
</table> | |
<br> | |
<p class=NB-Corpo1><font size=1 color=black face=Verdana><span lang=EN-US | |
style='font-size:9.0pt'>Next, we can use the Generic Languages Framework wizard | |
to generate the NBS template discussed in the previous section. This template | |
is found in the NetBeans Module Development section in the New File wizard (see </span></font><b><font face=Verdana><span lang=EN-US style='font-family: | |
Verdana;font-weight:bold'>Figure 3</span></font></b><span | |
lang=EN-US>). Once you’ve completed the wizard, you have a single new file, in | |
which we will do </span><i><font face=Verdana-Oblique><span lang=EN-US | |
style='font-family:Verdana;font-style:italic'>all</span></font></i><span lang=EN-US> our coding for this | |
module (see </span><b><font face=Verdana><span lang=EN-US | |
style='font-family:Verdana;font-weight:bold'>Figure 4</span></font></b><span lang=EN-US>).</span></p> | |
<table width="100%" border="0" cellspacing="0" cellpadding="0"> | |
<tr> | |
<td><img src="/images_www/magazine/schliemann/images/image005.png" width="663" height="430"></td> | |
</tr> | |
<tr> | |
<td><p class=NB-Corpo2211><strong>Figure 3.</strong> Generic Languages Framework Template. <br> | |
<br> | |
</p></td> | |
</tr> | |
</table> | |
<table width="100%" border="0" cellspacing="0" cellpadding="0"> | |
<tr> | |
<td><img src="/images_www/magazine/schliemann/images/image007.png" width="348" height="336"></td> | |
</tr> | |
<tr> | |
<td><p class=NB-Corpo2212><strong>Figure 4.</strong> Result of the New File wizard: One additional file! <br> | |
<br> | |
</p></td> | |
</tr> | |
</table> | |
<br> | |
<p class=NB-Corpo1><font size=1 color=black face=Verdana><span lang=EN-US | |
style='font-size:9.0pt'>Now, let’s begin! Unlike in the previous section, the | |
syntax we are dealing with here has the notion of </span></font><i><font | |
face=Verdana-Oblique><span lang=EN-US style='font-family:Verdana; | |
font-style:italic'>state</span></font></i><span | |
lang=EN-US>. By state we mean that if we know in which token we find ourselves, | |
we can always know where we are in relation to all the other tokens. So, for | |
example, if we are in the “key” part of a key/value statement in a Manifest, we | |
know that when we reach the colon we are entering the “value” part of the | |
statement. As a result, we can define our tokens in the context of their </span><i><font | |
face=Verdana-Oblique><span lang=EN-US style='font-family:Verdana; | |
font-style:italic'>states</span></font></i><span | |
lang=EN-US>. Below you see how this is done. Not much of this should be foreign | |
to you if you are familiar with regular expressions:</span></p> | |
<p class="style5">TOKEN:key:( | |
[^”#”] [^ “:” “\n” “\r”]* ):<VALUE></span></font><br> | |
<VALUE> | |
{</span></font><br> | |
TOKEN:whitespace:( [“\n” “\r”]+ | |
):<DEFAULT></span></font><br> | |
TOKEN:operator:( “:” ):<IN_VALUE></span></font><br> | |
}</span></font><br> | |
<font color=black><span lang=EN-US><IN_VALUE> | |
{</span></font><br> | |
<font color=black>T<span lang=EN-US>OKEN:whitespace:( [“\n” “\r”]+ | |
):<DEFAULT></span></font><br> | |
<font color=black>T<span lang=EN-US>OKEN:value:( [^ “\n” “\r”]* )</span></font><br> | |
<span class="style5"><font color=black>}</font></span><br> | |
</p> | |
<p class=NB-Corpo1><font size=1 color=black face=Verdana><span lang=EN-US | |
style='font-size:9.0pt'>Notice that we start out by saying that we are </span></font><i><font | |
face=Verdana-Oblique><span lang=EN-US style='font-family:Verdana; | |
font-style:italic'>not</span></font></i><span | |
lang=EN-US> in a key if the first character is a hash (</span><span | |
class=NB-NegritoTcnico1><b><font size=2 color=black | |
face=VerdanaBT-BoldCondensed><span lang=EN-US style='font-size:10.0pt'>#</span></font></b></span><span | |
lang=EN-US>). In that case we are, in fact, in a comment. It would also be good | |
to provide a specific syntax color for comments, so let’s define a token for | |
comments:</span><font size=1 color=black | |
face=VerdanaBT-RomanCondensed><span lang=EN-US style='font-size:8.0pt'> </span></font></p> | |
<p class="style5">TOKEN:comment:( | |
“#” [^ “\n” “\r”]* [“\n” “\r”]+ )</span></font><font size=1 color=black | |
face=VerdanaBT-RomanCondensed><span lang=EN-US style='font-size:8.0pt'> </span></font></p> | |
<p class=NB-Corpo1><font size=1 color=black face=Verdana><span lang=EN-US | |
style='font-size:9.0pt'>Right now, without going any further, we can already | |
assign colors. Again we do so declaratively:</span></font><font size=1 color=black | |
face=VerdanaBT-RomanCondensed><span lang=EN-US style='font-size:8.0pt'> </span></font></p> | |
<p class="style5"></span>foreground_color: “blue”;</span></font><br> | |
COLOR:operator: | |
{<br> | |
foreground_color: “black”;</span></font><br> | |
}</span></font> <br> | |
COLOR:value: | |
{</span></font><br> | |
foreground_color: “magenta”;<br> | |
}<br> | |
<p class=NB-Corpo1><font size=1 color=black face=Verdana><span lang=EN-US | |
style='font-size:9.0pt'>Apart from the foreground color, there are many other | |
attributes that we can set per token, such as the style and background color. | |
Without going much further, though, we can already install our module and then | |
we’ll have syntax coloring (see </span></font><b><font face=Verdana><span | |
lang=EN-US style='font-family:Verdana;font-weight:bold'>Figure 5</span></font></b><span lang=EN-US>)! It | |
couldn’t be much simpler. Before we do so, however, we need to create a MIME | |
type resolver, which is a small XML file that specifies the file extension of | |
the files we want to deal with. </span></p> | |
<table width="100%" border="0" cellspacing="0" cellpadding="0"> | |
<tr> | |
<td><img src="/images_www/magazine/schliemann/images/image009.png" width="576" height="183"></td> | |
</tr> | |
<tr> | |
<td><p class=NB-Corpo22121><strong>Figure 5.</strong> A Manifest file with syntax coloring. <br> | |
<br> | |
</p></td> | |
</tr> | |
</table> | |
<p class=NB-Corpo1><font size=1 color=black face=Verdana><span lang=EN-US | |
style='font-size:9.0pt;letter-spacing:-.1pt'>If you use the New File Type | |
wizard, you can let the IDE generate such a MIME type resolver for you. You | |
then need to register both the resolver and the NBS file in the XML layer file | |
and declare a dependency on the Generic Languages Framework API. Eventually, | |
the Generic Languages Framework template will do all of this for you, one | |
imagines; but at the time of writing this is not the case. </span></font></p> | |
<p class=NB-Corpo1><font size=1 color=black face=Verdana><span lang=EN-US | |
style='font-size:9.0pt;letter-spacing:-.1pt'>After installing the module, we | |
can develop it further. To help you, NetBeans 6.0 will provide a number of | |
developer tools, such as the new AST window (see </span></font><b><font | |
face=Verdana><span lang=EN-US style='font-family:Verdana; | |
letter-spacing:-.1pt;font-weight:bold'>Figure 6</span></font></b><span | |
lang=EN-US style='letter-spacing:-.1pt'>), which lets you analyze a file, based | |
on the tokens you have assigned to its MIME type. Ultimately, for Manifests, | |
you could create a very detailed Navigator (see </span><b><font | |
face=Verdana><span lang=EN-US style='font-family:Verdana; | |
letter-spacing:-.1pt;font-weight:bold'>Figure 7</span></font></b><span | |
lang=EN-US style='letter-spacing:-.1pt'>), among other useful features for the | |
end user. </span></p> | |
<table width="100%" border="0" cellspacing="0" cellpadding="0"> | |
<tr> | |
<td><img src="/images_www/magazine/schliemann/images/image011.png" width="767" height="203"></td> | |
</tr> | |
<tr> | |
<td><p class=NB-Corpo221211><strong>Figure 6.</strong> AST window.<br> | |
<br> | |
</p></td> | |
</tr> | |
</table> | |
<br> | |
<table width="100%" border="0" cellspacing="0" cellpadding="0"> | |
<tr> | |
<td><img src="/images_www/magazine/schliemann/images/image013.png" width="284" height="151"></td> | |
</tr> | |
<tr> | |
<td><p class=NB-Corpo221212><strong>Figure 7.</strong> Navigator. <br> | |
<br> | |
</p></td> | |
</tr> | |
</table> | |
<br> | |
<p class=NB-Interttulo1><b><font size=4 color="#b5216f" face=Verdana><span | |
lang=EN-US style='font-size:13.0pt;line-height:120%'>Conclusions</span></font></b></p> | |
<p class=NB-Corpo1><font size=1 color=black face=Verdana><span lang=EN-US | |
style='font-size:9.0pt'>Hopefully this broad introduction gives you a flavor of | |
what NetBeans 6.0 will do for scripting languages. Quickly and without much | |
fuss, language developers will be able to integrate their favorite scripting | |
languages into the IDE, thus turning NetBeans more and more into their own, | |
customized development environment. In short, just like Heinrich Schliemann, | |
NetBeans IDE will be able to pick up new languages and expand its usefulness | |
across more and more development | |
communities.</span></font></p> | |
<table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#0081C7"> | |
<tr> | |
<td bgcolor="#0081C7"><p class="NB-Listagenstitulos"><strong>Links</strong></p></td> | |
</tr> | |
<tr> | |
<td><br> | |
<table width="100%" border="0" cellspacing="0" cellpadding="0"> | |
<tr> | |
<td width="40"> </td> | |
<td><span class="style4"><font color="#0075a2" face="Verdana">contrib.netbeans.org/languages</font></span></td> | |
</tr> | |
<tr> | |
<td> </td> | |
<td><font size=1 color=black face="Verdana"><span style="font-size:9.0pt;letter-spacing:0pt">The official Schliemann project page on netbeans.org</span></font></td> | |
</tr> | |
</table> | |
<br> | |
<table width="100%" border="0" cellspacing="0" cellpadding="0"> | |
<tr> | |
<td width="40"> </td> | |
<td><a href="http://wiki.netbeans.org/Schliemann"><span class="style4"><font color="#0075a2" face="Verdana">wiki.netbeans.org/Schliemann</font></span></a></td> | |
</tr> | |
<tr> | |
<td> </td> | |
<td><font size=1 color=black face="Verdana"><span style="font-size:9.0pt;letter-spacing:0pt">The Schliemann page in the NetBeans Wiki</span></font></td> | |
</tr> | |
</table> | |
<br> | |
<table width="100%" border="0" cellspacing="0" cellpadding="0"> | |
<tr> | |
<td width="40"> </td> | |
<td><a href="http://blogs.sun.com/hanz"><span class="style4"><font color="#0075a2" face="Verdana">blogs.sun.com/hanz</font></span></a></td> | |
</tr> | |
<tr> | |
<td> </td> | |
<td><font size=1 color=black face="Verdana"><span style="font-size:9.0pt;letter-spacing:0pt">Blog by Jan Jancura, the lead NetBeans engineer for Schliemann</span></font></td> | |
</tr> | |
</table> | |
<br> | |
<table width="100%" border="0" cellspacing="0" cellpadding="0"> | |
<tr> | |
<td width="40"> </td> | |
<td><a href=""><span class="style4"><font color="#0075a2" face="Verdana">languages.netbeans.org</font></span></a></td> | |
</tr> | |
<tr> | |
<td> </td> | |
<td><font size=1 color=black face="Verdana"><span style="font-size:9.0pt;letter-spacing:0pt">The official Schliemann project page on netbeans.org</span></font></td> | |
</tr> | |
</table> | |
<br> | |
</tr> | |
</table> | |
<br> | |
<table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#0081C7"> | |
<tr> | |
<td><table width="100%" border="0" cellspacing="0" cellpadding="0"> | |
<tr> | |
<td width="93"><div align="center"><img src="/images_www/magazine/autores/Geertjan-Wielenga.jpg" alt="Autor" width="80" height="94"></div></td> | |
<td width="677"><p class=NB-Corpo1111><strong>Geertjan Wielenga</strong><br> | |
(<em>geertjan.wielenga@sun.com</em>) is a technical writer for NetBeans IDE and a co-author of the book “Rich Client Programming: Plugging into the NetBeans Platform”. He is passionate about NetBeans and blogs about it daily at | |
blogs.sun.com/geertjan.<br> | |
</p></td> | |
</tr> | |
</table></td> | |
</tr> | |
</table></td> | |
</tr> | |
</table> | |
</body> | |
</html> |