The grammar of a currency amount, read from the tokens of
Localize.Number.Lexer, behind
Localize.Number.Parser.parse_currency_amount/2.
An amount is a number with currency text before it or after it, inside the signs, parentheses and spaces that decorate the number. The grammar finds the two; the rules below decide what the currency text names, which separators the number is read with, and when an amount that could be read two ways is refused instead.
Grammar
amount = outer, [ currency ], inner, number, closing, [ currency ], outer ;
currency = text, [ mark ] ;
number = digits, { mark | space | digits } ;
outer = { space | tab | sign | "(" | ")" } ;
inner = outer ;
closing = { space | tab | sign | "(" | ")" | mark | dash } ;with at most one currency. number is the text from the first
digit to the last, which Localize.Number.Parser.parse/2 then reads
with the currency's separators. A mark that ends the currency text
before the digits ("$.50", "kr.5") is the currency's where CLDR
writes the currency with it, the number's where it is the currency's
decimal mark, and otherwise refused (amount_currency/3).
The rules, each a named function:
Currency text names a currency only where one alone takes it, after NFKC normalization, with a trailing period tried off as well as on (
text_currency/2).A caller's currencies (
:caller_currency) take text the locale does not name; text naming both a CLDR currency and a different one of the caller's is refused, except in a locale whose own currency it names (unclaimed_currency/3,uncontested_caller_currency/3).A caller's word with digits in it, such as a digital token identifier, is the first word or the last, and is read only where the amount has no other reading (
caller_word_amounts/3,one_reading/3).No currency is the
:default_currency, or a missing-currency error (amount_currency/3).The number is read with the currency's separators and
grouping: :sizes, and three fraction digits in a currency of fewer places are refused as a possible thousands group (amount_number/4,unambiguous_fraction/3).