This commit is contained in:
janyou 2016-12-14 11:40:07 +08:00
parent 57d8cc2e0c
commit be1b070a1a
1 changed files with 17 additions and 9 deletions

View File

@ -255,9 +255,13 @@ public class CommonToken: WritableToken {
}
public var description: String {
return toString(nil)
}
public func toString(_ r: Recognizer<ATNSimulator>?) -> String {
var channelStr: String = ""
if channel > 0 {
channelStr = "channel=\(channel)"
channelStr = ",channel=\(channel)"
}
var txt: String
if let tokenText = getText() {
@ -267,15 +271,19 @@ public class CommonToken: WritableToken {
} else {
txt = "<no text>"
}
let desc: StringBuilder = StringBuilder()
desc.append("[@\(getTokenIndex()),")
desc.append("\(start):\(stop)='\(txt)',")
desc.append("<\(type)>\(channelStr),")
desc.append("\(line):\(getCharPositionInLine())]")
return desc.toString()
var typeString = "\(type)"
if let r = r {
typeString = r.getVocabulary().getDisplayName(type);
}
return "[@"+getTokenIndex()+","+start+":"+stop+"='"+txt+"',<"+typeString+">"+channelStr+","+line+":"+getCharPositionInLine()+"]"
// let desc: StringBuilder = StringBuilder()
// desc.append("[@\(getTokenIndex()),")
// desc.append("\(start):\(stop)='\(txt)',")
// desc.append("<\(typeString)>\(channelStr),")
// desc.append("\(line):\(getCharPositionInLine())]")
//
// return desc.toString()
}
public var visited: Bool {
get {
return _visited