parsing: N, tag, end tag are now ignored; ledger sample.dat parses
This commit is contained in:
		
							parent
							
								
									6977a0eecb
								
							
						
					
					
						commit
						57c537de41
					
				| @ -92,6 +92,9 @@ ledgerFile = do items <- many ledgerItem | |||||||
|                           , liftM (return . addPeriodicTransaction) ledgerPeriodicTransaction |                           , liftM (return . addPeriodicTransaction) ledgerPeriodicTransaction | ||||||
|                           , liftM (return . addHistoricalPrice) ledgerHistoricalPrice |                           , liftM (return . addHistoricalPrice) ledgerHistoricalPrice | ||||||
|                           , ledgerDefaultYear |                           , ledgerDefaultYear | ||||||
|  |                           , ledgerIgnoredPrice | ||||||
|  |                           , ledgerTagDirective | ||||||
|  |                           , ledgerEndTagDirective | ||||||
|                           , emptyLine >> return (return id) |                           , emptyLine >> return (return id) | ||||||
|                           , liftM (return . addTimeLogEntry)  timelogentry |                           , liftM (return . addTimeLogEntry)  timelogentry | ||||||
|                           ] |                           ] | ||||||
| @ -295,6 +298,28 @@ ledgerHistoricalPrice = do | |||||||
|   restofline |   restofline | ||||||
|   return $ HistoricalPrice date symbol price |   return $ HistoricalPrice date symbol price | ||||||
| 
 | 
 | ||||||
|  | ledgerIgnoredPrice :: GenParser Char LedgerFileCtx (ErrorT String IO (Journal -> Journal)) | ||||||
|  | ledgerIgnoredPrice = do | ||||||
|  |   char 'N' <?> "ignored-price commodity" | ||||||
|  |   many1 spacenonewline | ||||||
|  |   commoditysymbol | ||||||
|  |   restofline | ||||||
|  |   return $ return id | ||||||
|  | 
 | ||||||
|  | ledgerTagDirective :: GenParser Char LedgerFileCtx (ErrorT String IO (Journal -> Journal)) | ||||||
|  | ledgerTagDirective = do | ||||||
|  |   string "tag" <?> "tag directive" | ||||||
|  |   many1 spacenonewline | ||||||
|  |   _ <- many1 nonspace | ||||||
|  |   restofline | ||||||
|  |   return $ return id | ||||||
|  | 
 | ||||||
|  | ledgerEndTagDirective :: GenParser Char LedgerFileCtx (ErrorT String IO (Journal -> Journal)) | ||||||
|  | ledgerEndTagDirective = do | ||||||
|  |   string "end tag" <?> "end tag directive" | ||||||
|  |   restofline | ||||||
|  |   return $ return id | ||||||
|  | 
 | ||||||
| -- like ledgerAccountBegin, updates the LedgerFileCtx | -- like ledgerAccountBegin, updates the LedgerFileCtx | ||||||
| ledgerDefaultYear :: GenParser Char LedgerFileCtx (ErrorT String IO (Journal -> Journal)) | ledgerDefaultYear :: GenParser Char LedgerFileCtx (ErrorT String IO (Journal -> Journal)) | ||||||
| ledgerDefaultYear = do | ledgerDefaultYear = do | ||||||
| @ -635,6 +660,17 @@ tests_Parse = TestList [ | |||||||
|     assertParseEqual (parseWithCtx emptyCtx postingamount " $1.") |     assertParseEqual (parseWithCtx emptyCtx postingamount " $1.") | ||||||
|                 (Mixed [Amount Commodity {symbol="$",side=L,spaced=False,comma=False,precision=0} 1 Nothing]) |                 (Mixed [Amount Commodity {symbol="$",side=L,spaced=False,comma=False,precision=0} 1 Nothing]) | ||||||
| 
 | 
 | ||||||
|  |   ,"ledgerIgnoredPrice" ~: do | ||||||
|  |      assertParse (parseWithCtx emptyCtx ledgerIgnoredPrice "N $\n") | ||||||
|  | 
 | ||||||
|  |   ,"ledgerTagDirective" ~: do | ||||||
|  |      assertParse (parseWithCtx emptyCtx ledgerTagDirective "tag foo\n") | ||||||
|  |      assertParse (parseWithCtx emptyCtx ledgerTagDirective "tag foo \n") | ||||||
|  | 
 | ||||||
|  |   ,"ledgerEndTagDirective" ~: do | ||||||
|  |      assertParse (parseWithCtx emptyCtx ledgerEndTagDirective "end tag\n") | ||||||
|  |      assertParse (parseWithCtx emptyCtx ledgerEndTagDirective "end tag \n") | ||||||
|  | 
 | ||||||
|  ] |  ] | ||||||
| 
 | 
 | ||||||
| price1_str = "P 2004/05/01 XYZ $55.00\n" | price1_str = "P 2004/05/01 XYZ $55.00\n" | ||||||
|  | |||||||
							
								
								
									
										57
									
								
								tests/parse-ledger-sample.test
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								tests/parse-ledger-sample.test
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,57 @@ | |||||||
|  | -f- | ||||||
|  | <<< | ||||||
|  | ; -*- ledger -*- | ||||||
|  | 
 | ||||||
|  | N $ | ||||||
|  | 
 | ||||||
|  | = /^Expenses:Books/ | ||||||
|  |     (Liabilities:Taxes)                                -0.10 | ||||||
|  | 
 | ||||||
|  | ~ Monthly | ||||||
|  |     Assets:Bank:Checking                             $500.00 | ||||||
|  |     Income:Salary | ||||||
|  | 
 | ||||||
|  | ~ Yearly | ||||||
|  |     Expenses:Donations                               $100.00 | ||||||
|  |     Assets:Bank:Checking | ||||||
|  | 
 | ||||||
|  | 2004/05/01 * Checking balance | ||||||
|  |     Assets:Bank:Checking                           $1,000.00 | ||||||
|  |     Equity:Opening Balances | ||||||
|  | 
 | ||||||
|  | 2004/05/03=2004/05/01 * Investment balance | ||||||
|  |     Assets:Brokerage                                 50 AAPL @ $30.00 | ||||||
|  |     Equity:Opening Balances | ||||||
|  | 
 | ||||||
|  | 2004/05/14 * Páy dày | ||||||
|  |     Assets:Bank:Checking                             500.00€ | ||||||
|  |     Income:Salary | ||||||
|  | 
 | ||||||
|  | 2004/05/14 * Another dày in which there is Páying | ||||||
|  |     Asséts:Bánk:Chécking:Asséts:Bánk:Chécking        $500.00 | ||||||
|  |     Income:Salary | ||||||
|  | 
 | ||||||
|  | 2004/05/14 * Another dày in which there is Páying | ||||||
|  |     Русский язык:Активы:Русский язык:Русский язык         $1000.00 | ||||||
|  |     Income:Salary | ||||||
|  | 
 | ||||||
|  | tag foo | ||||||
|  | 
 | ||||||
|  | 2004/05/27 Book Store | ||||||
|  |     Expenses:Books                                    $20.00 | ||||||
|  |     Expenses:Cards                                    $40.00 | ||||||
|  |     Expenses:Docs                                     $30.00 | ||||||
|  |     Liabilities:MasterCard | ||||||
|  | 
 | ||||||
|  | end tag | ||||||
|  | 
 | ||||||
|  | 2004/05/27 (100) Credit card company | ||||||
|  |     ; This is an xact note! | ||||||
|  |     ; Sample: Value | ||||||
|  |     Liabilities:MasterCard                            $20.00 | ||||||
|  |     ; This is a posting note! | ||||||
|  |     ; Sample: Another Value | ||||||
|  |     ; :MyTag: | ||||||
|  |     Assets:Bank:Checking | ||||||
|  |     ; :AnotherTag: | ||||||
|  | >>>= 0 | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user