mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-09 17:49:40 +00:00
LibWeb: Add CustomStringConvertible extension for HTMLToken types
This commit is contained in:
parent
fb074f9d0c
commit
33e50889f2
Notes:
github-actions[bot]
2024-08-24 01:18:16 +00:00
Author: https://github.com/ADKaster
Commit: 33e50889f2
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1130
Reviewed-by: https://github.com/AtkinsSJ
Reviewed-by: https://github.com/alimpfard
Reviewed-by: https://github.com/dzfrias
2 changed files with 44 additions and 0 deletions
|
@ -26,6 +26,8 @@ struct TestHTMLTokenizerSwift {
|
||||||
default_token.type = .Character(codePoint: "a")
|
default_token.type = .Character(codePoint: "a")
|
||||||
precondition(default_token.isCharacter())
|
precondition(default_token.isCharacter())
|
||||||
|
|
||||||
|
print("\(default_token)", to: &standardError)
|
||||||
|
|
||||||
print("HTMLToken types pass", to: &standardError)
|
print("HTMLToken types pass", to: &standardError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,3 +76,45 @@ public class HTMLToken {
|
||||||
self.type = type
|
self.type = type
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension HTMLToken.Position: Equatable, CustomStringConvertible {
|
||||||
|
public var description: String {
|
||||||
|
return "\(self.line):\(self.column)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension HTMLToken.TokenType: CustomStringConvertible {
|
||||||
|
// FIXME: Print attributes for start/end tags
|
||||||
|
public var description: String {
|
||||||
|
switch self {
|
||||||
|
case .Invalid:
|
||||||
|
return "Invalid"
|
||||||
|
case .DOCTYPE(let name, let publicIdentifier, let systemIdentifier, let forceQuirksMode):
|
||||||
|
return "DOCTYPE(name: \(name ?? "nil"), publicIdentifier: \(publicIdentifier ?? "nil"), systemIdentifier: \(systemIdentifier ?? "nil"), forceQuirksMode: \(forceQuirksMode))"
|
||||||
|
case .StartTag(let tagName, let selfClosing, let selfClosingAcknowledged, let attributes):
|
||||||
|
return "StartTag(tagName: \(tagName), selfClosing: \(selfClosing), selfClosingAcknowledged: \(selfClosingAcknowledged), attributes: \(attributes))"
|
||||||
|
case .EndTag(let tagName, let selfClosing, let selfClosingAcknowledged, let attributes):
|
||||||
|
return "EndTag(tagName: \(tagName), selfClosing: \(selfClosing), selfClosingAcknowledged: \(selfClosingAcknowledged), attributes: \(attributes))"
|
||||||
|
case .Comment(let data):
|
||||||
|
return "Comment(data: \(data))"
|
||||||
|
case .Character(let codePoint):
|
||||||
|
return "Character(codePoint: \(codePoint))"
|
||||||
|
case .EndOfFile:
|
||||||
|
return "EndOfFile"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension HTMLToken: CustomStringConvertible {
|
||||||
|
public var description: String {
|
||||||
|
if (self.startPosition == Position()) {
|
||||||
|
return "HTMLToken(type: \(self.type))"
|
||||||
|
}
|
||||||
|
else if (self.endPosition == Position()) {
|
||||||
|
return "HTMLToken(type: \(self.type))@\(self.startPosition)"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return "HTMLToken(type: \(self.type))@\(self.startPosition)-\(self.endPosition)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue