summaryrefslogtreecommitdiff
path: root/src/main/java/bjc/rgens/parser/RuleCase.java
blob: dacb16e6e559bca18d485200e55319586ba23658 (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
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 {
	public String debugName;

	public final int serial;

	private static int nextSerial = 0;

	public Rule belongsTo;

	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;
	}

	public abstract void generate(GenerationState state);

	public abstract RuleCase withElements(List<CaseElement> elements);

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

}