Generic Languages Framework (Project Schliemann)
Overview
What is Schliemann Project about? You have probably already seen some
programmers editors like Emacs, Vim or JEdit. They have editing support
for many programming languages (~100). But they do not contain special
hand coded support (module) for every language. They defines some
Generic Languages Framework only. Every programming language is
described in some file executed by the engine. Schliemann project
implements
Generic Language Framework for NetBeans IDE.
Schliemann engine allows you 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.
So, what can you do in nbs files?
You can define lexical structure of your language. Tokens are described
by regular expressions, syntax is similar to JavaCC.
Example:
TOKEN:keyword: ( "if" | "else" | "while" | "for" | "function" )
TOKEN:comment: ( "/*" - "*/" )
TOKEN:line_comment: ( "//" [^ "\n" "\r"]* )
TOKEN:number: ( ["0"-"9"]+ )
TOKEN:whitespace: ( [" " "\t" "\n" "\r"]+ )
TOKEN:identifier: ( ["a"-"z" "A"-"Z"]+ )
Now you can define coloring for your tokens:
COLOR:line_comment {
foreground_color: "lightGray";
font_type: "bold";
}
Definition of indentation is simple. You can define pairs of brackets
that should be indented,
INDENT "(:)"
INDENT "{:}"
or some regular expression. If some line of code fulfills this
expression, next line will be indented:
INDENT "\\s*(((if|while)\\s*\\(|else\\s*|else\\s+if\\s*\\(|for\\s*\\(.*\\))[^{;]*)"
Sometimes its hard to define some dynamic behavior in declarative
language. Thats why I have added possibility to call Java methods from
Schliemann code. Following example defines tooltip value for keywords
of our language.
TOOLTIP:keyword:org.foopackage.FooClass.fooMethod
public class FooClass {
public static String fooMethod (Cookie cookie) {
String keywordName = cookie.getTokenSequence ().token ().text ().toString ();
if (keywordName.equals ("for")) return "for: for (init, expression, update) defines for cycle";
else
...
}
}
Real parser is needed for some more advanced features like
Navigator (Structure View) or Code Folding. Thats why Schliemann engine
allows you to define grammar of your language.
Simple example:
S = (Statement ";")*;
Statement = ForStatement | WhileStatement | IfStatement | FunctionDeclaration;
ForStatement = "for" "(" Expression ";" Expression ";" Expression ")" Block;
Block = "{" (Statement ";")* "}";
FunctionDeclaration = "function" "(" Parameters ")" Block;
...
Schliemann engine generates parser for your language, and you can
base some other features on its parse tree. Following example defines
code folding for blocks defined in our language, and navigator content.
FOLD:Block
NAVIGATOR:FunctionDeclaration {
display_name:"$identifier$";
icon: "org.foo.FooIcon.gif";
}
So, Schliemann engine creates code fold for every part of source
corresponding to some "Block" nonterminal in parse tree. And it creates
special node in Navigator View for each FunctionDeclaration.
This is short preview of some Schiemann Project features. This project
is under development, planned for NetBeans 6.0. There are about 20
prototypes of languages based on this engine now. If you would like to
try it, you should download development version of NetBeans (or build
NetBeans trunk) and download "Languages Support" modules from
development auto update.
Screenshot
Top-right view contains JavaScript file, bottom-right view contains
definition of JavaSctipt language (NBS file). You can see tokens and AST of JavaScript file too.

Supported / Planned Features:
- syntax coloring, code completion, code folding,
indentation, navigator, hyperlink navigation, code templates, brace matching, brace completion, brace highlighting
- full featured embedding
Supported / Planned Langauges:
- JavaScript, PHP, Groovy, CSS, HTML, Velocity, .sh files, .bat
files, Properties files, Manifest files, .diff files, .ejx files, ...
Download Preview:
Links:
Project is still under development, so documentation is pure: