blob: fe088b8438584ccf3dee42e8922d950b538b9cf2 (
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
package bjc.rgens.newparser;
/**
* A element in a rule case.
*
* @author EVE
*/
public class CaseElement {
/**
* The possible types of an element.
*
* @author EVE
*
*/
public static enum ElementType {
/**
* A element that represents a literal string.
*/
LITERAL,
/**
* A element that represents a rule reference.
*/
RULEREF;
}
/**
* The type of this element.
*/
public final CaseElement.ElementType type;
/**
* The literal string value of this element.
*
* This means that it is a string whose value should always mean the
* same thing.
*
* <h2>Used For</h2>
* <dl>
* <dt>LITERAL</dt>
* <dd>The string this element represents</dd>
* <dt>RULEREF</dt>
* <dd>The name of the rule this element references</dd>
* </dl>
*/
private String literalVal;
/**
* Create a new case element.
*
* @param typ
* The type of this element.
*
* @throws IllegalArgumentException
* If the specified type needs parameters.
*/
public CaseElement(CaseElement.ElementType typ) {
switch(typ) {
case LITERAL:
case RULEREF:
throw new IllegalArgumentException("This type requires a string parameter.");
default:
break;
}
type = typ;
}
/**
* Create a new case element that has a single string value.
*
* @param typ
* The type of this element.
*
* @param val
* The string value of this element.
*
* @throws IllegalArgumentException
* If the specified type doesn't take a single string
* parameter.
*/
public CaseElement(CaseElement.ElementType typ, String val) {
switch(typ) {
case LITERAL:
case RULEREF:
break;
default:
throw new IllegalArgumentException("This type doesn't have a string parameter.");
}
type = typ;
literalVal = val;
}
/**
* Get the literal string value for this element.
*
* @return The literal string value for this element.
*/
public String getLiteral() {
return literalVal;
}
}
|