CtplEval

CtplEval — Expression evaluation

Synopsis

#include <ctpl/eval.h>

#define             CTPL_EVAL_ERROR
enum                CtplEvalError;
CtplValue *         ctpl_eval_value                     (const CtplTokenExpr *expr,
                                                         const CtplEnviron *env,
                                                         GError **error);
gboolean            ctpl_eval_bool                      (const CtplTokenExpr *expr,
                                                         const CtplEnviron *env,
                                                         GError **error);

Description

Computes a CtplTokenExpr against a CtplEnviron. It is the equivalent of the parser for expressions.

Theses functions computes an expressions and flattens it to a single value: the result. To evaluate an expression, use ctpl_eval_value(). You can evaluate an expression to a boolean with ctpl_eval_bool().

Details

CTPL_EVAL_ERROR

#define CTPL_EVAL_ERROR  (ctpl_eval_error_quark ())

Error domain of CtplEval.


enum CtplEvalError

typedef enum _CtplEvalError
{
  CTPL_EVAL_ERROR_INVALID_VALUE,
  CTPL_EVAL_ERROR_INVALID_OPERAND,
  CTPL_EVAL_ERROR_SYMBOL_NOT_FOUND,
  CTPL_EVAL_ERROR_FAILED
} CtplEvalError;

Error codes that eval functions can throw.

CTPL_EVAL_ERROR_INVALID_VALUE

CTPL_EVAL_ERROR_INVALID_OPERAND

An operand is incompatible with is usage.

CTPL_EVAL_ERROR_SYMBOL_NOT_FOUND

A symbol cannot be found in the environment.

CTPL_EVAL_ERROR_FAILED

An error occurred without any precision on what failed.

ctpl_eval_value ()

CtplValue *         ctpl_eval_value                     (const CtplTokenExpr *expr,
                                                         const CtplEnviron *env,
                                                         GError **error);

Computes the given expression.

expr :

The CtplTokenExpr to evaluate

env :

The expression's environment, where lookup symbols

error :

Return location for errors, or NULL to ignore them

Returns :

The result of the expression evaluation or NULL on error.

ctpl_eval_bool ()

gboolean            ctpl_eval_bool                      (const CtplTokenExpr *expr,
                                                         const CtplEnviron *env,
                                                         GError **error);

Computes the given expression to a boolean. Computing to a boolean means computing the expression's value and then check if this value should be considered as FALSE or TRUE.

As the returned value is not sufficient to know whether the evaluation actually succeeded or not, you should check whether an error was set or not to know it reliably.

expr :

The CtplTokenExpr to evaluate

env :

The expression's environment, where lookup symbols

error :

Return location for errors, or NULL to ignore them

Returns :

The result of the expression evaluation, or FALSE on error.