Safe Haskell | Safe-Infered |
---|
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-
.
- lvl1Char :: Char -> Bool
- lvl1Cmdty :: Parser Commodity
- quotedLvl1Cmdty :: Parser Commodity
- commandLineCmdty :: Parser Commodity
- lvl2FirstChar :: Char -> Bool
- lvl2OtherChars :: Char -> Bool
- lvl2Cmdty :: Parser Commodity
- lvl3FirstChar :: Char -> Bool
- lvl3OtherChars :: Char -> Bool
- lvl3Cmdty :: Parser Commodity
- leftSideCmdty :: Parser Commodity
- rightSideCmdty :: Parser Commodity
- renderQuotedLvl1 :: Commodity -> Maybe Text
- renderLvl2 :: Commodity -> Maybe Text
- renderLvl3 :: Commodity -> Maybe Text
Level 1 commodities
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.
lvl2OtherChars :: Char -> BoolSource
Level 3 commodities
lvl3FirstChar :: Char -> BoolSource
lvl3OtherChars :: Char -> BoolSource
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.