New Upstream Release - ledger2beancount

Ready changes

Summary

Merged new upstream version: 2.7 (was: 2.6).

Resulting package

Built on 2022-12-07T01:00 (took 12m6s)

The resulting binary packages can be installed (if you have the apt repository enabled) by running one of:

apt install -t fresh-releases ledger2beancount

Lintian Result

Diff

diff --git a/.aspell.en.pws b/.aspell.en.pws
index d44d99f..33803dc 100644
--- a/.aspell.en.pws
+++ b/.aspell.en.pws
@@ -1,8 +1,9 @@
-personal_ws-1.1 en 77 utf-8
+personal_ws-1.1 en 80 utf-8
 AUR
 Alen
 Baier
 Blais
+CSV
 Creasy
 Daniele
 FileCopyrightText
@@ -12,10 +13,12 @@ Goncharov
 Homebrew
 JPY
 Jelmer
+Kaleem
 Kirill
 Kurup
 MERCHANTABILITY
 Michlmayr
+Mohsin
 NetBSD
 Nicolodi
 PWD
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index 7c859c8..515bd00 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -20,8 +20,10 @@ jobs:
           - "git+https://github.com/beancount/beancount/@v2"
     runs-on: ${{ matrix.os }}
     steps:
-      - uses: actions/checkout@v2
-      - uses: actions/setup-python@v2
+      - uses: actions/checkout@v3
+      - uses: actions/setup-python@v4
+        with:
+          python-version: "3.10"
       - if: matrix.os == 'ubuntu-latest'
         run: sudo apt install hledger ledger
       - if: matrix.os == 'macos-latest'
@@ -42,8 +44,8 @@ jobs:
     name: Documentation
     runs-on: ubuntu-latest
     steps:
-      - uses: actions/checkout@v2
-      - uses: actions/setup-python@v2
+      - uses: actions/checkout@v3
+      - uses: actions/setup-python@v4
       - run: pip install -r requirements.txt
       - run: mkdocs build
       - run: find -name "*.yml" -exec yamllint -s {} \;
diff --git a/bin/ledger2beancount b/bin/ledger2beancount
index 54603a8..034138a 100755
--- a/bin/ledger2beancount
+++ b/bin/ledger2beancount
@@ -27,7 +27,7 @@ use String::Interpolate qw/safe_interpolate/;
 use Unicode::Normalize;
 use YAML::XS qw/LoadFile/;
 
-my $VERSION = "2.6";
+my $VERSION = "2.7";
 my $DEBUG = 0; # turn on for debugging output
 
 memoize('get_root_type');
@@ -54,7 +54,10 @@ my $hledger_tags_RE = qr/(?<key>[^ :]+):\s*(?<value>.*?)/;
 # To keep the regex simpler, we parse the () and [] for virtual accounts
 # as part of the account name and strip these brackets later.
 my $account_RE = qr/[^\s;][^\t]*?/;
-my $number_RE = qr/([\d\s,.]*\d([.,]\d+)?|\.\d+|,\d+)/;
+my $number_RE = qr/([\d\s,.]*\d([.,]\d*)?|\.\d+|,\d+)/;
+# Currently ledger only allows - as sign (see https://github.com/ledger/ledger/issues/1990)
+# but hledger allows + and - so just accept both.
+my $sign_RE = qr/[+-]/;
 # A quoted commodity ("LU0274208692") can contain anything
 # between quotes.
 my $commodity_quoted_RE = qr/(")(?:(?=(\\?))\g{-1}.)*?\g{-2}/;
@@ -174,6 +177,8 @@ my %root_mappings = (
     qr/Καθαρή θέση/ => "equity",
     qr/Έσοδα/ => "income",
     qr/Έξοδα/ => "expenses",
+    # en - English
+    qr/Revenues?/ => "income",
     # es - Spanish
     qr/Activos?/ => "assets",
     qr/Pasivos?/ => "liabilities",
@@ -976,7 +981,7 @@ sub convert_number($$) {
 	   # character.  We don't care if anything else is in
 	   # the right format.
 	   $number =~ s/\s+//g;
-	   if ($format =~ /,\d+$/) {
+	   if ($format =~ /,\d*$/) {
 		# Decimal marker: comma
 		$number =~ s/\.//g;
 		$number =~ s/,/./g;
@@ -1464,13 +1469,14 @@ sub get_default_commodity() {
 sub get_value_expr($) {
     my ($l) = @_;
 
-    if ($l !~ /^(?<math>$RE{balanced}{-parens=>'()'})\s*(?<rest>.*)/) {
+    if ($l !~ /^(?<math>$RE{balanced}{-parens=>'()'})(?<space>\s*)(?<rest>.*)/) {
 	die "Cannot parse inline math from $l\n";
     }
+    my $amount;
     my $math = $+{math};
+    $amount->[WHITESPACE] = $+{space};
     my $rest = $+{rest};
 
-    my $amount;
     $amount->[ADJUST_WHITESPACE] = length($math) - 1; # we subtract the new length later
     # Strip the outer () since beancount doesn't require them.
     $math =~ s/^\(//;
@@ -1509,48 +1515,66 @@ sub get_value_expr($) {
 
 
 # Parse an amount
-sub get_amount($) {
+sub parse_amount($) {
     my ($l) = @_;
 
-    # Inline math
-    if ($l =~ /^\(/) {
-	return get_value_expr $l;
-    }
-
     my $amount;
     $amount->[ADJUST_WHITESPACE] = 0;
     $amount->[FIXATED] = 1 if $l =~ s/^=\s*//;
 
     # Ledger supports three different amount formats:
-    # [minus] number currency
-    # [minus] currency number
-    # currency [minus] number
-    if ($l =~ /^(?<minus>-\s*)?(?<number>$number_RE)\s*(?<currency>$commodity_RE)(?<space>\s*)(?<rest>.*)/ ||
-        $l =~ /^(?<minus>-\s*)?(?<currency>$commodity_RE)\s*(?<number>$number_RE)(?<space>\s*)(?<rest>.*)/ ||
-        $l =~ /^(?<currency>$commodity_RE)\s*(?<minus>-\s*)(?<number>$number_RE)(?<space>\s*)(?<rest>.*)/ ||
-        $l =~ /^(?<minus>-\s*)?(?<number>$number_RE)(?<space>\s*)(?<rest>($|[;={(@]).*)$/) {
+    # [sign] number currency
+    # [sign] currency number
+    # currency [sign] number
+    if ($l =~ /^(?<sign>$sign_RE)?\s*(?<number>$number_RE)\s*(?<currency>$commodity_RE)(?<space>\s*)(?<rest>.*)/ ||
+        $l =~ /^(?<sign>$sign_RE)?\s*(?<currency>$commodity_RE)\s*(?<number>$number_RE)(?<space>\s*)(?<rest>.*)/ ||
+        $l =~ /^(?<currency>$commodity_RE)\s*(?<sign>$sign_RE)\s*(?<number>$number_RE)(?<space>\s*)(?<rest>.*)/ ||
+        $l =~ /^(?<sign>$sign_RE)?\s*(?<number>$number_RE)(?<space>\s*)(?<rest>($|[;={(@]).*)$/) {
 	$amount->[WHITESPACE] = $+{space};
 	my $rest = $+{rest};
-	my $minus = $+{minus} ? "-" : "";
+	my $sign = $+{sign} ? $+{sign} : "";
 	if ($+{currency}) {
 	    $amount->[CURRENCY] = map_commodity $+{currency};
 	} elsif ($config->{hledger} && defined $hledger_default_commodity) {
 	    $amount->[CURRENCY] = $hledger_default_commodity;
 	}
-	$amount->[NUMBER] = convert_number $+{number}, $amount->[CURRENCY];
+	$amount->[NUMBER] = $+{number};
+	return $sign, $amount, "$rest";
+    } else {
+	die "Cannot parse amount from $l\n";
+    }
+}
 
-	# ledger allows amounts without a leading zero (e.g. .10) but
-	# beancount doesn't.
-	if ($amount->[NUMBER] =~ s/^\./0./) {
-	    $amount->[ADJUST_WHITESPACE]--;
-	}
 
-	$amount->[NUMBER] = $minus . $amount->[NUMBER];
+# Get an amount
+sub get_amount($) {
+    my ($l) = @_;
 
-	return $amount, "$rest";
-    } else {
-	die "Cannot parse amount from $l\n";
+    # Inline math
+    if ($l =~ /^\(/) {
+	return get_value_expr $l;
+    }
+
+    my ($sign, $amount, $rest) = parse_amount $l;
+
+    $amount->[NUMBER] = convert_number $amount->[NUMBER], $amount->[CURRENCY];
+
+    # ledger allows amounts without a leading zero (e.g. .10) but
+    # beancount doesn't.
+    if ($amount->[NUMBER] =~ s/^\./0./) {
+	$amount->[ADJUST_WHITESPACE]--;
     }
+    $amount->[NUMBER] = $sign . $amount->[NUMBER];
+    return $amount, "$rest";
+}
+
+
+# Get the original format of an amount
+sub get_amount_format($) {
+    my ($l) = @_;
+
+    my ($sign, $amount, $rest) = parse_amount $l;
+    return $amount->[NUMBER];
 }
 
 
@@ -2528,13 +2552,13 @@ while (@input) {
 	    # In hledger, a commodity directive can contain an amount
 	    # where the amount defines the format for this commodity
 	    # instead of a separate format directive.
-	    my ($amount, $l) = get_amount $l;
+	    my ($amount, $rest) = get_amount $l;
 	    $commodity = $amount->[CURRENCY];
-	    $ledger_commodity_format{$commodity} = $amount->[NUMBER];
-	    if ($l =~ /^\s*$comment_RE/) {
+	    $ledger_commodity_format{$commodity} = get_amount_format $l;
+	    if ($rest =~ /^\s*$comment_RE/) {
 		$comment = " ;$+{comment}";
-            } elsif ($l) {
-		die "Unknown rest in commodity declaration for $commodity: $l";
+            } elsif ($rest) {
+		die "Unknown rest in commodity declaration for $commodity: $rest";
             }
 	} else {
 		die "Cannot parse commodity directive: $l";
@@ -2553,8 +2577,8 @@ while (@input) {
 	    if ($l =~ /^note\s+(.*)/) {  # note
 		print_line $depth, pp_metadata "name", mk_beancount_string $1;
 	    } elsif ($l =~ /^format\s+(.*)/) {  # format
-	        my ($amount, $l) = get_amount $1;
-		$ledger_commodity_format{$amount->[CURRENCY]} = $amount->[NUMBER];
+		my ($amount, $l) = get_amount $1;
+		$ledger_commodity_format{$amount->[CURRENCY]} = get_amount_format $1;
 		if ($l =~ /^\s*$comment_RE/) {
 		    # do nothing: we don't show format info in beancount,
 		    # so we can discard the comment
@@ -2577,7 +2601,8 @@ while (@input) {
 	# Not supported in beancount
 	print_comment_top_level $depth, $l;
 
-	my ($amount, $l) = get_amount $2;
+	my $info = $2;
+	my ($amount, $l) = get_amount $info;
 	my $commodity = $amount->[CURRENCY];
 	if ($l =~ /^\s*$comment_RE/) {
 	    # do nothing: we don't show D directive in beancount,
@@ -2586,7 +2611,7 @@ while (@input) {
 	    die "Unknown rest in D directive for $commodity: $l";
         }
 	if (!defined $ledger_commodity_format{$commodity}) {
-	    $ledger_commodity_format{$commodity} = $amount->[NUMBER];
+	    $ledger_commodity_format{$commodity} = get_amount_format $info;
 	}
 	$hledger_default_commodity = $commodity;
     } elsif ($l =~ /^[!@]?(payee\s+.*)/) {  # payee declaration
diff --git a/debian/changelog b/debian/changelog
index be93a35..0c3db49 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,9 +1,10 @@
-ledger2beancount (2.6-1) UNRELEASED; urgency=low
+ledger2beancount (2.7-1) UNRELEASED; urgency=low
 
   * New upstream release.
   * Update standards version to 4.5.1, no changes needed.
+  * New upstream release.
 
- -- Debian Janitor <janitor@jelmer.uk>  Thu, 15 Apr 2021 10:27:13 -0000
+ -- Debian Janitor <janitor@jelmer.uk>  Wed, 07 Dec 2022 00:49:10 -0000
 
 ledger2beancount (2.5-1) unstable; urgency=medium
 
diff --git a/devel/release-process.md b/devel/release-process.md
index 110d296..49a2c09 100644
--- a/devel/release-process.md
+++ b/devel/release-process.md
@@ -32,7 +32,7 @@
 * Go to the [GitHub release page](https://github.com/beancount/ledger2beancount/releases/new) to create a new release:
 
     * Select the tag
-    * Use 2.X as the version
+    * Use 2.X as the release title
     * Copy release notes from `docs/changelog.md`
 
 * Email packagers:
diff --git a/docs/authors.md b/docs/authors.md
index b775017..a9de2eb 100644
--- a/docs/authors.md
+++ b/docs/authors.md
@@ -24,6 +24,7 @@ We have also had contributions and input from:
 * Kirill Goncharov (bug reports; package for Arch Linux)
 * Marin Bernard (bug reports)
 * Martin Blais (help with compatibility with beancount)
+* Mohsin Kaleem (bug reports)
 * Remco Rijnders (feedback)
 * Simon Michael (bug reports; fixes; help with compatibility with hledger)
 * Taylor R. Campbell (package for pkgsrc)
diff --git a/docs/changelog.md b/docs/changelog.md
index 8a3e9b0..a418d77 100644
--- a/docs/changelog.md
+++ b/docs/changelog.md
@@ -1,5 +1,14 @@
 # ledger2beancount releases
 
+## 2.7 (2022-12-03)
+
+* Fix parsing of amounts with decimal comma with default commodity in hledger mode
+* Allow amounts without fractional part but decimal separator for hledger
+* Improve pre-processing example in documentation
+* Add support for amounts with plus sign
+* Set option `name_income` for top-level account `Revenue`
+* Fix whitespace handling for inline maths
+
 ## 2.6 (2021-04-15)
 
 * Round calculated total if needed for `price==cost` comparison
diff --git a/docs/index.md b/docs/index.md
index a25dda1..609f153 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -8,7 +8,7 @@ author:
     - Stefano Zacchiroli
     - Martin Michlmayr
 keywords: ledger, beancount, converter, conversion, accounting, bookkeeping, finance
-date: April 2021
+date: December 2022
 documentclass: scrartcl
 urlcolor: blue
 toc: true
diff --git a/docs/installation.md b/docs/installation.md
index ec48b36..1c3b28b 100644
--- a/docs/installation.md
+++ b/docs/installation.md
@@ -69,9 +69,10 @@ docker run --rm -v <HOSTDIR>:/usr/ledger2beancount/docker:rw <IMAGENAME> docker/
 
 ## macOS
 
-You can install `cpanm` from Homebrew:
+You can install Perl and `cpanm` from Homebrew:
 
 ```shell
+brew install perl
 brew install cpanminus
 ```
 
diff --git a/docs/tips.md b/docs/tips.md
index 6d89b99..7a85e77 100644
--- a/docs/tips.md
+++ b/docs/tips.md
@@ -8,23 +8,49 @@ meet all needs.  In some cases, it makes more sense to pre-process the
 input file or post-process the output file rather than to add more
 features to ledger2beancount.
 
-For example, let's consider an input file like this:
+An example where pre-processing is useful are ledger transactions that
+were created with [ledger's convert](https://www.ledger-cli.org/3.0/doc/ledger3.html#The-convert-command)
+command, which allows the generation of transactions from CSV.
+
+Since ledger doesn't distinguish between payee and narration, narration
+information can be stored in a transaction note.  The problem with
+processing such transactions is that ledger puts the note either on the
+same line as the payee or the next line depending on the length of the
+payee and narration information.  Furthermore, ledger2beancount doesn't
+support taking narration information from transaction notes, so we have
+to transform the transaction and store the information as metadata.
+
+Let's take this CSV file as an example:
+
+```csv
+date,note,payee,amount
+2021-04-21,A very long note that will be printed on the next line,Short Payee,-7.99 EUR
+2021-04-21,Short note,Short Payee,-7.99 EUR
+2021-04-21,Short note,A Long Payee Name that leaves no more room for the note,-7.99 EUR
+```
+
+The command `ledger convert --account Assets:Bank` produces this
+output:
 
 ```ledger
-2021-03-22 * Some Payee
-    ;Order Number or other description
-    Expenses:Unknown                                EUR 122.94
-    Assets:Current:Checking
+2021-04-21 * Short Payee
+    ;A very long note that will be printed on the next line
+    Expenses:Unknown                       -7.99 EUR
+    Assets:Bank
+
+2021-04-21 * Short Payee  ;Short note
+    Expenses:Unknown                       -7.99 EUR
+    Assets:Bank
+
+2021-04-21 * A Long Payee Name that leaves no more room for the note
+    ;Short note
+    Expenses:Unknown                       -7.99 EUR
+    Assets:Bank
 ```
 
-We want to use the payee (`Some Payee`) as the payee and use the first
-comment (`Order Number...`) as the narration.  If the narration
-information was on the same line as the payee, we could use
-`payee_split` to split payee and narration.  However, there is no way
-to access comments.
-
-The best solution is a script that changes the comment to metadata.
-A simple script like this one can be used:
+The following script takes the transaction notes (either the transaction
+note on the same line as the payee or the first comment of a transaction)
+and stores them as metadata with the key `narration`:
 
 ```perl
 #!/usr/bin/perl
@@ -33,29 +59,53 @@ use warnings;
 use strict;
 
 my $before_posting = 1;
+my $seen_note = 0;
 while (<>) {
     if (/^\d/) { # Transaction header
         $before_posting = 1;
+        if (/  ;/) {
+            my ($header, $note) = split /  ;/;
+            print "$header\n";
+            print "    ; narration: $note";
+            $seen_note = 1;
+        } else {
+            print;
+            $seen_note = 0;
+        }
     } elsif (/^\s+[^;\s]/) { # Posting
         $before_posting = 0;
+        print;
     } elsif (/^\s+;(.*)/) { # Comment
         my $note = $1;
-        if ($before_posting) {
-            print "    ;narration: $note\n";
-            next;
+        if ($before_posting && !$seen_note) {
+            print "    ; narration: $note\n";
+            $seen_note = 1;
+        } else {
+            print;
         }
+    } else {
+        print;
     }
-    print;
 }
 ```
 
 This changes the input file to:
 
 ```ledger
-2021-03-22 * Some Payee
-    ;narration: Order Number or other description
-    Expenses:Unknown                                EUR 122.94
-    Assets:Current:Checkings
+2021-04-21 * Short Payee
+    ; narration: A very long note that will be printed on the next line
+    Expenses:Unknown                       -7.99 EUR
+    Assets:Bank
+
+2021-04-21 * Short Payee
+    ; narration: Short note
+    Expenses:Unknown                       -7.99 EUR
+    Assets:Bank
+
+2021-04-21 * A Long Payee Name that leaves no more room for the note
+    ; narration: Short note
+    Expenses:Unknown                       -7.99 EUR
+    Assets:Bank
 ```
 
 Now the comment is metadata and we can use the following configuration:
@@ -70,7 +120,18 @@ narration_tag: narration
 to get the expected output:
 
 ```beancount
-2021-03-22 * "Some Payee" "Order Number or other description"
+2021-04-21 * "Short Payee" "A very long note that will be printed on the next line"
+  Expenses:Unknown                       -7.99 EUR
+  Assets:Bank
+
+2021-04-21 * "Short Payee" "Short note"
+  Expenses:Unknown                       -7.99 EUR
+  Assets:Bank
+
+2021-04-21 * "A Long Payee Name that leaves no more room for the note" "Short note"
+  Expenses:Unknown                       -7.99 EUR
+  Assets:Bank
+...
 ```
 
 An example of post-processing is to change the variable type of ledger
diff --git a/tests/accounts.beancount b/tests/accounts.beancount
index 884f728..ffdfda7 100644
--- a/tests/accounts.beancount
+++ b/tests/accounts.beancount
@@ -4,7 +4,7 @@
 ;   - Skipped second account declaration for Expenses:Travel (old Expenses:Bar:Travel)
 ;   - Virtual posting in parentheses ignored
 ;   - Account Revenue not allowed; it needs a sub-account, e.g. Revenue:Subaccount
-;   - Non-standard root name Revenue used; please set beancount options name_*
+;   - Non-standard root name Revenue used; setting beancount option name_income
 ;   - Skipped second account declaration for Expenses:Food (old Expenses:Food)
 ;   - Account Accrued:Accounts Payable:Baz renamed to Liabilities:Accounts-Payable:Baz
 ;   - Account Assets:Bank Debian)bar renamed to Assets:Bank-Debian-bar
@@ -28,9 +28,11 @@
 ;----------------------------------------------------------------------
 
 
-option "title" "Test account names"
 option "name_income" "Revenue"
 
+
+option "title" "Test account names"
+
 ; Beancount: 2.1.0
 
 ; SPDX-FileCopyrightText: © 2018 Martin Michlmayr <tbm@cyrius.com>
diff --git a/tests/accounts.header b/tests/accounts.header
index 9a4883a..d1e5dda 100644
--- a/tests/accounts.header
+++ b/tests/accounts.header
@@ -1,4 +1,3 @@
 
 option "title" "Test account names"
-option "name_income" "Revenue"
 
diff --git a/tests/amounts-plus-sign-decimal-comma.beancount b/tests/amounts-plus-sign-decimal-comma.beancount
new file mode 100644
index 0000000..d731d98
--- /dev/null
+++ b/tests/amounts-plus-sign-decimal-comma.beancount
@@ -0,0 +1,64 @@
+; SPDX-FileCopyrightText: © 2021 Martin Michlmayr <tbm@cyrius.com>
+;
+; SPDX-License-Identifier: GPL-3.0-or-later
+
+; This is an .hledger file because the +amount syntax is currently
+; not supported by ledger (https://github.com/ledger/ledger/issues/1990)
+
+1970-01-01 open Assets:Test
+
+1970-01-01 commodity AUD
+1970-01-01 commodity USD
+
+2021-08-29 * "Amount with plus sign"
+  Assets:Test                          +10.00 USD
+  Assets:Test                          -10.00 USD
+
+2021-08-29 * "Amount with plus sign"
+  Assets:Test                          +10.00 USD
+  Assets:Test                          -10.00 USD
+
+2021-08-29 * "Amount with plus sign"
+  Assets:Test                       +10.00 AUD
+  Assets:Test                       -10.00 AUD
+
+2021-08-29 * "Amount with plus sign"
+  Assets:Test                        +10.00 USD
+  Assets:Test                        -10.00 USD
+
+2021-08-29 * "Amount with plus sign"
+  Assets:Test                         +10.00 USD
+  Assets:Test                         -10.00 USD
+
+2021-08-29 * "Amount with plus sign"
+  Assets:Test                         +10.00 USD
+  Assets:Test                          -10.00 USD
+
+2021-08-29 * "Amount with plus sign"
+  Assets:Test                        +10.00 USD
+  Assets:Test                        -10.00 USD
+
+2021-08-29 * "Amount with plus sign"
+  Assets:Test                      +10.00 AUD
+  Assets:Test                      -10.00 AUD
+
+2021-08-29 * "Amount with plus sign"
+  Assets:Test                           +1.00 USD
+  Assets:Test                           -1.00 USD
+
+2021-08-29 * "Amount with plus sign"
+  Assets:Test                           +1.00 USD
+  Assets:Test                           -1.00 USD
+
+2021-08-29 * "Amount with plus sign"
+  Assets:Test                       +1.00 AUD
+  Assets:Test                       -1.00 AUD
+
+2021-08-29 * "Amount with plus sign"
+  Assets:Test                           +0.10 USD
+  Assets:Test                           -0.10 USD
+
+2021-08-29 * "Amount with plus sign"
+  Assets:Test                           +0.10 USD
+  Assets:Test                           -0.10 USD
+
diff --git a/tests/amounts-plus-sign-decimal-comma.hledger b/tests/amounts-plus-sign-decimal-comma.hledger
new file mode 100644
index 0000000..d2477ff
--- /dev/null
+++ b/tests/amounts-plus-sign-decimal-comma.hledger
@@ -0,0 +1,59 @@
+; SPDX-FileCopyrightText: © 2021 Martin Michlmayr <tbm@cyrius.com>
+;
+; SPDX-License-Identifier: GPL-3.0-or-later
+
+; This is an .hledger file because the +amount syntax is currently
+; not supported by ledger (https://github.com/ledger/ledger/issues/1990)
+
+2021-08-29 * Amount with plus sign
+    Assets:Test                          $+10,00
+    Assets:Test                          $-10,00
+
+2021-08-29 * Amount with plus sign
+    Assets:Test                          +$10,00
+    Assets:Test                          -$10,00
+
+2021-08-29 * Amount with plus sign
+    Assets:Test                       +10,00 AUD
+    Assets:Test                       -10,00 AUD
+
+2021-08-29 * Amount with plus sign
+    Assets:Test                        $ + 10,00
+    Assets:Test                        $ - 10,00
+
+2021-08-29 * Amount with plus sign
+    Assets:Test                         $+ 10,00
+    Assets:Test                         $- 10,00
+
+2021-08-29 * Amount with plus sign
+    Assets:Test                         + $10,00
+    Assets:Test                          -$10,00
+
+2021-08-29 * Amount with plus sign
+    Assets:Test                        + $ 10,00
+    Assets:Test                        - $ 10,00
+
+2021-08-29 * Amount with plus sign
+    Assets:Test                      + 10,00 AUD
+    Assets:Test                      - 10,00 AUD
+
+2021-08-29 * Amount with plus sign
+    Assets:Test                           $+1,00
+    Assets:Test                           $-1,00
+
+2021-08-29 * Amount with plus sign
+    Assets:Test                           +$1,00
+    Assets:Test                           -$1,00
+
+2021-08-29 * Amount with plus sign
+    Assets:Test                       + 1,00 AUD
+    Assets:Test                       - 1,00 AUD
+
+2021-08-29 * Amount with plus sign
+    Assets:Test                            $+,10
+    Assets:Test                            $-,10
+
+2021-08-29 * Amount with plus sign
+    Assets:Test                            +$,10
+    Assets:Test                            -$,10
+
diff --git a/tests/amounts-plus-sign-decimal-comma.yaml b/tests/amounts-plus-sign-decimal-comma.yaml
new file mode 100644
index 0000000..06d68a0
--- /dev/null
+++ b/tests/amounts-plus-sign-decimal-comma.yaml
@@ -0,0 +1,2 @@
+---
+decimal_comma: true
diff --git a/tests/amounts-plus-sign.beancount b/tests/amounts-plus-sign.beancount
new file mode 100644
index 0000000..d735f15
--- /dev/null
+++ b/tests/amounts-plus-sign.beancount
@@ -0,0 +1,68 @@
+; SPDX-FileCopyrightText: © 2021 Martin Michlmayr <tbm@cyrius.com>
+;
+; SPDX-License-Identifier: GPL-3.0-or-later
+
+; This is an .hledger file because the +amount syntax is currently
+; not supported by ledger (https://github.com/ledger/ledger/issues/1990)
+
+1970-01-01 open Assets:Test
+
+1970-01-01 commodity AUD
+1970-01-01 commodity USD
+
+2021-08-29 * "Amount with plus sign"
+  Assets:Test                          +10.00 USD
+  Assets:Test                          -10.00 USD
+
+2021-08-29 * "Amount with plus sign"
+  Assets:Test                          +10.00 USD
+  Assets:Test                          -10.00 USD
+
+2021-08-29 * "Amount with plus sign"
+  Assets:Test                       +10.00 AUD
+  Assets:Test                       -10.00 AUD
+
+2021-08-29 * "Amount with plus sign"
+  Assets:Test                        +10.00 USD
+  Assets:Test                        -10.00 USD
+
+2021-08-29 * "Amount with plus sign"
+  Assets:Test                         +10.00 USD
+  Assets:Test                         -10.00 USD
+
+2021-08-29 * "Amount with plus sign"
+  Assets:Test                         +10.00 USD
+  Assets:Test                          -10.00 USD
+
+2021-08-29 * "Amount with plus sign"
+  Assets:Test                        +10.00 USD
+  Assets:Test                        -10.00 USD
+
+2021-08-29 * "Amount with plus sign"
+  Assets:Test                      +10.00 AUD
+  Assets:Test                      -10.00 AUD
+
+2021-08-29 * "Amount with plus sign"
+  Assets:Test                           +1.00 USD
+  Assets:Test                           -1.00 USD
+
+2021-08-29 * "Amount with plus sign"
+  Assets:Test                           +1.00 USD
+  Assets:Test                           -1.00 USD
+
+2021-08-29 * "Amount with plus sign"
+  Assets:Test                       +1.00 AUD
+  Assets:Test                       -1.00 AUD
+
+2021-08-29 * "Amount with plus sign"
+  Assets:Test                           +0.10 USD
+  Assets:Test                           -0.10 USD
+
+2021-08-29 * "Amount with plus sign"
+  Assets:Test                           +0.10 USD
+  Assets:Test                           -0.10 USD
+
+2021-08-29 * "Amount with plus sign"
+  Assets:Test                       +0.10 AUD
+  Assets:Test                       -0.10 AUD
+
diff --git a/tests/amounts-plus-sign.hledger b/tests/amounts-plus-sign.hledger
new file mode 100644
index 0000000..a5819ed
--- /dev/null
+++ b/tests/amounts-plus-sign.hledger
@@ -0,0 +1,63 @@
+; SPDX-FileCopyrightText: © 2021 Martin Michlmayr <tbm@cyrius.com>
+;
+; SPDX-License-Identifier: GPL-3.0-or-later
+
+; This is an .hledger file because the +amount syntax is currently
+; not supported by ledger (https://github.com/ledger/ledger/issues/1990)
+
+2021-08-29 * Amount with plus sign
+    Assets:Test                          $+10.00
+    Assets:Test                          $-10.00
+
+2021-08-29 * Amount with plus sign
+    Assets:Test                          +$10.00
+    Assets:Test                          -$10.00
+
+2021-08-29 * Amount with plus sign
+    Assets:Test                       +10.00 AUD
+    Assets:Test                       -10.00 AUD
+
+2021-08-29 * Amount with plus sign
+    Assets:Test                        $ + 10.00
+    Assets:Test                        $ - 10.00
+
+2021-08-29 * Amount with plus sign
+    Assets:Test                         $+ 10.00
+    Assets:Test                         $- 10.00
+
+2021-08-29 * Amount with plus sign
+    Assets:Test                         + $10.00
+    Assets:Test                          -$10.00
+
+2021-08-29 * Amount with plus sign
+    Assets:Test                        + $ 10.00
+    Assets:Test                        - $ 10.00
+
+2021-08-29 * Amount with plus sign
+    Assets:Test                      + 10.00 AUD
+    Assets:Test                      - 10.00 AUD
+
+2021-08-29 * Amount with plus sign
+    Assets:Test                           $+1.00
+    Assets:Test                           $-1.00
+
+2021-08-29 * Amount with plus sign
+    Assets:Test                           +$1.00
+    Assets:Test                           -$1.00
+
+2021-08-29 * Amount with plus sign
+    Assets:Test                       + 1.00 AUD
+    Assets:Test                       - 1.00 AUD
+
+2021-08-29 * Amount with plus sign
+    Assets:Test                            $+.10
+    Assets:Test                            $-.10
+
+2021-08-29 * Amount with plus sign
+    Assets:Test                            +$.10
+    Assets:Test                            -$.10
+
+2021-08-29 * Amount with plus sign
+    Assets:Test                        + .10 AUD
+    Assets:Test                        - .10 AUD
+
diff --git a/tests/amounts.beancount b/tests/amounts.beancount
index ab45f0a..feb184c 100644
--- a/tests/amounts.beancount
+++ b/tests/amounts.beancount
@@ -28,6 +28,7 @@
 1970-01-01 open Assets:Rewards
 1970-01-01 open Assets:Test
 1970-01-01 open Equity:Exchange
+1970-01-01 open Expenses:Drinks
 1970-01-01 open Expenses:Housing:Rent
 1970-01-01 open Expenses:Travel:Airfare
 1970-01-01 open Income:401k:Match
@@ -290,3 +291,15 @@
   Assets:Test                            1 FOO
   Assets:Test                           -1 FOO
 
+2022-12-02 * "Inline math and whitespace"
+  Expenses:Drinks                 1/1.159 GBP ; comment
+  Assets:Test
+
+2022-12-02 * "Inline math and whitespace"
+  Expenses:Drinks                 1/1.159 GBP; comment
+  Assets:Test
+
+2022-12-02 * "Inline math and whitespace"
+  Expenses:Drinks                 1/1.159 GBP  ; comment
+  Assets:Test
+
diff --git a/tests/amounts.ledger b/tests/amounts.ledger
index 41b82fc..79deb99 100644
--- a/tests/amounts.ledger
+++ b/tests/amounts.ledger
@@ -263,3 +263,15 @@ commodity $
     Assets:Test                            1
     Assets:Test                           -1
 
+2022-12-02 * Inline math and whitespace
+    Expenses:Drinks                (1/1.159 GBP) ; comment
+    Assets:Test
+
+2022-12-02 * Inline math and whitespace
+    Expenses:Drinks                (1/1.159 GBP); comment
+    Assets:Test
+
+2022-12-02 * Inline math and whitespace
+    Expenses:Drinks                (1/1.159 GBP)  ; comment
+    Assets:Test
+
diff --git a/tests/hledger.beancount b/tests/hledger.beancount
index e36e2c5..b818fdd 100644
--- a/tests/hledger.beancount
+++ b/tests/hledger.beancount
@@ -11,6 +11,7 @@
 ;   - Metadata key foo,bar renamed to foo-bar
 ;   - Metadata key test♚ renamed to test-
 ;   - Collision for account Assets:Checking: Assets:Checking, assets:checking
+;   - Collision for commodity GBP: GBP, £
 ;----------------------------------------------------------------------
 
 ; SPDX-FileCopyrightText: © 2019 Martin Michlmayr <tbm@cyrius.com>
@@ -391,3 +392,33 @@
   Assets:Checking         1 GBP
 
 2021-04-15 balance Assets:Checking  11 GBP
+
+; D 1.000,00 EUR
+
+2022-08-04 txn "Decimal comma with default commodity"
+  Assets:Test                   1.00 EUR
+  Assets:Test
+
+2022-08-04 txn "Decimal comma with default commodity"
+  Assets:Test               1000.00 EUR
+  Assets:Test
+
+; D 1000. GBP
+
+2022-08-04 txn "Amount with decimal separator but no fractional part"
+  Assets:Test                     1. GBP
+  Assets:Test
+
+2022-08-04 txn "Amount with decimal separator but no fractional part"
+  Assets:Test                 1. GBP
+  Assets:Test
+
+; D 1.000, EUR
+
+2022-08-04 txn "Amount with decimal separator but no fractional part"
+  Assets:Test                     1. EUR
+  Assets:Test
+
+2022-08-04 txn "Amount with decimal separator but no fractional part"
+  Assets:Test                 1. EUR
+  Assets:Test
diff --git a/tests/hledger.hledger b/tests/hledger.hledger
index 5218fcf..4d392ee 100644
--- a/tests/hledger.hledger
+++ b/tests/hledger.hledger
@@ -319,3 +319,33 @@ D £1,000.00
   Assets:Checking:A       5
   Assets:Checking:B       5
   Assets:Checking         1 =* 11
+
+D 1.000,00 EUR
+
+2022-08-04 Decimal comma with default commodity
+    Assets:Test                   1,00
+    Assets:Test
+
+2022-08-04 Decimal comma with default commodity
+    Assets:Test               1.000,00
+    Assets:Test
+
+D 1000. GBP
+
+2022-08-04 Amount with decimal separator but no fractional part
+    Assets:Test                     1.
+    Assets:Test
+
+2022-08-04 Amount with decimal separator but no fractional part
+    Assets:Test                 1. GBP
+    Assets:Test
+
+D 1.000, EUR
+
+2022-08-04 Amount with decimal separator but no fractional part
+    Assets:Test                     1,
+    Assets:Test
+
+2022-08-04 Amount with decimal separator but no fractional part
+    Assets:Test                 1, EUR
+    Assets:Test
diff --git a/tests/runtests b/tests/runtests
index 0b592b8..9e1a40c 100755
--- a/tests/runtests
+++ b/tests/runtests
@@ -137,7 +137,7 @@ else
 fi
 
 # Validate hledger file
-hledger_version=$(hledger --version n 2>/dev/null | cut -d" " -f2)
+hledger_version=$(hledger --version 2>/dev/null | cut -d" " -f2)
 if [ -z $hledger_version ]; then
 	echo "Skipping hledger validation checks since hledger is not installed"
 elif ! $(meets_version $hledger_version 1.14.2); then

More details

Full run details