1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
module Parse.Config where
import List (isPrefixOf, isSuffixOf, last)
import Read (readInt)
import Pretty.ToJson (renderMessagesToJson)
import Pretty.ToString (renderMessagesToString)
import Types
defaultConfig :: Config
defaultConfig = Config (CheckList
True True True True
True True True True
True True True True
True True True True
True True True True
True True True True
True True True True
True
)
TEXT 1 True True 80
parseConfig :: Bool -> String -> IO Config
parseConfig verb conf = do
when verb $ putStrLn $ "INFO: Reading config file '" ++ conf ++ "'..."
file <- readFile conf
let ls = lines file
return $ Config (readCheckList ls (checks defaultConfig))
(readOType ls)
(readVerbosity ls (verbosity defaultConfig))
(readHint ls)
(readCode ls)
(readLength ls (maxLineLength defaultConfig))
readCheckList :: [String] -> CheckList -> CheckList
readCheckList [] checkl
= checkl
readCheckList (l:ls) checkl
| isPrefixOf "lineLength" l && isSuffixOf "0" l
= readCheckList ls $ checkl { lineLength = False }
| isPrefixOf "tabs" l && isSuffixOf "0" l
= readCheckList ls $ checkl {tab = False}
| isPrefixOf "ifThenElse" l && isSuffixOf "0" l
= readCheckList ls $ checkl {ifThenElse = False}
| isPrefixOf "case" l && isSuffixOf "0" l
= readCheckList ls $ checkl {caseIndent = False}
| isPrefixOf "do" l && isSuffixOf "0" l
= readCheckList ls $ checkl {doIndent = False}
| isPrefixOf "let" l && isSuffixOf "0" l
= readCheckList ls $ checkl {letIndent = False}
| isPrefixOf "guard" l && isSuffixOf "0" l
= readCheckList ls $ checkl {letIndent = False}
| isPrefixOf "functionRhs" l && isSuffixOf "0" l
= readCheckList ls $ checkl {rhsAlign = False}
| isPrefixOf "equalstrue" l && isSuffixOf "0" l
= readCheckList ls $ checkl {equalstrue = False}
| isPrefixOf "signatures" l && isSuffixOf "0" l
= readCheckList ls $ checkl {topLevelSig = False}
| isPrefixOf "blankLines" l && isSuffixOf "0" l
= readCheckList ls $ checkl {blankLines = False}
| isPrefixOf "trailingSpaces" l && isSuffixOf "0" l
= readCheckList ls $ checkl {trailingS = False}
| isPrefixOf "moduleHeader" l && isSuffixOf "0" l
= readCheckList ls $ checkl {moduleheader = False}
| isPrefixOf "imports" l && isSuffixOf "0" l
= readCheckList ls $ checkl {imports = False}
| isPrefixOf "data" l && isSuffixOf "0" l
= readCheckList ls $ checkl {dataIndent = False}
| isPrefixOf "list" l && isSuffixOf "0" l
= readCheckList ls $ checkl {listIndent = False}
| isPrefixOf "thentrueelsefalse" l && isSuffixOf "0" l
= readCheckList ls $ checkl {thenTrueElseFalse = False}
| isPrefixOf "notEqual" l && isSuffixOf "0" l
= readCheckList ls $ checkl {notEqual = False}
| isPrefixOf "notOrd" l && isSuffixOf "0" l
= readCheckList ls $ checkl {notOrd = False}
| isPrefixOf "equalsEmptyList" l && isSuffixOf "0" l
= readCheckList ls $ checkl {equalsEmptyList = False}
| isPrefixOf "identFunc" l && isSuffixOf "0" l
= readCheckList ls $ checkl {identFunc = False}
| isPrefixOf "constFunc" l && isSuffixOf "0" l
= readCheckList ls $ checkl {constFunc = False}
| isPrefixOf "andOr" l && isSuffixOf "0" l
= readCheckList ls $ checkl {andOr = False}
| isPrefixOf "print" l && isSuffixOf "0" l
= readCheckList ls $ checkl {printCheck = False}
| isPrefixOf "deriving" l && isSuffixOf "0" l
= readCheckList ls $ checkl {derivingIndent = False}
| isPrefixOf "class" l && isSuffixOf "0" l
= readCheckList ls $ checkl {classIndent = False}
| isPrefixOf "instance" l && isSuffixOf "0" l
= readCheckList ls $ checkl {instanceIndent = False}
| otherwise
= readCheckList ls checkl
readLength :: [String] -> Int -> Int
readLength [] len
= len
readLength (l:ls) len
| isPrefixOf "maxLineLength" l = readInt $ last $ words l
| otherwise = readLength ls len
readHint :: [String] -> Bool
readHint []
= True
readHint (l:ls)
| isPrefixOf "hints" l && isSuffixOf "0" l = False
| otherwise = readHint ls
readCode :: [String] -> Bool
readCode []
= True
readCode (l:ls)
| isPrefixOf "code" l && isSuffixOf "0" l = False
| otherwise = readCode ls
readOType :: [String] -> OutPut
readOType [] = TEXT
readOType (l:ls)
| isPrefixOf "oType" l && isSuffixOf "JSON" l = JSON
| otherwise = readOType ls
readVerbosity :: [String] -> Int -> Int
readVerbosity [] n = if ((n < 4) && ( n > -1)) then n else 1
readVerbosity (l:ls) n
| isPrefixOf "verbosity" l = readVerbosity ls (readInt $ last $ words l)
| otherwise = readVerbosity ls n
|