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