mirror of
https://github.com/simonmichael/hledger.git
synced 2024-09-19 10:17:35 +03:00
Merge branch 'feature/space-as-digits-sep' of https://github.com/ony/hledger into ony-feature/space-as-digits-sep
This commit is contained in:
commit
ecdbc05703
@ -24,6 +24,7 @@ import Prelude.Compat hiding (readFile)
|
||||
import Control.Monad.Compat
|
||||
import Control.Monad.Except (ExceptT(..), runExceptT, throwError) --, catchError)
|
||||
import Control.Monad.State.Strict
|
||||
import Data.Char
|
||||
import Data.Data
|
||||
import Data.Default
|
||||
import Data.Functor.Identity
|
||||
@ -599,7 +600,7 @@ rawnumberp = do
|
||||
(firstSep, groups) <- option (Nothing, []) $ do
|
||||
leadingDigits <- some digitChar
|
||||
option (Nothing, [leadingDigits]) . try $ do
|
||||
firstSep <- oneOf sepChars
|
||||
firstSep <- oneOf sepChars <|> whitespaceChar
|
||||
groups <- some digitChar `sepBy1` char firstSep
|
||||
return (Just firstSep, leadingDigits : groups)
|
||||
|
||||
@ -614,11 +615,14 @@ rawnumberp = do
|
||||
return (lastSep, fromMaybe [] digits)
|
||||
|
||||
-- make sure we didn't leading part of mistyped number
|
||||
notFollowedBy $ oneOf sepChars
|
||||
notFollowedBy $ oneOf sepChars <|> (whitespaceChar >> digitChar)
|
||||
|
||||
return $ dbg8 "rawnumberp" (firstSep, groups, extraGroup)
|
||||
<?> "rawnumberp"
|
||||
|
||||
-- | Parse a unicode char that represents any non-control space char (Zs general category).
|
||||
whitespaceChar :: TextParser m Char
|
||||
whitespaceChar = charCategory Space
|
||||
|
||||
-- test_numberp = do
|
||||
-- let s `is` n = assertParseEqual (parseWithState mempty numberp s) n
|
||||
|
@ -267,7 +267,8 @@ Amounts consist of a number and (usually) a currency symbol or commodity name. S
|
||||
`3 "green apples"`\
|
||||
`-$1,000,000.00`\
|
||||
`INR 9,99,99,999.00`\
|
||||
`EUR -2.000.000,00`
|
||||
`EUR -2.000.000,00`\
|
||||
`1 999 999.9455`
|
||||
|
||||
As you can see, the amount format is somewhat flexible:
|
||||
|
||||
@ -275,7 +276,8 @@ As you can see, the amount format is somewhat flexible:
|
||||
- the commodity is a symbol, word, or phrase, on the left or right, with or without a separating space.
|
||||
If the commodity contains numbers, spaces or non-word punctuation it must be enclosed in double quotes.
|
||||
- negative amounts with a commodity on the left can have the minus sign before or after it
|
||||
- digit groups (thousands, or any other grouping) can be separated by commas (in which case period is used for decimal point) or periods (in which case comma is used for decimal point)
|
||||
- digit groups (thousands, or any other grouping) can be separated by space or comma or period and should be used as separator between all groups
|
||||
- decimal part can be separated by comma or period and should be different from digit groups separator
|
||||
|
||||
You can use any of these variations when recording data. However, there is some ambiguous way of representing numbers like `$1.000` and `$1,000` both may mean either one thousand or one dollar. By default hledger will assume that this is sole delimiter is used only for decimals. On the other hand commodity format declared prior to that line will help to resolve that ambiguity differently:
|
||||
|
||||
|
@ -43,6 +43,32 @@ hledger bal -f -
|
||||
>>>
|
||||
>>>=1
|
||||
|
||||
# Space between digits groups
|
||||
hledger bal -f - --no-total
|
||||
<<<
|
||||
2017/1/1
|
||||
a 1 000.00 EUR
|
||||
b -1 000.00 EUR
|
||||
>>>
|
||||
1 000.00 EUR a
|
||||
-1 000.00 EUR b
|
||||
>>>2
|
||||
>>>=0
|
||||
|
||||
# Space between digits groups in commodity directive
|
||||
hledger bal -f - --no-total
|
||||
<<<
|
||||
commodity 1 000.00 EUR
|
||||
|
||||
2017/1/1
|
||||
a 1,000.00 EUR
|
||||
b -1,000.00 EUR
|
||||
>>>
|
||||
1 000.00 EUR a
|
||||
-1 000.00 EUR b
|
||||
>>>2
|
||||
>>>=0
|
||||
|
||||
# Default commodity
|
||||
hledger bal -f -
|
||||
<<<
|
||||
|
Loading…
Reference in New Issue
Block a user