@@ -25,7 +25,6 @@ import Core.Data
25
25
import Core.System.Base (IOMode (.. ), withFile )
26
26
import Core.System.Pretty
27
27
import Core.Text
28
- import Data.List (intersperse )
29
28
import qualified Data.List as List (find , isSuffixOf )
30
29
import Data.Maybe (fromMaybe )
31
30
import Data.String
@@ -148,23 +147,21 @@ readCabalFile = runIO $ do
148
147
-- pass to calling program
149
148
return pairs
150
149
150
+ -- TODO this could be improved; we really only need the data from the first
151
+ -- block of lines, with colons in them! We're probably reached the point where
152
+ -- a proper parser would be good, but whatever.
151
153
parseCabalFile :: Bytes -> Map Rope Rope
152
154
parseCabalFile contents =
153
- let breakup = intoMap . fmap (breakRope' (== ' :' )) . breakLines . fromBytes
155
+ let breakup = intoMap . fmap (\ (a, b) -> (a, trimValue b)) . fmap ( breakRope (== ' :' )) . breakLines . fromBytes
154
156
in breakup contents
155
157
156
- -- this should probably be a function in Core.Text.Rope
157
- breakRope' :: (Char -> Bool ) -> Rope -> (Rope , Rope )
158
- breakRope' predicate text =
159
- let pieces = take 2 (breakPieces predicate text)
160
- in case pieces of
161
- [] -> (" " , " " )
162
- [one] -> (one, " " )
163
- (one : two : _) -> (one, trimRope two)
164
-
165
- -- knock off the whitespace in "name: hello"
166
- trimRope :: Rope -> Rope
167
- trimRope = mconcat . intersperse " " . breakWords
158
+ -- knock off the colon and whitespace in ": hello"
159
+ trimValue :: Rope -> Rope
160
+ trimValue value = case unconsRope value of
161
+ Nothing -> emptyRope
162
+ Just (_, remainder) -> case findIndexRope (/= ' ' ) remainder of
163
+ Nothing -> emptyRope
164
+ Just i -> snd (splitRope i remainder)
168
165
169
166
{- |
170
167
Access the source location of the call site.
0 commit comments