blob: 6bf332f26cd29d5676bf8833b665594a1ade8a0c (
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
|
package bjc.rgens.parser.elements.vars;
import bjc.rgens.parser.GenerationState;
import bjc.rgens.parser.GrammarException;
import bjc.rgens.parser.Rule;
public class RRefVariableElement extends VariableElement {
public String value;
private boolean forbidSpaces;
public RRefVariableElement(boolean forbidSpaces, String val) {
value = val;
}
public void generate(GenerationState state) {
if(!state.rlVars.containsKey(value)) {
throw new GrammarException("No rule variable named " + value);
}
Rule rl = state.findRule(value, true);
GenerationState newState = state.newBuf();
rl.generate(newState);
String res = newState.contents.toString();
if(forbidSpaces && res.contains(" ")) {
throw new GrammarException("Spaces not allowed in this context (rule-reference %s)");
}
state.contents.append(res);
}
}
|