diff options
| author | bjcul <bjcul@192.168.1.26> | 2022-09-27 19:15:16 -0400 |
|---|---|---|
| committer | bjcul <bjcul@192.168.1.26> | 2022-09-27 19:15:16 -0400 |
| commit | e151e8490ed40231399618bf2dc4204c2ce99a82 (patch) | |
| tree | dce61b6e1a7f20bcba8411d412c83692e6019ed8 | |
| parent | da0b133cedf9fe4e464aadad1a451dacbf4d2b30 (diff) | |
Merge branch 'master' of git@github.com:bculkin2442/dice-lang.git
8 files changed, 58 insertions, 46 deletions
diff --git a/base/.settings/org.eclipse.jdt.core.prefs b/base/.settings/org.eclipse.jdt.core.prefs index cf2cd45..aeacc3c 100644 --- a/base/.settings/org.eclipse.jdt.core.prefs +++ b/base/.settings/org.eclipse.jdt.core.prefs @@ -2,7 +2,6 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 org.eclipse.jdt.core.compiler.compliance=17 org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled -org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.source=17 diff --git a/base/src/bjc/dicelang/expr/ExprREPL.java b/base/src/bjc/dicelang/expr/ExprREPL.java index 7cc53ee..f499c3b 100644 --- a/base/src/bjc/dicelang/expr/ExprREPL.java +++ b/base/src/bjc/dicelang/expr/ExprREPL.java @@ -24,6 +24,7 @@ public class ExprREPL { final Lexer lex = new Lexer(); /* Prepare our input source. */ + @SuppressWarnings("resource") final Scanner scan = new Scanner(System.in); /* Read initial command. */ diff --git a/base/src/module-info.java b/base/src/module-info.java index b3df025..4b3f019 100644 --- a/base/src/module-info.java +++ b/base/src/module-info.java @@ -1,3 +1,9 @@ +/** + * A language for rolling dice. + * + * @author bjcul + * + */ module dicelang.base { exports bjc.dicelang.cli; exports bjc.dicelang.eval; @@ -6,10 +12,10 @@ module dicelang.base { exports bjc.dicelang.expr; exports bjc.dicelang.util; - requires bjc.utils; - requires dicelang.dice; - requires dicelang.scl; - requires esodata; + requires transitive bjc.utils; + requires transitive dicelang.dice; + requires transitive dicelang.scl; + requires transitive esodata; requires guava; requires java.logging; requires jline; diff --git a/dice/src/example/java/bjc/dicelang/neodice/DieBoxCLI.java b/dice/src/example/java/bjc/dicelang/neodice/DieBoxCLI.java index 2c67e7f..edb7e5f 100644 --- a/dice/src/example/java/bjc/dicelang/neodice/DieBoxCLI.java +++ b/dice/src/example/java/bjc/dicelang/neodice/DieBoxCLI.java @@ -241,7 +241,7 @@ public class DieBoxCLI { } } - private DieBoxException handleUnknownCommand(String command) { + private static DieBoxException handleUnknownCommand(String command) { StringBuilder msg = new StringBuilder("Unknown command "); msg.append(command); msg.append("."); @@ -255,7 +255,7 @@ public class DieBoxCLI { return new DieBoxException(msg.toString()); } - private StatementValue parseActualLiteral(String litText) { + private static StatementValue parseActualLiteral(String litText) { if (INT_PATTERN.matcher(litText).matches()) { try { int val = Integer.parseInt(litText); @@ -266,9 +266,9 @@ public class DieBoxCLI { "Improper integer literal (%s)", litText); } - } else { - throw new DieBoxException("Unknown literal format (%s)", - litText); } + + throw new DieBoxException("Unknown literal format (%s)", + litText); } }
\ No newline at end of file diff --git a/dice/src/example/java/bjc/dicelang/neodice/commands/PolyhedralDieCommand.java b/dice/src/example/java/bjc/dicelang/neodice/commands/PolyhedralDieCommand.java index e0f66b1..ed74507 100644 --- a/dice/src/example/java/bjc/dicelang/neodice/commands/PolyhedralDieCommand.java +++ b/dice/src/example/java/bjc/dicelang/neodice/commands/PolyhedralDieCommand.java @@ -18,24 +18,24 @@ public class PolyhedralDieCommand implements Command { public StatementValue execute(Iterator<String> words, DieBoxCLI state) { if (!words.hasNext()) { throw new DieBoxException("Number of sides to polyhedral-die must be provided"); - } else { - StatementValue sideValue = state.runStatement(words); + } + + StatementValue sideValue = state.runStatement(words); + + if (sideValue.type == INTEGER) { + int numSides = ((IntegerStatementValue)sideValue).value; + + if (numSides < 0) throw new DieBoxException("Number of sides to polyhedral-die was not valid (must be less than 0, was %d)", numSides); + + Die<StatementValue> die = Die + .polyhedral(numSides) + .transform(IntegerStatementValue::new); - if (sideValue.type == INTEGER) { - int numSides = ((IntegerStatementValue)sideValue).value; - - if (numSides < 0) throw new DieBoxException("Number of sides to polyhedral-die was not valid (must be less than 0, was %d)", numSides); - - Die<StatementValue> die = Die - .polyhedral(numSides) - .transform(IntegerStatementValue::new); - - return new DieStatementValue(INTEGER, die); - } else { - throw new DieBoxException("Number of sides to polyhedral-die wasn't an integer (was %s, of type %s)", - sideValue, sideValue.type); - } + return new DieStatementValue(INTEGER, die); } + + throw new DieBoxException("Number of sides to polyhedral-die wasn't an integer (was %s, of type %s)", + sideValue, sideValue.type); } @Override diff --git a/dice/src/example/java/bjc/dicelang/neodice/commands/RollCommand.java b/dice/src/example/java/bjc/dicelang/neodice/commands/RollCommand.java index cec7c48..275c53e 100644 --- a/dice/src/example/java/bjc/dicelang/neodice/commands/RollCommand.java +++ b/dice/src/example/java/bjc/dicelang/neodice/commands/RollCommand.java @@ -18,26 +18,26 @@ public class RollCommand implements Command { public StatementValue execute(Iterator<String> words, DieBoxCLI state) { if (!words.hasNext()) { throw new DieBoxException("Roll must be provided an argument to roll"); - } else { - StatementValue toRoll = state.runStatement(words); + } + + StatementValue toRoll = state.runStatement(words); + + if (toRoll.type == DIE) { + DieStatementValue die = (DieStatementValue) toRoll; + + return die.value.roll(state.rng); + } else if (toRoll.type == DIEPOOL) { + DiePoolStatementValue pool = (DiePoolStatementValue) toRoll; - if (toRoll.type == DIE) { - DieStatementValue die = (DieStatementValue) toRoll; - - return die.value.roll(state.rng); - } else if (toRoll.type == DIEPOOL) { - DiePoolStatementValue pool = (DiePoolStatementValue) toRoll; - - StatementValue[] values = pool.value - .roll(state.rng) - .toArray((sz) -> new StatementValue[sz]); - - return new ArrayStatementValue<>(pool.elementType, - values); - } else { - throw new DieBoxException("Roll was provided something that wasn't rollable (only DIE and DIEPOOL objects are rollable) (was %s, of type %s)", - toRoll, toRoll.type); - } + StatementValue[] values = pool.value + .roll(state.rng) + .toArray((sz) -> new StatementValue[sz]); + + return new ArrayStatementValue<>(pool.elementType, + values); + } else { + throw new DieBoxException("Roll was provided something that wasn't rollable (only DIE and DIEPOOL objects are rollable) (was %s, of type %s)", + toRoll, toRoll.type); } } diff --git a/dice/src/example/java/bjc/dicelang/neodice/statements/DiePoolStatementValue.java b/dice/src/example/java/bjc/dicelang/neodice/statements/DiePoolStatementValue.java index 114475c..171dac6 100644 --- a/dice/src/example/java/bjc/dicelang/neodice/statements/DiePoolStatementValue.java +++ b/dice/src/example/java/bjc/dicelang/neodice/statements/DiePoolStatementValue.java @@ -7,7 +7,7 @@ import java.util.*; import bjc.dicelang.neodice.*; /** - * A StatementValue that represesnts a die pool + * A StatementValue that represents a die pool * @author Ben Culkin * */ diff --git a/dice/src/main/java/module-info.java b/dice/src/main/java/module-info.java index 74cc1b9..ab1d3b4 100644 --- a/dice/src/main/java/module-info.java +++ b/dice/src/main/java/module-info.java @@ -1,3 +1,9 @@ +/** + * An implementation for various sorts of dice rolling. + * + * @author bjculkin + * + */ module dicelang.dice { exports bjc.dicelang.neodice; exports bjc.dicelang.neodice.statements; |
