fix some issues with negative numbers

This commit is contained in:
xvrl 2013-03-07 14:10:46 -08:00
parent e4de6f3deb
commit a79c9ec183
1 changed files with 12 additions and 6 deletions

View File

@ -100,7 +100,7 @@ IDENT : (LETTER)(LETTER | DIGIT | '_')* ;
QUOTED_STRING : '\'' ( ESC | ~'\'' )*? '\'' ;
ESC : '\'' '\'';
NUMBER: ('+'|'-')?DIGIT*'.'?DIGIT+(EXPONENT)?;
NUMBER: DIGIT*'.'?DIGIT+(EXPONENT)?;
EXPONENT: ('e') ('+'|'-')? ('0'..'9')+;
fragment DIGIT : '0'..'9';
fragment LETTER : 'a'..'z' | 'A'..'Z';
@ -177,11 +177,17 @@ multiplyExpression returns [PostAggregator p]
unaryExpression returns [PostAggregator p]
: MINUS e=unaryExpression {
$p = new ArithmeticPostAggregator(
"-"+$e.p.getName(),
"*",
Lists.newArrayList($e.p, new ConstantPostAggregator("-1", -1.0))
);
if($e.p instanceof ConstantPostAggregator) {
ConstantPostAggregator c = (ConstantPostAggregator)$e.p;
double v = c.getConstantValue().doubleValue() * -1;
$p = new ConstantPostAggregator(Double.toString(v), v);
} else {
$p = new ArithmeticPostAggregator(
"-"+$e.p.getName(),
"*",
Lists.newArrayList($e.p, new ConstantPostAggregator("-1", -1.0))
);
}
}
| PLUS e=unaryExpression { $p = $e.p; }
| primaryExpression { $p = $primaryExpression.p; }