diff options
Diffstat (limited to 'Sources/NorgKit/Lexer/NorgToken.swift')
| -rw-r--r-- | Sources/NorgKit/Lexer/NorgToken.swift | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/Sources/NorgKit/Lexer/NorgToken.swift b/Sources/NorgKit/Lexer/NorgToken.swift new file mode 100644 index 0000000..050c37e --- /dev/null +++ b/Sources/NorgKit/Lexer/NorgToken.swift @@ -0,0 +1,65 @@ +/// A lexical token over Norg source. +public struct NorgToken: Equatable, Sendable { + + /// What a token represents. + public enum Kind: Equatable, Sendable { + + // MARK: Block / line level + + /// A heading marker run (`*`…), carrying its level. + case heading(level: Int) + /// An unordered-list marker run (`-`…). + case unorderedList(level: Int) + /// An ordered-list marker run (`~`…). + case orderedList(level: Int) + /// A quote marker run (`>`…). + case quote(level: Int) + /// A definition marker run (`$`…). + case definition(level: Int) + /// A footnote marker run (`^`…). + case footnote(level: Int) + /// A table-cell marker run (`:`…). + case tableCell(level: Int) + /// A task status marker including its parentheses, eg. `(x)`. + case taskStatus(TaskStatus) + /// A weak delimiting line (`---`). + case weakDelimiter + /// A strong delimiting line (`===`). + case strongDelimiter + /// A horizontal rule (`___`). + case horizontalRule + /// A ranged-tag fence marker: the `@` of an opener and of `@end`. + case tagDelimiter + /// A ranged-tag header after `@` (name and parameters), eg. `code swift`. + case tagName + /// A raw body line inside a ranged tag (`@code` … `@end`). + case verbatimBlock + + // MARK: Inline level + + /// An attached- or verbatim-modifier delimiter (`*`, `/`, `` ` ``, `$`, …); + /// the style identifies which. + case modifierDelimiter(InlineStyle) + /// A run of text carrying a non-empty cumulative style (the content of one + /// or more nested modifiers). + case styledText(InlineStyle) + /// An inline comment, markers included (`%…%`). + case comment + /// An escape: the backslash of `\x` (the escaped character is not a token). + case escape + /// A link/anchor delimiter: `{`, `}`, `[`, or `]`. + case linkDelimiter + /// A link/anchor location (inside `{…}`). + case linkTarget + /// A link/anchor description or label (inside `[…]`). + case linkDescription + } + + public let kind: Kind + public let range: Range<String.Index> + + public init(kind: Kind, range: Range<String.Index>) { + self.kind = kind + self.range = range + } +} |