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: /** A GrammarAtom is either a token ref, a character ref, or string.
09: * The analysis doesn't care.
10: */
11: abstract class GrammarAtom extends AlternativeElement {
12: protected String label;
13: protected String atomText;
14: protected int tokenType = Token.INVALID_TYPE;
15: protected boolean not = false; // ~T or ~'c' or ~"foo"
16: /** Set to type of AST node to create during parse. Defaults to what is
17: * set in the TokenSymbol.
18: */
19: protected String ASTNodeType = null;
20:
21: public GrammarAtom(Grammar g, Token t, int autoGenType) {
22: super (g, t, autoGenType);
23: atomText = t.getText();
24: }
25:
26: public String getLabel() {
27: return label;
28: }
29:
30: public String getText() {
31: return atomText;
32: }
33:
34: public int getType() {
35: return tokenType;
36: }
37:
38: public void setLabel(String label_) {
39: label = label_;
40: }
41:
42: public String getASTNodeType() {
43: return ASTNodeType;
44: }
45:
46: public void setASTNodeType(String type) {
47: ASTNodeType = type;
48: }
49:
50: public void setOption(Token option, Token value) {
51: if (option.getText().equals("AST")) {
52: setASTNodeType(value.getText());
53: } else {
54: grammar.antlrTool.error("Invalid element option:"
55: + option.getText(), grammar.getFilename(), option
56: .getLine(), option.getColumn());
57: }
58: }
59:
60: public String toString() {
61: String s = " ";
62: if (label != null)
63: s += label + ":";
64: if (not)
65: s += "~";
66: return s + atomText;
67: }
68: }
|