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