Skip to content

Commit e10c8ed

Browse files
committed
Hot fix
1 parent 3a6f005 commit e10c8ed

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

src/main/java/parser/TreeMappings.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,25 +317,29 @@ fun org.antlr.v4.runtime.Token.toToken(): Token =
317317
DEC -> Token(TokenCode.MinusMinus)
318318
VAR -> Token(TokenCode.Var)
319319
BANG -> Token(TokenCode.Negation)
320+
TILDE -> Token(TokenCode.Tilde)
320321
else -> throw Exception("unsupported token: $text ($type)")
321322
}
322323

323324
fun CompoundName.toExpression(): Expression = SimpleReference(this)
324325

325326
fun ExpressionContext.toBinaryExpression(): Binary? {
326-
val expr0 = expression(0)?.toExpression()
327-
val expr1 = expression(1)?.toExpression()
327+
val weakExpr0 = expression(0)
328+
val weakExpr1 = expression(1)
328329
val operand = terminal(0)?.symbol
329-
return if (expr0 != null && expr1 != null && operand != null)
330+
return if (weakExpr0 != null && weakExpr1 != null && operand != null) {
331+
val expr0 = weakExpr0.toExpression()
332+
val expr1 = weakExpr1.toExpression()
330333
Binary(expr0, expr1, operand.toToken())
331-
else
334+
} else
332335
null
333336
}
334337

335338
fun ExpressionContext.toUnaryPrefixPostfix(): Expression? {
336-
val expr = expression(0)?.toExpression()
339+
val weakExpr = expression(0)
337340
val operand = terminal(0)?.symbol
338-
return if (expr != null && operand != null) {
341+
return if (weakExpr != null && operand != null && childCount == 2) {
342+
val expr = weakExpr.toExpression()
339343
if (prefix != null) {
340344
UnaryPrefix(operand.toToken(), expr)
341345
} else if (postfix != null) {

0 commit comments

Comments
 (0)