Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xtext based language within Intellij Idea

I want to make a plugin for a language for the Intellij Idea IDE. The language has been developped using Eclipse Xtext and is open source. A plugin already exists for Eclipse.

My goal is to port this language to Intellij Idea. I want to be able to use Intellij to create source files, to have the specific syntax highlighting and to be able to compile and run programs written with this language.

Is there a simple way to generate the Intellij Idea plugin using the Xtext project?

If not is there an efficient solution to be able to have the specific syntax highlighting in Intellij? (an automatic way if possible, I would prefer not rewriting everything everytime the Xtext project is updated)

like image 959
Fitz Avatar asked Nov 18 '18 15:11

Fitz


Video Answer


1 Answers

Short answer

Yes, with a bit of work.

Long Answer

Sadly, Xtext uses antlr in the background and IntelliJ use their own grammar kit based on Parsing Expression Grammars. As such, the parsing and editor code generated by XText, as you might have guessed, will not work.

In order to get your language working in IntelliJ you will need to:

  1. Create grammar *.bnf file
  2. Generate lexer *.flex file, possibly tweak it and then run JFlex generator
  3. Implement helper classes to provide, among others, file recognition via file extension, syntax highlighting, color settings page, folding, etc.

The *.flex file is generated from the bnf. Luckily, most of the classes in step 3 follow a very similar structure so they can be easily generated (more on that later). So basically, if you manage to generate the *.bnf file, you are 80% there.

Although from different technologies, the syntax of bnf files is very similar to XText files. I recently migrated some antlr grammars to IntelliJ's bnf and I had to do very small changes. Thus, it should be possible to autogenerate the bnf files from your XText ones.

That brings me back to point 3. Using XTend, Epsilon's EGL, or similar, it would be easy to generate all the boiler plate classes. As part of the migration I mentioned before I also did this. I am in the process of making the code public, so I will post it here when done and add some details.

like image 70
Arcanefoam Avatar answered Nov 15 '22 09:11

Arcanefoam