aboutsummaryrefslogtreecommitdiff
path: root/Sources/NorgKit/Lexer/NorgToken.swift
diff options
context:
space:
mode:
authorRuben Beltran del Rio <jj@r.bdr.sh>2026-06-19 22:06:26 +0200
committerRuben Beltran del Rio <jj@r.bdr.sh>2026-06-19 22:15:42 +0200
commit647296d5a0799c2e9de05cd41b50bd161cdeac85 (patch)
tree61dd769ceadba7f139d2c299119e6b1b86d849ab /Sources/NorgKit/Lexer/NorgToken.swift
parentc796b061f2d1a1da02c92b71d518af6cef16d33a (diff)
Add NorgLexerHEAD1.1.0main
Diffstat (limited to 'Sources/NorgKit/Lexer/NorgToken.swift')
-rw-r--r--Sources/NorgKit/Lexer/NorgToken.swift65
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
+ }
+}