Skip to content

Commit fb33210

Browse files
authored
Merge pull request #394 from tayloraswift/improved-diagnostics
2 parents 985578d + ebcdd4f commit fb33210

File tree

60 files changed

+500
-373
lines changed

Some content is hidden

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

60 files changed

+500
-373
lines changed

Package.resolved

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
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+
struct AnyOption:Markdown.BlockDirectiveOption
5+
{
6+
public
7+
let rawValue:String
8+
9+
@inlinable public
10+
init(rawValue:String)
11+
{
12+
self.rawValue = rawValue
13+
}
14+
}
15+
}

Sources/MarkdownAST/BlockElements/Markdown.BlockDirective.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ extension Markdown
5252
extension Markdown.BlockDirective:Markdown.BlockDirectiveType
5353
{
5454
@inlinable public
55-
func configure(option:String, value:Markdown.SourceString) throws
55+
func configure(option:Markdown.AnyOption, value:Markdown.SourceString)
5656
{
57-
self.arguments.append((option, value.string))
57+
self.arguments.append((option.rawValue, value.string))
5858
}
5959

6060
@inlinable public
61-
func append(_ element:Markdown.BlockElement) throws
61+
func append(_ element:Markdown.BlockElement)
6262
{
6363
self.elements.append(element)
6464
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import MarkdownABI
2+
3+
extension Markdown
4+
{
5+
public
6+
protocol BlockDirectiveOption:RawRepresentable<String>, Sendable
7+
{
8+
}
9+
}

Sources/MarkdownAST/BlockElements/Markdown.BlockDirectiveType.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import Sources
44
extension Markdown
55
{
66
public
7-
protocol BlockDirectiveType:BlockElement
7+
protocol BlockDirectiveType<Option>:BlockElement
88
{
9-
func configure(option:String, value:SourceString) throws
9+
associatedtype Option:BlockDirectiveOption
10+
11+
func configure(option:Option, value:SourceString) throws
1012
func append(_ element:BlockElement) throws
1113

1214
/// Associates a source location with this block. For ideal formatting, this source range
@@ -17,7 +19,7 @@ extension Markdown
1719
extension Markdown.BlockDirectiveType where Self:Markdown.BlockContainer<Markdown.BlockElement>
1820
{
1921
public
20-
func append(_ element:Markdown.BlockElement) throws
22+
func append(_ element:Markdown.BlockElement)
2123
{
2224
self.elements.append(element)
2325
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
extension Markdown
2+
{
3+
@frozen public
4+
enum NeverOption:BlockDirectiveOption
5+
{
6+
@inlinable public
7+
init?(rawValue:String) { nil }
8+
9+
@inlinable public
10+
var rawValue:String { fatalError() }
11+
}
12+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import MarkdownAST
2+
3+
extension Markdown.BlockDirectiveType
4+
{
5+
func configure(option:String, value:Markdown.SourceString, block:String) throws
6+
{
7+
guard
8+
let option:Option = .init(rawValue: option)
9+
else
10+
{
11+
throw Markdown.BlockDirectiveUnexpectedOptionError.init(
12+
option: option,
13+
block: block)
14+
}
15+
16+
try self.configure(option: option, value: value)
17+
}
18+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import MarkdownAST
2+
3+
extension Markdown
4+
{
5+
struct BlockDirectiveUnexpectedOptionError:Error
6+
{
7+
let option:String
8+
let block:String
9+
}
10+
}
11+
extension Markdown.BlockDirectiveUnexpectedOptionError:CustomStringConvertible
12+
{
13+
var description:String
14+
{
15+
"unexpected option '\(self.option)' for block directive '@\(self.block)'"
16+
}
17+
}

Sources/MarkdownParsing/Markdown.Parser.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ extension Markdown.Parser
107107
option: argument.name,
108108
value: .init(
109109
source: .init(from: argument.valueRange, in: source),
110-
string: argument.value))
110+
string: argument.value),
111+
block: block.name)
111112
}
112113
catch let error
113114
{

Sources/MarkdownSemantics/AST/Layout/Markdown.BlockColumns.ArgumentError.swift

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)