Fix exponent parsing, remove impossible (?) case

(cherry picked from commit 02da42f90b8a912047c00479df789563853cfeee)
This commit is contained in:
Octavia Togami 2020-02-25 17:16:00 -08:00 committed by MattBDev
parent 57154224dc
commit f1fb51f748
2 changed files with 6 additions and 10 deletions

View File

@ -60,10 +60,11 @@ DEFAULT : 'default' ;
fragment DIGIT : [0-9] ; fragment DIGIT : [0-9] ;
fragment SIGN : [+-] ; fragment SIGN : [+-] ;
fragment EXP_CHAR : [eE] ; 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. // 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_]* ; ID : [A-Za-z] [0-9A-Za-z_]* ;

View File

@ -612,14 +612,9 @@ class CompilingVisitor extends ExpressionBaseVisitor<MethodHandle> {
@Override @Override
public MethodHandle visitConstantExpression(ExpressionParser.ConstantExpressionContext ctx) { public MethodHandle visitConstantExpression(ExpressionParser.ConstantExpressionContext ctx) {
try { return ExpressionHandles.dropData(
return ExpressionHandles.dropData( MethodHandles.constant(Double.class, Double.parseDouble(ctx.getText()))
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());
}
} }
@Override @Override