Sanny Builder
Search…
Enums.txt
An enumerated type or enum is a finite set of constants (called enum fields) under a common prefix (enum name).
Enumerated types have a few advantages over ordinary constants. They don't pollute the global namespace and are the first-class citizens in the type system. Parameters with an enumerated type are limited on allowed values range which in turn helps to avoid errors caused by an invalid id usage.
Enums.txt is a text file that defines a list of the enumerated types available in the edit mode.

File Format

Each enumerated type is defined with the following syntax:
enum <enum name> <enum fields> end
enum name - any combination of letters, digits and _ enum fields - one or many lines with the format: <enum field name> [= <enum field value>] where enum field name - any combination of letters, digits and _ enum field value - a number or a string literal enclosed in double quotes. if not present, the compiler assigns a new value automatically.
1
enum Town
2
LS = 0
3
SF = 1
4
LV = 2
5
end
Copied!
Enum fields can be separated with line breaks (see the example above) or with a comma:
1
enum Town
2
LS = 0, SF = 1, LV = 2
3
end
Copied!
It is possible to define many enumerated types in one file. Each enum must have an unique name.
No comments or any extra syntax are allowed in the enums file.

Enum fields

Each enum field gets a value either implicitly or explicitly. Explicit values are getting assigned when a combination of the equal sign and the value follows the field name. Sanny Builder allows integer numbers and string literals to be used as enum values:
1
enum Town
2
LS = 0
3
SF = 1
4
LV = 2
5
end
Copied!
Town.LS is equal to 0, Town.SF is equal to 1 and Town.LV is equal to 2.
1
enum TicTacToe
2
Player1 = "X"
3
Player2 = "O"
4
end
Copied!
TicTacToe.Player1 is equal to X and TicTacToe.Player2 is equal to O.
Implicit values are getting assigned automatically starting from 0 for the first field, 1 for the second field, 2 for the third and so on:
1
enum Town
2
LS
3
SF
4
LV
5
end
Copied!
Town.LS is equal to 0, Town.SF is equal to 1 and Town.LV is equal to 2.
For a mix of implicit and explicit values the following rules take place:
  • a field following an explicit value gets assigned to that value incremented by 1
1
enum E
2
A = 10
3
B
4
C = 100
5
D
6
E
7
end
Copied!
E.A = 10, E.B = 11, E.C = 100, E.D = 101, E.E = 102
  • a field following an explicit string value gets its value after the field name:
1
enum Month
2
Jan = "January"
3
Feb = "February"
4
March
5
end
Copied!
Month.Jan = "January", Month.Feb = "February", Month.March = "March"
An enum can't have a mix of both integer and string values. The first explicit value takes control of what type of values this enum gets:
1
enum Int
2
X, Y // X = 0, Y = 1,
3
end
4
5
enum String
6
X, Y = "Y" // X = "X", Y = "Y"
7
end
8
Copied!
Last modified 7mo ago
Copy link