Skip to content

Commit 6e19792

Browse files
committed
Document reserved forms similar to number literals
1 parent 6a379ac commit 6e19792

File tree

1 file changed

+43
-8
lines changed

1 file changed

+43
-8
lines changed

src/tokens.md

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ Note that `-1.0`, for example, is analyzed as two tokens: `-` followed by `1.0`.
497497
> NUMBER_PSEUDOLITERAL_SUFFIX_NO_E :\
498498
> &nbsp;&nbsp; NUMBER_PSEUDOLITERAL_SUFFIX <sub>_not beginning with `e` or `E`_</sub>
499499
500-
As described [above](#suffixes), tokens with the same form as numeric literals other than in the content of their suffix are accepted by the lexer, with the exception of some cases in which the suffix begins with `e` or `E`.
500+
As described [above](#suffixes), tokens with the same form as numeric literals other than in the content of their suffix are accepted by the lexer (with the exception of some reserved forms described below).
501501

502502
Examples of such tokens:
503503
```rust,compile_fail
@@ -509,14 +509,49 @@ Examples of such tokens:
509509
2e5f80;
510510
2e5e6;
511511
2.0e5e6;
512+
```
513+
514+
#### Reserved forms similar to number literals
515+
516+
> **<sup>Lexer</sup>**\
517+
> RESERVED_NUMBER :\
518+
> &nbsp;&nbsp; &nbsp;&nbsp; BIN_LITERAL \[`2`-`9`]\
519+
> &nbsp;&nbsp; | OCT_LITERAL \[`8`-`9`]\
520+
> &nbsp;&nbsp; | ( BIN_LITERAL | OCT_LITERAL | HEX_LITERAL ) `.` \
521+
> &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; _(not immediately followed by `.`, `_` or an [identifier] or [keyword][keywords]_)\
522+
> &nbsp;&nbsp; | ( BIN_LITERAL | OCT_LITERAL ) `e`\
523+
> &nbsp;&nbsp; | `0b` `_`<sup>\*</sup> _end of input or not BIN_DIGIT_\
524+
> &nbsp;&nbsp; | `0o` `_`<sup>\*</sup> _end of input or not OCT_DIGIT_\
525+
> &nbsp;&nbsp; | `0x` `_`<sup>\*</sup> _end of input or not HEX_DIGIT_\
526+
> &nbsp;&nbsp; | DEC_LITERAL ( . DEC_LITERAL)? (`e`|`E`) (`+`|`-`)? _end of input or not DEC_DIGIT_
527+
528+
The following lexical forms similar to number literals are _reserved forms_:
529+
530+
* An unsuffixed binary or octal literal followed, without intervening whitespace, by a decimal digit out of the range for its radix.
531+
532+
* An unsuffixed binary, octal, or hexadecimal literal followed, without intervening whitespace, by a period character (with the same restrictions on what follows the period as for floating-point literals).
512533

513-
// Lexer errors:
514-
2e;
515-
2.0e;
516-
0b101e;
517-
2em;
518-
2.0em;
519-
0b101em;
534+
* An unsuffixed binary or octal literal followed, without intervening whitespace, by the character `e`.
535+
536+
* Input which begins with one of the radix prefixes but is not a valid binary, octal, or hexadecimal literal (because it contains no digits).
537+
538+
* Input which has the form of a floating-point literal with no digits in the exponent.
539+
540+
Any input containing one of these reserved forms is reported as an error by the lexer.
541+
542+
Examples of reserved forms:
543+
544+
```rust,compile_fail
545+
0b0102; // this is not `0b010` followed by `2`
546+
0o1279; // this is not `0o127` followed by `9`
547+
0x80.0; // this is not `0x80` followed by `.` and `0`
548+
0b101e; // this is not a pseudoliteral, or `0b101` followed by `e`
549+
0b; // this is not a pseudoliteral, or `0` followed by `b`
550+
0b_; // this is not a pseudoliteral, or `0` followed by `b_`
551+
2e; // this is not a pseudoliteral, or `2` followed by `e`
552+
2.0e; // this is not a pseudoliteral, or `2.0` followed by `e`
553+
2em; // this is not a pseudoliteral, or `2` followed by `em`
554+
2.0em; // this is not a pseudoliteral, or `2.0` followed by `em`
520555
```
521556

522557
### Boolean literals

0 commit comments

Comments
 (0)