How to highlight custom xml tag?



I want to develop a plugin to highlight the custom language which based on xml.

I chose the JFlex to implement, and I copy the flex code on intellij-community.

the code below:

But it still highlight when the xml tag is different, like:

I want to throw error when the tag is different or tag is invalid, but I don't know how :)

Any advice?


Comment actions Permalink

If your custom language is based on XML I'd recommend to reuse existing XML lexer/parser, etc.

You can add your language specific code highlighting/completion/etc. to IntelliIJ's XML support. Depending on what you want choose and implement corresponding extension points

Comment actions Permalink


Is there any demo or documents to introduce how to use extension points?

To be honest, I just begin to contact plug-in development,and have no idea about the extension points.

Comment actions Permalink

Well, I just use existing XML lexer/parser


Unfortunately, I got the same result ;)

But I have used some similar plugins, when I change an XML tag, the corresponding tag will be changed too.

What should I do base on existing XML lexer/parser.


Comment actions Permalink

Sorry, I'm afraid I don't fully understand what you've already done in your plugin and what you want to accomplish.

My answer was general: if your language is based on XML you should reuse IntelliJ's XML support. To add language specific highlighting/completion/whatever you should implement extension point(s) that fit your needs. To give more specific answers we need more specific questions and more detailed problem description.

Comment actions Permalink

I have a similar question. What's the starting point to write something similar to the Maven plugin support?

In our company we have a set of XML files with a custom file extension, which are extensively used in our internal tooling. We store these in our git repository, etc., so I would love to use an IntelliJ plugin to highlight, error-check, etc. these specific type of files.

So far, the Custom Language Support plugin and tutorial is very nice, but it assumes I'll use a BNF grammar and a lexer. I first thought, what the heck, let's use an existing XML BNF grammar, but I haven't found one that can be used with GrammarKit. But if I start searching about XML-based language, every single tutorial or question about this same issue ends up with the same answer: just use the DOM. The problem is: how do I get from the Custom Language support tutorial, which uses a BNF grammar, to a DOM based one?

The Maven plugin could be used as inspiration, but it's an extremely complicated project.


Comment actions Permalink


First of all, do you know that you may configure IDE to treat a file with custom extension as an XML file? See Settings (Preferences) | Editor | File Types.

Comment actions Permalink

Okay, after a long hiatus I'm revisiting this.

I'm sorry I wasn't clear at all about my requirements. The format I want to parse is not really XML: is a custom text template that contains XML fragments. 


some_custom_lang_var = blah, whatever
some_custom_lang_var2 = blah, whatever
some_custom_lang_var3 = blah, whatever









Now, all those XML elements or blocks are valid XML. The IntelliJ plugin even manages to correctly highlight them, but obviously the rest of the invalid XML is marked as such.

Is there a way to handle this, that doesn't involves creating a full blown XML parser / BNF / lexer / whatever intermixed with the custom language?

(I know this format is awful. Sadly, it is used extensively inside my organization, and there is tooling, services, etc. using it, so changing it is not feasible.)




Please sign in to leave a comment.