---
title: "Lexical Rules"
url: https://docs.zeroc.com/ice/3.8/slice/lexical-rules
language: swift
docs_index: https://docs.zeroc.com/llms.txt
---

> For an index of every page, see [llms.txt](https://docs.zeroc.com/llms.txt).

# Lexical Rules

Programming language: Swift. Other languages: [C++](https://docs.zeroc.com/ice/3.8/slice/lexical-rules/cpp.md), [C#](https://docs.zeroc.com/ice/3.8/slice/lexical-rules/csharp.md), [Java](https://docs.zeroc.com/ice/3.8/slice/lexical-rules/java.md), [JavaScript](https://docs.zeroc.com/ice/3.8/slice/lexical-rules/js.md), [MATLAB](https://docs.zeroc.com/ice/3.8/slice/lexical-rules/matlab.md), [PHP](https://docs.zeroc.com/ice/3.8/slice/lexical-rules/php.md), [Python](https://docs.zeroc.com/ice/3.8/slice/lexical-rules/python.md), [Ruby](https://docs.zeroc.com/ice/3.8/slice/lexical-rules/ruby.md).

## Comments

Slice supports block comments, delimited by `/*` and `*/`, and line comments, which start with `//` and extend to the end of the line:

```slice
/*
 * Block comment.
 */

// Line comment.
```

Slice also supports doc comments, which document the definition that follows them: line comments that start with `///` and block comments that start with `/**`. See [Comment Syntax](https://docs.zeroc.com/ice/3.8/slice/documenting-slice-definitions/comment-syntax.md).

## Keywords

Slice uses a number of [keywords](https://docs.zeroc.com/ice/3.8/slice/slice-keywords.md), which must be spelled in lowercase, such as `class` and `dictionary`. The keywords `Object` and `Value` are the exceptions: they must be capitalized as shown.

## Identifiers

An identifier begins with an ASCII letter, followed by any number of ASCII letters, digits, and underscores. An identifier cannot begin or end with an underscore, or contain two consecutive underscores: `get_account_name` is legal, but `_account`, `account_`, and `get__account` are not. Non-ASCII letters, such as Å, cannot appear in an identifier.

An identifier cannot end with `Helper`, `Holder`, `Prx`, or `Ptr`: the Slice compilers reserve these suffixes.

### Case Sensitivity

Identifiers that differ only in capitalization are the same identifier: you cannot declare both `TimeOfDay` and `TIMEOFDAY` in the same scope. After you declare an identifier, you must refer to it with the same capitalization; otherwise, the compiler rejects the reference.

### Escaped Identifiers

You can use a Slice keyword as an identifier by prefixing it with a backslash:

```slice
struct Value     // Error!
{
    // ...
}

struct \Value    // OK
{
    // ...
}
```

The backslash lets an existing definition keep a name that a later version of Slice makes a keyword. In new definitions, avoid keywords as identifiers. A backslash before an identifier that is not a keyword has no effect.

### Language Mapping

A Slice identifier maps to an identical Swift identifier. For example, the Slice identifier `Clock` becomes the Swift identifier `Clock`. A single Slice identifier often results in several Swift identifiers: for a Slice interface named `Greeter`, the generated Swift code uses the identifiers `Greeter`, `GreeterPrx`, and `GreeterTraits`.

A Slice identifier that is a Swift keyword keeps its name in the generated Swift code, which then does not compile. Give this identifier a Swift name of your choice with the `swift:identifier` metadata directive. For example, `protocol` is a Swift keyword but a valid Slice identifier:

```slice
struct Endpoint
{
    ["swift:identifier:protocolName"]
    string protocol;
}
```

In the generated Swift code, the field `protocol` becomes `protocolName`.

## See Also

- [Slice Keywords](https://docs.zeroc.com/ice/3.8/slice/slice-keywords.md)
- [Comment Syntax](https://docs.zeroc.com/ice/3.8/slice/documenting-slice-definitions/comment-syntax.md)
- [Slice Metadata Directives](https://docs.zeroc.com/ice/3.8/slice/slice-metadata-directives/swift.md)
