blob: bebb9f76c1979dcf49090cd68c3f305989c7be61 (
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
|
package bjc.rgens.parser.elements;
import bjc.rgens.parser.GrammarException;
import bjc.rgens.parser.GenerationState;
public class VariableRuleReference extends RuleCaseElement {
public VariableRuleReference(String vl) {
super(vl, ReferenceType.VARIABLE);
}
public void generate(GenerationState state) {
String refBody = val.substring(1, val.length() - 1);
/* Handle string references. */
if (refBody.equals("$")) {
throw new GrammarException("Cannot refer to unnamed variables");
}
String key = refBody.substring(1);
if (!state.vars.containsKey(key)) {
String msg = String.format("No variable '%s' defined", key);
throw new GrammarException(msg);
}
state.contents.append(state.vars.get(key));
return;
}
}
|