Skip to content

Commit

Permalink
feat: define DOM
Browse files Browse the repository at this point in the history
  • Loading branch information
kkebo committed Jul 7, 2024
1 parent b919988 commit 0e8bce6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Sources/TreeConstructor/Document.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public struct Document: ~Copyable, Sendable {
public var title: String
public var body: Optional<Node>
public var head: Optional<Node>
}
3 changes: 3 additions & 0 deletions Sources/TreeConstructor/HTMLElement.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public struct HTMLElement: Sendable {
public var tagName: String
}
9 changes: 9 additions & 0 deletions Sources/TreeConstructor/Node.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public struct Node: Sendable {
public var value: NodeValue
public var childNodes: [Self]
}

public enum NodeValue: Sendable {
case element(HTMLElement)
case text(Text)
}
3 changes: 3 additions & 0 deletions Sources/TreeConstructor/Text.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public struct Text: Sendable {
public var data: String
}
2 changes: 2 additions & 0 deletions Sources/TreeConstructor/TreeConstructor.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
public import Tokenizer

public struct TreeConstructor: ~Copyable {
public var document: Document
private var mode: InsertionMode

public init() {
self.document = .init(title: "", body: nil, head: nil)
self.mode = .initial
}
}
Expand Down

0 comments on commit 0e8bce6

Please sign in to comment.