|
@@ -39,7 +39,7 @@ findFragments root s sources = case (T.splitOn "/" s) of
|
|
where
|
|
where
|
|
|
|
|
|
go q [] (ExposeFile path) =
|
|
go q [] (ExposeFile path) =
|
|
- return (TL.readFile (root </> sourceDir q </> path))
|
|
|
|
|
|
+ return (cOpenFile "file source" (root </> sourceDir q </> path))
|
|
go _ [] ExposeSections{} =
|
|
go _ [] ExposeSections{} =
|
|
throw ("Splice identifier «" % stext %
|
|
throw ("Splice identifier «" % stext %
|
|
"» matches a file with sections") s
|
|
"» matches a file with sections") s
|
|
@@ -73,16 +73,16 @@ doReplacements root e original =
|
|
where
|
|
where
|
|
doReplace file frag = do
|
|
doReplace file frag = do
|
|
new <- case findFragments root frag e of
|
|
new <- case findFragments root frag e of
|
|
- Left err -> cError err
|
|
|
|
|
|
+ Left err -> cError ("Fragment error: " % text) err
|
|
Right x -> x
|
|
Right x -> x
|
|
return (TL.replace (toIdent frag) new file)
|
|
return (TL.replace (toIdent frag) new file)
|
|
|
|
|
|
readSection :: FilePath -> T.Text -> IO TL.Text
|
|
readSection :: FilePath -> T.Text -> IO TL.Text
|
|
readSection path f = do
|
|
readSection path f = do
|
|
- contents <- TL.readFile path
|
|
|
|
|
|
+ contents <- cOpenFile "section source" path
|
|
case TL.breakOn (toIdent f) contents of
|
|
case TL.breakOn (toIdent f) contents of
|
|
- (_, "") -> cError (format ("Unable to find section " % shown %
|
|
|
|
- " in file " % string) f path)
|
|
|
|
|
|
+ (_, "") -> cError ("Unable to find section " % shown %
|
|
|
|
+ " in file " % string) f path
|
|
(_, rs) ->
|
|
(_, rs) ->
|
|
let (_, skipLine) = TL.breakOn "\n" rs
|
|
let (_, skipLine) = TL.breakOn "\n" rs
|
|
(section, _) = TL.breakOn "«end»" (TL.drop 1 skipLine)
|
|
(section, _) = TL.breakOn "«end»" (TL.drop 1 skipLine)
|
|
@@ -92,6 +92,6 @@ readSection path f = do
|
|
runSplice :: Config -> Options -> IO ()
|
|
runSplice :: Config -> Options -> IO ()
|
|
runSplice conf opts = do
|
|
runSplice conf opts = do
|
|
let root = Sys.takeDirectory (optFile opts)
|
|
let root = Sys.takeDirectory (optFile opts)
|
|
- f <- TL.readFile (root </> confDocument conf)
|
|
|
|
|
|
+ f <- cOpenFile "document" (root </> confDocument conf)
|
|
rs <- doReplacements root (confSources conf) f
|
|
rs <- doReplacements root (confSources conf) f
|
|
TL.putStrLn rs
|
|
TL.putStrLn rs
|