Home Explore Blog Models CI



nix

doc/manual/source/language/identifiers.md
14add335758496079b5a4a2ae50e71ac86471a9e54a268de0000000300000672
# Identifiers

An *identifier* is an [ASCII](https://en.wikipedia.org/wiki/ASCII) character sequence that:
- Starts with a letter (`a-z`, `A-Z`) or underscore (`_`)
- Can contain any number of:
  - Letters (`a-z`, `A-Z`)
  - Digits (`0-9`)
  - Underscores (`_`)
  - Apostrophes (`'`)
  - Hyphens (`-`)
- Is not one of the [keywords](#keywords)

> **Syntax**
>
> *identifier* ~ `[A-Za-z_][A-Za-z0-9_'-]*`

# Names

A *name* can be written as an [identifier](#identifier) or a [string literal](./string-literals.md).

> **Syntax**
>
> *name* → *identifier* | *string*

Names are used in [attribute sets](./syntax.md#attrs-literal), [`let` bindings](./syntax.md#let-expressions), and [`inherit`](./syntax.md#inheriting-attributes).
Two names are the same if they represent the same sequence of characters, regardless of whether they are written as identifiers or strings.

# Keywords

These keywords are reserved and cannot be used as [identifiers](#identifiers):

- [`assert`](./syntax.md#assertions)
- [`else`][if]
- [`if`][if]
- [`in`][let]
- [`inherit`](./syntax.md#inheriting-attributes)
- [`let`][let]
- [`or`](./operators.md#attribute-selection) (see note)
- [`rec`](./syntax.md#recursive-sets)
- [`then`][if]
- [`with`](./syntax.md#with-expressions)


> **Note**
>
> The Nix language evaluator currently allows `or` to be used as a name in some contexts, for backwards compatibility reasons.
> Users are advised not to rely on this.
>
> There are long-standing issues with how `or` is parsed as a name, which can't be resolved without making a breaking change to the language.

Chunks
f902a42b (1st chunk of `doc/manual/source/language/identifiers.md`)
Title: Identifiers, Names, and Keywords
Summary
This chunk defines the rules for identifiers, names, and lists reserved keywords within a programming language context. An identifier is an ASCII sequence starting with a letter or underscore, followed by letters, digits, underscores, apostrophes, or hyphens, and cannot be a keyword. A name can be an identifier or a string literal, used in various language constructs, and is considered identical if the underlying character sequence matches. A list of keywords, such as `assert`, `else`, `if`, and `let`, are reserved and cannot be used as identifiers, with a specific note advising against using `or` as a name despite current backward compatibility.