@@ -42,15 +42,15 @@ parsePackage =
42
42
parseComponent :: Indent -> Parser Component
43
43
parseComponent i =
44
44
parseLib i
45
- <|> parseNamed i " executable " Exe
45
+ <|> parseExe i
46
46
<|> parseNamed i " test-suite" Test
47
47
48
48
parseLib :: Indent -> Parser Component
49
49
parseLib i =
50
50
indent i
51
51
>> asciiCI " library"
52
52
>> skipToNextLine
53
- >> Lib <$> parsePath (i + 1 )
53
+ >> Lib <$> extractPath (i + 1 )
54
54
55
55
parseQuoted :: Parser Text
56
56
parseQuoted = do
@@ -60,7 +60,25 @@ parseQuoted = do
60
60
parseString :: Parser Name
61
61
parseString = do
62
62
skipSpace
63
- parseQuoted <|> takeWhile1 (not . isSpace)
63
+ parseQuoted <|> takeWhile1 (not . (\ c -> isSpace c || c == ' ,' ))
64
+
65
+ parseExe :: Indent -> Parser Component
66
+ parseExe i =
67
+ do
68
+ indent i
69
+ _ <- asciiCI " executable"
70
+ _ <- skipSpace
71
+ n <- parseString <?> " Exe Name"
72
+ skipToNextLine
73
+ Exe n <$> pathMain (i + 1 ) " ." " "
74
+ <?> T. unpack " parseExe"
75
+
76
+ pathMain :: Indent -> Text -> Text -> Parser Text
77
+ pathMain i p m =
78
+ (field i " hs-source-dirs" >>= (\ p' -> pathMain i p' m))
79
+ <|> (field i " main-is" >>= pathMain i p)
80
+ <|> (skipBlockLine i >> pathMain i p m)
81
+ <|> pure (p <> " /" <> m)
64
82
65
83
parseNamed :: Indent -> Text -> (Name -> Path -> Component ) -> Parser Component
66
84
parseNamed i compType compCon =
@@ -70,43 +88,52 @@ parseNamed i compType compCon =
70
88
_ <- skipSpace <?> " skipSpace"
71
89
n <- parseString <?> " N"
72
90
skipToNextLine
73
- compCon n <$> parsePath (i + 1 )
91
+ compCon n <$> extractPath (i + 1 )
74
92
<?> T. unpack (" parseNamed " <> compType)
75
93
76
94
skipToNextLine :: Parser ()
77
95
skipToNextLine = skipWhile (not . isEndOfLine) >> endOfLine
78
96
79
97
skipBlock :: Indent -> Parser ()
80
- skipBlock i =
81
- skipMany $
82
- (indent i >> skipToNextLine)
83
- <|> (skipMany tabOrSpace >> endOfLine)
84
- <|> (skipSpace >> " --" >> skipToNextLine)
98
+ skipBlock i = skipMany $ skipBlockLine i
99
+
100
+ skipBlockLine :: Indent -> Parser ()
101
+ skipBlockLine i =
102
+ (indent i >> skipToNextLine)
103
+ <|> (skipMany tabOrSpace >> endOfLine)
104
+ <|> (skipSpace >> " --" >> skipToNextLine)
85
105
86
106
tabOrSpace :: Parser Char
87
107
tabOrSpace = char ' ' <|> char ' \t '
88
108
89
- parsePath :: Indent -> Parser Path
90
- parsePath i =
109
+ field :: Indent -> Text -> Parser Text
110
+ field i f =
111
+ do
112
+ indent i
113
+ _ <- asciiCI f
114
+ skipSpace
115
+ _ <- char ' :'
116
+ p <- parseString
117
+ skipToNextLine
118
+ pure p
119
+
120
+ parseMainIs :: Indent -> Parser Path
121
+ parseMainIs i =
122
+ do
123
+ p <- field i " main-is"
124
+ skipBlock i
125
+ pure p
126
+ <?> " hs-source-dirs"
127
+
128
+ extractPath :: Indent -> Parser Path
129
+ extractPath i =
91
130
( do
92
- indent i
93
- _ <- " hs-source-dirs"
94
- skipSpace
95
- _ <- char ' :'
96
- -- FIXME paths can be in quotes
97
- p <- parseString
98
- skipToNextLine
131
+ p <- field i " hs-source-dirs"
99
132
skipBlock i
100
133
pure p
101
- <?> " hs-source-dirs"
102
134
)
103
- <|> ( do
104
- indent i
105
- skipToNextLine
106
- parsePath i
107
- <?> " skip line"
108
- )
109
- <|> (pure " ." <?> " not found" ) <?> " parsePath"
135
+ <|> (skipBlockLine i >> extractPath i <?> " skip line" )
136
+ <|> (pure " ." <?> " not found" ) <?> " extractPath"
110
137
111
138
-- | Skip at least n spaces
112
139
indent :: Indent -> Parser ()
0 commit comments