mirror of
https://github.com/apple/pkl.git
synced 2026-04-25 01:38:34 +02:00
Fix double unary minus (#697)
Fix an issue where doubly unary minus (e.g. `--1`) on int/float literals are incorrectly parsed as single unary minus.
This commit is contained in:
@@ -1869,12 +1869,12 @@ public final class AstBuilder extends AbstractAstBuilder<Object> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ExpressionNode visitUnaryMinusExpr(UnaryMinusExprContext ctx) {
|
public ExpressionNode visitUnaryMinusExpr(UnaryMinusExprContext ctx) {
|
||||||
var childExpr = visitExpr(ctx.expr());
|
var childCtx = ctx.expr();
|
||||||
if (childExpr instanceof IntLiteralNode || childExpr instanceof FloatLiteralNode) {
|
var childExpr = visitExpr(childCtx);
|
||||||
// negation already handled in child expr (see corresponding code)
|
if (childCtx instanceof IntLiteralContext || childCtx instanceof FloatLiteralContext) {
|
||||||
|
// negation already handled (see visitIntLiteral/visitFloatLiteral)
|
||||||
return childExpr;
|
return childExpr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return UnaryMinusNodeGen.create(createSourceSection(ctx), childExpr);
|
return UnaryMinusNodeGen.create(createSourceSection(ctx), childExpr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -141,6 +141,10 @@ examples {
|
|||||||
|
|
||||||
-1.2.abs
|
-1.2.abs
|
||||||
-x.abs
|
-x.abs
|
||||||
|
|
||||||
|
// https://github.com/apple/pkl/issues/650
|
||||||
|
--1.0
|
||||||
|
-(-1.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
["power"] {
|
["power"] {
|
||||||
|
|||||||
@@ -163,6 +163,10 @@ examples {
|
|||||||
-0b11.abs
|
-0b11.abs
|
||||||
local x = 4
|
local x = 4
|
||||||
-x.abs
|
-x.abs
|
||||||
|
|
||||||
|
// https://github.com/apple/pkl/issues/650
|
||||||
|
--1
|
||||||
|
-(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
["power"] {
|
["power"] {
|
||||||
|
|||||||
@@ -98,6 +98,8 @@ examples {
|
|||||||
["negation"] {
|
["negation"] {
|
||||||
-1.2
|
-1.2
|
||||||
-1.2
|
-1.2
|
||||||
|
1.0
|
||||||
|
1.0
|
||||||
}
|
}
|
||||||
["power"] {
|
["power"] {
|
||||||
27.98409999999999
|
27.98409999999999
|
||||||
|
|||||||
@@ -121,6 +121,8 @@ examples {
|
|||||||
-2
|
-2
|
||||||
-3
|
-3
|
||||||
-4
|
-4
|
||||||
|
1
|
||||||
|
1
|
||||||
}
|
}
|
||||||
["power"] {
|
["power"] {
|
||||||
16
|
16
|
||||||
|
|||||||
Reference in New Issue
Block a user