@@ -216,9 +216,15 @@ rather than referring to it by name or some other evaluation rule. A literal is
216216a 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" ] ;
388388exponent : ['E' | 'e'] ['-' | '+' ] ? dec_lit ;
389389dec_lit : [ dec_digit | '_' ] + ;
390390```
391391
392392A _ 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
445444By 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
452449Examples of floating-point literals of various forms:
453450
0 commit comments