From faf3e39fee32226ee72c6d43b2ba8a0f4e4bd837 Mon Sep 17 00:00:00 2001 From: "Benjamin J. Culkin" Date: Tue, 29 May 2018 18:02:46 -0300 Subject: Refactor case element generation Case elements are now responsible for generating themselves. --- .../java/bjc/rgens/parser/GenerationState.java | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/main/java/bjc/rgens/parser/GenerationState.java (limited to 'src/main/java/bjc/rgens/parser/GenerationState.java') 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 rules; + /** The rules imported from other grammars. */ + public Map importRules; + + /* + * @NOTE + * + * For planned features, this will need to be refactored. + */ + /** The current set of variables. */ + public Map 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 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); + } +} -- cgit v1.2.3