Skip to content

Commit 5844d6b

Browse files
committed
namespace MarkdownABI types
1 parent bfce54f commit 5844d6b

File tree

120 files changed

+343
-307
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+343
-307
lines changed

Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ let package:Package = .init(
466466
.target(name: "InlineArray"),
467467
.target(name: "InlineDictionary"),
468468
.target(name: "MarkdownParsing"),
469+
.target(name: "MarkdownRendering"),
469470
.target(name: "MarkdownSemantics"),
470471
.target(name: "SemanticVersions"),
471472
.target(name: "SHA1"),

Sources/MarkdownABI/Encoding/MarkdownAttributeEncoder.swift renamed to Sources/MarkdownABI/Bytecode/Markdown.AttributeEncoder.swift

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
@frozen public
2-
struct MarkdownAttributeEncoder
1+
extension Markdown
32
{
4-
@usableFromInline internal
5-
var bytecode:MarkdownBytecode
6-
7-
@inlinable internal
8-
init(bytecode:MarkdownBytecode)
3+
@frozen public
4+
struct AttributeEncoder
95
{
10-
self.bytecode = bytecode
6+
@usableFromInline internal
7+
var bytecode:Bytecode
8+
9+
@inlinable internal
10+
init(bytecode:Bytecode)
11+
{
12+
self.bytecode = bytecode
13+
}
1114
}
1215
}
13-
extension MarkdownAttributeEncoder
16+
extension Markdown.AttributeEncoder
1417
{
1518
/// Serializes an empty attribute, if the assigned boolean is true.
1619
/// Does nothing if it is false. The getter always returns false.
1720
@inlinable public
18-
subscript(attribute:MarkdownBytecode.Attribute) -> Bool
21+
subscript(attribute:Markdown.Bytecode.Attribute) -> Bool
1922
{
2023
get
2124
{
@@ -27,7 +30,7 @@ extension MarkdownAttributeEncoder
2730
}
2831
}
2932
@inlinable public
30-
subscript(attribute:MarkdownBytecode.Attribute) -> String?
33+
subscript(attribute:Markdown.Bytecode.Attribute) -> String?
3134
{
3235
get
3336
{
@@ -43,7 +46,7 @@ extension MarkdownAttributeEncoder
4346
}
4447
}
4548
@inlinable public
46-
subscript(attribute:MarkdownBytecode.Attribute) -> Int?
49+
subscript(attribute:Markdown.Bytecode.Attribute) -> Int?
4750
{
4851
get
4952
{

Sources/MarkdownABI/Instructions/MarkdownBinaryDecoder.swift renamed to Sources/MarkdownABI/Bytecode/Markdown.BinaryDecoder.swift

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
@frozen public
2-
struct MarkdownBinaryDecoder
1+
extension Markdown
32
{
4-
@usableFromInline
5-
let bytes:[UInt8]
6-
@usableFromInline
7-
var index:Int
8-
9-
@inlinable internal
10-
init(bytes:[UInt8])
3+
@frozen public
4+
struct BinaryDecoder
115
{
12-
self.bytes = bytes
13-
self.index = bytes.startIndex
6+
@usableFromInline
7+
let bytes:[UInt8]
8+
@usableFromInline
9+
var index:Int
10+
11+
@inlinable internal
12+
init(bytes:[UInt8])
13+
{
14+
self.bytes = bytes
15+
self.index = bytes.startIndex
16+
}
1417
}
1518
}
16-
extension MarkdownBinaryDecoder
19+
extension Markdown.BinaryDecoder
1720
{
1821
@inlinable internal mutating
1922
func read() -> UInt8?
@@ -68,10 +71,10 @@ extension MarkdownBinaryDecoder
6871
self.read().flatMap(Instruction.init(rawValue:))
6972
}
7073
}
71-
extension MarkdownBinaryDecoder:IteratorProtocol
74+
extension Markdown.BinaryDecoder:IteratorProtocol
7275
{
7376
@inlinable public mutating
74-
func next() -> MarkdownInstruction?
77+
func next() -> Markdown.Instruction?
7578
{
7679
guard let byte:UInt8 = self.read()
7780
else
@@ -87,10 +90,10 @@ extension MarkdownBinaryDecoder:IteratorProtocol
8790
break
8891
}
8992

90-
switch MarkdownBytecode.Marker.init(rawValue: byte)
93+
switch Markdown.Bytecode.Marker.init(rawValue: byte)
9194
{
9295
case .push?:
93-
if let instruction:MarkdownBytecode.Context = self.read()
96+
if let instruction:Markdown.Bytecode.Context = self.read()
9497
{
9598
return .push(instruction)
9699
}
@@ -99,41 +102,41 @@ extension MarkdownBinaryDecoder:IteratorProtocol
99102
return .pop
100103

101104
case .attribute?:
102-
if let attribute:MarkdownBytecode.Attribute = self.read()
105+
if let attribute:Markdown.Bytecode.Attribute = self.read()
103106
{
104107
return .attribute(attribute)
105108
}
106109

107110
case .attribute8?:
108-
if let attribute:MarkdownBytecode.Attribute = self.read(),
111+
if let attribute:Markdown.Bytecode.Attribute = self.read(),
109112
let reference:Int = self.read(UInt8.self)
110113
{
111114
return .attribute(attribute, reference)
112115
}
113116

114117
case .attribute16?:
115-
if let attribute:MarkdownBytecode.Attribute = self.read(),
118+
if let attribute:Markdown.Bytecode.Attribute = self.read(),
116119
let reference:Int = self.read(UInt16.self)
117120
{
118121
return .attribute(attribute, reference)
119122
}
120123

121124
case .attribute32?:
122-
if let attribute:MarkdownBytecode.Attribute = self.read(),
125+
if let attribute:Markdown.Bytecode.Attribute = self.read(),
123126
let reference:Int = self.read(UInt32.self)
124127
{
125128
return .attribute(attribute, reference)
126129
}
127130

128131
case .attribute64?:
129-
if let attribute:MarkdownBytecode.Attribute = self.read(),
132+
if let attribute:Markdown.Bytecode.Attribute = self.read(),
130133
let reference:Int = self.read(UInt64.self)
131134
{
132135
return .attribute(attribute, reference)
133136
}
134137

135138
case .emit?:
136-
if let instruction:MarkdownBytecode.Emission = self.read()
139+
if let instruction:Markdown.Bytecode.Emission = self.read()
137140
{
138141
return .emit(instruction)
139142
}

Sources/MarkdownABI/Encoding/MarkdownBinaryEncoder.swift renamed to Sources/MarkdownABI/Bytecode/Markdown.BinaryEncoder.swift

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
@frozen public
2-
struct MarkdownBinaryEncoder
1+
extension Markdown
32
{
4-
@usableFromInline internal
5-
var attribute:MarkdownAttributeEncoder
6-
7-
@inlinable internal
8-
init()
3+
@frozen public
4+
struct BinaryEncoder
95
{
10-
self.attribute = .init(bytecode: [])
6+
@usableFromInline internal
7+
var attribute:AttributeEncoder
8+
9+
@inlinable internal
10+
init()
11+
{
12+
self.attribute = .init(bytecode: [])
13+
}
1114
}
1215
}
13-
extension MarkdownBinaryEncoder
16+
extension Markdown.BinaryEncoder
1417
{
1518
@inlinable public internal(set)
16-
var bytecode:MarkdownBytecode
19+
var bytecode:Markdown.Bytecode
1720
{
1821
_read
1922
{
@@ -25,7 +28,7 @@ extension MarkdownBinaryEncoder
2528
}
2629
}
2730
}
28-
extension MarkdownBinaryEncoder
31+
extension Markdown.BinaryEncoder
2932
{
3033
@inlinable public static
3134
func += (self:inout Self, codepoint:Unicode.Scalar)
@@ -53,11 +56,11 @@ extension MarkdownBinaryEncoder
5356
self.bytecode.write(reference: reference)
5457
}
5558
}
56-
extension MarkdownBinaryEncoder
59+
extension Markdown.BinaryEncoder
5760
{
5861
@inlinable public
59-
subscript(_ emission:MarkdownBytecode.Emission,
60-
attributes:(inout MarkdownAttributeEncoder) -> () = { _ in }) -> Void
62+
subscript(_ emission:Markdown.Bytecode.Emission,
63+
attributes:(inout Markdown.AttributeEncoder) -> () = { _ in }) -> Void
6164
{
6265
mutating get
6366
{
@@ -66,8 +69,8 @@ extension MarkdownBinaryEncoder
6669
}
6770
}
6871
@inlinable public
69-
subscript(_ context:MarkdownBytecode.Context,
70-
attributes:(inout MarkdownAttributeEncoder) -> (),
72+
subscript(_ context:Markdown.Bytecode.Context,
73+
attributes:(inout Markdown.AttributeEncoder) -> (),
7174
content encode:(inout Self) -> () = { _ in }) -> Void
7275
{
7376
mutating get
@@ -79,7 +82,7 @@ extension MarkdownBinaryEncoder
7982
}
8083
}
8184
@inlinable public
82-
subscript(_ context:MarkdownBytecode.Context,
85+
subscript(_ context:Markdown.Bytecode.Context,
8386
content encode:(inout Self) -> () = { _ in }) -> Void
8487
{
8588
mutating get
@@ -90,15 +93,15 @@ extension MarkdownBinaryEncoder
9093
}
9194
}
9295
}
93-
extension MarkdownBinaryEncoder
96+
extension Markdown.BinaryEncoder
9497
{
9598
/// Emits the UTF-8 contents of the assigned string, if non-nil, into
9699
/// this binary, framed by the specified context. The setter does nothing
97100
/// if the assigned value is nil; it will not create an empty context.
98101
/// The getter always returns nil.
99102
@inlinable public
100-
subscript<String>(_ context:MarkdownBytecode.Context,
101-
attributes:(inout MarkdownAttributeEncoder) -> () = { _ in }) -> String?
103+
subscript<String>(_ context:Markdown.Bytecode.Context,
104+
attributes:(inout Markdown.AttributeEncoder) -> () = { _ in }) -> String?
102105
where String:StringProtocol
103106
{
104107
get

Sources/MarkdownABI/Bytecode/MarkdownBytecode.Attribute.swift renamed to Sources/MarkdownABI/Bytecode/Markdown.Bytecode.Attribute.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
extension MarkdownBytecode
1+
extension Markdown.Bytecode
22
{
33
@frozen public
44
enum Attribute:UInt8, RawRepresentable, Equatable, Hashable, Sendable

Sources/MarkdownABI/Bytecode/MarkdownBytecode.Context.swift renamed to Sources/MarkdownABI/Bytecode/Markdown.Bytecode.Context.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
extension MarkdownBytecode
1+
extension Markdown.Bytecode
22
{
33
/// An instruction that pushes a container element onto the document stack.
44
@frozen public
@@ -89,7 +89,7 @@ extension MarkdownBytecode
8989
case warning
9090
}
9191
}
92-
extension MarkdownBytecode.Context
92+
extension Markdown.Bytecode.Context
9393
{
9494
/// Returns a heading context, clamping the given heading `level`. If
9595
/// `level` is less than 1, this function returns ``h1``. If `level`

Sources/MarkdownABI/Bytecode/MarkdownBytecode.Emission.swift renamed to Sources/MarkdownABI/Bytecode/Markdown.Bytecode.Emission.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
extension MarkdownBytecode
1+
extension Markdown.Bytecode
22
{
33
/// An instruction that emits a void element.
44
@frozen public

Sources/MarkdownABI/Bytecode/MarkdownBytecode.Marker.swift renamed to Sources/MarkdownABI/Bytecode/Markdown.Bytecode.Marker.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
extension MarkdownBytecode
1+
extension Markdown.Bytecode
22
{
33
/// Markers inhabit the unassigned codepoints of the UTF-8 encoding.
44
///

Sources/MarkdownABI/Bytecode/MarkdownBytecode.swift renamed to Sources/MarkdownABI/Bytecode/Markdown.Bytecode.swift

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,45 @@
1-
@frozen public
2-
struct MarkdownBytecode:Equatable, Sendable
1+
extension Markdown
32
{
4-
public
5-
var bytes:[UInt8]
6-
7-
@inlinable public
8-
init(bytes:[UInt8])
3+
@frozen public
4+
struct Bytecode:Equatable, Sendable
95
{
10-
self.bytes = bytes
6+
public
7+
var bytes:[UInt8]
8+
9+
@inlinable public
10+
init(bytes:[UInt8])
11+
{
12+
self.bytes = bytes
13+
}
1114
}
1215
}
13-
extension MarkdownBytecode
16+
extension Markdown.Bytecode
1417
{
1518
@inlinable public
1619
var isEmpty:Bool
1720
{
1821
self.bytes.isEmpty
1922
}
2023
}
21-
extension MarkdownBytecode
24+
extension Markdown.Bytecode
2225
{
2326
@inlinable public
24-
init(with encode:(inout MarkdownBinaryEncoder) throws -> ()) rethrows
27+
init(with encode:(inout Markdown.BinaryEncoder) throws -> ()) rethrows
2528
{
26-
var encoder:MarkdownBinaryEncoder = .init()
29+
var encoder:Markdown.BinaryEncoder = .init()
2730
try encode(&encoder)
2831
self = encoder.bytecode
2932
}
3033
}
31-
extension MarkdownBytecode:ExpressibleByArrayLiteral
34+
extension Markdown.Bytecode:ExpressibleByArrayLiteral
3235
{
3336
@inlinable public
3437
init(arrayLiteral:UInt8...)
3538
{
3639
self.init(bytes: arrayLiteral)
3740
}
3841
}
39-
extension MarkdownBytecode
42+
extension Markdown.Bytecode
4043
{
4144
@inlinable internal mutating
4245
func write(marker:Marker)
@@ -159,10 +162,10 @@ extension MarkdownBytecode
159162
self.bytes.append(contentsOf: utf8)
160163
}
161164
}
162-
extension MarkdownBytecode:Sequence
165+
extension Markdown.Bytecode:Sequence
163166
{
164167
@inlinable public
165-
func makeIterator() -> MarkdownBinaryDecoder
168+
func makeIterator() -> Markdown.BinaryDecoder
166169
{
167170
.init(bytes: self.bytes)
168171
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
extension Markdown
2+
{
3+
@frozen public
4+
enum Instruction:Equatable, Hashable, Sendable
5+
{
6+
case invalid
7+
8+
case attribute(Bytecode.Attribute, Int? = nil)
9+
case emit(Bytecode.Emission)
10+
case load(Int)
11+
case push(Bytecode.Context)
12+
case pop
13+
case utf8(UInt8)
14+
}
15+
}

0 commit comments

Comments
 (0)