Skip to content

Commit bc952b1

Browse files
authored
Document numeric type literals in lexical conventions. (#4842)
Also improve the precision of some other nearby documentation.
1 parent ad49647 commit bc952b1

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

docs/design/expressions/literals.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1414

1515
- [Numeric literals](#numeric-literals)
1616
- [Numeric literal syntax](#numeric-literal-syntax)
17-
- [Defined Types](#defined-types)
17+
- [Defined types](#defined-types)
1818
- [Implicit conversions](#implicit-conversions)
1919
- [Examples](#examples)
2020
- [Alternatives Considered](#alternatives-considered)
@@ -70,7 +70,7 @@ Numeric literal syntax is covered in the
7070
doc. Both Integer and Real-Number syntax is defined, with decimal, hexadecimal
7171
and binary integer literals, and decimal and hexadecimal real number literals.
7272

73-
### Defined Types
73+
### Defined types
7474

7575
The following types are defined in the Carbon prelude:
7676

docs/design/lexical_conventions/words.md

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1212

1313
- [Overview](#overview)
1414
- [Keywords](#keywords)
15+
- [Type literals](#type-literals)
16+
- [Identifiers](#identifiers)
1517
- [Raw identifiers](#raw-identifiers)
1618
- [Alternatives considered](#alternatives-considered)
1719
- [References](#references)
@@ -21,7 +23,7 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2123
## Overview
2224

2325
A _word_ is a lexical element formed from a sequence of letters or letter-like
24-
characters, such as `fn` or `Foo` or `Int`.
26+
characters, such as `fn` or `Foo` or `Int`, optionally preceded by `r#`.
2527

2628
The exact lexical form of words has not yet been settled. However, Carbon will
2729
follow lexical conventions for identifiers based on
@@ -98,20 +100,47 @@ The following words are interpreted as keywords:
98100
- `where`
99101
- `while`
100102

103+
### Type literals
104+
105+
A word starting with `i`, `u`, or `f`, followed by a decimal integer, is a
106+
[_numeric type literal_](/docs/design/expressions/literals.md#numeric-type-literals).
107+
108+
### Identifiers
109+
110+
A word is interpreted as an _identifier_ if it is neither a keyword nor a type
111+
literal.
112+
101113
### Raw identifiers
102114

103-
A raw identifier looks like `r#<identifier>`. This can be used for identifiers
104-
which have the same spelling as keywords; for example, `r#impl`. It can help
105-
when using C++ code with identifiers that are keywords in Carbon.
115+
A _raw identifier_ is a word starting with `r#`. A raw identifier is equivalent
116+
to the word following the `r#` prefix, except that it is always interpreted as
117+
an identifier, even if it would otherwise be a keyword or type literal.
118+
119+
Raw identifiers can be used to specify identifiers which have the same spelling
120+
as keywords; for example, `r#impl`. This can be useful when interoperating with
121+
C++ code that uses identifiers that are keywords in Carbon, and when migrating
122+
between versions of Carbon.
106123

107-
The identifier doesn't need to be a keyword, in order to support forwards
108-
compatibility when a keyword is planned to be added. When `<identifier>` is not
109-
a keyword, it will refer to the same entity as `r#<identifier>`.
124+
The word doesn't need to be a keyword, in order to support forwards
125+
compatibility when a keyword is planned to be added. If `word` is an identifier,
126+
then `word` and `r#word` have the same meaning.
110127

111128
## Alternatives considered
112129

130+
Overview:
131+
113132
- [Character encoding: We could restrict words to ASCII.](/proposals/p0142.md#character-encoding-1)
114133
- [Normalization form alternatives considered](/proposals/p0142.md#normalization-forms)
134+
135+
Type literals:
136+
137+
- [Use C++ type keywords with LP64 convention](/proposals/p2015.md#c-lp64-convention)
138+
- [Use full type name with length suffix](/proposals/p2015.md#type-name-with-length-suffix)
139+
- [Use uppercase for type names](/proposals/p2015.md#uppercase-suffixes)
140+
- [Support additional bit widths](/proposals/p2015.md#additional-bit-sizes)
141+
142+
Raw identifiers:
143+
115144
- [Other raw identifier syntaxes](/proposals/p3797.md#other-raw-identifier-syntaxes)
116145
- [Restrict raw identifier syntax to current and future keywords](/proposals/p3797.md#restrict-raw-identifier-syntax-to-current-and-future-keywords)
117146
- [Don't require syntax for references to raw identifiers](/proposals/p3797.md#dont-require-syntax-for-references-to-raw-identifiers)
@@ -121,5 +150,7 @@ a keyword, it will refer to the same entity as `r#<identifier>`.
121150

122151
- Proposal
123152
[#142: Unicode source files](https://github.com/carbon-language/carbon-lang/pull/142)
153+
- Proposal
154+
[#2015: Numeric type literal syntax](https://github.com/carbon-language/carbon-lang/pull/2015)
124155
- Proposal
125156
[#3797: Raw identifier syntax](https://github.com/carbon-language/carbon-lang/pull/3797)

0 commit comments

Comments
 (0)