Tilde expansion in !include
This commit is contained in:
parent
600582184c
commit
68682fa0ee
@ -13,6 +13,7 @@ import Text.ParserCombinators.Parsec.Char
|
|||||||
import Text.ParserCombinators.Parsec.Language
|
import Text.ParserCombinators.Parsec.Language
|
||||||
import Text.ParserCombinators.Parsec.Combinator
|
import Text.ParserCombinators.Parsec.Combinator
|
||||||
import qualified Text.ParserCombinators.Parsec.Token as P
|
import qualified Text.ParserCombinators.Parsec.Token as P
|
||||||
|
import System.Directory
|
||||||
import System.IO
|
import System.IO
|
||||||
import qualified Data.Map as Map
|
import qualified Data.Map as Map
|
||||||
import Ledger.Utils
|
import Ledger.Utils
|
||||||
@ -96,7 +97,7 @@ ledgerInclude = do many1 spacenonewline
|
|||||||
outerState <- getState
|
outerState <- getState
|
||||||
outerPos <- getPosition
|
outerPos <- getPosition
|
||||||
let inIncluded = show outerPos ++ " in included file " ++ show filename ++ ":\n"
|
let inIncluded = show outerPos ++ " in included file " ++ show filename ++ ":\n"
|
||||||
return $ do contents <- readFileE outerPos filename
|
return $ do contents <- expandPath filename >>= readFileE outerPos
|
||||||
case runParser ledgerFile outerState filename contents of
|
case runParser ledgerFile outerState filename contents of
|
||||||
Right l -> l `catchError` (\err -> throwError $ inIncluded ++ err)
|
Right l -> l `catchError` (\err -> throwError $ inIncluded ++ err)
|
||||||
Left perr -> throwError $ inIncluded ++ show perr
|
Left perr -> throwError $ inIncluded ++ show perr
|
||||||
@ -105,6 +106,11 @@ ledgerInclude = do many1 spacenonewline
|
|||||||
currentPos = show outerPos
|
currentPos = show outerPos
|
||||||
whileReading = " reading " ++ show filename ++ ":\n"
|
whileReading = " reading " ++ show filename ++ ":\n"
|
||||||
|
|
||||||
|
expandPath :: (MonadIO m) => FilePath -> m FilePath
|
||||||
|
expandPath inname | "~/" `isPrefixOf` inname = do homedir <- liftIO getHomeDirectory
|
||||||
|
return $ homedir ++ drop 1 inname
|
||||||
|
| otherwise = return inname
|
||||||
|
|
||||||
ledgerAccountBegin :: GenParser Char LedgerFileCtx (ErrorT String IO (RawLedger -> RawLedger))
|
ledgerAccountBegin :: GenParser Char LedgerFileCtx (ErrorT String IO (RawLedger -> RawLedger))
|
||||||
ledgerAccountBegin = do many1 spacenonewline
|
ledgerAccountBegin = do many1 spacenonewline
|
||||||
parent <- ledgeraccountname
|
parent <- ledgeraccountname
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user