remember all included file paths, if any
This commit is contained in:
		
							parent
							
								
									96036e56a0
								
							
						
					
					
						commit
						8429df0f32
					
				| @ -41,6 +41,7 @@ nulljournal = Journal { jmodifiertxns = [] | ||||
|                       , historical_prices = [] | ||||
|                       , final_comment_lines = [] | ||||
|                       , filepath = "" | ||||
|                       , allfilepaths = [] | ||||
|                       , filereadtime = TOD 0 0 | ||||
|                       , jtext = "" | ||||
|                       } | ||||
| @ -216,7 +217,7 @@ journalFinalise :: ClockTime -> LocalTime -> FilePath -> String -> Journal -> Jo | ||||
| journalFinalise tclock tlocal path txt j = journalCanonicaliseAmounts $ | ||||
|                                            journalApplyHistoricalPrices $ | ||||
|                                            journalCloseTimeLogEntries tlocal | ||||
|                                              j{filepath=path, filereadtime=tclock, jtext=txt} | ||||
|                                              j{filepath=path, allfilepaths=path:(allfilepaths j), filereadtime=tclock, jtext=txt} | ||||
| 
 | ||||
| -- | Convert all the journal's amounts to their canonical display | ||||
| -- settings.  Ie, all amounts in a given commodity will use (a) the | ||||
|  | ||||
| @ -129,6 +129,7 @@ data Journal = Journal { | ||||
|       historical_prices :: [HistoricalPrice], | ||||
|       final_comment_lines :: String, -- ^ any trailing comments from the journal file | ||||
|       filepath :: FilePath,      -- ^ file path of this journal | ||||
|       allfilepaths :: [FilePath], -- ^ file paths of this and any included journals | ||||
|       filereadtime :: ClockTime, -- ^ when this journal was read from its file | ||||
|       jtext :: String            -- ^ the raw text read from the journal's file | ||||
|     } deriving (Eq, Typeable) | ||||
|  | ||||
| @ -28,6 +28,9 @@ data Reader = Reader {rFormat   :: String | ||||
| -- or raise an error. | ||||
| type JournalUpdate = ErrorT String IO (Journal -> Journal) | ||||
| 
 | ||||
| juSequence :: [JournalUpdate] -> JournalUpdate | ||||
| juSequence us = liftM (foldr (.) id) $ sequence us | ||||
| 
 | ||||
| -- | Given a JournalUpdate-generating parsec parser, file path and data string, | ||||
| -- parse and post-process a Journal so that it's ready to use, or give an error. | ||||
| parseJournalWith :: (GenParser Char JournalContext JournalUpdate) -> FilePath -> String -> ErrorT String IO Journal | ||||
|  | ||||
| @ -156,9 +156,9 @@ parse = parseJournalWith journalFile | ||||
| -- error-raising "JournalUpdate" which can be applied to an empty journal | ||||
| -- to get the final result. | ||||
| journalFile :: GenParser Char JournalContext JournalUpdate | ||||
| journalFile = do items <- many journalItem | ||||
| journalFile = do journalupdates <- many journalItem | ||||
|                  eof | ||||
|                  return $ liftM (foldr (.) id) $ sequence items | ||||
|                  return $ juSequence journalupdates | ||||
|     where  | ||||
|       -- As all journal line types can be distinguished by the first | ||||
|       -- character, excepting transactions versus empty (blank or | ||||
| @ -175,6 +175,9 @@ journalFile = do items <- many journalItem | ||||
|                           , emptyLine >> return (return id) | ||||
|                           ] <?> "journal transaction or directive" | ||||
| 
 | ||||
| journalAddFilePath :: FilePath -> Journal -> Journal | ||||
| journalAddFilePath f j@Journal{allfilepaths=fs} = j{allfilepaths=fs++[f]} | ||||
| 
 | ||||
| emptyLine :: GenParser Char st () | ||||
| emptyLine = do many spacenonewline | ||||
|                optional $ (char ';' <?> "comment") >> many (noneOf "\n") | ||||
| @ -217,7 +220,7 @@ ledgerInclude = do | ||||
|               contents <- readFileOrError outerPos filepath | ||||
|               let inIncluded = show outerPos ++ " in included file " ++ show filename ++ ":\n" | ||||
|               case runParser journalFile outerState filepath contents of | ||||
|                 Right ju -> ju `catchError` (throwError . (inIncluded ++)) | ||||
|                 Right ju -> juSequence [return $ journalAddFilePath filepath, ju] `catchError` (throwError . (inIncluded ++)) | ||||
|                 Left err -> throwError $ inIncluded ++ show err | ||||
|       where readFileOrError pos fp = | ||||
|                 ErrorT $ liftM Right (readFile fp) `catch` | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user