I am trying to write a parser for the D programming language using grammar-kit and have made good progress, but I am having an issue with their specification for expressions.
Their language spec specifies that expressions are like this:
Expression ::= CommaExpression
CommaExpression ::= AssignExpression ( "," CommaExpression)?
AssignExpression ::= ConditionalExpxression | (ConditionalExpression "=" AssignExpression) | // ...
ConditionalExpression ::= OrOrExpression | (OrOrExpression "?" Expression ":" ConditionalExpression)
... and like twenty other downward expressions until it reaches...
PrimaryExpression ::= INTEGER_LITERAL | IDENTIFIER | // ...
This means that, for something as simple as this:
int x = 0;
, the content to the right of the assignment operator and before the semicolon, (literally just the zero), has about twenty nested levels deep of PSI elements. Is there some way I can have a single root psi element (Expression) that has a string identifier on it corresponding to the type of expression it contains? Or does somebody know a better solution to this?