Fix exponent parsing, remove impossible (?) case

(cherry picked from commit 02da42f90b8a912047c00479df789563853cfeee)
Dieser Commit ist enthalten in:
Octavia Togami 2020-02-25 17:16:00 -08:00 committet von MattBDev
Ursprung 57154224dc
Commit f1fb51f748
2 geänderte Dateien mit 6 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -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_]* ;

Datei anzeigen

@ -612,14 +612,9 @@ class CompilingVisitor extends ExpressionBaseVisitor<MethodHandle> {
@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