Highlighting for laguage which has extended javascript
Hi,
I am doing syntax highlighting for language wich has the syntax of javascript. I followed the http://devnet.jetbrains.com/message/5450284 tutorial.
I used fileviewprovider and idea ultimate version.
That language is is built extending javascript. Which means it has no symbol to differentiate that language and javascript.
So there is no way to start a new state in the lexer called
<JAVASCRIPT>
example syntax :
///////////////////////////////////////////////////////////////////////
<%
print("<html><body>");
print("Method : " + request.getMethod() + "<br/>");
print("Protocol : " + response.status+ "<br/>");
print("User-Agent : " + request.getHeader("User-Agent"));
print("</body></html>");
session.get("new");
application.remove('bar');
var w = "ede";
%>
//////////////////////////////////////////////////////
How this should be done?
Thanks.!!
Please sign in to leave a comment.
Hi,
I feel that I can do that with writing java script library which contains relevent objects and methods.
For an example
I can create request object and getMethod() method in javascript which I can import.
So what I need is just to enable javascript in <% %> tags
Eg:
start of file...................................................................
SHOULD NOT ENABLE JAVASCRIPT
<%
PURE JAVASCRIPT CODE
%>
SHOULD NOT ENABLE JAVASCRIPT
end of file........................................................................
Your kind help is really appreciated.
Thanks..!!
Have a look at ILazyParseableElementType. I'm not totoally sure - but perhaps you can just create a subclass of it which sets the language to Javascript and use an instance of that as the element type of the token returned by your lexer.
There is also language injection, though I am not very familiar with how to implement it.
Hi,
Thank you for the reply. I did syntax higlighting for javascript in the given tags. It seems that I need to implement the html at out of the given tags.
I got the my syntax highlighting done . Which means
//////////////////////////////////////////////////////////////////////
html
<% javascript %>
html
//////////////////////////////////////////////////////
Is there any good example of implementation of FileViewProvider for this purpose?
Hi,
I could manage to highlight javascript with the support of html outside.
Though the autocompletion of html is possible syntax of html do not get highlighted.
Screenshot is attatched.
Below is my fileViewProvider class.
code 1:
And relevent Token types class(refer : JaggeryTokenTypes.TEMPLATE_DATA_JAVASCRIPT) would be as follows.
code 2:
And also As you may think, If I change the(please refer Code 1 red coloured part)
code 3:
else if(lang == StdFileTypes.HTML.getLanguage()){
return LanguageParserDefinitions.INSTANCE.forLanguage(lang).createFile(this);
}
to
code 4:
I do not get the autocompletion even.
Can somebdy explain me this behaviour with how fileviewprovider works??
Thank You..!!
Attachment(s):
Screenshot from 2012-09-18 14:24:30.png