Top |
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.
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()
.
stream |
A CtplInputStream from where read the expression |
|
error |
Return location for errors, or |
CtplTokenExpr * ctpl_lexer_expr_lex_full (CtplInputStream *stream
,gboolean lex_all
,GError **error
);
Tries to lex the expression in stream
.
stream |
||
lex_all |
Whether to lex |
|
error |
Return location for errors, or |
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()
.
expr |
An expression |
|
len |
Length of |
|
error |
Return location for errors, or |
Error codes that lexing functions can throw, from the CTPL_LEXER_EXPR_ERROR
domain.