1 module antlr.v4.runtime.tree.pattern.TokenTagToken; 2 3 import antlr.v4.runtime.CommonToken; 4 import std.conv; 5 6 /** 7 * @uml 8 * {@link Token} object representing a token of a particular type; e.g., 9 * {@code <ID>}. These tokens are created for {@link TagChunk} chunks where the 10 * tag corresponds to a lexer rule or token type. 11 */ 12 class TokenTagToken : CommonToken 13 { 14 15 /** 16 * @uml 17 * This is the backing field for {@link #getTokenName}. 18 * @final 19 */ 20 private string tokenName; 21 22 /** 23 * @uml 24 * This is the backing field for {@link #getLabel}. 25 * @final 26 */ 27 private string label; 28 29 /** 30 * @uml 31 * Constructs a new instance of {@link TokenTagToken} for an unlabeled tag 32 * with the specified token name and type. 33 * 34 * @param tokenName The token name. 35 * @param type The token type. 36 */ 37 public this(string tokenName, int type) 38 { 39 this(tokenName, type, null); 40 } 41 42 /** 43 * @uml 44 * Constructs a new instance of {@link TokenTagToken} with the specified 45 * token name, type, and label. 46 * 47 * @param tokenName The token name. 48 * @param type The token type. 49 * @param label The label associated with the token tag, or {@code null} if 50 * the token tag is unlabeled. 51 */ 52 public this(string tokenName, int type, string label) 53 { 54 super(type); 55 this.tokenName = tokenName; 56 this.label = label; 57 } 58 59 /** 60 * @uml 61 * Gets the token name. 62 * @return The token name. 63 */ 64 public string getTokenName() 65 { 66 return tokenName; 67 } 68 69 /** 70 * @uml 71 * Gets the label associated with the rule tag. 72 * 73 * @return The name of the label associated with the rule tag, or 74 * {@code null} if this is an unlabeled rule tag. 75 */ 76 public string getLabel() 77 { 78 return label; 79 } 80 81 /** 82 * @uml 83 * <p>The implementation for {@link TokenTagToken} returns the token tag 84 * formatted with {@code <} and {@code >} delimiters.</p> 85 * @override 86 */ 87 public override string getText() 88 { 89 if (label !is null) { 90 return "<" ~ label ~ ":" ~ tokenName ~ ">"; 91 } 92 return "<" ~ tokenName ~ ">"; 93 } 94 95 /** 96 * @uml 97 * <p>The implementation for {@link TokenTagToken} returns a string of the form 98 * {@code tokenName:type}.</p> 99 * @override 100 */ 101 public override string toString() 102 { 103 return tokenName ~ ":" ~ to!string(type); 104 } 105 106 }