diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2017-02-05 07:02:45 -0500 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2017-02-05 07:02:45 -0500 |
| commit | 186b9131d46d886c98316e5b582e0cdd734a5024 (patch) | |
| tree | 5a81a9163817f1b4cd9948a57dc9569d975bc38f /dice-lang/src/bjc/dicelang/IDiceExpression.java | |
| parent | e7a7cf10e2e9e05a6b12fd7c4d8d0ff2146901d9 (diff) | |
Cleanup
Diffstat (limited to 'dice-lang/src/bjc/dicelang/IDiceExpression.java')
| -rw-r--r-- | dice-lang/src/bjc/dicelang/IDiceExpression.java | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/dice-lang/src/bjc/dicelang/IDiceExpression.java b/dice-lang/src/bjc/dicelang/IDiceExpression.java index acb1d4d..9d29960 100644 --- a/dice-lang/src/bjc/dicelang/IDiceExpression.java +++ b/dice-lang/src/bjc/dicelang/IDiceExpression.java @@ -33,6 +33,8 @@ public interface IDiceExpression { static IDiceExpression toExpression(String expression) { String literalData = expression; + String diceMatcher = "\\Ad\\d+\\Z"; + if (StringUtils.containsInfixOperator(literalData, "c")) { // Parse a compound die String[] strangs = literalData.split("c"); @@ -41,7 +43,7 @@ public interface IDiceExpression { } else if (StringUtils.containsInfixOperator(literalData, "d")) { // Handle groups of similiar dice return ComplexDice.fromString(literalData); - } else if (literalData.matches("\\Ad\\d+\\Z")) { + } else if (literalData.matches(diceMatcher)) { // Handle people who put 'd6' instead of '1d6' return new Die(Integer.parseInt(literalData.substring(1))); } else { @@ -50,7 +52,8 @@ public interface IDiceExpression { return new ScalarDie(Integer.parseInt(literalData)); } catch (NumberFormatException nfex) { UnsupportedOperationException usex = new UnsupportedOperationException( - "Found malformed leaf token " + expression); + "Found malformed leaf token " + expression + ". Floating point numbers " + + "are not supported."); usex.initCause(nfex); @@ -88,4 +91,4 @@ public interface IDiceExpression { * @return The result of rowing the dice */ public int roll(); -}
\ No newline at end of file +} |
