summaryrefslogtreecommitdiff
path: root/dice/src/example/java
diff options
context:
space:
mode:
Diffstat (limited to 'dice/src/example/java')
-rw-r--r--dice/src/example/java/bjc/dicelang/neodice/DieBoxCLI.java245
-rw-r--r--dice/src/example/java/bjc/dicelang/neodice/DieBoxException.java36
-rw-r--r--dice/src/example/java/bjc/dicelang/neodice/commands/BindCommand.java5
-rw-r--r--dice/src/example/java/bjc/dicelang/neodice/commands/HelpCommand.java5
-rw-r--r--dice/src/example/java/bjc/dicelang/neodice/commands/LiteralCommand.java16
-rw-r--r--dice/src/example/java/bjc/dicelang/neodice/commands/PolyhedralDieCommand.java12
-rw-r--r--dice/src/example/java/bjc/dicelang/neodice/commands/RollCommand.java15
-rw-r--r--dice/src/example/java/bjc/dicelang/neodice/commands/ShowBindingsCommand.java6
-rw-r--r--dice/src/example/java/bjc/dicelang/neodice/statements/ArrayStatementValue.java16
-rw-r--r--dice/src/example/java/bjc/dicelang/neodice/statements/BooleanStatementValue.java7
-rw-r--r--dice/src/example/java/bjc/dicelang/neodice/statements/DiePoolStatementValue.java19
-rw-r--r--dice/src/example/java/bjc/dicelang/neodice/statements/DieStatementValue.java19
-rw-r--r--dice/src/example/java/bjc/dicelang/neodice/statements/IntArrayStatementValue.java50
-rw-r--r--dice/src/example/java/bjc/dicelang/neodice/statements/IntegerStatementValue.java12
-rw-r--r--dice/src/example/java/bjc/dicelang/neodice/statements/StatementValue.java23
-rw-r--r--dice/src/example/java/bjc/dicelang/neodice/statements/VoidStatementValue.java4
16 files changed, 331 insertions, 159 deletions
diff --git a/dice/src/example/java/bjc/dicelang/neodice/DieBoxCLI.java b/dice/src/example/java/bjc/dicelang/neodice/DieBoxCLI.java
index 557fd51..2c67e7f 100644
--- a/dice/src/example/java/bjc/dicelang/neodice/DieBoxCLI.java
+++ b/dice/src/example/java/bjc/dicelang/neodice/DieBoxCLI.java
@@ -20,88 +20,111 @@ import bjc.funcdata.*;
*/
public class DieBoxCLI {
private static final Pattern INT_PATTERN = Pattern.compile("(?:\\+|-)?\\d+");
- Scanner input;
+ /**
+ * The scanner we read input from.
+ */
+ public Scanner input;
+ /**
+ * The place we write output to.
+ */
public PrintStream output;
-
- public IMap<String, StatementValue> bindings = new FunctionalMap<>();
+ /**
+ * The current set of variable bindings
+ */
+ public MapEx<String, StatementValue> bindings = new FunctionalMap<>();
+
+ /**
+ * The current source of random numbers.
+ */
public Random rng = new Random();
-
- static final IMap<String, Command> builtInCommands;
- static final IMap<String, Command> builtInliterals;
-
- final IMap<String, Command> commands;
- final IMap<String, Command> literals;
-
+
+ /**
+ * The built-in diebox commands.
+ */
+ public static final MapEx<String, Command> builtInCommands;
+ /**
+ * The built-in diebox literal formers.
+ */
+ public static final MapEx<String, Command> builtInliterals;
+
+ /**
+ * The current set of diebox commands.
+ */
+ public final MapEx<String, Command> commands;
+ /**
+ * The current set of diebox literal-formers.
+ */
+ public final MapEx<String, Command> literals;
+
private int numStatements = 0;
/**
* Whether or not to print out a prompt before asking for input
*/
public boolean doPrompt = true;
-
+
/**
* Whether or not to output the results of each command.
*/
public boolean doOutput = true;
-
+
/**
* Should warning messages be printed?
*/
public boolean doWarn = true;
-
+
static {
// Initialize all of our literal-formers
builtInliterals = new FunctionalMap<>();
-
- builtInliterals.put("void",
- new LiteralCommand(
- VOID_INST,
- "the unique instance of type VOID",
- "Returns a reference to the unique instance of type VOID."));
- builtInliterals.put("true",
- new LiteralCommand(
- TRUE_INST,
- "the unique true value of type BOOLEAN",
- "Returns a reference to the unique true instance of type BOOLEAN"));
- builtInliterals.put("false",
- new LiteralCommand(
- FALSE_INST,
- "the unique false value of type BOOLEAN",
- "Returns a reference to the unique false instance of type BOOLEAN"));
-
+
+ builtInliterals.put("void", new LiteralCommand(VOID_INST,
+ "the unique instance of type VOID",
+ "Returns a reference to the unique instance of type VOID."));
+ builtInliterals.put("true", new LiteralCommand(TRUE_INST,
+ "the unique true value of type BOOLEAN",
+ "Returns a reference to the unique true instance of type BOOLEAN"));
+ builtInliterals.put("false", new LiteralCommand(FALSE_INST,
+ "the unique false value of type BOOLEAN",
+ "Returns a reference to the unique false instance of type BOOLEAN"));
+
builtInliterals.deepFreeze();
-
- // Initialize all of our built-in commands
+
+ // Initialize all of our built-in commands
builtInCommands = new FunctionalMap<>();
-
+
builtInCommands.put("show-bindings", new ShowBindingsCommand());
builtInCommands.put("bind", new BindCommand());
builtInCommands.put("polyhedral-die", new PolyhedralDieCommand());
builtInCommands.put("roll", new RollCommand());
builtInCommands.put("help", new HelpCommand());
+
builtInCommands.deepFreeze();
}
-
+
/**
* Create a new CLI for interacting with dice.
*
- * @param input The place to read input from.
- * @param output The place to read output from.
+ * @param input
+ * The place to read input from.
+ * @param output
+ * The place to read output from.
*/
public DieBoxCLI(Scanner input, PrintStream output) {
- this.input = input;
+ this.input = input;
this.output = output;
-
+
this.commands = builtInCommands.extend();
this.literals = builtInliterals.extend();
}
-
+
/**
* Create a new CLI for interacting with dice.
*
- * @param input The place to read input from.
- * @param output The place to read output from.
+ * @param input
+ * The place to read input from.
+ * @param output
+ * The place to read output from.
*/
public DieBoxCLI(InputStream input, OutputStream output) {
this(new Scanner(input), new PrintStream(output));
@@ -110,45 +133,51 @@ public class DieBoxCLI {
/**
* Main method.
*
- * @param args Currently unused CLI arguments.
+ * @param args
+ * Currently unused CLI arguments.
*/
public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
+ Scanner input = new Scanner(System.in);
PrintStream output = System.out;
-
+
DieBoxCLI box = new DieBoxCLI(input, output);
box.run();
}
- private void run() {
+ private void run() {
if (doPrompt) {
output.println("diebox CLI - enter 'help' for help, 'exit' to exit");
}
-
- if (doPrompt) output.printf("diebox(%d)> ", numStatements);
- while(input.hasNextLine()) {
+
+ if (doPrompt)
+ output.printf("diebox(%d)> ", numStatements);
+ while (input.hasNextLine()) {
String nextLine = input.nextLine().trim();
-
+
numStatements += 1;
-
- if (nextLine.equals("")) continue;
+
+ if (nextLine.equals(""))
+ continue;
// @FIXME Nov 15th, 2020 Ben Culkin :HardcodeExit
// Exit should not be hard-coded like this
- if (nextLine.equals("exit")) break;
-
+ if (nextLine.equals("exit"))
+ break;
+
String[] lineWords = nextLine.split("\\s+");
Iterator<String> wordIter = new ArrayIterator<>(lineWords);
try {
StatementValue val = runStatement(wordIter);
-
- if (doOutput) output.printf("%s%s\n", doPrompt ? "==> " : "", val);
+
+ if (doOutput)
+ output.printf("%s%s\n", doPrompt ? "==> " : "",
+ val);
} catch (DieBoxException dbex) {
output.printf("ERROR (in statement %d): %s\n",
numStatements, dbex.getMessage());
Throwable curEx = dbex.getCause();
while (curEx != null) {
output.printf("...caused by: %s\n", curEx);
-
+
curEx = dbex.getCause();
}
} catch (Exception ex) {
@@ -156,64 +185,90 @@ public class DieBoxCLI {
numStatements, ex.getMessage());
ex.printStackTrace(output);
}
-
- if (doPrompt) output.printf("diebox(%d)> ", numStatements);
+
+ if (doPrompt)
+ output.printf("diebox(%d)> ", numStatements);
}
-
+
input.close();
output.close();
}
+ /**
+ * Extract an instance of {@link StatementValue} from a source of strings.
+ *
+ * @param words The strings to use.
+ *
+ * @return A statement value, parsed from the strings.
+ */
public StatementValue runStatement(Iterator<String> words) {
if (!words.hasNext()) {
return VOID_INST;
}
-
+
String command = words.next().trim();
-
+ DieBoxCLI state = this;
+
if (command.startsWith("$")) {
// All variable refs start with $
String varName = command.substring(1);
-
- if (bindings.containsKey(varName)) {
- return bindings.get(varName);
- } else {
- // @TODO Nov 15th, 2020 Ben Culkin :Autovars
- // Perhaps something along the lines of 'auto-variables' (here
- // called 'spring-loaded variables') should be created? These
- // would be essentially values which invoke a given expression
- // whenever they are referenced.
- throw new DieBoxException("Attempted to reference non-existing variable %s", varName);
- }
+
+ return bindings.get(varName)
+ .orElseThrow(() -> new DieBoxException(
+ "Attempted to reference non-existing variable %s",
+ varName));
+ // @TODO Nov 15th, 2020 Ben Culkin :Autovars
+ // Perhaps something along the lines of 'auto-variables' (here
+ // called 'spring-loaded variables') should be created? These
+ // would be essentially values which invoke a given expression
+ // whenever they are referenced.
} else if (command.startsWith("#")) {
// All literals/literal-formers start with #
String actualCommand = command.substring(1);
-
+
// Attempt to use a mapped literal/literal-former
- Command literalCommand = literals.get(actualCommand);
- if (literalCommand != null) {
- return literalCommand.execute(words, this);
- } else {
- if (INT_PATTERN.matcher(actualCommand).matches()) {
- try {
- int val = Integer.parseInt(actualCommand);
-
- return new IntegerStatementValue(val);
- } catch (NumberFormatException nfex) {
- throw new DieBoxException(nfex, "Improper integer literal (%s)", actualCommand);
- }
- } else {
- throw new DieBoxException("Unknown literal format (%s)", actualCommand);
- }
+ StatementValue val = literals.get(actualCommand)
+ .map((com) -> com.execute(words, state))
+ .orElseGet(() -> parseActualLiteral(actualCommand));
+
+ return val;
+ } else {
+ // Attempt to use a mapped command first
+ StatementValue val = commands.get(command)
+ .map((com) -> com.execute(words, state))
+ .orElseThrow(() -> handleUnknownCommand(command));
+ return val;
+ }
+ }
+
+ private DieBoxException handleUnknownCommand(String command) {
+ StringBuilder msg = new StringBuilder("Unknown command ");
+ msg.append(command);
+ msg.append(".");
+
+ if (INT_PATTERN.matcher(command).matches()) {
+ msg.append("\n...Int literals must start with #, so try #");
+ msg.append(command);
+ msg.append(" instead.");
+ }
+
+ return new DieBoxException(msg.toString());
+ }
+
+ private StatementValue parseActualLiteral(String litText) {
+ if (INT_PATTERN.matcher(litText).matches()) {
+ try {
+ int val = Integer.parseInt(litText);
+
+ return new IntegerStatementValue(val);
+ } catch (NumberFormatException nfex) {
+ throw new DieBoxException(nfex,
+ "Improper integer literal (%s)",
+ litText);
}
} else {
- // Attempt to use a mapped command first
- Command mapCommand = commands.get(command);
- if (mapCommand != null) {
- return mapCommand.execute(words, this);
- } else {
- throw new DieBoxException("Unknown command %s", command);
- }
+ throw new DieBoxException("Unknown literal format (%s)",
+ litText);
}
}
} \ No newline at end of file
diff --git a/dice/src/example/java/bjc/dicelang/neodice/DieBoxException.java b/dice/src/example/java/bjc/dicelang/neodice/DieBoxException.java
index efa3d54..e1de67e 100644
--- a/dice/src/example/java/bjc/dicelang/neodice/DieBoxException.java
+++ b/dice/src/example/java/bjc/dicelang/neodice/DieBoxException.java
@@ -1,28 +1,60 @@
package bjc.dicelang.neodice;
+/**
+ * The exception thrown when something goes wrong with diebox.
+ * @author Ben Culkin
+ *
+ */
public class DieBoxException extends RuntimeException {
private static final long serialVersionUID = 1851356458656622896L;
+ /** Create a new exception */
public DieBoxException() {
super();
}
+ /**
+ * Create a new exception with a given message.
+ *
+ * @param message The message for the exception.
+ */
public DieBoxException(String message) {
super(message);
}
+ /**
+ * Create a new exception with a given formatted message.
+ *
+ * @param format The format string.
+ * @param args The format arguments.
+ */
public DieBoxException(String format, Object... args) {
super(String.format(format, args));
}
+ /**
+ * Create a new diebox exception with a cause.
+ * @param cause The cause of this exception.
+ */
public DieBoxException(Throwable cause) {
super(cause);
}
-
+
+ /**
+ * Create a new diebox exception with a cause and message.
+ * @param cause The cause of this exception.
+ * @param message The message for the exception.
+ */
public DieBoxException(Throwable cause, String message) {
super(message, cause);
}
-
+
+ /**
+ * Create a new diebox exception with a cause and formatted message.
+ * @param cause The cause of this exception.
+ * @param format The format string.
+ * @param args The format arguments.
+ */
public DieBoxException(Throwable cause, String format, Object... args) {
super(String.format(format, args), cause);
}
diff --git a/dice/src/example/java/bjc/dicelang/neodice/commands/BindCommand.java b/dice/src/example/java/bjc/dicelang/neodice/commands/BindCommand.java
index 5091c4b..8664379 100644
--- a/dice/src/example/java/bjc/dicelang/neodice/commands/BindCommand.java
+++ b/dice/src/example/java/bjc/dicelang/neodice/commands/BindCommand.java
@@ -7,6 +7,11 @@ import java.util.*;
import bjc.dicelang.neodice.*;
import bjc.dicelang.neodice.statements.*;
+/**
+ * This command binds a name to a variable slot.
+ * @author Ben Culkin
+ *
+ */
public class BindCommand implements Command {
@Override
public StatementValue execute(Iterator<String> words, DieBoxCLI state) {
diff --git a/dice/src/example/java/bjc/dicelang/neodice/commands/HelpCommand.java b/dice/src/example/java/bjc/dicelang/neodice/commands/HelpCommand.java
index 705745e..c10db4e 100644
--- a/dice/src/example/java/bjc/dicelang/neodice/commands/HelpCommand.java
+++ b/dice/src/example/java/bjc/dicelang/neodice/commands/HelpCommand.java
@@ -7,6 +7,11 @@ import java.util.*;
import bjc.dicelang.neodice.*;
import bjc.dicelang.neodice.statements.*;
+/**
+ * Diebox help command. Unimplemented as of yet.
+ * @author Ben Culkin
+ *
+ */
public class HelpCommand implements Command {
@Override
public StatementValue execute(Iterator<String> words, DieBoxCLI state) {
diff --git a/dice/src/example/java/bjc/dicelang/neodice/commands/LiteralCommand.java b/dice/src/example/java/bjc/dicelang/neodice/commands/LiteralCommand.java
index 9b42b42..b781ae9 100644
--- a/dice/src/example/java/bjc/dicelang/neodice/commands/LiteralCommand.java
+++ b/dice/src/example/java/bjc/dicelang/neodice/commands/LiteralCommand.java
@@ -5,12 +5,28 @@ import java.util.*;
import bjc.dicelang.neodice.*;
import bjc.dicelang.neodice.statements.*;
+/**
+ * A command that produces a literal statement value.
+ *
+ * This command will always produce the same statement value, so passing any sort
+ * of mutable statement value to it is asking to be hurt.
+ *
+ * @author Ben Culkin
+ *
+ */
public class LiteralCommand implements Command {
private final StatementValue value;
private final String shortHelp;
private final String longHelp;
+ /**
+ * Create a new command producing a literal statement value.
+ *
+ * @param value The value this command returns.
+ * @param shortHelp The short-help (summary) for this command.
+ * @param longHelp The long-help (description) for this command.
+ */
public LiteralCommand(StatementValue value, String shortHelp, String longHelp) {
this.value = value;
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 02fc9cf..e0f66b1 100644
--- a/dice/src/example/java/bjc/dicelang/neodice/commands/PolyhedralDieCommand.java
+++ b/dice/src/example/java/bjc/dicelang/neodice/commands/PolyhedralDieCommand.java
@@ -7,6 +7,12 @@ import java.util.*;
import bjc.dicelang.neodice.*;
import bjc.dicelang.neodice.statements.*;
+/**
+ * A command that produces a polyhedral die.
+ *
+ * @author Ben Culkin
+ *
+ */
public class PolyhedralDieCommand implements Command {
@Override
public StatementValue execute(Iterator<String> words, DieBoxCLI state) {
@@ -20,7 +26,11 @@ public class PolyhedralDieCommand implements Command {
if (numSides < 0) throw new DieBoxException("Number of sides to polyhedral-die was not valid (must be less than 0, was %d)", numSides);
- return new DieStatementValue(DieFactory.polyhedral(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);
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 eb7b597..cec7c48 100644
--- a/dice/src/example/java/bjc/dicelang/neodice/commands/RollCommand.java
+++ b/dice/src/example/java/bjc/dicelang/neodice/commands/RollCommand.java
@@ -7,6 +7,12 @@ import java.util.*;
import bjc.dicelang.neodice.*;
import bjc.dicelang.neodice.statements.*;
+/**
+ * A command that rolls a die or die-pool.
+ *
+ * @author Ben Culkin
+ *
+ */
public class RollCommand implements Command {
@Override
public StatementValue execute(Iterator<String> words, DieBoxCLI state) {
@@ -18,11 +24,16 @@ public class RollCommand implements Command {
if (toRoll.type == DIE) {
DieStatementValue die = (DieStatementValue) toRoll;
- return new IntegerStatementValue(die.value.roll(state.rng));
+ return die.value.roll(state.rng);
} else if (toRoll.type == DIEPOOL) {
DiePoolStatementValue pool = (DiePoolStatementValue) toRoll;
- return new IntArrayStatementValue(pool.value.roll(state.rng));
+ 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/commands/ShowBindingsCommand.java b/dice/src/example/java/bjc/dicelang/neodice/commands/ShowBindingsCommand.java
index fe2ac89..75811b6 100644
--- a/dice/src/example/java/bjc/dicelang/neodice/commands/ShowBindingsCommand.java
+++ b/dice/src/example/java/bjc/dicelang/neodice/commands/ShowBindingsCommand.java
@@ -7,6 +7,12 @@ import java.util.*;
import bjc.dicelang.neodice.*;
import bjc.dicelang.neodice.statements.*;
+/**
+ * A command that shows all of the currently bound variables.
+ *
+ * @author Ben Culkin
+ *
+ */
public class ShowBindingsCommand implements Command {
@Override
public StatementValue execute(Iterator<String> words, DieBoxCLI state) {
diff --git a/dice/src/example/java/bjc/dicelang/neodice/statements/ArrayStatementValue.java b/dice/src/example/java/bjc/dicelang/neodice/statements/ArrayStatementValue.java
index 66e14ad..1a54ca5 100644
--- a/dice/src/example/java/bjc/dicelang/neodice/statements/ArrayStatementValue.java
+++ b/dice/src/example/java/bjc/dicelang/neodice/statements/ArrayStatementValue.java
@@ -4,10 +4,24 @@ import static bjc.dicelang.neodice.statements.StatementValue.Type.*;
import java.util.*;
+/**
+ * A statement value which represents an array of statement values.
+ * @author Ben Culkin
+ *
+ * @param <ElementType> The contained type of value.
+ */
public class ArrayStatementValue<ElementType extends StatementValue> extends StatementValue {
- public final Type elementType;
+ /** The type of the contained values. */
+ public final Type elementType;
+ /** The contained values. */
public final ElementType[] values;
+ /**
+ * Create a new array statement value.
+ *
+ * @param elementType The type of the contained values.
+ * @param values The contained values.
+ */
@SafeVarargs
public ArrayStatementValue(Type elementType, ElementType... values) {
super(ARRAY);
diff --git a/dice/src/example/java/bjc/dicelang/neodice/statements/BooleanStatementValue.java b/dice/src/example/java/bjc/dicelang/neodice/statements/BooleanStatementValue.java
index ba89893..aef912b 100644
--- a/dice/src/example/java/bjc/dicelang/neodice/statements/BooleanStatementValue.java
+++ b/dice/src/example/java/bjc/dicelang/neodice/statements/BooleanStatementValue.java
@@ -4,10 +4,17 @@ import static bjc.dicelang.neodice.statements.StatementValue.Type.*;
import java.util.*;
+/**
+ * Represents the boolean type for diebox.
+ * @author Ben Culkin
+ *
+ */
public class BooleanStatementValue extends StatementValue {
private boolean value;
+ /** The true boolean instance. */
public static final BooleanStatementValue TRUE_INST = new BooleanStatementValue(true);
+ /** The false boolean instance. */
public static final BooleanStatementValue FALSE_INST = new BooleanStatementValue(false);
private BooleanStatementValue(boolean value) {
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 a4a9104..114475c 100644
--- a/dice/src/example/java/bjc/dicelang/neodice/statements/DiePoolStatementValue.java
+++ b/dice/src/example/java/bjc/dicelang/neodice/statements/DiePoolStatementValue.java
@@ -6,12 +6,27 @@ import java.util.*;
import bjc.dicelang.neodice.*;
+/**
+ * A StatementValue that represesnts a die pool
+ * @author Ben Culkin
+ *
+ */
public class DiePoolStatementValue extends StatementValue {
- public final DiePool value;
+ /** The type of the contained value. */
+ public final Type elementType;
+ /** The die pool itself. */
+ public final DiePool<StatementValue> value;
- public DiePoolStatementValue(DiePool value) {
+ /**
+ * Create a new diepool value.
+ *
+ * @param elementType The contained type.
+ * @param value The die pool itself.
+ */
+ public DiePoolStatementValue(Type elementType, DiePool<StatementValue> value) {
super(DIEPOOL);
+ this.elementType = elementType;
this.value = value;
}
diff --git a/dice/src/example/java/bjc/dicelang/neodice/statements/DieStatementValue.java b/dice/src/example/java/bjc/dicelang/neodice/statements/DieStatementValue.java
index 55a6856..5662a59 100644
--- a/dice/src/example/java/bjc/dicelang/neodice/statements/DieStatementValue.java
+++ b/dice/src/example/java/bjc/dicelang/neodice/statements/DieStatementValue.java
@@ -6,12 +6,27 @@ import java.util.*;
import bjc.dicelang.neodice.*;
+/**
+ * A StatementValue that represents a die.
+ * @author Ben Culkin
+ *
+ */
public class DieStatementValue extends StatementValue {
- public final Die value;
+ /** The type of values this die rolls. */
+ public final Type sideType;
+ /** The die itself. */
+ public final Die<StatementValue> value;
- public DieStatementValue(Die value) {
+ /**
+ * Create a new die StatementValue.
+ *
+ * @param sideType The type of value this die rolls.
+ * @param value The die itself.
+ */
+ public DieStatementValue(Type sideType, Die<StatementValue> value) {
super(DIE);
+ this.sideType = sideType;
this.value = value;
}
diff --git a/dice/src/example/java/bjc/dicelang/neodice/statements/IntArrayStatementValue.java b/dice/src/example/java/bjc/dicelang/neodice/statements/IntArrayStatementValue.java
deleted file mode 100644
index b313d42..0000000
--- a/dice/src/example/java/bjc/dicelang/neodice/statements/IntArrayStatementValue.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package bjc.dicelang.neodice.statements;
-
-import static bjc.dicelang.neodice.statements.StatementValue.Type.*;
-
-import java.util.*;
-
-public class IntArrayStatementValue extends StatementValue {
- public final int[] values;
-
- public IntArrayStatementValue(int... values) {
- super(INT_ARRAY);
-
- this.values = values;
- }
-
- @Override
- public String toString() {
- StringBuilder buffer = new StringBuilder();
-
- buffer.append('(');
- for (int index = 0; index < values.length; index++) {
- int value = values[index];
-
- buffer.append(value);
- if (index < values.length - 1) buffer.append(", ");
- }
- buffer.append(')');
-
- return buffer.toString();
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = super.hashCode();
- result = prime * result + Arrays.hashCode(values);
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (!super.equals(obj)) return false;
- if (getClass() != obj.getClass()) return false;
-
- IntArrayStatementValue other = (IntArrayStatementValue) obj;
-
- return Arrays.equals(values, other.values);
- }
-} \ No newline at end of file
diff --git a/dice/src/example/java/bjc/dicelang/neodice/statements/IntegerStatementValue.java b/dice/src/example/java/bjc/dicelang/neodice/statements/IntegerStatementValue.java
index 91e45b6..88508d2 100644
--- a/dice/src/example/java/bjc/dicelang/neodice/statements/IntegerStatementValue.java
+++ b/dice/src/example/java/bjc/dicelang/neodice/statements/IntegerStatementValue.java
@@ -2,9 +2,19 @@ package bjc.dicelang.neodice.statements;
import static bjc.dicelang.neodice.statements.StatementValue.Type.*;
+/**
+ * Statement value that represents an integer.
+ * @author Ben Culkin
+ *
+ */
public class IntegerStatementValue extends StatementValue {
- public final int value;
+ /** The integer value. */
+ public final int value;
+ /**
+ * Create an integer statement value.
+ * @param value The int to use as the value.
+ */
public IntegerStatementValue(int value) {
super(INTEGER);
diff --git a/dice/src/example/java/bjc/dicelang/neodice/statements/StatementValue.java b/dice/src/example/java/bjc/dicelang/neodice/statements/StatementValue.java
index 5090bc7..d804a10 100644
--- a/dice/src/example/java/bjc/dicelang/neodice/statements/StatementValue.java
+++ b/dice/src/example/java/bjc/dicelang/neodice/statements/StatementValue.java
@@ -2,22 +2,41 @@ package bjc.dicelang.neodice.statements;
import java.util.*;
+/**
+ * Represents a value for diebox, as a base class.
+ * @author Ben Culkin
+ *
+ */
public abstract class StatementValue {
+ /**
+ * The type of the value.
+ * @author Ben Culkin
+ *
+ */
public static enum Type {
+ /** The 'void' value. There is only one value of this type. */
VOID,
+ /** The 'boolean' type. There is one true value, and one false value. */
BOOLEAN,
+ /** Represents an integer. */
INTEGER,
- INT_ARRAY,
-
+ /** Represents a single die. */
DIE,
+ /** Represents a pool of dice. */
DIEPOOL,
+ /** Represents an array of some type. */
ARRAY,
}
+ /** The type of this value. */
public final Type type;
+ /**
+ * Create a new statement value.
+ * @param type The type of the value.
+ */
protected StatementValue(Type type) {
this.type = type;
}
diff --git a/dice/src/example/java/bjc/dicelang/neodice/statements/VoidStatementValue.java b/dice/src/example/java/bjc/dicelang/neodice/statements/VoidStatementValue.java
index 7e437e7..a71d49c 100644
--- a/dice/src/example/java/bjc/dicelang/neodice/statements/VoidStatementValue.java
+++ b/dice/src/example/java/bjc/dicelang/neodice/statements/VoidStatementValue.java
@@ -3,11 +3,13 @@ package bjc.dicelang.neodice.statements;
import static bjc.dicelang.neodice.statements.StatementValue.Type.*;
/**
+ * The statement value of the null type.
* @author Ben Culkin
*
*/
public class VoidStatementValue extends StatementValue {
- public static final VoidStatementValue VOID_INST = new VoidStatementValue();
+ /** The singular instance of the null value. */
+ public static final VoidStatementValue VOID_INST = new VoidStatementValue();
private VoidStatementValue() {
super(VOID);