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