Skip to content

Commit aba6c18

Browse files
committed
Add language configuration for Cabal files
FIxes #128
1 parent 0a7299c commit aba6c18

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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

Comments
 (0)