1 /*
2 * Copyright (c) 2012-2019 The ANTLR Project. All rights reserved.
3 * Use of this file is governed by the BSD 3-clause license that
4 * can be found in the LICENSE.txt file in the project root.
5 */6 7 moduleantlr.v4.runtime.tree.pattern.TokenTagToken;
8 9 importantlr.v4.runtime.CommonToken;
10 importstd.conv;
11 importstd.format;
12 importstd.variant;
13 14 /**
15 * @uml
16 * {@link Token} object representing a token of a particular type; e.g.,
17 * {@code <ID>}. These tokens are created for {@link TagChunk} chunks where the
18 * tag corresponds to a lexer rule or token type.
19 */20 classTokenTagToken : CommonToken21 {
22 23 /**
24 * @uml
25 * This is the backing field for {@link #getTokenName}.
26 * @final
27 */28 privatestringtokenName;
29 30 /**
31 * @uml
32 * This is the backing field for {@link #getLabel}.
33 * @final
34 */35 privatestringlabel;
36 37 /**
38 * @uml
39 * Constructs a new instance of {@link TokenTagToken} for an unlabeled tag
40 * with the specified token name and type.
41 *
42 * @param tokenName The token name.
43 * @param type The token type.
44 */45 publicthis(stringtokenName, inttype)
46 {
47 this(tokenName, type, null);
48 }
49 50 /**
51 * @uml
52 * Constructs a new instance of {@link TokenTagToken} with the specified
53 * token name, type, and label.
54 *
55 * @param tokenName The token name.
56 * @param type The token type.
57 * @param label The label associated with the token tag, or {@code null} if
58 * the token tag is unlabeled.
59 */60 publicthis(stringtokenName, inttype, stringlabel)
61 {
62 super(type);
63 this.tokenName = tokenName;
64 this.label = label;
65 }
66 67 /**
68 * @uml
69 * Gets the token name.
70 * @return The token name.
71 */72 publicstringgetTokenName()
73 {
74 returntokenName;
75 }
76 77 /**
78 * @uml
79 * Gets the label associated with the rule tag.
80 *
81 * @return The name of the label associated with the rule tag, or
82 * {@code null} if this is an unlabeled rule tag.
83 */84 publicstringgetLabel()
85 {
86 returnlabel;
87 }
88 89 /**
90 * @uml
91 * <p>The implementation for {@link TokenTagToken} returns the token tag
92 * formatted with {@code <} and {@code >} delimiters.</p>
93 * @override
94 */95 publicoverrideVariantgetText()
96 {
97 if (label !isnull) {
98 Variantr = format("<%s:%s>", label, tokenName);
99 returnr;
100 }
101 Variantr = format("<%s>", tokenName);
102 returnr;
103 }
104 105 /**
106 * @uml
107 * <p>The implementation for {@link TokenTagToken} returns a string of the form
108 * {@code tokenName:type}.</p>
109 * @override
110 */111 publicoverridestringtoString()
112 {
113 returntokenName ~ ":" ~ to!string(type);
114 }
115 116 }