penny-lib-0.4.0.0: Extensible double-entry accounting system - library

Safe HaskellSafe-Infered

Penny.Copper.Commodity

Contents

Description

Commodity parsers. Commodity names fall into three groups:

  • Level 1 commodities. These can have a broad selection of characters, including spaces. The downside is that they need to be quoted when they appear in a file. (They don't have to be quoted from the command line, presuming that a single command line argument captures the entire commodity name and nothing else.)
  • Level 2 commodities. The first sub-commodity begins with a letter or a symbol. All other characters may be nearly any other character. Spaces however are not permitted.
  • Level 3 commodities. All charcters must be letters or symbols. In addition, the first character cannot be a + or a -.

Synopsis

Level 1 commodities

lvl1Char :: Char -> BoolSource

Most liberal set of letters allowed in a commodity.

lvl1Cmdty :: Parser CommoditySource

A commodity that might have spaces inside of the name. To parse this when it is in a ledger file, it must be quoted; use quotedLvl1Cmdty for that. This parser can be used directly for values entered from the command line.

quotedLvl1Cmdty :: Parser CommoditySource

A commodity that may have spaces in the name; is wrapped inside of double quotes.

commandLineCmdty :: Parser CommoditySource

A commodity being read in from the command line, where the commodity is guaranteed to be the only thing to parse.

Level 2 commodities

lvl2FirstChar :: Char -> BoolSource

Allows only letters and symbols.

Level 3 commodities

Helpers when parsing from a file

leftSideCmdty :: Parser CommoditySource

A commodity on the left side of a quantity in a ledger file.

rightSideCmdty :: Parser CommoditySource

A commodity on the right side of a quantity in a ledger file.

Rendering

renderQuotedLvl1 :: Commodity -> Maybe TextSource

Render a quoted Level 1 commodity. Fails if any character does not satisfy lvl1Char.

renderLvl2 :: Commodity -> Maybe TextSource

Render a Level 2 commodity. Fails if the first character is not a letter or a symbol, or if any other character is a space.

renderLvl3 :: Commodity -> Maybe TextSource

Render a Level 3 commodity. Fails if any character is not a letter or a symbol.