-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow treating all number literals as BigDecimals to avoid NumberForm…
…atExceptions (#503) * enhance Parser Options: add possibility to treat all number literals as BigDecimals * code style fix * update docs - add literalNumbersAsBigDecimals
- Loading branch information
Showing
6 changed files
with
119 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...src/main/java/com/mitchellbosecke/pebble/node/expression/LiteralBigDecimalExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* This file is part of Pebble. | ||
* | ||
* Copyright (c) 2014 by Mitchell Bösecke | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
package com.mitchellbosecke.pebble.node.expression; | ||
|
||
import com.mitchellbosecke.pebble.extension.NodeVisitor; | ||
import com.mitchellbosecke.pebble.template.EvaluationContextImpl; | ||
import com.mitchellbosecke.pebble.template.PebbleTemplateImpl; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public class LiteralBigDecimalExpression implements Expression<BigDecimal> { | ||
|
||
private final BigDecimal value; | ||
private final int lineNumber; | ||
|
||
public LiteralBigDecimalExpression(BigDecimal value, int lineNumber) { | ||
this.value = value; | ||
this.lineNumber = lineNumber; | ||
} | ||
|
||
@Override | ||
public void accept(NodeVisitor visitor) { | ||
visitor.visit(this); | ||
} | ||
|
||
@Override | ||
public BigDecimal evaluate(PebbleTemplateImpl self, EvaluationContextImpl context) { | ||
return this.value; | ||
} | ||
|
||
@Override | ||
public int getLineNumber() { | ||
return this.lineNumber; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.value.toString(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters