![]() |
![]() |
![]() |
CTPL Reference Manual | ![]() |
---|---|---|---|---|
Top | Description |
#include <ctpl/ctpl.h> #define CTPL_LEXER_EXPR_ERROR enum CtplLexerExprError; CtplTokenExpr * ctpl_lexer_expr_lex (CtplInputStream *stream
,GError **error
); CtplTokenExpr * ctpl_lexer_expr_lex_full (CtplInputStream *stream
,gboolean lex_all
,GError **error
); CtplTokenExpr * ctpl_lexer_expr_lex_string (const gchar *expr
,gssize len
,GError **error
);
Syntax analyser for mathematical or test expressions creating a token tree from an expression.
To analyse an expression, use ctpl_lexer_expr_lex()
. The resulting expression
should be freed with ctpl_token_expr_free()
when no longer needed.
An expression is something like a mathematical expression that can include references to variables. The allowed things are:
Binary operators |
addition ( The boolean operators results to the integer 0 if their expression evaluates to false, or to the positive integer 1 if their expression evaluates to true. This result might be used as a plain integer. The operators' priority is very common: boolean operators have the higher priority, followed by division, modulo and multiplication, and finally addition and subtraction which have the lower priority. When two operators have the same priority, the left one is prior over the right one. |
Unary operators |
The unary operators plus ( |
Operands |
Any numeric constant that |
Parentheses |
Parentheses may be placed to delimit sub-expressions, allowing a fine control over operator priority. |
Of course, the latter examples supposes that the environment contains the
variables foo
, bar
, array
and idx
, and that they contains appropriate
values for latter evaluation.
#define CTPL_LEXER_EXPR_ERROR (ctpl_lexer_expr_error_quark ())
Error domain of CtplLexerExprError.
typedef enum _CtplLexerExprError { CTPL_LEXER_EXPR_ERROR_MISSING_OPERAND, CTPL_LEXER_EXPR_ERROR_MISSING_OPERATOR, CTPL_LEXER_EXPR_ERROR_SYNTAX_ERROR, CTPL_LEXER_EXPR_ERROR_FAILED } CtplLexerExprError;
Error codes that lexing functions can throw, from the CTPL_LEXER_EXPR_ERROR
domain.
CtplTokenExpr * ctpl_lexer_expr_lex (CtplInputStream *stream
,GError **error
);
Tries to lex the expression in stream
.
If you want to lex a CtplInputStream that (may) hold other data after the
expression, see ctpl_lexer_expr_lex_full()
.
|
A CtplInputStream from where read the expression |
|
Return location for errors, or NULL to ignore them.
|
Returns : |
A new CtplTokenExpr or NULL on error.
|
CtplTokenExpr * ctpl_lexer_expr_lex_full (CtplInputStream *stream
,gboolean lex_all
,GError **error
);
Tries to lex the expression in stream
.
|
A CtplInputStream |
|
Whether to lex stream until EOF or until the end of a valid
expression. This is useful for expressions inside other data.
|
|
Return location for errors, or NULL to ignore them.
|
Returns : |
A new CtplTokenExpr or NULL on error.
|
CtplTokenExpr * ctpl_lexer_expr_lex_string (const gchar *expr
,gssize len
,GError **error
);
Tries to lex the expression in expr
.
See ctpl_lexer_expr_lex()
.
|
An expression |
|
Length of expr or -1 to read the whole string
|
|
Return location for errors, or NULL to ignore them
|
Returns : |
A new CtplTokenExpr or NULL on error.
|