From 05c17c6e0e8e5e9015da4d1396587c4af0ea09d3 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Sun, 10 Apr 2016 21:39:05 -0400 Subject: Removed old code that wasn't being used --- .../main/java/bjc/dicelang/IDiceExpression.java | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'dice-lang/src/main/java/bjc/dicelang/IDiceExpression.java') diff --git a/dice-lang/src/main/java/bjc/dicelang/IDiceExpression.java b/dice-lang/src/main/java/bjc/dicelang/IDiceExpression.java index c6aa0a7..16e1761 100644 --- a/dice-lang/src/main/java/bjc/dicelang/IDiceExpression.java +++ b/dice-lang/src/main/java/bjc/dicelang/IDiceExpression.java @@ -1,5 +1,7 @@ package bjc.dicelang; +import bjc.utils.funcutils.StringUtils; + /** * An expression for something that can be rolled like a polyhedral die * @@ -37,4 +39,37 @@ public interface IDiceExpression { public default boolean canOptimize() { return false; } + + /** + * Parse this node into an expression + * @param exp The string to convert to an expression + * + * @return The node in expression form + */ + static IDiceExpression toExpression(String exp) { + String literalData = exp; + + if (StringUtils.containsInfixOperator(literalData, "c")) { + String[] strangs = literalData.split("c"); + + return new CompoundDice(strangs); + } else if (StringUtils.containsInfixOperator(literalData, + "d")) { + /* + * Handle dice groups + */ + return ComplexDice.fromString(literalData); + } else { + try { + return new ScalarDie(Integer.parseInt(literalData)); + } catch (NumberFormatException nfex) { + UnsupportedOperationException usex = new UnsupportedOperationException( + "Found malformed leaf token " + exp); + + usex.initCause(nfex); + + throw usex; + } + } + } } \ No newline at end of file -- cgit v1.2.3