Jan (Hanz) Jancura's Blog

pageicon Saturday Dec 23, 2006

Project Schliemann

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 Languages 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 Scripting) 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.
See NetBeans Wiki for more info.
Comments:

NetBeans 6 is going to rock!

Now that I got that out of the way (:-)), I do have a couple of questions: Is the Ruby plugin related to Schliemann? Tor Norbye said in his blog that project Semplice was not limited to VB and the Ruby plugin built on that infrastructure. So, I wonder if there is any relation.

The second question is if more advanced features are possible using Schliemann, such as code completion and semantic (compile-time) error highlighting? Of course it is impossible (or pretty close to impossible) to provide this generically for all variety of statically typed languages, but is there any hook for implementing this sort of thing for specific languages?

Posted by Rafael de F. Ferreira on March 14, 2007 at 09:08 PM PDT #

This is a welcome addition to Netbeans for sure! I'm just starting to play with it now, is there a still a way to get the AST for a file, as you have in the screenshot? I'm using NB 6 milestone 9.

Posted by Jeremy Faden on May 22, 2007 at 12:16 PM PDT #

What is the package for the Cookie class in the fooMethod signature?

I'm trying this out today and nb6 resolves the class as org.netbeans.modules.languages.parser.Parser.Cookie but will not compile. That seems to be the only Cookie class in the GLF module.

Posted by Erik Earle on December 11, 2007 at 11:15 AM PST #

Hi,

I've a serious problem I hope you can help me with. I need editor support for my homebrew script language. I have a file type text/x-irleprg, extension .prg and my own icon.
Everything works well. My files are displayed with the right icon.
But when I create a language support project, something funny happens. My script is recognized, but now my file icon has reverted to the .nbs icon!???

How can this be?
Thanks Paul

Posted by Paul D'haene on January 22, 2008 at 05:20 AM PST #

Hi can you help me how to make languages/html/..html.nbs work well,i found it now work curect when i build the project.

Posted by li wei on March 17, 2008 at 09:27 PM PDT #

I am currently trying to create a new C-like language with code completion. So far I have tried using the COMPLETION keyword but whenever I use it with whitespace the completed word appears incomplete.

I am also having trouble creating semantically-aware completion (for example, give declared int variables where an int variable is expected).

Could you point me to a tutorial or to some documentation which could point me in the correct direction to implement code completion?

Thanks!

Posted by Francisco Laborde on January 16, 2009 at 09:10 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed

« November 2009
SunMonTueWedThuFriSat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
     
       
Today

Feeds

Search this blog

Links

Weblog menu

Today's referrers

Today's Page Hits: 6