-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathFootnote.swift
39 lines (34 loc) · 1002 Bytes
/
Footnote.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
// Footnote.swift
// SwiftOrg
//
// Created by Xiaoxing Hu on 27/09/16.
// Copyright © 2016 Xiaoxing Hu. All rights reserved.
//
import Foundation
public struct Footnote: Node {
public var label: String
public var content: [Node] = []
public var description: String {
return "Footnote(content: \(content))"
}
}
extension OrgParser {
func parseFootnote() throws -> Footnote {
guard case let(_, .footnote(label, content)) = tokens.dequeue()! else {
throw Errors.unexpectedToken("footnote expected")
}
var footnote = Footnote(label: label, content: [try parseParagraph(content)!])
while let (_, token) = tokens.peek() {
switch token {
case .headline, .footnote:
return footnote
default:
if let n = try parseTheRest() {
footnote.content.append(n)
}
}
}
return footnote
}
}