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 CharRangeElement extends AlternativeElement {
09: String label;
10: protected char begin = 0;
11: protected char end = 0;
12: protected String beginText;
13: protected String endText;
14:
15: public CharRangeElement(LexerGrammar g, Token t1, Token t2,
16: int autoGenType) {
17: super (g);
18: begin = (char) ANTLRLexer.tokenTypeForCharLiteral(t1.getText());
19: beginText = t1.getText();
20: end = (char) ANTLRLexer.tokenTypeForCharLiteral(t2.getText());
21: endText = t2.getText();
22: line = t1.getLine();
23: // track which characters are referenced in the grammar
24: for (int i = begin; i <= end; i++) {
25: g.charVocabulary.add(i);
26: }
27: this .autoGenType = autoGenType;
28: }
29:
30: public void generate(Context context) {
31: grammar.generator.gen(this , context);
32: }
33:
34: public String getLabel() {
35: return label;
36: }
37:
38: public Lookahead look(int k) {
39: return grammar.theLLkAnalyzer.look(k, this );
40: }
41:
42: public void setLabel(String label_) {
43: label = label_;
44: }
45:
46: public String toString() {
47: if (label != null)
48: return " " + label + ":" + beginText + ".." + endText;
49: else
50: return " " + beginText + ".." + endText;
51: }
52: }
|