lib: remove partial code from journalApplyAliases etc.
This commit is contained in:
		
							parent
							
								
									794c5f32a5
								
							
						
					
					
						commit
						0dc8eca68a
					
				| @ -1228,9 +1228,12 @@ postingFindTag :: TagName -> Posting -> Maybe (TagName, TagValue) | |||||||
| postingFindTag tagname p = find ((tagname==) . fst) $ postingAllTags p | postingFindTag tagname p = find ((tagname==) . fst) $ postingAllTags p | ||||||
| 
 | 
 | ||||||
| -- | Apply some account aliases to all posting account names in the journal, as described by accountNameApplyAliases. | -- | Apply some account aliases to all posting account names in the journal, as described by accountNameApplyAliases. | ||||||
| -- This can raise an error arising from a bad replacement pattern in a regular expression alias. | -- This can fail due to a bad replacement pattern in a regular expression alias. | ||||||
| journalApplyAliases :: [AccountAlias] -> Journal -> Journal | journalApplyAliases :: [AccountAlias] -> Journal -> Either RegexError Journal | ||||||
| journalApplyAliases aliases j = j{jtxns = map (transactionApplyAliases aliases) $ jtxns j}  -- PARTIAL: | journalApplyAliases aliases j =  | ||||||
|  |   case mapM (transactionApplyAliases aliases) $ jtxns j of | ||||||
|  |     Right ts -> Right j{jtxns = ts} | ||||||
|  |     Left err -> Left err | ||||||
|    |    | ||||||
| -- -- | Build a database of market prices in effect on the given date, | -- -- | Build a database of market prices in effect on the given date, | ||||||
| -- -- from the journal's price directives. | -- -- from the journal's price directives. | ||||||
|  | |||||||
| @ -291,14 +291,15 @@ concatAccountNames as = accountNameWithPostingType t $ T.intercalate ":" $ map a | |||||||
|     where t = headDef RegularPosting $ filter (/= RegularPosting) $ map accountNamePostingType as |     where t = headDef RegularPosting $ filter (/= RegularPosting) $ map accountNamePostingType as | ||||||
| 
 | 
 | ||||||
| -- | Apply some account aliases to the posting's account name, as described by accountNameApplyAliases. | -- | Apply some account aliases to the posting's account name, as described by accountNameApplyAliases. | ||||||
| -- This can raise an error arising from a bad replacement pattern in a regular expression alias. | -- This can fail due to a bad replacement pattern in a regular expression alias. | ||||||
| postingApplyAliases :: [AccountAlias] -> Posting -> Posting | postingApplyAliases :: [AccountAlias] -> Posting -> Either RegexError Posting | ||||||
| postingApplyAliases aliases p@Posting{paccount} = | postingApplyAliases aliases p@Posting{paccount} = | ||||||
|   case accountNameApplyAliases aliases paccount of |   case accountNameApplyAliases aliases paccount of | ||||||
|     Right a -> p{paccount=a} |     Right a -> Right p{paccount=a} | ||||||
|     Left e  -> error' err  -- PARTIAL: |     Left e  -> Left err | ||||||
|       where |       where | ||||||
|         err = "problem in account aliases:\n" ++ pshow aliases ++ "\n applied to account name: "++T.unpack paccount++"\n "++e |         err = "problem while applying account aliases:\n" ++ pshow aliases  | ||||||
|  |           ++ "\n to account name: "++T.unpack paccount++"\n "++e | ||||||
| 
 | 
 | ||||||
| -- | Rewrite an account name using all matching aliases from the given list, in sequence. | -- | Rewrite an account name using all matching aliases from the given list, in sequence. | ||||||
| -- Each alias sees the result of applying the previous aliases. | -- Each alias sees the result of applying the previous aliases. | ||||||
|  | |||||||
| @ -593,10 +593,12 @@ transactionToCost :: M.Map CommoditySymbol AmountStyle -> Transaction -> Transac | |||||||
| transactionToCost styles t@Transaction{tpostings=ps} = t{tpostings=map (postingToCost styles) ps} | transactionToCost styles t@Transaction{tpostings=ps} = t{tpostings=map (postingToCost styles) ps} | ||||||
| 
 | 
 | ||||||
| -- | Apply some account aliases to all posting account names in the transaction, as described by accountNameApplyAliases. | -- | Apply some account aliases to all posting account names in the transaction, as described by accountNameApplyAliases. | ||||||
| -- This can raise an error arising from a bad replacement pattern in a regular expression alias. | -- This can fail due to a bad replacement pattern in a regular expression alias. | ||||||
| transactionApplyAliases :: [AccountAlias] -> Transaction -> Transaction | transactionApplyAliases :: [AccountAlias] -> Transaction -> Either RegexError Transaction | ||||||
| transactionApplyAliases aliases t = | transactionApplyAliases aliases t = | ||||||
|   txnTieKnot $ t{tpostings = map (postingApplyAliases aliases) $ tpostings t}  -- PARTIAL: |   case mapM (postingApplyAliases aliases) $ tpostings t of | ||||||
|  |     Right ps -> Right $ txnTieKnot $ t{tpostings=ps} | ||||||
|  |     Left err -> Left err | ||||||
| 
 | 
 | ||||||
| -- tests | -- tests | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -296,10 +296,11 @@ parseAndFinaliseJournal' parser iopts f txt = do | |||||||
|   -- see notes above |   -- see notes above | ||||||
|   case ep of |   case ep of | ||||||
|     Left e   -> throwError $ customErrorBundlePretty e |     Left e   -> throwError $ customErrorBundlePretty e | ||||||
|     Right pj -> journalFinalise iopts f txt $ |     Right pj ->  | ||||||
|                 -- apply any command line account aliases. Can fail with a bad replacement pattern. |       -- apply any command line account aliases. Can fail with a bad replacement pattern. | ||||||
|                 journalApplyAliases (aliasesFromOpts iopts) $  -- PARTIAL: |       case journalApplyAliases (aliasesFromOpts iopts) pj of | ||||||
|                 pj |         Left e    -> throwError e | ||||||
|  |         Right pj' -> journalFinalise iopts f txt pj' | ||||||
| 
 | 
 | ||||||
| -- | Post-process a Journal that has just been parsed or generated, in this order: | -- | Post-process a Journal that has just been parsed or generated, in this order: | ||||||
| -- | -- | ||||||
|  | |||||||
| @ -108,15 +108,16 @@ parse iopts f t = do | |||||||
|   let rulesfile = mrules_file_ iopts |   let rulesfile = mrules_file_ iopts | ||||||
|   r <- liftIO $ readJournalFromCsv rulesfile f t |   r <- liftIO $ readJournalFromCsv rulesfile f t | ||||||
|   case r of Left e   -> throwError e |   case r of Left e   -> throwError e | ||||||
|             Right pj -> journalFinalise iopts{ignore_assertions_=True} f t pj'' |             Right pj -> | ||||||
|               where |               -- journalFinalise assumes the journal's items are | ||||||
|                 -- journalFinalise assumes the journal's items are |               -- reversed, as produced by JournalReader's parser. | ||||||
|                 -- reversed, as produced by JournalReader's parser. |               -- But here they are already properly ordered. So we'd | ||||||
|                 -- But here they are already properly ordered. So we'd |               -- better preemptively reverse them once more. XXX inefficient | ||||||
|                 -- better preemptively reverse them once more. XXX inefficient |               let pj' = journalReverse pj | ||||||
|                 pj' = journalReverse pj |               -- apply any command line account aliases. Can fail with a bad replacement pattern. | ||||||
|                 -- apply any command line account aliases. Can fail with a bad replacement pattern. |               in case journalApplyAliases (aliasesFromOpts iopts) pj' of | ||||||
|                 pj'' = journalApplyAliases (aliasesFromOpts iopts)  pj'  -- PARTIAL: |                   Left e -> throwError e | ||||||
|  |                   Right pj'' -> journalFinalise iopts{ignore_assertions_=True} f t pj'' | ||||||
| 
 | 
 | ||||||
| --- ** reading rules files | --- ** reading rules files | ||||||
| --- *** rules utilities | --- *** rules utilities | ||||||
|  | |||||||
| @ -147,7 +147,9 @@ toRegexCI' = either error' id . toRegexCI | |||||||
| -- | A replacement pattern. May include numeric backreferences (\N). | -- | A replacement pattern. May include numeric backreferences (\N). | ||||||
| type Replacement = String | type Replacement = String | ||||||
| 
 | 
 | ||||||
| -- | An regular expression compilation/processing error message. | -- | An error message arising during a regular expression operation. | ||||||
|  | -- Eg: trying to compile a malformed regular expression, or | ||||||
|  | -- trying to apply a malformed replacement pattern. | ||||||
| type RegexError = String | type RegexError = String | ||||||
| 
 | 
 | ||||||
| -- helpers | -- helpers | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user