Skip to content

Commit 6a379ac

Browse files
committed
Add a Lexer rules block for number literals with arbitrary suffixes
1 parent e2015cc commit 6a379ac

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

src/tokens.md

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -398,13 +398,8 @@ Note that `-1i8`, for example, is analyzed as two tokens: `-` followed by `1i8`.
398398
Examples of invalid integer literals:
399399

400400
```rust,compile_fail
401-
// invalid suffixes
402-
403-
0invalidSuffix;
404-
405401
// uses numbers of the wrong base
406402
407-
123AFB43;
408403
0b0102;
409404
0o0581;
410405
@@ -488,6 +483,42 @@ to call a method named `f64` on `2`.
488483

489484
Note that `-1.0`, for example, is analyzed as two tokens: `-` followed by `1.0`.
490485

486+
#### Number pseudoliterals
487+
488+
> **<sup>Lexer</sup>**\
489+
> NUMBER_PSEUDOLITERAL :\
490+
> &nbsp;&nbsp; &nbsp;&nbsp; DEC_LITERAL ( . DEC_LITERAL)? FLOAT_EXPONENT NUMBER_PSEUDOLITERAL_SUFFIX\
491+
> &nbsp;&nbsp; | DEC_LITERAL ( . DEC_LITERAL)? NUMBER_PSEUDOLITERAL_SUFFIX_NO_E\
492+
> &nbsp;&nbsp; | ( BIN_LITERAL | OCT_LITERAL | HEX_LITERAL ) NUMBER_PSEUDOLITERAL_SUFFIX_NO_E
493+
>
494+
> NUMBER_PSEUDOLITERAL_SUFFIX :\
495+
> &nbsp;&nbsp; IDENTIFIER_OR_KEYWORD <sub>_not matching INTEGER_SUFFIX or FLOAT_SUFFIX_</sub>
496+
>
497+
> NUMBER_PSEUDOLITERAL_SUFFIX_NO_E :\
498+
> &nbsp;&nbsp; NUMBER_PSEUDOLITERAL_SUFFIX <sub>_not beginning with `e` or `E`_</sub>
499+
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`.
501+
502+
Examples of such tokens:
503+
```rust,compile_fail
504+
0invalidSuffix;
505+
123AFB43;
506+
0b010a;
507+
0xAB_CD_EF_GH;
508+
2.0f80;
509+
2e5f80;
510+
2e5e6;
511+
2.0e5e6;
512+
513+
// Lexer errors:
514+
2e;
515+
2.0e;
516+
0b101e;
517+
2em;
518+
2.0em;
519+
0b101em;
520+
```
521+
491522
### Boolean literals
492523

493524
> **<sup>Lexer</sup>**\

0 commit comments

Comments
 (0)