lib: journal: require a space between period expr. and other fields
This commit is contained in:
		
							parent
							
								
									eb23504906
								
							
						
					
					
						commit
						c4d45cffc4
					
				| @ -460,30 +460,37 @@ modifiertransactionp = do | |||||||
| -- | Parse a periodic transaction | -- | Parse a periodic transaction | ||||||
| periodictransactionp :: MonadIO m => JournalParser m PeriodicTransaction | periodictransactionp :: MonadIO m => JournalParser m PeriodicTransaction | ||||||
| periodictransactionp = do | periodictransactionp = do | ||||||
|  | 
 | ||||||
|  |   -- first line | ||||||
|   char '~' <?> "periodic transaction" |   char '~' <?> "periodic transaction" | ||||||
|   lift $ skipMany spacenonewline |   lift $ skipMany spacenonewline | ||||||
| 
 |   -- a period expression | ||||||
|   pos <- getPosition |   pos <- getPosition | ||||||
|   d <- liftIO getCurrentDay |   d <- liftIO getCurrentDay | ||||||
| 
 |  | ||||||
|   -- T.strip is for removing the trailing two spaces |  | ||||||
|   (periodtxt, (interval, span)) <- lift $ first T.strip <$> match (periodexprp d) |   (periodtxt, (interval, span)) <- lift $ first T.strip <$> match (periodexprp d) | ||||||
| 
 |  | ||||||
|   -- not yet sure how I should add context ("while parsing a period expression") and |  | ||||||
|   -- suggestions ("2+ spaces are needed ...") to `TrivialError` parse errors |  | ||||||
| 
 |  | ||||||
|   -- In periodic transactions, the period expression has an additional constraint: |   -- In periodic transactions, the period expression has an additional constraint: | ||||||
|   case checkPeriodicTransactionStartDate interval span periodtxt of |   case checkPeriodicTransactionStartDate interval span periodtxt of | ||||||
|     Just e -> parseErrorAt pos e |     Just e -> parseErrorAt pos e | ||||||
|     Nothing -> pure () |     Nothing -> pure () | ||||||
|  |   -- The line can end here, or it can continue with one or more spaces | ||||||
|  |   -- and then zero or more of the following fields. A bit awkward. | ||||||
|  |   (status, code, description, (comment, tags)) <- | ||||||
|  |     (lift eolof >> return (Unmarked, "", "", ("", []))) | ||||||
|  |     <|> | ||||||
|  |     (do | ||||||
|  |       lift $ skipSome spacenonewline  | ||||||
|  |       s         <- lift statusp | ||||||
|  |       c         <- lift codep | ||||||
|  |       desc      <- lift $ T.strip <$> descriptionp | ||||||
|  |       (cmt, ts) <- lift transactioncommentp | ||||||
|  |       return (s,c,desc,(cmt,ts)) | ||||||
|  |     ) | ||||||
| 
 | 
 | ||||||
|   status <- lift statusp |   -- next lines | ||||||
|   code <- lift codep |  | ||||||
|   description <- lift $ T.strip <$> descriptionp |  | ||||||
|   (comment, tags) <- lift transactioncommentp |  | ||||||
|   postings <- postingsp (Just $ first3 $ toGregorian d) |   postings <- postingsp (Just $ first3 $ toGregorian d) | ||||||
|  | 
 | ||||||
|   return $ nullperiodictransaction{ |   return $ nullperiodictransaction{ | ||||||
|       ptperiodexpr=periodtxt |      ptperiodexpr=periodtxt | ||||||
|     ,ptinterval=interval |     ,ptinterval=interval | ||||||
|     ,ptspan=span |     ,ptspan=span | ||||||
|     ,ptstatus=status |     ,ptstatus=status | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user