diff options
| author | bjculkin <bjculkin@mix.wvu.edu> | 2017-03-21 14:08:50 -0400 |
|---|---|---|
| committer | bjculkin <bjculkin@mix.wvu.edu> | 2017-03-21 14:08:50 -0400 |
| commit | a7e84eea087a35721a971e827149f0ca5fba4676 (patch) | |
| tree | fbb7b0e5e402fb2a4aae5614c51f1955640a09e8 /dice-lang/src/bjc/dicelang/v1/IDiceExpression.java | |
| parent | 94913a2fccff9e80f84ac477c2020bd7c7b1833a (diff) | |
Remove version 1 files
Remove the old, not used version 1 files from the repository. Check the
history if you care about them.
Diffstat (limited to 'dice-lang/src/bjc/dicelang/v1/IDiceExpression.java')
| -rw-r--r-- | dice-lang/src/bjc/dicelang/v1/IDiceExpression.java | 93 |
1 files changed, 0 insertions, 93 deletions
diff --git a/dice-lang/src/bjc/dicelang/v1/IDiceExpression.java b/dice-lang/src/bjc/dicelang/v1/IDiceExpression.java deleted file mode 100644 index 9de7553..0000000 --- a/dice-lang/src/bjc/dicelang/v1/IDiceExpression.java +++ /dev/null @@ -1,93 +0,0 @@ -package bjc.dicelang.v1; - -import bjc.utils.parserutils.TokenUtils; - -/** - * An expression for something that can be rolled like a polyhedral die - * - * @author ben - * - */ -@FunctionalInterface -public interface IDiceExpression { - /** - * Parse a string into an expression. - * - * It can accept the following types of expressions - * <ul> - * <li>Simple integers - '2'</li> - * <li>Simple dice - 'd6'</li> - * <li>Groups of simple dice - '2d6'</li> - * <li>Number concatenation - '2c6'</li> - * <li>Dice concatenation - '1d10c1d10</li> - * </ul> - * - * Dice concatenation is like using 2 d10s to emulate a d100, so instead - * of adding them, it reads them side by side. - * - * @param expression - * The string to convert to an expression - * - * @return The string, converted into expression form - */ - static IDiceExpression toExpression(String expression) { - String literalData = expression; - - String diceMatcher = "\\Ad\\d+\\Z"; - - if(TokenUtils.containsInfixOperator(literalData, "c")) { - // Parse a compound die - String[] strangs = literalData.split("c"); - - return new CompoundDice(strangs); - } else if(TokenUtils.containsInfixOperator(literalData, "d")) - // Handle groups of similiar dice - return ComplexDice.fromString(literalData); - else if(literalData.matches(diceMatcher)) - // Handle people who put 'd6' instead of '1d6' - return new Die(Integer.parseInt(literalData.substring(1))); - else { - // Parse a scalar number - try { - return new ScalarDie(Integer.parseInt(literalData)); - } catch(NumberFormatException nfex) { - UnsupportedOperationException usex = new UnsupportedOperationException( - "Found malformed leaf token " + expression + ". Floating point numbers " - + "are not supported."); - - usex.initCause(nfex); - - throw usex; - } - } - } - - /** - * Check if this expression can be optimized to a scalar value - * - * @return Whether or not this expression can be optimized to a scalar - * value - */ - public default boolean canOptimize() { - return false; - } - - /** - * Optimize this expression to a scalar value - * - * @return This expression, optimized to a scalar value - * - * @throws UnsupportedOperationException - * if this type of expression can't be optimized - */ - public default int optimize() { - throw new UnsupportedOperationException("Can't optimize this type of expression"); - } - - /** - * Roll the dice once - * - * @return The result of rowing the dice - */ - public int roll(); -} |
