Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » Extending the HTML Editor(Add Syntax-Highlight and Code-Assist for template languages)
Extending the HTML Editor [message #676047] Thu, 02 June 2011 15:50 Go to next message
Robert Gruendler is currently offline Robert GruendlerFriend
Messages: 66
Registered: June 2011
Member
Hi,

sorry for crossposting, but i thought i'd create a separate subject instead of hijacking an existing thread.

i'm trying to extend the html editor to provide syntax highlighting for a templating language which looks like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
  <head>
    <title>My Webpage</title>
  </head>
  <body>
    <ul id="navigation">
    {% for item in navigation %}
      <li><a href="{{ item.href }}">{{ item.caption }}</a></li>
    {% endfor %}
    </ul>

    <h1>My Webpage</h1>
    {{ a_variable }}
  </body>
</html>


What i've found out so far is for that to work i need to do the following:

1. Declare a org.eclipse.wst.sse.core.modelHandler
2. In that ModelHandler, implement "getDocumentLoader()" and return a custom DocumentLoader, which extends "HTMLDocumentLoader".
3. In the DocumentLoader, override "getParser()" and return a custom RegionParser (which in turn extends XMLSourceParser)
4. The SourceParser overrides the "getTokenizer()" method.

I assume that the Tokenizer is responsible for detecting the Tokens in the InputString - which are the tokens of the custom templating languages grammar.

This is where i'm stuck. The Tokenizer which is returned by the XMLSourceParser is a XMLTokenizer. From what i could find out, the source code
of the XMLTokenizer has been generated by jflex - from a file like

org.eclipse.wst.sse.core/DevTimeSupport/SedModel/HTMLTokenizer/devel/XMLTokenizer.jflex

My question now is: To add syntax-highlighting for a templating engine which adds non-xml structures to the document, do i need to specify such a .jflex
grammar and generate the corresponding tokenizer from this "jflex" library?

Is there probably a simpler solution for this problem? I've found the org.eclipse.wst.sse.ui.semanticHighlighting extension point, but i think this works only for language constructs already known by WTP.

thanks!
Re: Extending the HTML Editor [message #676129 is a reply to message #676047] Thu, 02 June 2011 22:23 Go to previous messageGo to next message
Robert Gruendler is currently offline Robert GruendlerFriend
Messages: 66
Registered: June 2011
Member
I've found some more info about this topic, apperently there's no way to hook into the tokenizing process, which means one would re-implement the whole thing.

eclipse.org/forums/index.php?t=msg&goto=228286&



This post is quite old though, so i still have some slight hope that the semanticHighlighting extension could be used for that purpose.

The only project i could find which does something like this based on WTP tools is the smartypdt plugin, and it also implements a custom tokenizer using the jflex library:


code.google.com/p/smartypdt/source/browse/trunk/org.eclipse.php.smarty.core/src/org/eclipse/php/smarty/internal/core/documentModel/parser/SmartyTokenizer.java

[Updated on: Thu, 02 June 2011 22:24]

Report message to a moderator

Re: Extending the HTML Editor [message #677216 is a reply to message #676047] Tue, 07 June 2011 20:42 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4434
Registered: July 2009
Senior Member

On 6/2/2011 11:50 AM, Robert Gruendler wrote:
> My question now is: To add syntax-highlighting for a templating engine
> which adds non-xml structures to the document, do i need to specify such
> a .jflex
> grammar and generate the corresponding tokenizer from this "jflex" library?
>
> Is there probably a simpler solution for this problem? I've found the
> org.eclipse.wst.sse.ui.semanticHighlighting extension point, but i think
> this works only for language constructs already known by WTP.

There's no requirement that you use JFlex, we only did so because it's
well documented and using a generator produces faster lexers. But
you're going to have to accept that supporting a different syntax means
using a different grammar, even if it starts with one we already provide.

--
Nitin Dahyabhai
Eclipse WTP Source Editing and JSDT
IBM Rational


_
Nitin Dahyabhai
Eclipse Web Tools Platform
Re: Extending the HTML Editor [message #677260 is a reply to message #677216] Tue, 07 June 2011 23:11 Go to previous message
Robert Gruendler is currently offline Robert GruendlerFriend
Messages: 66
Registered: June 2011
Member
i see, so i can use the grammar from the xml editor as a starting point and extend that.

thanks a lot!
Previous Topic:How to validate XML files without specifying xmlns namespace attribute in the root element?
Next Topic:Weblogic Server Plugin in Eclipse Helios Service Release 2
Goto Forum:
  


Current Time: Sat Apr 20 03:13:01 GMT 2024

Powered by FUDForum. Page generated in 0.02879 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top