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