Digit separators

Under construction. Digit grouping, Digit separators ADA, Java SE 7, Ruby

Motivation

Definition

Replace the syntax productions for integer constant, binary constant, octal constant, hexadecimal constant, float number token, and exponent. Add digit separator.
integer constant (* 6.4.4 *)
   = decimal digit char (* 6.5.2 *),
     { [ digit separator (* 6.4.4 *) ] ,
       decimal digit char (* 6.5.2 *) } ;

binary constant (* 6.4.4 *)
   = binary constant indicator (* 6.4.4 *),
     binary digit char (* 6.5.2 *),
     { [ digit separator (* 6.4.4 *) ] ,
       binary digit char (* 6.5.2 *) } ;

octal constant (* 6.4.4 *)
   = octal constant indicator (* 6.4.4 *),
     octal digit char (* 6.5.2 *),
     { [ digit separator (* 6.4.4 *) ] ,
       octal digit char (* 6.5.2 *) } ;

hexadecimal constant (* 6.4.4 *)
   = hexadecimal constant indicator (* 6.4.4 *),
     hexadecimal digit char (* 6.5.2 *),
     { [ digit separator (* 6.4.4 *) ] ,
       hexadecimal digit char (* 6.5.2 *) } ;

digit separator (* 6.4.4 *)
   = underscore char (* 6.5.2 *),
     [ layout text sequence (* 6.4.1 *) ] ;

float number token (* 6.4.5 *)
   = integer constant (* 6.4.4 *),
     decimal digit char (* 6.5.2 *),
     { decimal digit char (* 6.5.2 *) },
     fraction (* 6.4.5 *),
     [ exponent (* 6.4.5 *) ] ;

exponent (* 6.4.5 *)
   = exponent char (* 6.4.5 *),
     sign (* 6.4.5 *),
     integer constant (* 6.4.4 *) ;
     decimal digit char (* 6.5.2 *),
     { decimal digit char (* 6.5.2 *) } ;

Options

  1. single underscore 1_000 (accepted)
  2. multiple underscores 1__000_000 (undecided)
  3. followed by layout chars 1_ 000 (accepted)
  4. followed by layout text 1_ /* comment */ 000 (accepted)
  5. single space for decimals (octal, binary) ISO 31-0 3.3, 80000-1:2009,2022 7.2.1 (rejected)
  6. multiple spaces for decimals (octal,binary) (rejected)
  7. layout chars for decimals (octal, binary) (rejected)
  8. write options?
  9. float support for 1_1.25 ?
  10. float support for 11.2_5 ?
  11. float support for 1.0e1_0 ?

History

2010-11-19 pllib Draft 8 added in 6. Numbers as 6.0 Syntax (digit separator problematic):
digit separator =
    underscore char, [new line char, {layout char}];

2013-01-23 Discussion on SWI list "format/2 Thousands separator"
2013-0?-?? SWI includes 1,3,4,5
2013-05-21 Added to main page (check-in 2013-07-11 as 1.11)
digit separator
   = underscore char (* 6.5.2 *),
     [ layout text sequence (* 6.4.1 *) ] ;
Additionally exactly one space for integer, binary, and octal constant.
2013-12-20 pllib Draft 18 changed to
digit separator =
    underscore char, {layout char}, [new line char, {layout char}];
Note that this uses {layout char}, not [layout text sequence]. This is deliberate; comments are not allowed inside numbers.
2021-06-28 Trealla include 1
2021-08-18 Trealla include 5
2021-11-27 Scryer 1,3,4 but only decimals (#994,#1112)
2025-04-24 Trealla 1,3,4
2025-06-02 WG17 rejects options 5,6,7; accepts options 1,3,4
2025-10-15 Scryer pull request #3125