LEVIATHAN vd52e79c4 · d52e79c486

Lexical

Identifiers

The characters a name may use and the camelCase house style.

since 0.1.0-alpha.1linuxwindowswasm

Description

An identifier names a variable, parameter, field, method, class, namespace or any other declaration. It starts with an ASCII letter or an underscore and continues with ASCII letters, digits and underscores:

[A-Za-z_][A-Za-z0-9_]*

Identifiers are case-sensitive, so total and Total are two different names. A name must not be a keyword (see lang.keywords). Non-ASCII letters, - and a leading digit are not allowed: café, my-var and 9x are compile errors.

Legal identifiers

use io::console;

int _count = 1;
int item2 = 20;
int total_so_far = _count + item2;
string userName = "ada";
console.writeln(total_so_far);
console.writeln(userName.startsWith("a"));
console.writeln("ada".toUpper());
21
true
ADA

Rules

  • An identifier matches [A-Za-z_][A-Za-z0-9_]*. The comparison is case-sensitive.
  • A keyword cannot be used as an identifier, with the member-name exceptions listed in lang.keywords.
  • The names of the built-in types (int, string, bool, float, char, void and the sized numeric types) are identifiers, not keywords. They may name a variable, a parameter, a function or a member, but no type declaration in any scope, including a type parameter: a class, struct, interface, enum, type parameter, namespace or use ... as alias named like a primitive is a compile error (lang.primitives).
  • House style, which the standard library follows: names are camelCase. Each word after the first starts with a capital letter (startsWith, toUpper, indexOf, not startswith). Classes, interfaces, structs and enums start with a capital letter. The compiler does not enforce this.
  • System is an ordinary name. An undeclared System is an unknown name like any other.

Examples

The same letters in different cases are different names:

Case matters

use io::console;

int total = 1;
int Total = 2;
console.writeln(total + Total);
3