![]() |
![]() |
![]() |
CTPL Reference Manual | ![]() |
---|---|---|---|---|
Top | Description |
#include <ctpl/token.h> enum CtplOperator; enum CtplTokenType; union CtplTokenValue; struct CtplToken; struct CtplTokenFor; struct CtplTokenIf; enum CtplTokenExprType; union CtplTokenExprValue; struct CtplTokenExpr; struct CtplTokenExprOperator; CtplToken * ctpl_token_new_data (const gchar *data
,gssize len
); CtplToken * ctpl_token_new_expr (CtplTokenExpr *expr
); CtplToken * ctpl_token_new_for (const gchar *array
,const gchar *iterator
,CtplToken *children
); CtplToken * ctpl_token_new_if (CtplTokenExpr *condition
,CtplToken *if_children
,CtplToken *else_children
); void ctpl_token_free (CtplToken *token
,gboolean chain
); void ctpl_token_append (CtplToken *token
,CtplToken *brother
); void ctpl_token_prepend (CtplToken *token
,CtplToken *brother
); #define ctpl_token_get_type (token) void ctpl_token_dump (const CtplToken *token
,gboolean chain
); CtplTokenExpr * ctpl_token_expr_new_operator (CtplOperator operator
,CtplTokenExpr *loperand
,CtplTokenExpr *roperand
); CtplTokenExpr * ctpl_token_expr_new_integer (glong integer
); CtplTokenExpr * ctpl_token_expr_new_float (gdouble real
); CtplTokenExpr * ctpl_token_expr_new_symbol (const gchar *symbol
,gssize len
); void ctpl_token_expr_free (CtplTokenExpr *token
,gboolean recurse
); void ctpl_token_expr_dump (const CtplTokenExpr *token
);
Represents a CTPL language token.
A CtplToken is created with ctpl_token_new_data()
, ctpl_token_new_expr()
,
ctpl_token_new_for()
or ctpl_token_new_if()
, and freed with
ctpl_token_free()
.
You can append or prepend tokens to others with ctpl_token_append()
and
ctpl_token_prepend()
.
To dump a CtplToken, use ctpl_token_dump()
.
A CtplTokenExpr is created with ctpl_token_expr_new_operator()
,
ctpl_token_expr_new_integer()
, ctpl_token_expr_new_float()
or
ctpl_token_expr_new_symbol()
, and freed with ctpl_token_expr_free()
.
To dump a CtplTokenExpr, use ctpl_token_expr_dump()
.
typedef enum { CTPL_OPERATOR_PLUS, CTPL_OPERATOR_MINUS, CTPL_OPERATOR_DIV, CTPL_OPERATOR_MUL, CTPL_OPERATOR_EQUAL, CTPL_OPERATOR_INF, CTPL_OPERATOR_SUP, CTPL_OPERATOR_MODULO, CTPL_OPERATOR_SUPEQ, CTPL_OPERATOR_INFEQ, CTPL_OPERATOR_NEQ, CTPL_OPERATOR_AND, CTPL_OPERATOR_OR, /* must be last */ CTPL_OPERATOR_NONE } CtplOperator;
Operators constants.
See also ctpl_operator_to_string()
and ctpl_operator_from_string()
.
Addition operator | |
Subtraction operator | |
Division operator | |
Multiplication operator | |
Equality test operator | |
Inferiority test operator | |
Superiority test operator | |
Modulo operator | |
CTPL_OPERATOR_SUP || CTPL_OPERATOR_EQUAL
|
|
CTPL_OPERATOR_INF || CTPL_OPERATOR_EQUAL
|
|
Non-equality test operator (! CTPL_OPERATOR_EQUAL )
|
|
Boolean AND operator | |
Boolean OR operator | |
Not an operator, denoting no operator |
typedef enum _CtplTokenType { CTPL_TOKEN_TYPE_DATA, CTPL_TOKEN_TYPE_FOR, CTPL_TOKEN_TYPE_IF, CTPL_TOKEN_TYPE_EXPR } CtplTokenType;
Possible types of a token.
union _CtplTokenValue { gchar *t_data; CtplTokenExpr *t_expr; CtplTokenFor *t_for; CtplTokenIf *t_if; };
Represents the possible values of a token (see CtplToken).
gchar * |
The data of a data token |
CtplTokenExpr * |
The value of an expression token |
CtplTokenFor * |
The value of a for token |
CtplTokenIf * |
The value of an if token |
struct CtplToken { CtplTokenType type; CtplTokenValue token; CtplToken *next; CtplToken *last; };
The CtplToken structure. The fields in this structure should be considered private and are documented only for internal usage.
CtplTokenType |
Type of the token |
CtplTokenValue |
Union holding the corresponding token (according to type ) |
CtplToken * |
Next token |
CtplToken * |
Last token |
struct CtplTokenFor { gchar *array; gchar *iter; CtplToken *children; };
Holds information about a for
statement.
struct CtplTokenIf { CtplTokenExpr *condition; CtplToken *if_children; CtplToken *else_children; };
Holds information about an if
statement.
CtplTokenExpr * |
The condition string |
CtplToken * |
Branching if condition evaluate to true |
CtplToken * |
Branching if condition evaluate to false |
typedef enum _CtplTokenExprType { CTPL_TOKEN_EXPR_TYPE_OPERATOR, CTPL_TOKEN_EXPR_TYPE_INTEGER, CTPL_TOKEN_EXPR_TYPE_FLOAT, CTPL_TOKEN_EXPR_TYPE_SYMBOL } CtplTokenExprType;
Possibles types of an expression token.
An operator
(CTPL_OPERATOR_* )
|
|
An integer | |
A floating-point value | |
A symbol (a name to be found in the environ) |
union _CtplTokenExprValue { CtplTokenExprOperator *t_operator; glong t_integer; gdouble t_float; gchar *t_symbol; };
Represents the possible values of an expression token (see CtplTokenExpr).
CtplTokenExprOperator * |
The value of an operator token |
glong |
The value of an integer token |
gdouble |
The value of a floating-point token |
gchar * |
The name of a symbol token |
struct CtplTokenExpr { CtplTokenExprType type; CtplTokenExprValue token; };
Represents an expression token. The fields in this structure should be considered private and are documented only for internal usage.
CtplTokenExprType |
The type of the expression token |
CtplTokenExprValue |
The value of the token |
struct CtplTokenExprOperator { CtplOperator operator; CtplTokenExpr *loperand; CtplTokenExpr *roperand; };
Represents a operator token in an expression.
CtplOperator |
The operator |
CtplTokenExpr * |
The left operand |
CtplTokenExpr * |
The right operand |
CtplToken * ctpl_token_new_data (const gchar *data
,gssize len
);
Creates a new token holding raw data.
|
Buffer containing token value (raw data) |
|
length of the data or -1 if 0-terminated |
Returns : |
A new CtplToken that should be freed with ctpl_token_free() when no
longer needed. |
CtplToken * ctpl_token_new_expr (CtplTokenExpr *expr
);
Creates a new token holding an expression. Such tokens are used to represent any expression that will be simply replaced, including simple reference to variables or constants, as of complex expressions with or without variable or expression references.
|
The expression |
Returns : |
A new CtplToken that should be freed with ctpl_token_free() when no
longer needed. |
CtplToken * ctpl_token_new_for (const gchar *array
,const gchar *iterator
,CtplToken *children
);
Creates a new token holding a for statement.
|
String containing the name of the array to iterate over |
|
String containing the name of the array iterator |
|
Sub-tree that should be computed on each loop iteration |
Returns : |
A new CtplToken that should be freed with ctpl_token_free() when no
longer needed. |
CtplToken * ctpl_token_new_if (CtplTokenExpr *condition
,CtplToken *if_children
,CtplToken *else_children
);
Creates a new token holding an if statement.
|
The expression condition |
|
Branching if condition evaluate to true |
|
Branching if condition evaluate to false, or NULL
|
Returns : |
A new CtplToken that should be freed with ctpl_token_free() when no
longer needed. |
void ctpl_token_free (CtplToken *token
,gboolean chain
);
Frees all memory used by a CtplToken.
If chain
is TRUE
, all tokens attached at the right of token
(appended
ones) will be freed too. Then, if this function is called with chain
set to
TRUE
on the root token of a tree, all the tree will be freed.
Otherwise, if chain
is FALSE
, token
is freed and detached from its
neighbours.
|
A CtplToken to free |
|
Whether all next tokens should be freed too or not. |
void ctpl_token_append (CtplToken *token
,CtplToken *brother
);
Appends (link at the end) brother
to token
.
void ctpl_token_prepend (CtplToken *token
,CtplToken *brother
);
Prepends (link at the start) btother
to token
.
#define ctpl_token_get_type(token) ((token)->type)
Gets the type of a CtplToken.
void ctpl_token_dump (const CtplToken *token
,gboolean chain
);
Dumps a token with g_print()
.
If chain
is TRUE
, all next tokens will be dumped too.
|
A CtplToken |
|
Whether to dump all next tokens |
CtplTokenExpr * ctpl_token_expr_new_operator (CtplOperator operator
,CtplTokenExpr *loperand
,CtplTokenExpr *roperand
);
Creates a new CtplTokenExpr holding an operator.
|
A binary operator (one of the
CTPL_OPERATOR_* ) |
|
The left operand of the operator |
|
The right operand of the operator |
Returns : |
A new CtplTokenExpr that should be freed with
ctpl_token_expr_free() when no longer needed. |
CtplTokenExpr * ctpl_token_expr_new_integer (glong integer
);
Creates a new CtplTokenExpr holding an integer.
|
The value of the integer token |
Returns : |
A new CtplTokenExpr that should be freed with
ctpl_token_expr_free() when no longer needed. |
CtplTokenExpr * ctpl_token_expr_new_float (gdouble real
);
Creates a new CtplTokenExpr holding a floating-point value.
|
The value of the floating-point token |
Returns : |
A new CtplTokenExpr that should be freed with
ctpl_token_expr_free() when no longer needed. |
CtplTokenExpr * ctpl_token_expr_new_symbol (const gchar *symbol
,gssize len
);
Creates a new CtplTokenExpr holding a symbol.
|
String holding the symbol name |
|
Length to read from symbol or -1 to read the whole string. |
Returns : |
A new CtplTokenExpr that should be freed with
ctpl_token_expr_free() when no longer needed. |
void ctpl_token_expr_free (CtplTokenExpr *token
,gboolean recurse
);
Frees all memory used by a CtplTokenExpr.
|
A CtplTokenExpr to free |
|
Whether to free sub-tokens too. |
void ctpl_token_expr_dump (const CtplTokenExpr *token
);
Dumps the given CtplTokenExpr using g_print()
.
|
A CtplTokenExpr |