JetBrains / Grammar-Kit

Grammar files support & parser/PSI generation for IntelliJ IDEA
Other
715 stars 125 forks source link

Should we have comments in BNF? #337

Open ris58h opened 1 year ago

ris58h commented 1 year ago

PsiBuilder ignores whitespace and comment tokens but we have to use comment token in BNF just to have corresponding IElementType generated.

Even the official documentation for Custom Language has it as example: private item_ ::= (property|COMMENT|CRLF).

In my own grammar I've ended up with an 'orphan' rule and it works fine: private comment ::= COMMENT

If comment tokens doesn't add anything to a parser, shouldn't we stop using them as we do for whitespace tokens. Of course they are necessary for corresponding IElementType generation but we could use an 'orphan' rules for them or even have a predefined com.intellij.psi.TokenType.