Jelajahi Sumber

Update digit separator notes in design (#2117)

Jon Ross-Perkins 3 tahun lalu
induk
melakukan
9572a33ba9
2 mengubah file dengan 20 tambahan dan 18 penghapusan
  1. 6 2
      docs/design/README.md
  2. 14 16
      docs/design/lexical_conventions/numeric_literals.md

+ 6 - 2
docs/design/README.md

@@ -285,8 +285,7 @@ Integers may be written in decimal, hexadecimal, or binary:
 -   `0x1FE` (hexadecimal)
 -   `0b1010` (binary)
 
-Underscores `_` may be used as digit separators, but for decimal and hexadecimal
-literals, they can only appear in conventional locations. Numeric literals are
+Underscores (`_`) may be used as digit separators. Numeric literals are
 case-sensitive: `0x`, `0b` must be lowercase, whereas hexadecimal digits must be
 uppercase. Integer literals never contain a `.`.
 
@@ -304,6 +303,8 @@ represent that value.
 >     [#144: Numeric literal semantics](https://github.com/carbon-language/carbon-lang/pull/144)
 > -   Proposal
 >     [#820: Implicit conversions](https://github.com/carbon-language/carbon-lang/pull/820)
+> -   Proposal
+>     [#1983: Weaken digit separator placement rules](https://github.com/carbon-language/carbon-lang/pull/1983)
 
 ### Floating-point types
 
@@ -331,6 +332,7 @@ literals are supported:
 -   `123.456e789` (optional `+` or `-` after the `e`)
 -   `0x1.Ap123` (optional `+` or `-` after the `p`)
 
+As with integer literals, underscores (`_`) may be used as digit separators.
 Real-number literals always have a period (`.`) and a digit on each side of the
 period. When a real-number literal is interpreted as a value of a floating-point
 type, its value is the representable real number closest to the value of the
@@ -348,6 +350,8 @@ selected.
 >     [#820: Implicit conversions](https://github.com/carbon-language/carbon-lang/pull/820)
 > -   Proposal
 >     [#866: Allow ties in floating literals](https://github.com/carbon-language/carbon-lang/pull/866)
+> -   Proposal
+>     [#1983: Weaken digit separator placement rules](https://github.com/carbon-language/carbon-lang/pull/1983)
 
 ### String types
 

+ 14 - 16
docs/design/lexical_conventions/numeric_literals.md

@@ -25,16 +25,15 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
 The following syntaxes are supported:
 
--   Integer literals
+-   [Integer literals](#integer-literals)
     -   `12345` (decimal)
     -   `0x1FE` (hexadecimal)
     -   `0b1010` (binary)
--   Real-number literals
+-   [Real-number literals](#real-number-literals)
     -   `123.456` (digits on both sides of the `.`)
     -   `123.456e789` (optional `+` or `-` after the `e`)
     -   `0x1.2p123` (optional `+` or `-` after the `p`)
--   Digit separators (`_`) may be used, with
-    [some restrictions](#digit-separators)
+-   [Digit separators](#digit-separators) (`_`)
 
 Note that real-number literals always contain a `.` with digits on both sides,
 and integer literals never contain a `.`.
@@ -102,19 +101,13 @@ or fixed point real-number types to be expressed directly.
 
 ### Digit separators
 
-If digit separators (`_`) are included in literals, they must meet the
-respective condition:
+A digit separator (`_`) may occur between any two digits within a literal. For
+example:
 
--   For decimal integers, the digit separators shall occur every three digits
-    starting from the right. For example, `2_147_483_648`.
--   For hexadecimal integers, the digit separators shall occur every four digits
-    starting from the right. For example, `0x7FFF_FFFF`.
--   For real-number literals, digit separators can appear in the decimal and
-    hexadecimal integer portions (prior to the period and after the optional `e`
-    or mandatory `p`) as described in the previous bullets. For example,
-    `2_147.483648e12_345` or `0x1_00CA.FEF00Dp+24`
--   For binary literals, digit separators can appear between any two digits. For
-    example, `0b1_000_101_11`.
+-   Decimal integers: `1_23_456_7890`
+-   Hexadecimal integers: `0x7_F_FF_FFFF`
+-   Real-number literals: `2_147.48_3648e12_345` or `0x1_00CA.FE_F00Dp+2_4`
+-   Binary literals: `0b1_000_101_11`
 
 ## Divergence from other languages
 
@@ -144,6 +137,9 @@ cases for the goal of not leaving room for a lower level language:
 -   [Real number syntax](/proposals/p0143.md#real-number-syntax)
     -   [Disallow ties](/proposals/p0866.md)
 -   [Digit separator syntax](/proposals/p0143.md#digit-separator-syntax)
+    -   [3-digit decimal groupings](/proposals/p1983.md#3-digit-decimal-groupings)
+    -   [2-digit or 4-digit hexadecimal digit groupings](/proposals/p1983.md#2-digit-or-4-digit-hexadecimal-digit-groupings)
+    -   [Disallow digit separators in fractions](/proposals/p1983.md#disallow-digit-separators-in-fractions)
 
 ## References
 
@@ -151,3 +147,5 @@ cases for the goal of not leaving room for a lower level language:
     [#143: Numeric literals](https://github.com/carbon-language/carbon-lang/pull/143)
 -   Proposal
     [#866: Allow ties in floating literals](https://github.com/carbon-language/carbon-lang/pull/866)
+-   Proposal
+    [#1983: Weaken digit separator placement rules](https://github.com/carbon-language/carbon-lang/pull/1983)