refactor
This commit is contained in:
		
							parent
							
								
									f1813fbb0e
								
							
						
					
					
						commit
						8405072ff6
					
				@ -29,16 +29,16 @@ instance Show Journal where
 | 
				
			|||||||
             -- ++ (show $ journalTransactions l)
 | 
					             -- ++ (show $ journalTransactions l)
 | 
				
			||||||
             where accounts = flatten $ journalAccountNameTree l
 | 
					             where accounts = flatten $ journalAccountNameTree l
 | 
				
			||||||
 | 
					
 | 
				
			||||||
journalEmpty :: Journal
 | 
					nulljournal :: Journal
 | 
				
			||||||
journalEmpty = Journal { jmodifiertxns = []
 | 
					nulljournal = Journal { jmodifiertxns = []
 | 
				
			||||||
                           , jperiodictxns = []
 | 
					                      , jperiodictxns = []
 | 
				
			||||||
                           , jtxns = []
 | 
					                      , jtxns = []
 | 
				
			||||||
                           , open_timelog_entries = []
 | 
					                      , open_timelog_entries = []
 | 
				
			||||||
                           , historical_prices = []
 | 
					                      , historical_prices = []
 | 
				
			||||||
                           , final_comment_lines = []
 | 
					                      , final_comment_lines = []
 | 
				
			||||||
                           , filepath = ""
 | 
					                      , filepath = ""
 | 
				
			||||||
                           , filereadtime = TOD 0 0
 | 
					                      , filereadtime = TOD 0 0
 | 
				
			||||||
                           }
 | 
					                      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
addTransaction :: Transaction -> Journal -> Journal
 | 
					addTransaction :: Transaction -> Journal -> Journal
 | 
				
			||||||
addTransaction t l0 = l0 { jtxns = t : jtxns l0 }
 | 
					addTransaction t l0 = l0 { jtxns = t : jtxns l0 }
 | 
				
			||||||
 | 
				
			|||||||
@ -73,7 +73,7 @@ parseLedgerFile t f   = liftIO (readFile f) >>= parseLedger t f
 | 
				
			|||||||
parseLedger :: LocalTime -> FilePath -> String -> ErrorT String IO Journal
 | 
					parseLedger :: LocalTime -> FilePath -> String -> ErrorT String IO Journal
 | 
				
			||||||
parseLedger reftime inname intxt =
 | 
					parseLedger reftime inname intxt =
 | 
				
			||||||
  case runParser ledgerFile emptyCtx inname intxt of
 | 
					  case runParser ledgerFile emptyCtx inname intxt of
 | 
				
			||||||
    Right m  -> liftM (journalConvertTimeLog reftime) $ m `ap` return journalEmpty
 | 
					    Right m  -> liftM (journalConvertTimeLog reftime) $ m `ap` return nulljournal
 | 
				
			||||||
    Left err -> throwError $ show err
 | 
					    Left err -> throwError $ show err
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										2
									
								
								Utils.hs
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								Utils.hs
									
									
									
									
									
								
							@ -34,7 +34,7 @@ withLedgerDo opts args cmdname cmd = do
 | 
				
			|||||||
  t <- getCurrentLocalTime
 | 
					  t <- getCurrentLocalTime
 | 
				
			||||||
  tc <- getClockTime
 | 
					  tc <- getClockTime
 | 
				
			||||||
  let go = cmd opts args . filterAndCacheLedgerWithOpts opts args t rawtext . (\rl -> rl{filepath=f,filereadtime=tc})
 | 
					  let go = cmd opts args . filterAndCacheLedgerWithOpts opts args t rawtext . (\rl -> rl{filepath=f,filereadtime=tc})
 | 
				
			||||||
  if creating then go journalEmpty else (runErrorT . parseLedgerFile t) f
 | 
					  if creating then go nulljournal else (runErrorT . parseLedgerFile t) f
 | 
				
			||||||
         >>= flip either go
 | 
					         >>= flip either go
 | 
				
			||||||
                 (\e -> hPutStrLn stderr e >> exitWith (ExitFailure 1))
 | 
					                 (\e -> hPutStrLn stderr e >> exitWith (ExitFailure 1))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user