---
title: "Lexical Rules"
url: https://docs.zeroc.com/ice/3.8/slice/lexical-rules
language: ruby
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: Ruby. 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), [Swift](https://docs.zeroc.com/ice/3.8/slice/lexical-rules/swift.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 a Ruby identifier derived from it. For example, the Slice interface `Greeter` maps to the Ruby class `GreeterPrx`.

The mapping changes the case of the first letter of some identifiers:

- It capitalizes the names of modules, interfaces, classes, exceptions, structures, enumerations, enumerators, and constants, as Ruby requires for constant, class, and module names. For example, the Slice enumerator `red` maps to the Ruby constant `Red`.
- It lowercases the first letter of parameter names.

Operation and field names keep their case.

A Slice identifier that is a Ruby keyword keeps its name in the generated Ruby code, which is then invalid. Give this identifier a Ruby name of your choice with the `ruby:identifier` metadata directive. For example, `retry` is a Ruby keyword but a valid Slice identifier:

```slice
struct Policy
{
    ["ruby:identifier:retryCount"]
    int retry;
}
```

In the generated Ruby code, the field `retry` becomes `retryCount`. The mapping uses an identifier set with `ruby:identifier` as is.

## 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/ruby.md)
