mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-06 08:10:02 +00:00
LibWeb: Implement the Data state for the Swift tokenizer
And add tests! This implementation closely follows the current C++ implementation, replacing macros and gotos with a slightly more complex state machine. It's very possible that an async version that yields tokens on "emit" would be even simpler, but let's get this one working first :).
This commit is contained in:
parent
01c4625a42
commit
77718c0a66
Notes:
github-actions[bot]
2024-08-29 04:32:14 +00:00
Author: https://github.com/ADKaster
Commit: 77718c0a66
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1220
3 changed files with 296 additions and 21 deletions
|
@ -7,13 +7,13 @@
|
|||
@_exported import WebCxx
|
||||
|
||||
public class HTMLToken {
|
||||
public struct Position {
|
||||
public struct Position: Equatable {
|
||||
var line = UInt()
|
||||
var column = UInt()
|
||||
var byteOffset = UInt()
|
||||
}
|
||||
|
||||
public struct Attribute {
|
||||
public struct Attribute: Equatable {
|
||||
var prefix: Swift.String?
|
||||
var localName: Swift.String
|
||||
var namespace_: Swift.String?
|
||||
|
@ -24,7 +24,7 @@ public class HTMLToken {
|
|||
var valueEndPosition: Position
|
||||
}
|
||||
|
||||
public enum TokenType {
|
||||
public enum TokenType: Equatable {
|
||||
case Invalid
|
||||
case DOCTYPE(
|
||||
name: Swift.String?,
|
||||
|
@ -79,7 +79,7 @@ public class HTMLToken {
|
|||
}
|
||||
}
|
||||
|
||||
extension HTMLToken.Position: Equatable, CustomStringConvertible {
|
||||
extension HTMLToken.Position: CustomStringConvertible {
|
||||
public var description: Swift.String {
|
||||
return "\(self.line):\(self.column)"
|
||||
}
|
||||
|
@ -109,13 +109,11 @@ extension HTMLToken.TokenType: CustomStringConvertible {
|
|||
|
||||
extension HTMLToken: CustomStringConvertible {
|
||||
public var description: Swift.String {
|
||||
if (self.startPosition == Position()) {
|
||||
if self.startPosition == Position() {
|
||||
return "HTMLToken(type: \(self.type))"
|
||||
}
|
||||
else if (self.endPosition == Position()) {
|
||||
} else if self.endPosition == Position() {
|
||||
return "HTMLToken(type: \(self.type))@\(self.startPosition)"
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return "HTMLToken(type: \(self.type))@\(self.startPosition)-\(self.endPosition)"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue