summaryrefslogtreecommitdiff
path: root/src/main/java/bjc/rgens/parser/GenerationState.java
blob: 78fce96f8b551eddd6b4762b3b97c5e4a8794038 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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;
	public Map<String, Rule> rlVars;

	/**
	 * 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, Map<String, Rule> rvs, RGrammar gram) {
		contents = cont;
		rnd      = rand;
		vars     = vs;
		rlVars   = rvs;

		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, rlVars, gram);
	}
}