blob: 33aea0c19d2e9b1b636bcbdbc6e875e99354f64f (
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
|
package bjc.rgens.parser;
import bjc.rgens.parser.elements.CaseElement;
import bjc.utils.funcdata.IList;
/*
* @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 IList<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(IList<CaseElement> elements) {
elementList = elements;
serial = nextSerial;
nextSerial += 1;
}
public abstract void generate(GenerationState state);
public abstract RuleCase withElements(IList<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);
}
}
}
|