journal: support ledger3-compatible "apply account"
This commit is contained in:
		
							parent
							
								
									eaaaf6ddec
								
							
						
					
					
						commit
						a2b989d898
					
				| @ -295,19 +295,19 @@ journalAddFile f j@Journal{files=fs} = j{files=fs++[f]} | ||||
| 
 | ||||
| accountdirectivep :: ParsecT [Char] JournalContext (ExceptT String IO) JournalUpdate | ||||
| accountdirectivep = do | ||||
|   string "account" | ||||
|   (try $ string "apply" >> many1 spacenonewline >> string "account") | ||||
|     <|> string "account" | ||||
|   many1 spacenonewline | ||||
|   parent <- accountnamep | ||||
|   newline | ||||
|   pushParentAccount parent | ||||
|   -- return $ return id | ||||
|   return $ ExceptT $ return $ Right id | ||||
| 
 | ||||
| enddirectivep :: ParsecT [Char] JournalContext (ExceptT String IO) JournalUpdate | ||||
| enddirectivep = do | ||||
|   string "end" | ||||
|   optional $ many1 spacenonewline >> string "apply" >> many1 spacenonewline >> string "account" | ||||
|   popParentAccount | ||||
|   -- return (return id) | ||||
|   return $ ExceptT $ return $ Right id | ||||
| 
 | ||||
| aliasdirectivep :: ParsecT [Char] JournalContext (ExceptT String IO) JournalUpdate | ||||
|  | ||||
| @ -596,10 +596,10 @@ $ hledger print | ||||
| ## Default parent account | ||||
| 
 | ||||
| You can specify a parent account which will be prepended to all accounts | ||||
| within a section of the journal. Use the `account` directive like so: | ||||
| within a section of the journal. Use the `apply account` directive like so: | ||||
| 
 | ||||
| ``` {.journal} | ||||
| account home | ||||
| apply account home | ||||
| 
 | ||||
| 2010/1/1 | ||||
|     food    $10 | ||||
| @ -608,6 +608,8 @@ account home | ||||
| end | ||||
| ``` | ||||
| 
 | ||||
| (`!account`, `account`, and `end apply account` are also supported). | ||||
| 
 | ||||
| If `end` is omitted, the effect lasts to the end of the file. | ||||
| The above is equivalent to: | ||||
| 
 | ||||
|  | ||||
| @ -711,10 +711,10 @@ $ hledger print | ||||
| ##### Default parent account | ||||
| 
 | ||||
| You can specify a parent account which will be prepended to all accounts | ||||
| within a section of the journal. Use the `account` directive like so: | ||||
| within a section of the journal. Use the `apply account` directive like so: | ||||
| 
 | ||||
| ``` {.journal} | ||||
| account home | ||||
| apply account home | ||||
| 
 | ||||
| 2010/1/1 | ||||
|     food    $10 | ||||
| @ -723,6 +723,8 @@ account home | ||||
| end | ||||
| ``` | ||||
| 
 | ||||
| (`!account`, `account`, and `end apply account` are also supported). | ||||
| 
 | ||||
| If `end` is omitted, the effect lasts to the end of the file. | ||||
| The above is equivalent to: | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										48
									
								
								tests/journal/directives.test
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								tests/journal/directives.test
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,48 @@ | ||||
| # Accept three forms of the account directive | ||||
| # . !account, !end (ledger 2, hledger) | ||||
| hledger -f - accounts | ||||
| <<< | ||||
| !account a | ||||
| 2016/1/1 | ||||
|     (b)  1 | ||||
| !end | ||||
| 2016/1/2 | ||||
|     (c)  1 | ||||
| >>> | ||||
| a:b | ||||
| c | ||||
| >>>=0 | ||||
| 
 | ||||
| # . account, end (ledger 3 pre ?, hledger) | ||||
| hledger -f - accounts | ||||
| <<< | ||||
| account a | ||||
| 2016/1/1 | ||||
|     (b)  1 | ||||
| end | ||||
| 2016/1/2 | ||||
|     (c)  1 | ||||
| >>> | ||||
| a:b | ||||
| c | ||||
| >>>=0 | ||||
| 
 | ||||
| # . apply account, end [apply account] (ledger 3, hledger) | ||||
| # . now: apply account | ||||
| hledger -f - accounts | ||||
| <<< | ||||
| apply account a | ||||
| 2016/1/1 | ||||
|     (b)  1 | ||||
| end | ||||
| apply account aa | ||||
| 2016/1/1 | ||||
|     (b)  1 | ||||
| end apply account | ||||
| 2016/1/2 | ||||
|     (c)  1 | ||||
| >>> | ||||
| a:b | ||||
| aa:b | ||||
| c | ||||
| >>>=0 | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user