blob: a7fdbecc03eb38209b76506f09266e7ee3761011 (
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
|
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;
import static bjc.rgens.parser.RGrammarLogging.*;
public class RuleVariableCaseElement extends VariableDefCaseElement {
public final boolean exhaust;
public RuleVariableCaseElement(String varName, String varDef, boolean exhaust) {
super(varName, varDef);
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.defineRuleVar(varName, rl);
if(exhaust) {
fine("Defined exhausted rulevar '%s' ('%s')", varName, varDef);
} else {
fine("Defined rulevar '%s' ('%s')", varName, varDef);
}
}
}
|