01: package antlr;
02:
03: /* ANTLR Translator Generator
04: * Project led by Terence Parr at http://www.cs.usfca.edu
05: * Software rights: http://www.antlr.org/license.html
06: */
07:
08: class RuleRefElement extends AlternativeElement {
09: protected String targetRule; // which rule is being called?
10: protected String args = null; // were any args passed to rule?
11: protected String idAssign = null; // is the return type assigned to a variable?
12: protected String label;
13:
14: public RuleRefElement(Grammar g, Token t, int autoGenType_) {
15: super (g, t, autoGenType_);
16: targetRule = t.getText();
17: // if ( Character.isUpperCase(targetRule.charAt(0)) ) { // lexer rule?
18: if (t.getType() == ANTLRTokenTypes.TOKEN_REF) { // lexer rule?
19: targetRule = CodeGenerator.encodeLexerRuleName(targetRule);
20: }
21: }
22:
23: // public RuleRefElement(Grammar g, String t, int line, int autoGenType_) {
24: // super(g, autoGenType_);
25: // targetRule = t;
26: // if ( Character.isUpperCase(targetRule.charAt(0)) ) { // lexer rule?
27: // targetRule = CodeGenerator.lexerRuleName(targetRule);
28: // }
29: // this.line = line;
30: // }
31:
32: public void generate(Context context) {
33: grammar.generator.gen(this , context);
34: }
35:
36: public String getArgs() {
37: return args;
38: }
39:
40: public String getIdAssign() {
41: return idAssign;
42: }
43:
44: public String getLabel() {
45: return label;
46: }
47:
48: public Lookahead look(int k) {
49: return grammar.theLLkAnalyzer.look(k, this );
50: }
51:
52: public void setArgs(String a) {
53: args = a;
54: }
55:
56: public void setIdAssign(String id) {
57: idAssign = id;
58: }
59:
60: public void setLabel(String label_) {
61: label = label_;
62: }
63:
64: public String toString() {
65: if (args != null)
66: return " " + targetRule + args;
67: else
68: return " " + targetRule;
69: }
70: }
|