KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > persistence > antlr > RuleRefElement


1 package persistence.antlr;
2
3 /* ANTLR Translator Generator
4  * Project led by Terence Parr at http://www.jGuru.com
5  * Software rights: http://www.antlr.org/license.html
6  *
7  */

8
9 class RuleRefElement extends AlternativeElement {
10     protected String JavaDoc targetRule; // which rule is being called?
11
protected String JavaDoc args = null; // were any args passed to rule?
12
protected String JavaDoc idAssign = null; // is the return type assigned to a variable?
13
protected String JavaDoc label;
14
15
16     public RuleRefElement(Grammar g, Token t, int autoGenType_) {
17         super(g, t, autoGenType_);
18         targetRule = t.getText();
19         // if ( Character.isUpperCase(targetRule.charAt(0)) ) { // lexer rule?
20
if (t.type == ANTLRTokenTypes.TOKEN_REF) { // lexer rule?
21
targetRule = CodeGenerator.encodeLexerRuleName(targetRule);
22         }
23     }
24
25 // public RuleRefElement(Grammar g, String t, int line, int autoGenType_) {
26
// super(g, autoGenType_);
27
// targetRule = t;
28
// if ( Character.isUpperCase(targetRule.charAt(0)) ) { // lexer rule?
29
// targetRule = CodeGenerator.lexerRuleName(targetRule);
30
// }
31
// this.line = line;
32
// }
33

34     public void generate() {
35         grammar.generator.gen(this);
36     }
37
38     public String JavaDoc getArgs() {
39         return args;
40     }
41
42     public String JavaDoc getIdAssign() {
43         return idAssign;
44     }
45
46     public String JavaDoc getLabel() {
47         return label;
48     }
49
50     public Lookahead look(int k) {
51         return grammar.theLLkAnalyzer.look(k, this);
52     }
53
54     public void setArgs(String JavaDoc a) {
55         args = a;
56     }
57
58     public void setIdAssign(String JavaDoc id) {
59         idAssign = id;
60     }
61
62     public void setLabel(String JavaDoc label_) {
63         label = label_;
64     }
65
66     public String JavaDoc toString() {
67         if (args != null)
68             return " " + targetRule + args;
69         else
70             return " " + targetRule;
71     }
72 }
73
Popular Tags