diff --git a/hledger-lib/Hledger/Read/Common.hs b/hledger-lib/Hledger/Read/Common.hs index 59b0e7d08..7c38af3be 100644 --- a/hledger-lib/Hledger/Read/Common.hs +++ b/hledger-lib/Hledger/Read/Common.hs @@ -77,4 +77,4 @@ expandPath pos fp = liftM mkRelative (expandHome fp) | otherwise = return inname fileSuffix :: FilePath -> String -fileSuffix = reverse . takeWhile (/='.') . reverse . dropWhile (/='.') \ No newline at end of file +fileSuffix = reverse . takeWhile (/='.') . reverse . dropWhile (/='.') diff --git a/hledger-lib/Hledger/Read/Journal.hs b/hledger-lib/Hledger/Read/Journal.hs index a3d4783b6..5b47d1b34 100644 --- a/hledger-lib/Hledger/Read/Journal.hs +++ b/hledger-lib/Hledger/Read/Journal.hs @@ -123,6 +123,7 @@ import Text.ParserCombinators.Parsec hiding (parse) import Prelude hiding (readFile, putStr, putStrLn, print, getContents) import System.IO.UTF8 #endif +import System.FilePath import Hledger.Data.Utils import Hledger.Data.Types import Hledger.Data.Dates @@ -214,7 +215,7 @@ ledgerInclude = do many1 spacenonewline outerPos <- getPosition let inIncluded = show outerPos ++ " in included file " ++ show filename ++ ":\n" return $ do contents <- expandPath outerPos filename >>= readFileE outerPos - case runParser journalFile outerState filename contents of + case runParser journalFile outerState (combine ((takeDirectory . sourceName) outerPos) filename) contents of Right l -> l `catchError` (throwError . (inIncluded ++)) Left perr -> throwError $ inIncluded ++ show perr where readFileE outerPos filename = ErrorT $ liftM Right (readFile filename) `catch` leftError diff --git a/tests/include.test b/tests/include.test index 6e9ebca76..fa088b39a 100644 --- a/tests/include.test +++ b/tests/include.test @@ -1,5 +1,5 @@ # nested includes in subdirectories -mkdir -p b/c ; printf '2010/1/1\n (C) 1\n' >b/c/c.journal ; printf '2010/1/1\n (B) 1\n!include c/c.journal\n' >b/b.journal ; printf '2010/1/1\n (A) 1\n!include b/b.journal\n' >a.journal ; hledger -f a.journal print; rm -rf b +mkdir -p b/c/d ; printf '2010/1/1\n (D) 1\n' >b/c/d/d.journal ; printf '2010/1/1\n (C) 1\n!include d/d.journal\n' >b/c/c.journal ; printf '2010/1/1\n (B) 1\n!include c/c.journal\n' >b/b.journal ; printf '2010/1/1\n (A) 1\n!include b/b.journal\n' >a.journal ; hledger -f a.journal print; rm -rf b >>> 2010/01/01 (A) 1 @@ -10,3 +10,6 @@ mkdir -p b/c ; printf '2010/1/1\n (C) 1\n' >b/c/c.journal ; printf '2010/1/1\n 2010/01/01 (C) 1 +2010/01/01 + (D) 1 +