Skip to content

Commit 2e5433e

Browse files
committed
---
yaml --- r: 160240 b: refs/heads/snap-stage3 c: a11078f h: refs/heads/master v: v3
1 parent aa83389 commit 2e5433e

File tree

2 files changed

+21
-24
lines changed

2 files changed

+21
-24
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: bfaa7bcab3459907014c31d3bf980f65ccd14b08
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 7586abf01b5c6fcbb60926c7cab7d3e5d133fa9a
4+
refs/heads/snap-stage3: a11078f8c3a69f0d4ea20ca10aaf96622770615b
55
refs/heads/try: 225de0d60f8ca8dcc62ab2fd8818ebbda4b58cfe
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d

branches/snap-stage3/src/doc/reference.md

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,15 @@ rather than referring to it by name or some other evaluation rule. A literal is
216216
a form of constant expression, so is evaluated (primarily) at compile time.
217217

218218
```{.ebnf .gram}
219-
literal : string_lit | char_lit | byte_string_lit | byte_lit | num_lit ;
219+
lit_suffix : ident;
220+
literal : [ string_lit | char_lit | byte_string_lit | byte_lit | num_lit ] lit_suffix ?;
220221
```
221222

223+
The optional suffix is only used for certain numeric literals, but is
224+
reserved for future extension, that is, the above gives the lexical
225+
grammar, but a Rust parser will reject everything but the 12 special
226+
cases mentioned in [Number literals](#number-literals) below.
227+
222228
#### Character and string literals
223229

224230
```{.ebnf .gram}
@@ -371,27 +377,20 @@ b"\\x52"; br"\x52"; // \x52
371377
#### Number literals
372378

373379
```{.ebnf .gram}
374-
num_lit : nonzero_dec [ dec_digit | '_' ] * num_suffix ?
375-
| '0' [ [ dec_digit | '_' ] * num_suffix ?
376-
| 'b' [ '1' | '0' | '_' ] + int_suffix ?
377-
| 'o' [ oct_digit | '_' ] + int_suffix ?
378-
| 'x' [ hex_digit | '_' ] + int_suffix ? ] ;
379-
380-
num_suffix : int_suffix | float_suffix ;
380+
num_lit : nonzero_dec [ dec_digit | '_' ] * float_suffix ?
381+
| '0' [ [ dec_digit | '_' ] * float_suffix ?
382+
| 'b' [ '1' | '0' | '_' ] +
383+
| 'o' [ oct_digit | '_' ] +
384+
| 'x' [ hex_digit | '_' ] + ] ;
381385
382-
int_suffix : 'u' int_suffix_size ?
383-
| 'i' int_suffix_size ? ;
384-
int_suffix_size : [ '8' | "16" | "32" | "64" ] ;
386+
float_suffix : [ exponent | '.' dec_lit exponent ? ] ? ;
385387
386-
float_suffix : [ exponent | '.' dec_lit exponent ? ] ? float_suffix_ty ? ;
387-
float_suffix_ty : 'f' [ "32" | "64" ] ;
388388
exponent : ['E' | 'e'] ['-' | '+' ] ? dec_lit ;
389389
dec_lit : [ dec_digit | '_' ] + ;
390390
```
391391

392392
A _number literal_ is either an _integer literal_ or a _floating-point
393-
literal_. The grammar for recognizing the two kinds of literals is mixed, as
394-
they are differentiated by suffixes.
393+
literal_. The grammar for recognizing the two kinds of literals is mixed.
395394

396395
##### Integer literals
397396

@@ -406,9 +405,9 @@ An _integer literal_ has one of four forms:
406405
* A _binary literal_ starts with the character sequence `U+0030` `U+0062`
407406
(`0b`) and continues as any mixture of binary digits and underscores.
408407

409-
An integer literal may be followed (immediately, without any spaces) by an
410-
_integer suffix_, which changes the type of the literal. There are two kinds of
411-
integer literal suffix:
408+
Like any literal, an integer literal may be followed (immediately,
409+
without any spaces) by an _integer suffix_, which forcibly sets the
410+
type of the literal. There are 10 valid values for an integer suffix:
412411

413412
* The `i` and `u` suffixes give the literal type `int` or `uint`,
414413
respectively.
@@ -443,11 +442,9 @@ A _floating-point literal_ has one of two forms:
443442
* A single _decimal literal_ followed by an _exponent_.
444443

445444
By default, a floating-point literal has a generic type, and, like integer
446-
literals, the type must be uniquely determined from the context. A
447-
floating-point literal may be followed (immediately, without any spaces) by a
448-
_floating-point suffix_, which changes the type of the literal. There are two
449-
floating-point suffixes: `f32`, and `f64` (the 32-bit and 64-bit floating point
450-
types).
445+
literals, the type must be uniquely determined from the context. There are two valid
446+
_floating-point suffixes_, `f32` and `f64` (the 32-bit and 64-bit floating point
447+
types), which explicitly determine the type of the literal.
451448

452449
Examples of floating-point literals of various forms:
453450

0 commit comments

Comments
 (0)