|
| 1 | +// |
| 2 | +// CabalConfiguration.swift |
| 3 | +// CodeEditorView |
| 4 | +// |
| 5 | +// Created by Manuel M T Chakravarty on 05/04/2025. |
| 6 | +// |
| 7 | +// Cabal configuration files: https://www.haskell.org/cabal/ |
| 8 | + |
| 9 | +import Foundation |
| 10 | +import RegexBuilder |
| 11 | + |
| 12 | + |
| 13 | +private let cabalReservedIds: [String] = [] |
| 14 | +private let cabalReservedOperators = [":"] |
| 15 | + |
| 16 | +extension LanguageConfiguration { |
| 17 | + |
| 18 | + /// Language configuration for Cabal configurations |
| 19 | + /// |
| 20 | + public static func cabal(_ languageService: LanguageService? = nil) -> LanguageConfiguration { |
| 21 | + let numberRegex = Regex { |
| 22 | + optNegation |
| 23 | + ChoiceOf { |
| 24 | + Regex{ decimalLit; ZeroOrMore { "."; decimalLit } } |
| 25 | + } |
| 26 | + } |
| 27 | + let identifierRegex = Regex { |
| 28 | + identifierHeadCharacters |
| 29 | + ZeroOrMore { |
| 30 | + CharacterClass(identifierCharacters, .anyOf("'-")) |
| 31 | + } |
| 32 | + /\:/ |
| 33 | + } |
| 34 | + let symbolCharacter = CharacterClass(.anyOf("&<=>|~")), |
| 35 | + operatorRegex = Regex { |
| 36 | + symbolCharacter |
| 37 | + ZeroOrMore { symbolCharacter } |
| 38 | + } |
| 39 | + return LanguageConfiguration(name: "Cabal", |
| 40 | + supportsSquareBrackets: false, |
| 41 | + supportsCurlyBrackets: false, |
| 42 | + indentationSensitiveScoping: true, |
| 43 | + stringRegex: /\"/, |
| 44 | + characterRegex: /'/, |
| 45 | + numberRegex: numberRegex, |
| 46 | + singleLineComment: "--", |
| 47 | + nestedComment: (open: "{-", close: "-}"), |
| 48 | + identifierRegex: identifierRegex, |
| 49 | + operatorRegex: operatorRegex, |
| 50 | + reservedIdentifiers: cabalReservedIds, |
| 51 | + reservedOperators: cabalReservedOperators, |
| 52 | + languageService: languageService) |
| 53 | + } |
| 54 | +} |
0 commit comments