Skip to content

Commit

Permalink
Merge pull request rust-lang#253 from matthewjasper/identifier-and-ke…
Browse files Browse the repository at this point in the history
…ywords

Split identifiers from keywords or identifiers
  • Loading branch information
Havvy authored Feb 26, 2018
2 parents ec079d3 + 08d1207 commit 267cdd8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
18 changes: 12 additions & 6 deletions src/identifiers.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
# Identifiers

> **<sup>Lexer:<sup>**
> IDENTIFIER :
> IDENTIFIER_OR_KEYWORD :
> &nbsp;&nbsp; &nbsp;&nbsp; [`a`-`z` `A`-`Z`]&nbsp;[`a`-`z` `A`-`Z` `0`-`9` `_`]<sup>\*</sup>
> &nbsp;&nbsp; | `_` [`a`-`z` `A`-`Z` `0`-`9` `_`]<sup>+</sup>
>
> IDENTIFIER :
> IDENTIFIER_OR_KEYWORD <sub>*Except a [strict] or [reserved] keyword*</sub>
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
3 changes: 2 additions & 1 deletion src/macros-by-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/tokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,16 @@ The two values of the boolean type are written `true` and `false`.
## Lifetimes and loop labels

> **<sup>Lexer</sup>**
> LIFETIME_TOKEN
> &nbsp;&nbsp; &nbsp;&nbsp; `'` [IDENTIFIER_OR_KEYWORD][identifier]
> &nbsp;&nbsp; | `'_`
>
> LIFETIME_OR_LABEL:
> &nbsp;&nbsp; &nbsp;&nbsp; `'` [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

Expand Down

0 comments on commit 267cdd8

Please sign in to comment.