Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imp: Add ' as possible digit separator #1890

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion hledger-lib/Hledger/Read/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,8 @@ disambiguateNumber msuggestedStyle (AmbiguousNumber grp1 sep grp2) =
-- Left (AmbiguousNumber "1" ',' "000")
-- >>> parseTest rawnumberp "1 000"
-- Right (WithSeparators ' ' ["1","000"] Nothing)
-- >>> parseTest rawnumberp "1'000"
-- Right (WithSeparators '\'' ["1","000"] Nothing)
--
rawnumberp :: TextParser m (Either AmbiguousNumber RawNumber)
rawnumberp = label "number" $ do
Expand Down Expand Up @@ -1142,7 +1144,7 @@ rawnumberp = label "number" $ do
pure $ NoSeparators grp1 (Just (decPt, mempty))

isDigitSeparatorChar :: Char -> Bool
isDigitSeparatorChar c = isDecimalMark c || c == ' '
isDigitSeparatorChar c = isDecimalMark c || c == ' ' || c == '\''

-- | Some kinds of number literal we might parse.
data RawNumber
Expand Down
6 changes: 4 additions & 2 deletions hledger/hledger.m4.md
Original file line number Diff line number Diff line change
Expand Up @@ -1184,10 +1184,11 @@ A *decimal mark* can be written as a period or a comma:

In the integer part of the quantity (left of the decimal mark), groups
of digits can optionally be separated by a *digit group mark* - a
space, comma, or period (different from the decimal mark):
space, comma, single quote, or period (different from the decimal mark):

$1,000,000.00
EUR 2.000.000,00
CHF 2'000'000.00
INR 9,99,99,999.00
1 000 000.9455

Expand Down Expand Up @@ -2192,9 +2193,10 @@ by 0 or more decimal digits.

A few more examples:
```journal
# number formats for $, EUR, INR and the no-symbol commodity:
# number formats for $, EUR, CHF, INR and the no-symbol commodity:
commodity $1,000.00
commodity EUR 1.000,00
commodity CHF 1'000.00
commodity INR 9,99,99,999.0
commodity 1 000 000.
```
Expand Down
13 changes: 13 additions & 0 deletions hledger/test/journal/numbers.test
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,16 @@ Balance changes in 2021:
===++===================================
a || -0.12345678901234567890123456 EUR
>>>=0

# 21. commodity with single quote digit group
hledger bal -f -
<<<
commodity 1'000.00 CHF

2017/1/1
a 1000 CHF
b -1000 CHF
>>>
1'000.00 CHF a
-1'000.00 CHF b
>>>=0