summaryrefslogtreecommitdiff
path: root/src/main/java/bjc/rgens/parser/GenerationState.java
diff options
context:
space:
mode:
authorBenjamin J. Culkin <bjculkin@mix.wvu.edu>2018-05-29 18:02:46 -0300
committerBenjamin J. Culkin <bjculkin@mix.wvu.edu>2018-05-29 18:02:46 -0300
commitfaf3e39fee32226ee72c6d43b2ba8a0f4e4bd837 (patch)
tree900bdc5a803c7ac0d616d9ceb09e2293a6bd84ce /src/main/java/bjc/rgens/parser/GenerationState.java
parent986870048e06fa0de2dd81d244a78c43cd2aa769 (diff)
Refactor case element generation
Case elements are now responsible for generating themselves.
Diffstat (limited to 'src/main/java/bjc/rgens/parser/GenerationState.java')
-rw-r--r--src/main/java/bjc/rgens/parser/GenerationState.java71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/main/java/bjc/rgens/parser/GenerationState.java b/src/main/java/bjc/rgens/parser/GenerationState.java
new file mode 100644
index 0000000..7ab55bf
--- /dev/null
+++ b/src/main/java/bjc/rgens/parser/GenerationState.java
@@ -0,0 +1,71 @@
+package bjc.rgens.parser;
+
+import java.util.Map;
+import java.util.Random;
+
+/*
+ * The current state during generation.
+ *
+ */
+public class GenerationState {
+ /** The current string. */
+ public StringBuilder contents;
+ /** The RNG. */
+ public Random rnd;
+
+ /*
+ * @NOTE
+ *
+ * Once the planned refactor for importing rules happens, this will need
+ * to be changed.
+ */
+ /** The current grammar. */
+ public RGrammar gram;
+ /** The rules of the grammar. */
+ public Map<String, Rule> rules;
+ /** The rules imported from other grammars. */
+ public Map<String, RGrammar> importRules;
+
+ /*
+ * @NOTE
+ *
+ * For planned features, this will need to be refactored.
+ */
+ /** The current set of variables. */
+ public Map<String, String> vars;
+
+ /**
+ * Create a new generation state.
+ *
+ * @param cont
+ * The string being generated.
+ *
+ * @param rand
+ * The RNG to use.
+ *
+ * @param vs
+ * The variables to use.
+ */
+ public GenerationState(StringBuilder cont, Random rand, Map<String, String> vs, RGrammar gram) {
+ contents = cont;
+ rnd = rand;
+ vars = vs;
+
+ this.gram = gram;
+
+ this.rules = gram.getRules();
+ this.importRules = gram.getImportRules();
+ }
+
+ public void swapGrammar(RGrammar gram) {
+ this.gram = gram;
+
+ rules = gram.getRules();
+
+ importRules = gram.getImportRules();
+ }
+
+ public GenerationState newBuf() {
+ return new GenerationState(new StringBuilder(), rnd, vars, gram);
+ }
+}