Skip to content

Commit

Permalink
Merge pull request #612 from petrochenkov/master
Browse files Browse the repository at this point in the history
Document that literals with any suffixes are valid as tokens
  • Loading branch information
Centril committed May 31, 2019
2 parents 73f7cba + 8c75c7a commit f8ae436
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/tokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ evaluated (primarily) at compile time.
|----------------------------------------------|-----------------|-------------|-------------|---------------------|
| [Character](#character-literals) | `'H'` | 0 | All Unicode | [Quote](#quote-escapes) & [ASCII](#ascii-escapes) & [Unicode](#unicode-escapes) |
| [String](#string-literals) | `"hello"` | 0 | All Unicode | [Quote](#quote-escapes) & [ASCII](#ascii-escapes) & [Unicode](#unicode-escapes) |
| [Raw](#raw-string-literals) | `r#"hello"#` | 0 or more\* | All Unicode | `N/A` |
| [Raw string](#raw-string-literals) | `r#"hello"#` | 0 or more\* | All Unicode | `N/A` |
| [Byte](#byte-literals) | `b'H'` | 0 | All ASCII | [Quote](#quote-escapes) & [Byte](#byte-escapes) |
| [Byte string](#byte-string-literals) | `b"hello"` | 0 | All ASCII | [Quote](#quote-escapes) & [Byte](#byte-escapes) |
| [Raw byte string](#raw-byte-string-literals) | `br#"hello"#` | 0 or more\* | All ASCII | `N/A` |
Expand Down Expand Up @@ -88,6 +88,23 @@ evaluated (primarily) at compile time.

#### Suffixes

A suffix is a non-raw identifier immediately (without whitespace)
following the primary part of a literal.

Any kind of literal (string, integer, etc) with any suffix is valid as a token,
and can be passed to a macro without producing an error.
The macro itself will decide how to interpret such a token and whether to produce an error or not.

```rust
macro_rules! blackhole { ($tt:tt) => () }

blackhole!("string"suffix); // OK
```

However, suffixes on literal tokens parsed as Rust code are restricted.
Any suffixes are rejected on non-numeric literal tokens,
and numeric literal tokens are accepted only with suffixes from the list below.

| Integer | Floating-point |
|---------|----------------|
| `u8`, `i8`, `u16`, `i16`, `u32`, `i32`, `u64`, `i64`, `u128`, `i128`, `usize`, `isize` | `f32`, `f64` |
Expand Down

0 comments on commit f8ae436

Please sign in to comment.