Skip to main content

Flex Syntax Overview

Flex is a specification language that allows you to define message data types and transform functions for component software interfaces. From Flex specifications, Tangram Pro generates consistent interface libraries, even as your system design changes.

Tangram Pro provides a Flex Editor and Package Manager that allows you to write code in your web browser with realtime typechecking, and create releases to be used in project designs.

Flex Overview

Additional Resources

Example Flex File

flex
module ExamplePackage.ExampleModule
// This is a comment
/* This is a block comment
that ends on another line */
const pi : float64 = 3.14;
abstract extensible struct Foo {}
extensible struct StructA {
a : int32;
b : bit;
}
struct StructB extends StructA {
c : int32;
}
variant VariantA {
Simple;
Complex(int8, float32);
}
enum color int32 {
Red = 1;
Green = 2;
Yellow = 3;
Blue = 4;
}
function square(i : int32) -> int32 {
i * i;
}

General Tips

  • Flex is case-sensitive.
  • Declared names may contain letters a-z,A-Z , numbers 0-9 , and underscores _. They must begin with a letter or an underscore.
  • An object's data type is declared after its name, separated by a colon. NAME : TYPE
  • Functions must have a return data type defined. function NAME( PARAMETERS ) -> RETURN TYPE { BODY; }
  • End of lines are specified using a semicolon. ;

Comments

  • // Single line comment
  • /* */ Multi line comment

Types

  • bit Single bit (true or false)
  • intN N bit two's complement signed integer. May be int8, int16, int32, or int64
  • uintN N bit unsigned integer. May be uint8, uint16, uint32, or uint64
  • floatN N bit IEEE 754 floating point number. May be float32 or float64
  • string Encoding independent string
  • T[] An array of indeterminate length of things of type T
  • T[N] An array of N things of type T
  • T[N..M] An array of anywhere from N to M things of type T
  • T[][] A multidimensional array (array of arrays)
  • (T0, T1, ..., TN) A tuple with element types T0 .. TN
  • Optional<T> An optional type T - may either contain a T or nothing
  • Stream<T> An infinite stream of objects of type T

Declarations

  • const Declare a constant object of a given type
  • struct Declare a structured type object containing fields that each have an explicitly declared type
  • message Declare a message type object that can be used as a Message in Tangram ProTM, and used as input and output for a transform
  • variant Declare a variant type object containing fields that may not have an explicitly declared type
  • enum Declare an enumerated type object containing fields and values that all share the same type
  • newtype Declare a new type object containing a single field
  • function Declare a function
  • transform Declare a transform function that can be used as a Transform in Tangram ProTM
  • let Declare a variable within the scope of a function or transform

Operators

  • Arithmetic: +, -, /, *, % Defined for numeric types
  • Comparison: <, >, <=, >= Defined for numeric types
  • Equality: ==, != Defined for almost all types
  • Boolean: &&, ||, ! Defined for bit
  • Bitwise: &, |, ~, ^ Defined for bit, bit[], int, uint

Literals

  • Bit literals are true and false
  • String literals are delimited by double quotes. "This is a string"
  • Floating literals contain a decimal point. 1.618 and 0.05 are valid, whereas 1. and .05 are invalid
  • Array literals are delimited with square brackets. [1,2,3] : int32[]
  • Tuple literals are delimited with parentheses. (1,false,"foo") : (int32,bit,string)
  • Hexadecimal literals begin with 0x
  • Binary literals begin with 0b
  • Zero can be represented as 0 in intN and uintN, and represented as 0.0 in float32 and float64
  • Underscores _ can be used in numeric literals as digit separators. 1_000_000 is equivalent to 1000000