Skip to content

clarify amount parsing/rendering/commodity directives #793

Description

@simonmichael

Here are some notes and actions aimed at improving amount parsing, rendering, and commodity directives, from this mail thread which spun off from #698. Other issues that might be affected:
#489 #561 #688

(Here's a shorter summary of the points below.)

problems

Problems with amount parsing/rendering in current master:

  • numbers are parsed loosely, accepting any of two decimal separators
  • we don't warn about inconsistent choice of decimal separator across amounts
  • ambiguous-separator amounts can be silently misparsed (a single digit group separator is interpreted as a decimal separator)
  • commodity directives, the recommended solution, have unclear semantics
    • they are used for: declaring commodity symbols, resolving input decimal separator ambiguity, controlling output style
    • the directive's scope for each of of these is non-obvious. Should subfiles be affected ? other files ? transactions in the same file preceding the directive ?
  • commodity directives used to resolve the input decimal separator also limit output style
    • they force digit group separators to appear in output
    • they force the output decimal separator to match the input
  • D directives do all that commodity directives do and more, adding complexity
  • allowing commodities to have different input decimal separators within a file is excessive flexibility
  • allowing commodities to have different output decimal separator within a report is excessive flexibility
  • lack of clarity makes this annoying to learn, costly to support; ongoing issue reports

goals

  • be convenient and intuitive
  • be i18n-aware
  • detect and report errors, avoid guessing
  • don't require learning detailed rules
  • in every situation, do something that's sensible at least in hindsight
  • keep as much backward and sideways compatibility as possible
  • end confusion and bug reports about basic number parsing and rendering

short term

clarify how commodity directives can control both input and output

  • a directive for a commodity sets its input decimal point for the rest of the current file, exclusive of subfiles
  • a directive for a commodity declares its symbol's validity for the rest of the current file, exclusive of subfiles
  • the first directive for a commodity across all files sets its output style in the report

parse decimal separators more carefully

  • commodities and input decimal separators are always declared together, and per file
  • at the start of each file (and each included file), no commodities or input decimal separators are known
  • parsing a commodity directive
    • declares the commodity and its input decimal separator for the current file
    • the directive's amount must have a separator
    • if the separator is ambiguous is it assumed to be the decimal separator. Could display a warning.
    • if this is the first directive for this commodity among all files: also declares the commodity's output style for the report
  • parsing a definite-separator amount whose commodity is not yet declared, has the same effect as a commodity directive. Could display a warning. In a future strict mode, this will raise an error.
  • parsing an ambiguous-separator amount whose commodity is not yet declared, has the same effect as a commodity directive and also displays a warning (one per file)
  • parsing an amount whose decimal separator is inconsistent with the one declared for its commodity, raises an error

clarify docs

  • "use commodity directives in each file to help parse it correctly, declaring commodity symbols and the decimal separator used"
  • "use commodity directives in the first/uppermost file to help control each commodity's output style, declaring the symbol position, digit groups, decimal separator, and number of decimal places"

simplify D directive if it gives any trouble

  • D only specifies a default symbol, eg: D $ . The old syntax is accepted for backwards compatibility but only the symbol matters.

medium term

  • add a decimal or decimal-separator directive to set that once per file. "decimal ,"
  • add an alternate simpler form of commodity directive that just defines a symbol. "commodity $". And perhaps allow declaring multiple symbols with one directive.
  • use system locale to choose a default output decimal separator
  • add an --amount-style command line option that overrides output style, for individual commodities or all commodities.
  • add a strict mode that does more error checking

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-WISHSome kind of improvement request or proposal.journalThe journal file format, and its features.needs-codeTo unblock: needs code/code updatesneeds-docsTo unblock: needs corresponding documentation or doc updatesneeds-testsTo unblock: needs more automated tests or test updates

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions