1 /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 * Use of this file is governed by the BSD 3-clause license that 3 * can be found in the LICENSE.txt file in the project root. 4 */ 5 6 7 8 /// 9 /// A _org.antlr.v4.runtime.Token_ object representing a token of a particular type; e.g., 10 /// `<ID>`. These tokens are created for _org.antlr.v4.runtime.tree.pattern.TagChunk_ chunks where the 11 /// tag corresponds to a lexer rule or token type. 12 /// 13 14 public class TokenTagToken: CommonToken { 15 /// 16 /// This is the backing field for _#getTokenName_. 17 /// 18 19 private let tokenName: String 20 /// 21 /// This is the backing field for _#getLabel_. 22 /// 23 24 private let label: String? 25 26 /// 27 /// Constructs a new instance of _org.antlr.v4.runtime.tree.pattern.TokenTagToken_ for an unlabeled tag 28 /// with the specified token name and type. 29 /// 30 /// - Parameter tokenName: The token name. 31 /// - Parameter type: The token type. 32 /// 33 public convenience init(_ tokenName: String, _ type: Int) { 34 self.init(tokenName, type, nil) 35 } 36 37 /// 38 /// Constructs a new instance of _org.antlr.v4.runtime.tree.pattern.TokenTagToken_ with the specified 39 /// token name, type, and label. 40 /// 41 /// - Parameter tokenName: The token name. 42 /// - Parameter type: The token type. 43 /// - Parameter label: The label associated with the token tag, or `null` if 44 /// the token tag is unlabeled. 45 /// 46 public init(_ tokenName: String, _ type: Int, _ label: String?) { 47 48 self.tokenName = tokenName 49 self.label = label 50 super.init(type) 51 } 52 53 /// 54 /// Gets the token name. 55 /// - Returns: The token name. 56 /// 57 getTokenNamenull58 public final func getTokenName() -> String { 59 return tokenName 60 } 61 62 /// 63 /// Gets the label associated with the rule tag. 64 /// 65 /// - Returns: The name of the label associated with the rule tag, or 66 /// `null` if this is an unlabeled rule tag. 67 /// 68 getLabelnull69 public final func getLabel() -> String? { 70 return label 71 } 72 73 /// 74 /// 75 /// 76 /// The implementation for _org.antlr.v4.runtime.tree.pattern.TokenTagToken_ returns the token tag 77 /// formatted with `<` and `>` delimiters. 78 /// 79 override getTextnull80 public func getText() -> String { 81 if label != nil { 82 return "<" + label! + ":" + tokenName + ">" 83 } 84 85 return "<" + tokenName + ">" 86 } 87 88 /// 89 /// 90 /// 91 /// The implementation for _org.antlr.v4.runtime.tree.pattern.TokenTagToken_ returns a string of the form 92 /// `tokenName:type`. 93 /// 94 95 override 96 public var description: String { 97 return tokenName + ":" + String(type) 98 } 99 } 100