summaryrefslogtreecommitdiff
path: root/src/main/java/bjc/rgens/parser/RuleCase.java
blob: 67ca864a226655bdafbb0207fb7b80c415c87895 (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
74
75
76
77
78
package bjc.rgens.parser;

import bjc.rgens.parser.elements.CaseElement;

import java.util.List;

/*
 * @NOTE
 * 	If at some point we add new case types, they should go into subclasses,
 * 	not into this class.
 */
/**
 * A case in a rule in a randomized grammar.
 *
 * @author EVE
 */
public abstract class RuleCase {
	/**
	 * Debugging name for this case.
	 */
	public String debugName;

	/**
	 * Serial number for this case.
	 */
	public final int serial;
	private static int nextSerial = 0;

	/**
	 * The rule this case belongs to.
	 */
	public Rule belongsTo;

	/**
	 * The elements that make up this case.
	 */
	public List<CaseElement> elementList;

	/**
	 * Create a new case of the specified type that takes a element list
	 * parameter.
	 *
	 * @param elements
	 * 	The element list parameter of the case.
	 *
	 */
	protected RuleCase(List<CaseElement> elements) {
		elementList = elements;

		serial      = nextSerial;
		nextSerial += 1;
	}

	/**
	 * Generate this case.
	 * 
	 * @param state The state to use.
	 */
	public abstract void generate(GenerationState state);

	/**
	 * Create a new case with a different set of elements.
	 * 
	 * @param elements The elements for this case.
	 * 
	 * @return The case with the same settings, but a different set of elements.
	 */
	public abstract RuleCase withElements(List<CaseElement> elements);

	@Override
	public String toString() {
		if(debugName != null) {
			return String.format("Case %s (#%d) of %s", debugName, serial, belongsTo);
		}
		return String.format("Case #%d of %s", serial, belongsTo, serial, belongsTo);
	}

}