libxexpr/xexprtypes.h
author ali <ali@juiblex.co.uk>
Wed Oct 10 22:58:21 2012 +0100 (2012-10-10)
changeset 0 bc8c9a11cbfc
permissions -rw-r--r--
Initial version
     1 #ifndef __XEXPER_TYPES_H__
     2 #define __XEXPER_TYPES_H__
     3 
     4 #include <glib.h>
     5 #include <libxml/tree.h>
     6 
     7 G_BEGIN_DECLS
     8 
     9 /**
    10  * XexprInvocation:
    11  * @ns: the namespace to which @function belongs, or %NULL
    12  * @function: the function to be invoked
    13  * @bindings: (element-type XexprBinding): the pre-bound arguments
    14  * @constants: (element-type XexprConstant): the other arguments
    15  *
    16  * A structure describing the invocation of a function.
    17  */
    18 typedef struct xexpr_invocation {
    19     char *ns;
    20     char *function;
    21     GSList *bindings;
    22     GSList *constants;
    23 } XexprInvocation;
    24 
    25 /**
    26  * XexprFunction:
    27  * @args: (element-type utf8): the parameter names
    28  * @constants: (element-type XexprConstant): the constants
    29  *   which will be evaluated when the function is invoked
    30  *
    31  * A structure describing the definition of a function.
    32  */
    33 typedef struct xexpr_function {
    34     GSList *args;
    35     GSList *constants;
    36 } XexprFunction;
    37 
    38 typedef struct xexpr_constant XexprConstant;
    39 
    40 /**
    41  * XexprBinding:
    42  * @id: the bound name
    43  * @value: the expresion bound to @id
    44  *
    45  * A structure describing the binding of a value to a name.
    46  */
    47 typedef struct xexpr_binding {
    48     char *id;
    49     XexprConstant *value;
    50 } XexprBinding;
    51 
    52 /**
    53  * XexprType:
    54  * @XEXPR_TYPE_INVOCATION: a function invocation
    55  * @XEXPR_TYPE_FUNCTION: a function definition
    56  * @XEXPR_TYPE_STRING: a string
    57  * @XEXPR_TYPE_INTEGER: an integer
    58  * @XEXPR_TYPE_NUMBER: a floating-point number
    59  *
    60  * Enum values for the type, to specify the type of expression.
    61  */
    62 typedef enum {
    63     XEXPR_TYPE_INVOCATION=1,
    64     XEXPR_TYPE_FUNCTION,
    65     XEXPR_TYPE_STRING,
    66     XEXPR_TYPE_INTEGER,
    67     XEXPR_TYPE_NUMBER
    68 } XexprType;
    69 
    70 /**
    71  * XexprConstant:
    72  * @type: the type of expression
    73  * @u: type-specific parameters
    74  *
    75  * A structure describing an XEXPR expression
    76  */
    77 struct xexpr_constant {
    78     XexprType type;
    79     union {
    80 	XexprInvocation *invocation;
    81 	XexprFunction *function;
    82 	char *string;
    83 	long long int integer;
    84 	double number;
    85     } u;
    86 };
    87 
    88 /**
    89  * XexprEnvironment:
    90  * @function: the name of the function to which the environment belongs,
    91  *   or %NULL if this is the outermost environment
    92  * @outer: the next environment in the chain from innermost to outermost,
    93  *   or %NULL if this is the outermost environment
    94  * @bindings: (element-type XexprBinding): the variables set in this environment
    95  *
    96  * A structure describing an XEXPR environment
    97  */
    98 typedef struct xexpr_environment {
    99     /*< private >*/
   100     int refcount;
   101     /*< public >*/
   102     char *function;
   103     struct xexpr_environment *outer;
   104     GSList *bindings;
   105 } XexprEnvironment;
   106 
   107 /**
   108  * Xexpr:
   109  * @constants: (element-type XexprConstant): the constants that make up this
   110  *   expression
   111  * @environment: the innermost environment
   112  *
   113  * A structure describing an XEXPR expression
   114  */
   115 typedef struct xexpr {
   116     /*< private >*/
   117     GSList *tracing;
   118     /*< public >*/
   119     GSList *constants;
   120     XexprEnvironment *environment;
   121 } Xexpr;
   122 
   123 /**
   124  * XexprExtension:
   125  * @ns: the namespace of the extension
   126  * @function_evaluate: evaluates functions defined in the extension
   127  *
   128  * A structure describing an XEXPR extension
   129  */
   130 typedef struct xexpr_extension {
   131     char *ns;
   132     XexprConstant *(*function_evaluate)(Xexpr *xexpr,const char *ns,
   133       const char *id,GSList *bindings,GSList *args,GError **err);
   134 } XexprExtension;
   135 
   136 XexprConstant *xexpr_new_string(const char *s,gssize len);
   137 XexprConstant *xexpr_new_string_take_ownership(char *s);
   138 XexprConstant *xexpr_new_integer(long long int integer);
   139 XexprConstant *xexpr_new_number(double number);
   140 XexprConstant *xexpr_new_invocation(const char *ns,const char *function,
   141   GSList *bindings,GSList *constants);
   142 XexprConstant *xexpr_new_invocation_take_ownership(char *ns,char *function,
   143   GSList *bindings,GSList *constants);
   144 XexprConstant *xexpr_new_function_take_ownership(GSList *args,
   145   GSList *constants);
   146 XexprConstant *xexpr_new_function(GSList *args,GSList *constants);
   147 XexprConstant *xexpr_constant_dup(XexprConstant *constant);
   148 void xexpr_constant_free(XexprConstant *constant);
   149 
   150 void xexpr_binding_free(XexprBinding *binding);
   151 
   152 XexprConstant *xexpr_bindings_get(GSList *bindings,const char *id);
   153 gboolean xexpr_bindings_set(GSList *bindings,const char *id,
   154   XexprConstant *value);
   155 GSList *xexpr_bindings_new(GSList *bindings,const char *id,
   156   XexprConstant *value);
   157 GSList *xexpr_bindings_dup(GSList *bindings);
   158 
   159 Xexpr *xexpr_new(void);
   160 Xexpr *xexpr_sub(Xexpr *xexpr);
   161 void xexpr_var_new(Xexpr *xexpr,const char *id,XexprConstant *value);
   162 void xexpr_var_set(Xexpr *xexpr,const char *id,XexprConstant *value);
   163 XexprConstant *xexpr_var_get(Xexpr *xexpr,const char *id);
   164 void xexpr_start_tracing(Xexpr *xexpr,const char *id);
   165 gboolean xexpr_is_tracing(Xexpr *xexpr,const char *id);
   166 void xexpr_free(Xexpr *xexpr);
   167 XexprEnvironment *xexpr_get_environment(Xexpr *xexpr);
   168 void xexpr_set_constants(Xexpr *xexpr,GSList *constants);
   169 void xexpr_set_constants_take_ownership(Xexpr *xexpr,GSList *constants);
   170 
   171 void xexpr_environment_foreach(XexprEnvironment *environment,GTraverseFunc func,
   172   gpointer user_data);
   173 
   174 G_END_DECLS
   175 
   176 #endif	/* __XEXPER_TYPES_H__ */