mirror of
https://github.com/simonmichael/hledger.git
synced 2024-12-27 12:24:43 +03:00
csv: include path is relative to current (close #198)
This commit is contained in:
parent
09a6f79334
commit
733a7b12ef
@ -331,7 +331,7 @@ getDirective directivename = lookup directivename . rdirectives
|
||||
|
||||
parseRulesFile :: FilePath -> ErrorT String IO CsvRules
|
||||
parseRulesFile f = do
|
||||
s <- liftIO $ (readFile' f >>= expandIncludes)
|
||||
s <- liftIO $ (readFile' f >>= expandIncludes (takeDirectory f))
|
||||
let rules = parseCsvRules f s
|
||||
case rules of
|
||||
Left e -> ErrorT $ return $ Left $ show e
|
||||
@ -345,14 +345,15 @@ parseRulesFile f = do
|
||||
|
||||
-- | Pre-parse csv rules to interpolate included files, recursively.
|
||||
-- This is a cheap hack to avoid rewriting the existing parser.
|
||||
expandIncludes :: String -> IO String
|
||||
expandIncludes s = do
|
||||
let (ls,rest) = break (isPrefixOf "include") $ lines s
|
||||
expandIncludes :: FilePath -> String -> IO String
|
||||
expandIncludes basedir content = do
|
||||
let (ls,rest) = break (isPrefixOf "include") $ lines content
|
||||
case rest of
|
||||
[] -> return $ unlines ls
|
||||
(('i':'n':'c':'l':'u':'d':'e':f):ls') -> do
|
||||
let f' = dropWhile isSpace f
|
||||
included <- readFile f' >>= expandIncludes
|
||||
let f' = basedir </> dropWhile isSpace f
|
||||
basedir' = takeDirectory f'
|
||||
included <- readFile f' >>= expandIncludes basedir'
|
||||
return $ unlines [unlines ls, included, unlines ls']
|
||||
ls' -> return $ unlines $ ls ++ ls' -- should never get here
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user