lib: reduce backtracking of various parsers
This commit is contained in:
parent
e3a755b5b1
commit
ed0106b209
@ -328,9 +328,13 @@ statusp =
|
||||
]
|
||||
|
||||
codep :: TextParser m Text
|
||||
codep = option "" $ try $ do
|
||||
codep = option "" $ do
|
||||
try $ do
|
||||
skipSome spacenonewline
|
||||
between (char '(') (char ')') $ takeWhileP Nothing (/= ')')
|
||||
char '('
|
||||
code <- takeWhileP Nothing $ \c -> c /= ')' && c /= '\n'
|
||||
char ')' <?> "closing bracket ')' for transaction code"
|
||||
pure code
|
||||
|
||||
descriptionp :: TextParser m Text
|
||||
descriptionp = takeWhileP Nothing (not . semicolonOrNewline)
|
||||
@ -652,9 +656,8 @@ simplecommoditysymbolp :: TextParser m CommoditySymbol
|
||||
simplecommoditysymbolp = takeWhile1P Nothing (not . isNonsimpleCommodityChar)
|
||||
|
||||
priceamountp :: JournalParser m Price
|
||||
priceamountp = option NoPrice $ try $ do
|
||||
lift (skipMany spacenonewline)
|
||||
char '@'
|
||||
priceamountp = option NoPrice $ do
|
||||
try $ lift (skipMany spacenonewline) *> char '@'
|
||||
priceConstructor <- char '@' *> pure TotalPrice <|> pure UnitPrice
|
||||
|
||||
lift (skipMany spacenonewline)
|
||||
@ -663,10 +666,12 @@ priceamountp = option NoPrice $ try $ do
|
||||
pure $ priceConstructor priceAmount
|
||||
|
||||
partialbalanceassertionp :: JournalParser m BalanceAssertion
|
||||
partialbalanceassertionp = optional $ try $ do
|
||||
partialbalanceassertionp = optional $ do
|
||||
sourcepos <- try $ do
|
||||
lift (skipMany spacenonewline)
|
||||
sourcepos <- genericSourcePos <$> lift getPosition
|
||||
char '='
|
||||
pure sourcepos
|
||||
lift (skipMany spacenonewline)
|
||||
a <- amountp -- XXX should restrict to a simple amount
|
||||
return (a, sourcepos)
|
||||
@ -683,7 +688,8 @@ partialbalanceassertionp = optional $ try $ do
|
||||
|
||||
-- http://ledger-cli.org/3.0/doc/ledger3.html#Fixing-Lot-Prices
|
||||
fixedlotpricep :: JournalParser m (Maybe Amount)
|
||||
fixedlotpricep = optional $ try $ do
|
||||
fixedlotpricep = optional $ do
|
||||
try $ do
|
||||
lift (skipMany spacenonewline)
|
||||
char '{'
|
||||
lift (skipMany spacenonewline)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user