Jan (Hanz) Jancura's Blog

pageicon Thursday Mar 08, 2007

Languages Embedding (in GLF)

During the last month I was working on languages embedding mainly, so I have two screenshots. Languages embedding is not easy and there are many interesting issues. But it is a long story.

The first picture shows HTML with JavaScript and CSS inside a PHP file:



You can see that blocks of PHP code can break one token of other language (JavaScript). It means that you have to preprocess PHP file and connect all blocks of inner code, if you want correctly parse language embedded inside PHP.

Current version of GLF (Generic Languages Framework) supports three types of embedding:

1) Token based embedding: One token of outside language can be reparsed by some other language's parser. For example CSS in HTML. Definitions of both languages can be merged together in this case (theoretically). So, you can define one common tokenizer for both languages, and one grammar.

HTML tokens <token type, token text>:
<tag,"<script>">
<text,"a {\n  color: #454545;\n}">
<end_tag,"<\script>">
HTML text token in this example is replaced by several CSS tokens. Tokens of outside language are not broken. So you can parse outside language without any constraints.

2) Preprocessor (templates) like embedding: Outside language contains blocks of some other language. Borders between languages are recognized by some preprocessor. (PHP, Velocity, Freemaker, EJS, RHTML, ...). EJS (Phobos) example:


There are two kinds of JavaScript in this example - server side and client side. Output of server side JavaScript can generate blocks of client side JavaScript code :-)

3) Last possibility is importing definition of one GLF based language to another one, or to some state of outer language tokenizer. So you can import definition of HTML language to PHP language definition.

So, GLF definition of PHP looks like:
IMPORT:html {
    mimeType:"text/html2";
    state: "DEFAULT";
}

IMPORT:php {
    mimeType:"text/x-php2";
    start:( "" );
    background_color:"#EEEEBB";
}
The first import loads definition of HTML (with all HTML embedded languages) to default state of PHP tokenizer. And second import defines "template" language (blocks between "" should be parsed by php2 language). "text/x-php2" language defines structure of plain PHP.
Comments:

This project is a wonderful idea! I've been waiting for something like this for quite a while now. Is there any possibility that the formatting directives could go beyond just color selection and bold/italic/underline? For example, having the ability to specify a different font / font size for a method declaration, or a different indentation?

Posted by Mark M on March 31, 2007 at 11:20 PM PDT #

Theoretically, could the Token based embedding be used to style the inside of attributes? It would be nice if the value of an html style attribute would show up as a bit of embedded css.

Posted by David Thompson on April 18, 2007 at 11:04 AM PDT #

Hi, I am really keen on moving from Eclipse to Netbeans 6. But before I can do so, I need help getting the php and html language frameworks working. Also cvs+ssh, but I know that is for another place and time. A mini howto would be much appreciated. Thanks!

Posted by Steve van de Heuvel on June 18, 2007 at 03:33 PM PDT #

Would it be possible to get a NBS file for the base C/C++ support. The language I want to add Netbeans support for is basically a superset of C++ and if I could start at that point instead of recoding it that would be great.

Posted by ChessMess on September 18, 2007 at 03:04 PM PDT #

I'm writting a nbs file, and I got the message "string grammar rule not defined" what does it mean?

Posted by Ron King on October 19, 2007 at 08:01 PM PDT #

How to add preprocessing syntax? I'd like to parse it using a separate .nbs file, but it doesn't seem to be useful to add a mime-type or even an extension for this, so sth. like "IMPORT:preprocessing{use:"pre.nbs"...} would be fine ...

Posted by Peter on January 30, 2008 at 09:47 PM PST #

How to use "IMPORT" in GLF nbs file,I found that HTML.nbs file was now work currectly.Can you help me to solve the problem.

Posted by li wei on March 18, 2008 at 02:14 AM PDT #

If there isn't already, there really needs to be some sort of newsgroup for Schliemann support. This is a wonderful new facility for Netbeans, but I am heavily reliant on reverse-engineering .nbs files I find in the Netbeans source code. If there is already a special discussion group, please post a reference here so it can be easily found.

Wonderful facility, but documentation is somewhat limiting. I look forward to a book or book chapter! Thanks for your efforts!

Posted by jeremy faden on May 05, 2008 at 07:21 AM PDT #

I belatedly second jeremy faden's comment.

Schliemann is still alive and well, right? :(

Posted by Yi Ming Woo on January 27, 2009 at 02:22 PM PST #

Those interested in (Schliemann | building other language plugins for NetBeans) may want to read this thread:

http://www.nabble.com/Project-Schliemann-%21%21%21-to17507885.html#a17509937

Posted by Yi Ming Woo on January 29, 2009 at 10:29 AM PST #

Anyone know where i can get the language.nbs for php syntax in netbeans?
//built a plugin for asp classic and want to use the php one for a template since it is similar/jumps between html.

Thanks,

Posted by Miramar Design on July 23, 2009 at 10:19 PM PDT #

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: 12