1// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers 2// 3// SPDX-License-Identifier: MPL-2.0 4 5import Foundation 6import LanguageServerProtocol 7 8public enum Keyword: String, Codable, Sendable, CaseIterable { 9 case theory = "theory" 10 case `where` = "where" 11 case `import` = "import" 12} 13 14public enum Punctuation: String, CaseIterable, Codable, Equatable, Sendable { 15 case lparen = "(" 16 case rparen = ")" 17 case lbrace = "{" 18 case rbrace = "}" 19 case comma = "," 20 case dot = "." 21 case colon = ":" 22 case doubleLeftArrow = "<=" 23 case doubleRightArrow = "=>" 24 case equal = "=" 25} 26 27public enum TokenKind: Codable, Equatable, Sendable, Hashable { 28 case eof 29 case keyword(Keyword) 30 case punctuation(Punctuation) 31 case error 32 case identifier 33 case newline 34 case whitespace 35 case blockBegin 36 case blockEnd 37 case blockSep 38 case lineComment 39 case blockComment(terminated: Bool) 40} 41 42extension TokenKind { 43 public var isTrivia: Bool { 44 switch self { 45 case .whitespace, .newline, .lineComment, .blockComment: true 46 default: false 47 } 48 } 49 50 public var isVisible: Bool { 51 switch self { 52 case .whitespace, .blockBegin, .blockSep, .blockEnd, .newline: false 53 default: true 54 } 55 } 56 57 public var canDetermineLayoutColumn: Bool { 58 switch self { 59 case .whitespace, .eof: false 60 default: true 61 } 62 } 63 64 public var isBlockHerald: Bool { 65 switch self { 66 case .keyword(.where): true 67 default: false 68 } 69 } 70 71} 72 73public final class SyntaxTreeKind: Codable, Equatable, Sendable { 74 static let error: SyntaxTreeKind = .init(name: "error") 75 76 public static func == (lhs: SyntaxTreeKind, rhs: SyntaxTreeKind) -> Bool { 77 lhs === rhs 78 } 79 80 let name: String 81 var description: String { name } 82 83 required init(name: String) { 84 self.name = name 85 } 86} 87 88public struct TokenMetadata: Equatable, Codable, Sendable { 89 public var semanticTokenType: SemanticTokenTypes 90 public var semanticTokenModifiers: Set<SemanticTokenModifiers> = [] 91 public var delimitedFoldingRangeKind: FoldingRangeKind? = nil 92} 93 94public struct SyntaxTreeMetadata: Codable, Equatable, Sendable { 95 public var delimitedFoldingRangeKind: FoldingRangeKind? = nil 96}