Update leading-separator.md (#3192)
This commit is contained in:
parent
87aa78f742
commit
75153abf53
|
@ -1,17 +1,32 @@
|
|||
# Allow digit separator after 0b or 0x
|
||||
|
||||
In C# 7.2, we extend the set of places that digit separators (the underscore character) can appear in integral literals. [Beginning in C# 7.0, separators are permitted between the digits of a literal](../csharp-7.0/digit-separators.md). Now, in C# 7.2, we also permit digit separators before the first significant digit of a binary or hexadecimal literal, after the prefix.
|
||||
This proposal specifies the changes required to the [C# 7.1 (draft) Language specification](XXX) to support leading underscores in binary and hex literals. It builds on top of the changes added in 7.0 when binary literals were introduced.
|
||||
|
||||
```csharp
|
||||
123 // permitted in C# 1.0 and later
|
||||
1_2_3 // permitted in C# 7.0 and later
|
||||
0x1_2_3 // permitted in C# 7.0 and later
|
||||
0b101 // binary literals added in C# 7.0
|
||||
0b1_0_1 // permitted in C# 7.0 and later
|
||||
## Changes to [Lexical structure](../../spec/lexical-structure.md)
|
||||
|
||||
// in C# 7.2, _ is permitted after the `0x` or `0b`
|
||||
0x_1_2 // permitted in C# 7.2 and later
|
||||
0b_1_0_1 // permitted in C# 7.2 and later
|
||||
### Literals
|
||||
|
||||
#### Integer literals
|
||||
|
||||
> The grammar for [integer literals](../../spec/lexical-structure.md#Integer-literals) is modified to allow one or more `_` separators before the first digit of a hex or binary literal.
|
||||
|
||||
```antlr
|
||||
hex_digits
|
||||
: '_'? hex_digit
|
||||
| '_'? hex_digit hex_digits_and_underscores? hex_digit
|
||||
;
|
||||
|
||||
binary_digits
|
||||
: '_'? binary_digit
|
||||
| '_'? binary_digit binary_digits_and_underscores? binary_digit
|
||||
;
|
||||
```
|
||||
|
||||
We do not permit a decimal integer literal to have a leading underscore. A token such as `_123` is an identifier.
|
||||
> Make the following changes to the examples:
|
||||
|
||||
\[Example:
|
||||
```csharp
|
||||
0x_abc // hex, int
|
||||
0B__111 // binary, int
|
||||
```
|
||||
end example\]
|
Loading…
Reference in a new issue