Skip to main content

What Is Flex?

Flex is a specification language that allows you to define message data types and transform functions for component software interfaces.

A Flex specification is organized into packages and modules. The standard unit of Flex code is called a package (e.g., MyExamplePackage::v1).

A single package corresponds to a folder in the file system. Within a package are zero or more modules (e.g., MyExampleModule), each contained in its own separate file with the .flex extension. A module file should begin with a module header followed by zero or more import statements followed by a list of declarations.

Minor Notes
  • Flex supports single line // and multi-line /* */ comments.
  • Identifiers may contain alphanumeric characters and underscores. They must begin with a letter or underscore.
  • Identifiers are case-sensitive.

To see these pieces put together in a complete module, work through the Getting Started with Flex tutorial.

Import Statements

An import statement brings other modules and declarations therein into this module's scope. There are two forms of import statement:

import PACKAGE_NAME.MODULE_NAME (DECL1, DECL2, ...);
import PACKAGE_NAME.MODULE_NAME as ALIAS;

The first form directly imports the declarations listed in the parentheses. In other words, DECL1 and DECL2 can now be referenced elsewhere in this module. The second form imports another module and establishes an alias to refer to it. A declaration named MYDECL in PACKAGE_NAME.MODULE_NAME is now accessible as ALIAS.MYDECL.

Wildcard Imports

Flex does not include a "wildcard" import that directly imports all declarations in a module. This is so that the definitions of all identifiers can be easily found.

Declarations

The rest of a Flex module, after the imports, is a list of declarations. A declaration can define a data type, transform, function, or constant.

The order in which the declarations appear is unimportant. Although it is generally good practice to place a declaration before its uses.

Data Type Declarations

See section Data Types.

Flex's user-defined data types include structs, enums, variants, newtypes and type aliases.

Transforms and Functions

See section Transforms.

Transforms describe conversions between data types of a message standard. The message keyword indicates that a data type is part of a message standard, and thus is a valid input or output type of a transform. While the syntax of transforms is intended to be familiar to C++ and Java programmers, the semantics are designed to be amenable to formal verification and program transformation.

Constants

A const definition binds an expression to an identifier. Note that Flex does not have mutable state, so a const definition says that the identifier "is precisely equal to" or "can be replaced with" its definition. It is not a variable or place in memory that contains a value, and its value cannot be changed.

const NAME: TYPE = EXPRESSION;
Syntax Overview