From f1fb51f7489be3668352df7f5a36e0c29e06b038 Mon Sep 17 00:00:00 2001 From: Octavia Togami Date: Tue, 25 Feb 2020 17:16:00 -0800 Subject: [PATCH] Fix exponent parsing, remove impossible (?) case (cherry picked from commit 02da42f90b8a912047c00479df789563853cfeee) --- .../antlr/com/sk89q/worldedit/antlr/Expression.g4 | 5 +++-- .../internal/expression/invoke/CompilingVisitor.java | 11 +++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/worldedit-core/src/main/antlr/com/sk89q/worldedit/antlr/Expression.g4 b/worldedit-core/src/main/antlr/com/sk89q/worldedit/antlr/Expression.g4 index 505ce3062..2c2e9497c 100644 --- a/worldedit-core/src/main/antlr/com/sk89q/worldedit/antlr/Expression.g4 +++ b/worldedit-core/src/main/antlr/com/sk89q/worldedit/antlr/Expression.g4 @@ -60,10 +60,11 @@ DEFAULT : 'default' ; fragment DIGIT : [0-9] ; fragment SIGN : [+-] ; fragment EXP_CHAR : [eE] ; -fragment DECIMAL : '.' DIGIT+ ( EXP_CHAR SIGN? DIGIT+ )? ; +fragment EXPONENT : EXP_CHAR SIGN? DIGIT+ ; +fragment DECIMAL : '.' DIGIT+ ; // All numbers are treated the same. No int/dec divide. -NUMBER : ( DIGIT+ DECIMAL? | DECIMAL ) ; +NUMBER : ( DIGIT+ DECIMAL? | DECIMAL ) EXPONENT? ; ID : [A-Za-z] [0-9A-Za-z_]* ; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/invoke/CompilingVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/invoke/CompilingVisitor.java index ac8a1308d..f7daa16be 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/invoke/CompilingVisitor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/invoke/CompilingVisitor.java @@ -612,14 +612,9 @@ class CompilingVisitor extends ExpressionBaseVisitor { @Override public MethodHandle visitConstantExpression(ExpressionParser.ConstantExpressionContext ctx) { - try { - return ExpressionHandles.dropData( - MethodHandles.constant(Double.class, Double.parseDouble(ctx.getText())) - ); - } catch (NumberFormatException e) { - // Rare, but might happen, e.g. if too many digits - throw ExpressionHelper.evalException(ctx, "Invalid constant: " + e.getMessage()); - } + return ExpressionHandles.dropData( + MethodHandles.constant(Double.class, Double.parseDouble(ctx.getText())) + ); } @Override