From 08d12075c43c912136a0c983cef8d80be28a193b Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Sun, 25 Feb 2018 13:13:14 +0000 Subject: [PATCH] Split identifiers from keywords or identifiers --- src/identifiers.md | 18 ++++++++++++------ src/macros-by-example.md | 3 ++- src/tokens.md | 8 +++++++- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/identifiers.md b/src/identifiers.md index 4f87997aa4304..6631cc59664b5 100644 --- a/src/identifiers.md +++ b/src/identifiers.md @@ -1,19 +1,25 @@ # Identifiers > **Lexer:** -> IDENTIFIER : +> IDENTIFIER_OR_KEYWORD : >       [`a`-`z` `A`-`Z`] [`a`-`z` `A`-`Z` `0`-`9` `_`]\* >    | `_` [`a`-`z` `A`-`Z` `0`-`9` `_`]+ +> +> IDENTIFIER : +> IDENTIFIER_OR_KEYWORD *Except a [strict] or [reserved] keyword* An identifier is any nonempty ASCII string of the following form: Either - * The first character is a letter - * The remaining characters are alphanumeric or `_` +* The first character is a letter. +* The remaining characters are alphanumeric or `_`. Or - * The first character is `_` - * The identifier is more than one character, `_` alone is not an identifier - * The remaining characters are alphanumeric or `_` +* The first character is `_`. +* The identifier is more than one character. `_` alone is not an identifier. +* The remaining characters are alphanumeric or `_`. + +[strict]: keywords.html#strict-keywords +[reserved]: keywords.html#reserved-keywords diff --git a/src/macros-by-example.md b/src/macros-by-example.md index 5b224ca5402d7..a0d90954aef5b 100644 --- a/src/macros-by-example.md +++ b/src/macros-by-example.md @@ -26,7 +26,7 @@ syntax named by _designator_. Valid designators are: * `pat`: a [pattern] * `expr`: an [expression] * `ty`: a [type] -* `ident`: an [identifier] +* `ident`: an [identifier] or [keyword] * `path`: a [path] * `tt`: a token tree (a single [token] by matching `()`, `[]`, or `{}`) * `meta`: the contents of an [attribute] @@ -38,6 +38,7 @@ syntax named by _designator_. Valid designators are: [expression]: expressions.html [type]: types.html [identifier]: identifiers.html +[keyword]: keyword.html [path]: paths.html [token]: tokens.html [attribute]: attributes.html diff --git a/src/tokens.md b/src/tokens.md index 2470f7766d5a5..ceea2c4ff1a9c 100644 --- a/src/tokens.md +++ b/src/tokens.md @@ -486,10 +486,16 @@ The two values of the boolean type are written `true` and `false`. ## Lifetimes and loop labels > **Lexer** +> LIFETIME_TOKEN +>       `'` [IDENTIFIER_OR_KEYWORD][identifier] +>    | `'_` +> > LIFETIME_OR_LABEL: >       `'` [IDENTIFIER][identifier] -Lifetime parameters and [loop labels] both use this syntax. +Lifetime parameters and [loop labels] use LIFETIME_OR_LABEL tokens. Any +LIFETIME_TOKEN will be accepted by the lexer, and for example, can be used in +macros. [loop labels]: expressions/loop-expr.html