This description is not formally perfect nor is it exhaustive. It is intended for fast learning only.
Any TL program is made of:
Program "write" Comment "Write In into Out" Data t_write param arg1:string; call writefnc:string;
Comments are made of the reserved word Comment followed by a string or sum of strings. Several comments are contatenated as if string + newline + string would be used.
They are used to document a type/command/parameter/option. The comments are used with the automatic documentation.
Examples:
Program "abc" Comment "This is a test program." Comment "Written by Pinco Pallino." ... ... param name:string comment "user name" ... ... option "format" format:string comment "printf-like format"+ "see C documentation" ...
At any point you can insert an annotation; simply write double slash (//) and the rest of the line is the annotation.
Annotations are used as internal comments as they are ignored by the compiler.
Examples:
Program "write" Comment "Write In into Out" // This is a very simple program ... ... //param a:string param a:integer ...
TL supports five types of constants:
A constant definition is made of the reserved word Const, followed by an identifier, a = and a constant value.
Another possible definition is made of the reserved word Const, followed by an identifier. The value of such a constant is a unique natural value.
Do not mix the two definitions.
Example:
Program "Consts" Const a1 a2 a3 a4 a5 b1str = "b1" b2str = "b2" val1 = -200 val2 = 400 Const r1 = -1.23e2 r2 = 2.456e2 Intype myset = set("a1":a1,"a2":a2,"a3":a3,"a4":a4,"a5":a5,b1str,b2str) Intype myrange = rrange(r1..r2) myrange1 = irange(val1..val2) data t_consts param a:myset param b:myrange param c:myrange1 call myfunc:string
TL supports two types of types: intype and outtype.
Any basic (in or out) type can be used directly, except set, iset and user types that can only be used to create new types.
To define a new type you have to insert the intype/outtype type
definition in a type definition part of the program.
Type definition parts can be put immediately before the
command body
of the program and/or a command.
A type definition if made of the reserved word Intype/Outtype followed by an identifier, a = , the types definition and an optional comment line.
See Types section
for details about available types.
Example:
Program "Types" Intype myset = set("a1":1,"a2":2,"a3":3,"a4":4,"a5":5,"b1","b2","b3") myrec = record a:myset b:integer end Outtype myuser = user mydeffunc myfreefunc Comment "This is my very personal type." mycase = case a of 1 n1:myuser 2 n2:freal else e1:string end data t_types param a:myrec call myfunc:mycase
There are three types of command bodies:
The select bodies are used to create subcommands.
They are made of the reserved word Select, two or more command instructions and the reserved word end.
Example:
... Select Command "open" data t_open ... call openfunc:int Command "close" data t_close ... call closefunc:string end
The data body is the most used command body. It is used to parse input, compute the data and create the output.
The data bodies are made of the reserved word data, a data identifier(*), some param, at most one optparam, and some option instructions, followed by the reserved word Call, a function identifier(**), a colon(:) and an output type(***).
The data identifier(*) is used to create the internal data structure. The param, optparam and option instructions are used to create the parsing code. The function identifier(**) is the name of a user supplied function. This function actually compute the data that is finally converted in the output string using the output type(***).
The parsers created by this command bodies do strong type checking.
The resulting command will accept only the input specified in the
data body. This can limit the use of the command,
but can improve error detection.
If you need more flexibility,
use the unixdata bodies.
Example:
... data t_mydata param p1:integer param p2:real; option "format" format:string optparam op1:bool call mydatafunc:integer ...
The unixdata body is similar to the data body. It is used to parse input, compute the data and create the output.
The unixdata bodies are made of the reserved word unixdata, a data identifier(*), some option and some short option instructions, followed by the reserved word Call, a function identifier(**), a colon(:) and an output type(***).
The data identifier(*) is used to create the internal data structure. The option and short option instructions are used to create the parsing code. The function identifier(**) is the name of a user supplied function. This function actually compute the data that is finally converted in the output string using the output type(***).
The parsers created by this command bodies are very flexible.
They do type checking only on option parameters, all the other
data is passed unchanged to the user supplied function.
This allows very flexible commands, but requires much more
complicated user supplied functions. Moreover there is very little
automatic error detection.
So it is better to use data bodies
whenever possible.
Example:
... unixdata t_myudata option "maxsize" format:integer option "docache" docache call myudatafunc:freal ...
There are five types of instructions:
Command instructions are used in select bodies. They define a list of subcommands.
They are made of the reserved word Command, a string, an optional case statement, an optional comment, an optional constant definition part, an optional type definition part and a command body.
Example:
... Command "open" Comment "Open file" Outtype id=integer data t_open param name:string call openfunc:id ...
Param instructions are used in data bodies. They define a list of parameters and their types. These parameters are the first input parameters. This is independent of the other instructions.
The param instructions are made of
the reserved word Param,
a data identifier, a colon(:) and an input type.
Should be followed by a comment.
Example:
... data t_mydata param a:integer Comment "First parameter" param b:real // do not comment param c:string Comment "Last parameter" call ...This command expects 3 parameters: an integer, a real and a generic string.
Optparam instructions are used in data bodies. There can be at most one optparam instruction per data body. If present it specify an optional parameter and his type. If the optparam instruction is present before any option instruction these parameter must be written before any option parameter, else it must be the last parameter (if present).
The optparam instructions are made of
the reserved word Optparam,
a data identifier, a colon(:) and an input type.
Should be followed by a comment.
Example:
... data t_mydata option "format" format:string Comment "Some type of format" optparam a:integer Comment "Must be the last param, if present" option "size" size:integer call fmyfunc:string ...Some valid inputs:
-format abc -format abc 12 12
Option instructions are used in data bodies and in unixdata bodies. They define a list of possible options, their names and their types. These options can be present as parameters in any order and any number of times. Only the last will be recorded and their presence is notified.
The option instructions are made of
the reserved word Option,
a string(*), a data identifier, a colon(:) and an input type.
Can be followed by a case statement.
Should be followed by a comment.
The string(*) is the name of the option. The option parameter must start with - followed by the string(*). The next parameter represents the option data.
Example:
... data t_mydata option "format" format:string option "maxsize" size:integer comment "Max cache size" option "cancache" ccache:bool call myfunc:string ...Some valid inputs:
-format abc -cancache True -maxsize 12 -format "This is the true format!" -maxsize 3 <empty>
Short option instructions are used in unixdata bodies. They define a list of possible options and their names. These options can be present as parameters in any order and any number of times. Only their presence is notified.
The short option instructions are made of
the reserved word Option,
a string(*) and a data identifier.
Can be followed by a case statement.
Should be followed by a comment.
The string(*) is the name of the option. The option parameter must start with - followed by the string(*).
Example:
... unixdata t_mydata option "format" format:string option "maxsize" size:integer option "cancache" cancache Comment "If present, enable cache" call fmyfunc:string ...Some valid inputs:
-format abc -cancache -maxsize 12 -format "This is the true format!" -maxsize 3 -cancache
Case statements can be one of:
... Command "open" case insensitive unixdata t_open option "X11" X11 case sensitive option "format" format:string case insensitive call ud_open:integer ...
Back to main page. | Send comments to: Igor Sfiligoi |