blob: cbd8ce16ee0f38693c1cfedb7ce9b4826b80c190 (
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
|
package bjc.rgens.parser.elements;
import bjc.utils.data.IPair;
import bjc.utils.data.Pair;
import bjc.rgens.parser.GrammarException;
import bjc.rgens.parser.GenerationState;
import bjc.rgens.parser.Rule;
import bjc.rgens.parser.RGrammar;
public class RuleVariableCaseElement extends VariableCaseElement {
public final boolean exhaust;
public RuleVariableCaseElement(String varName, String varDef, boolean exhaust) {
super(varName, varDef, VariableType.RULE);
this.exhaust = exhaust;
}
public void generate(GenerationState state) {
Rule rl = state.findRule(varDef, true);
if(rl == null) {
throw new GrammarException("Can't create variable referencing non-existent rule " + varDef);
}
if(exhaust) {
rl = rl.exhaust();
}
state.rlVars.put(varName, rl);
if(exhaust) {
System.err.printf("\t\tFINE: Defined exhausted rulevar '%s' ('%s')\n", varName, varDef);
} else {
System.err.printf("\t\tFINE: Defined rulevar '%s' ('%s')\n", varName, varDef);
}
}
}
|