» Language: Values

Values are the data that Sentinel policies operate on. You can create this data yourself, for example by just typing the number 42, or you may access this data from an external source to make policy decisions.

Values have a type, which determines what kind of operatins can be performed on the data. Example types are booleans (true and false), numbers, and strings (text).

This page documents all the available value types. You can also convert between types.

» Boolean

A boolean is a value that is either true or false.

A boolean value is created literally with true or false.

As a policy language, booleans are central to the behavior of Sentinel. Booleans are used as conditions in if statements, are the result of rules, and more. The ultimate result of a Sentinel policy is true or false.

» Integer

An integer is a whole number.

An integer is a 64-bit value. This means it can represent numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,808.

Integers are created by typing them out literally with no separators (such as a comma). An optional prefix can set a non-decimal base: 0 for octal, and 0x for hexadecimal. In hexadecimal literals, letters a-f and A-F represent values 10 to 15.

Example integers are shown below:


Integers are used for math and numerical comparison.

» Float

A float is a number with a decimal point. It has an integer part, a decimal point, a fractional part, and optionally an exponent part. Example floats are shown below:

072.40  // == 72.40

Floats are IEEE-754 64-bit floating point numbers.

» String

Strings are text values.

Strings are created by wrapping text in double quotes, such as "hello". Within the quotes, any character may appear except newline and an unescaped double quote. The text between the quotes is the value.

Because Sentinel policies must be UTF-8 encoded text, strings themselves are UTF-8 encoded text. This means you can put any value UTF-8 character into a string, such as "日本語".

You can have a string with a literal double-quote by escaping it with a backslash. For example: "they said \"hello\"" turns into the value they said "hello".

Backslash escapes can be used for much more than only escaping a double quote. Newlines are \n, a literal backslash is \\, and many more. The full list of available backslash escapes can be found in the language specification.

Example strings:

`abc`                // same as "abc"
\n`                  // same as "\\n\n\\n"
"\""                 // same as `"`
"Hello, world!\n"
"\uD800"             // illegal: surrogate half
"\U00110000"         // illegal: invalid Unicode code point

Strings support indexing. Indexing a string will access that byte in the string as if the string were a byte array. This is an important distinction: it will not access the character at that position if you're using multi-byte characters.

Strings support slicing to efficiently create substrings.

» List

See Lists.

» Map

See Maps.

» Rule

See Rules.

» Function

See Functions.

» Type Conversion

The built-in functions int, float, string convert a value to a value of that type. Some examples are shown below followed by a list of exact rules for type conversion.

int(42)   // 42
int("42") // 42
int(42.8) // 42

float(1.2)   // 1.2
float(1)     // 1.0
float("4.2") // 4.2

string("foo") // "foo"
string(88)    // "88"
string(0xF)   // "15"

For int:

  • Integer values are unchanged
  • String values are converted according to the syntax of integer literals
  • Float values are rounded down to their nearest integer value

For float:

  • Float values are unchanged
  • Integer values are converted to the nearest equivalent floating point value
  • String values are converted according to the syntax of float literals

For string:

  • String values are unchanged
  • Integer values are converted to the base 10 string representation
  • Float values are converted to a string formatted xxx.xxx with a precision of 6. This is equivalent to %f for C's sprintf.

For any other unspecified type, the result is the undefined value.