Yuriy Chulovskyy
Yuriy Chulovskyy

Reputation: 163

Use ANTLR grammar for IntelliJ IDEA code highlighting plugins?

I use an ANTLRv4 grammar to parse my DSL. I would like to create a plugin to support code highlighting and code completion in IntelliJ IDEA for my DSL.

As far as I can tell, IntelliJ uses BNF and Flex formats for parsing.

Is it possible to:

  1. use an ANTLR grammar, or
  2. convert an ANTLR grammar to BNF and Flex ...

... to make an IntelliJ plugin for my DSL?

Upvotes: 5

Views: 2018

Answers (1)

David J.
David J.

Reputation: 32705

Updated on 2020-Dec-22

Question #1: Is it possible to directly use an ANTLR grammar to generate a JetBrains plugin for language support?

Yes, to some degree. It looks like the antlr4-intellij-adaptor library will help. I don't have firsthand experience. It describes itself as "A library to support the use of ANTLRv4 grammars for custom languages in IntelliJ-based IDEs plug-in development."

Just for clarification, a different tool, the ANTLRv4 Plugin for IntelliJ is designed to aid in the development of ANTLRv4 grammars. It does not support using an ANTLRv4 grammar to generate a lexer and parser for use by the JetBrains editors (e.g CLion, GoLand, IntelliJ, PyCharm, RubyMine, and so on).


Question #2: Is it possible to convert an ANTLR grammar to some other forms (e.g. BNF and Flex) which can be used to generate a JetBrains plugin for language support?

Yes, but this is a large topic. I would direct you to this Stack Overflow post: Are there tools to convert between ANTLR and other forms of BNF?


Related Tooling: You may find Grammar Kit by Jetbrains useful, it is "An IntelliJ IDEA plugin for language plugin developers."

Recommended Docs: Also, JetBrains provides extensive documentation on how to extend language support for its editors.

Upvotes: 3

Related Questions