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.
Additional Resources
- Follow this tutorial to create your own Flex package and use it within a component software interface: Author a Message Set with Flex.
- For general information about managing Flex packages in Tangram Pro see Flex Package Management.
Example Flex File
flex
module ExamplePackage.ExampleModule// This is a comment/* This is a block commentthat 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
, numbers0-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
orfalse
)intN
N bit two's complement signed integer. May beint8
,int16
,int32
, orint64
uintN
N bit unsigned integer. May beuint8
,uint16
,uint32
, oruint64
floatN
N bit IEEE 754 floating point number. May befloat32
orfloat64
string
Encoding independent stringT[]
An array of indeterminate length of things of type TT[N]
An array of N things of type TT[N..M]
An array of anywhere from N to M things of type TT[][]
A multidimensional array (array of arrays)(T0, T1, ..., TN)
A tuple with element types T0 .. TNOptional<T>
An optional type T - may either contain a T or nothingStream<T>
An infinite stream of objects of type T
Declarations
const
Declare a constant object of a given typestruct
Declare a structured type object containing fields that each have an explicitly declared typemessage
Declare a message type object that can be used as a Message in Tangram ProTM, and used as input and output for atransform
variant
Declare a variant type object containing fields that may not have an explicitly declared typeenum
Declare an enumerated type object containing fields and values that all share the same typenewtype
Declare a new type object containing a single fieldfunction
Declare a functiontransform
Declare a transform function that can be used as a Transform in Tangram ProTMlet
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 forbit
- Bitwise:
&
,|
,~
,^
Defined forbit
,bit[]
,int
,uint
Literals
- Bit literals are
true
andfalse
- String literals are delimited by double quotes.
"This is a string"
- Floating literals contain a decimal point.
1.618
and0.05
are valid, whereas1.
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
inintN
anduintN
, and represented as0.0
infloat32
andfloat64
- Underscores
_
can be used in numeric literals as digit separators.1_000_000
is equivalent to1000000