Skip to content

Jetbrains IDE (Intellij IDEA, PyStorm, CLion, ...) support for Coco/R compiler generator grammar files

Notifications You must be signed in to change notification settings

azrdev/coco-idea-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Coco/R grammar support for Jetbrains IDEs

Plugin for Jetbrains IDEs to support grammar files (*.atg) of the Coco/R compiler generator. Check it out from Jetbrains' plugin repository.

Screenshot of v3

Implementation

Following the Custom Language Support Tutorial, the lexer is generated from Coco.flex using JFlex, and the parser from Coco.bnf using Grammar-Kit.

TODOs

  • language injection
    • configurable language and/or good guess
    • prefix & suffix as needed
    • file header
  • folding: comments, injected blocks (esp. at file start)

  • references: not resolved in IGNORE, COMMENTS, PRAGMAS

  • customizable syntax highlighting: Color Settings Page

    • syntax highlighting: different colors for keywords, charsets, tokens, productions
  • PRAGMAs in structure view

  • $CNF file header

  • code completion, templates, "new file" (template), build system integration, quick fix, code style, ...

Tutorial deficits

  • "register" occurs in plugin.xml
  • for references: methods from .bnf are delegated to psiImplUtilClass, if signature fits
  • bnf: methods(nonterminals)=[] are not resolved correctly in "attributes" header
  • bug in SimpleStructureViewModel.isAlwaysLeaf: element instanceof SimpleFile is always false, it should be treeElement.psiElement instanceof ...
  • PsiReference.resolve() is only called when you return a valid value from .rangeInsideHost() (which PsiReferenceBase does not do)

What may help understanding the tutorial:

howto language embedding, other plugins & forum posts

gitter.im Alexander Zolotov @zolotov 2017-08-15 09:17

You can properly lex/parse A language inside B language to get rid of injection A into B. We do so for CSS and JS in HTML, or for Python in SQL, so you can write JS in HTML and inject something into that JS. Take a look at com.intellij.psi.impl.source.tree.LazyParseablePsiElement and com.intellij.lexer.EmbeddedTokenTypesProvider (this one is for embedding into HTML)

https://github.com/bjansen/pebble-intellij/commit/72640eeddbb650204f45e9578581b2b1550319bb#diff-b576c185db1751b8f65142d839a73714

This thread about the Play! plugin1 explains the differences between the three possible embedding "types":

The last paragraph in Custom Language Tutorial/Lexer tells about mixing languages using chameleon tokens implementing ILazyParseableElementType, probably that's the method with multiple Psi files.

Footnotes

  1. For Play! see also https://groups.google.com/forum/#!topic/play-framework/fB-2SXtlYfc