summaryrefslogtreecommitdiff
path: root/dice/src/example/java/bjc/dicelang/neodice/commands/BindCommand.java
diff options
context:
space:
mode:
authorBen Culkin <scorpress@gmail.com>2020-11-21 18:04:20 -0500
committerBen Culkin <scorpress@gmail.com>2020-11-21 18:04:20 -0500
commit3ddd062d60d621971af59b480ba70e8bf9e705f1 (patch)
tree8d24f91e4f695a526777b5fe75fe268669b8c9a6 /dice/src/example/java/bjc/dicelang/neodice/commands/BindCommand.java
parent2afb54eecd8e8b5d663a05131c07c6b8d15e65ba (diff)
Rudimentary CLI for new die implementation
Diffstat (limited to 'dice/src/example/java/bjc/dicelang/neodice/commands/BindCommand.java')
-rw-r--r--dice/src/example/java/bjc/dicelang/neodice/commands/BindCommand.java39
1 files changed, 39 insertions, 0 deletions
diff --git a/dice/src/example/java/bjc/dicelang/neodice/commands/BindCommand.java b/dice/src/example/java/bjc/dicelang/neodice/commands/BindCommand.java
new file mode 100644
index 0000000..5091c4b
--- /dev/null
+++ b/dice/src/example/java/bjc/dicelang/neodice/commands/BindCommand.java
@@ -0,0 +1,39 @@
+package bjc.dicelang.neodice.commands;
+
+import static bjc.dicelang.neodice.statements.StatementValue.Type.*;
+
+import java.util.*;
+
+import bjc.dicelang.neodice.*;
+import bjc.dicelang.neodice.statements.*;
+
+public class BindCommand implements Command {
+ @Override
+ public StatementValue execute(Iterator<String> words, DieBoxCLI state) {
+ if (!words.hasNext()) {
+ throw new DieBoxException("bind requires a name to bind the value to");
+ }
+
+ String name = words.next();
+
+ StatementValue value = state.runStatement(words);
+
+ if (state.doWarn && value.type == VOID) {
+ state.output.printf("Warning: bound %s to the instance of void. Should you have provided a value?", name);
+ }
+
+ state.bindings.put(name, value);
+
+ return value;
+ }
+
+ @Override
+ public String shortHelp() {
+ return "bind a value to a name";
+ }
+
+ @Override
+ public String longHelp() {
+ return "Binds a value to a name, and returns that name. Currently, all variables go into a single global scope, but this will probably change";
+ }
+} \ No newline at end of file