Skip to content

Latest commit

 

History

History
156 lines (126 loc) · 4.3 KB

File metadata and controls

156 lines (126 loc) · 4.3 KB

Words

Table of contents

Overview

A word is a lexical element formed from a sequence of letters or letter-like characters, such as fn or Foo or Int, optionally preceded by r#.

The exact lexical form of words has not yet been settled. However, Carbon will follow lexical conventions for identifiers based on Unicode Annex #31. TODO: Update this once the precise rules are decided; see the Unicode source files proposal.

Carbon source files, including comments and string literals, are required to be in Unicode Normalization Form C (NFC).

Keywords

The following words are interpreted as keywords:

  • abstract
  • adapt
  • addr
  • alias
  • and
  • as
  • auto
  • base
  • break
  • case
  • choice
  • class
  • constraint
  • continue
  • default
  • destructor
  • else
  • export
  • extend
  • final
  • fn
  • for
  • forall
  • friend
  • if
  • impl
  • impls
  • import
  • in
  • interface
  • let
  • library
  • like
  • match
  • namespace
  • not
  • observe
  • or
  • override
  • package
  • partial
  • private
  • protected
  • require
  • return
  • returned
  • Self
  • template
  • then
  • type
  • var
  • virtual
  • where
  • while

Type literals

A word starting with i, u, or f, followed by a decimal integer, is a numeric type literal.

Identifiers

A word is interpreted as an identifier if it is neither a keyword nor a type literal.

Raw identifiers

A raw identifier is a word starting with r#. A raw identifier is equivalent to the word following the r# prefix, except that it is always interpreted as an identifier, even if it would otherwise be a keyword or type literal.

Raw identifiers can be used to specify identifiers which have the same spelling as keywords; for example, r#impl. This can be useful when interoperating with C++ code that uses identifiers that are keywords in Carbon, and when migrating between versions of Carbon.

The word doesn't need to be a keyword, in order to support forwards compatibility when a keyword is planned to be added. If word is an identifier, then word and r#word have the same meaning.

Alternatives considered

Overview:

Type literals:

Raw identifiers:

References