Custom language with several not backward-compatible versions of syntax

Answered

Hi everyone.

I am contributing to the Intellij plugin for the AEM platform. 

I am implementing custom language for HTL (Sightly) based on HTML.

However, it provides 2 actual versions: 1.3 and 1.4. In 1.4 they introduced new operators for expression language. It requires changes to my parser and lexer to support 'in' operator in language. For completion I can implement check for HTL language version, but for operator I can't understand how to do it.

As a workaround, I can modify bnf and lexer to support new relational operator and implement Annotator to mark it as not supported in the older version. For completion, documentation and other stuff I am going to inject some conditions to check project HTL version.

Can you please suggest another approach how can I easily build custom language syntax depending on HTL version? Maybe some mixins, etc...

2 comments
Comment actions Permalink

You can take a look at Java language support, starting from com.intellij.lang.java.parser.JavaParserUtil#getLanguageLevel. It allows even setting language level on per-file basis. But all of this adds huge complexity - if there's only minor differences I'd rather take the approach you mentioned above and do the highlighting only instead of putting all knowledge into lexer/parser.

1
Comment actions Permalink

Yes, I am totally agree with you. In new language syntax there is only 1 syntax change, which I can annotate with error. I quickly checked com.intellij.lang.java.parser.JavaParserUtil#getLanguageLevel and understood that I am not ready to re-implement a lot of places in the code. 

Completion, annotating and documentation will work depending on selected HTL language version.

Thank you for your help. 

0

Please sign in to leave a comment.