Grammar-kit : psi tree for prefix expressions
Hi!
I'm trying to make a bnf and have such a problem with priority:
When I describe rules for prefix or unary not expressions like that
unary_not_expression ::= ("~"|"!") expression
psi tree for expression a = !b^c looks like it were a = !(b^c)
Changing order in rule
expression ::= xor_expression | unary_not_expression | … | primary_expression
doesn't help. By the way, there is the same problem here https://github.com/JetBrains/Grammar-Kit/blob/master/HOWTO.md in part 2.4 Compact expression parsing with priorities. Although there is such list of priorities for an example in this tutorial
// Expression root: expr// Operator priority table:// 0: BINARY(assign_expr)// 1: BINARY(plus_expr) BINARY(minus_expr)// 2: BINARY(mul_expr) BINARY(div_expr)// 3: PREFIX(unary_plus_expr) PREFIX(unary_min_expr)// 4: N_ARY(exp_expr)// 5: POSTFIX(ref_expr)// 6: ATOM(simple_ref_expr) ATOM(literal_expr) PREFIX(paren_expr)in fact in makes psi tree like expression were a = !(b^c).My solution was to write a rule like thatunary_not_expression ::= ("~"|"!") primary_expressionwhere rule for primary_expression isprimary_expression ::= parenthesized_expression | identifier | literalBut I don't like this solution, because primary_expression is listed in rule for expression and the whole bnf doesn't look good.Is there any other solution for that problem?.
请先登录再写评论。
Hi Liudmila!

Thanks for mentioning. There is indeed a bug in LiverPreviewParser which is now fixed in 1.1.10_1 release.
The generated parser doesn't suffer from this:
I've included your sample in Gramamr-Kit testData both for generated and LivePreview modes.

Here's the screenshot after the fix:
Message was edited by: Gregory Shrago