xexpreval

xexpreval — An evaluator for the XEXPR language

Stability Level

Stable, unless otherwise indicated

Synopsis


#include <libxexpr/xexpr.h>

#define             XEXPR_EVAL_ERROR
enum                XexprEvalError;
GQuark              xexpr_eval_error_quark              (void);
gboolean            xexpr_register_extension            (XexprExtension *extension);
XexprConstant *     xexpr_constant_evaluate             (Xexpr *xexpr,
                                                         XexprConstant *constant,
                                                         GError **err);
Xexpr *             xexpr_evaluate                      (Xexpr *xexpr,
                                                         GError **err);
gboolean            xexpr_constant_cast                 (XexprConstant *constant,
                                                         XexprType to);
gboolean            xexpr_test                          (Xexpr *xexpr,
                                                         GError **err);

Description

An evaluator for the XEXPR language.

Details

XEXPR_EVAL_ERROR

#define XEXPR_EVAL_ERROR		xexpr_eval_error_quark()

Used to get the GError quark for libxexpr evaluator errors.


enum XexprEvalError

typedef enum
{
    XEXPR_EVAL_ERROR_FAILED
} XexprEvalError;

Enum values for evaluator errors.

XEXPR_EVAL_ERROR_FAILED

Indicates a generic failure.

xexpr_eval_error_quark ()

GQuark              xexpr_eval_error_quark              (void);

Registers an error quark for the libxexpr evaluator if necessary.

Returns :

The error quark used for libxexpr evaluator errors.

xexpr_register_extension ()

gboolean            xexpr_register_extension            (XexprExtension *extension);

Registers an extension to handle the evaluation of functions and retrieval of variables in a new namespace.

extension :

an XexprExtension. transfer none.

Returns :

TRUE if the extension was successfully registered

xexpr_constant_evaluate ()

XexprConstant *     xexpr_constant_evaluate             (Xexpr *xexpr,
                                                         XexprConstant *constant,
                                                         GError **err);

Evaluate an XEXPR expression. Typically, an expression will evaluate to one of the basic types: string, integer or float. However, the XEXPR language specification states that <define> returns a function object (ie., an XexprConstant with type XEXPR_TYPE_FUNCTION). If such a function object is passed to xexpr_constant_evaluate(), then the function definition will be evaluated. If the function takes arguments, then these will be taken as <nil>.

The returned expresion should be freed with xexpr_constant_free() when no longer needed.

xexpr :

an Xexpr

constant :

the XexprConstant to evaluate

err :

location to store error, or NULL. allow-none.

Returns :

The evaluated result, or NULL on error. transfer full.

xexpr_evaluate ()

Xexpr *             xexpr_evaluate                      (Xexpr *xexpr,
                                                         GError **err);

Evaluate an XEXPR expression. Typically, an expression will evaluate to one of the basic types: string, integer or float. However, the XEXPR language specification states that <define> returns a function object (ie., an XexprConstant with type XEXPR_TYPE_FUNCTION). If such a function object is passed to xexpr_evaluate(), then the function definition will be evaluated. If the function takes arguments, then these will be taken as <nil>.

The returned expresion should be freed with xexpr_free() when no longer needed.

xexpr :

an Xexpr to evaluate

err :

location to store error, or NULL. allow-none.

Returns :

The evaluated result, or NULL on error. transfer full.

xexpr_constant_cast ()

gboolean            xexpr_constant_cast                 (XexprConstant *constant,
                                                         XexprType to);

Attempt to perform an implicit cast of constant to the given type to. Implicit casting can only be performed between the two numeric types and then only where the quantity can be represented without loss of precision.

constant :

an XexprConstant to cast

to :

type to cast constant to

Returns :

TRUE if constant is now of type to.

xexpr_test ()

gboolean            xexpr_test                          (Xexpr *xexpr,
                                                         GError **err);

Test an expression by looking at the last constant in the expression. Numerical constants are treated as <true> if they are non-zero, string constants are treated as <true> if they are non-empty, function invocations are treated as <true> unless they are <false> or <nil>, function definitions are recursively evaluated before they are tested.

xexpr :

an Xexpr to test

err :

location to store error, or NULL. allow-none.

Returns :

TRUE if the expression is equivalent to <true>.