## ESExp ESExp |

## Synopsis

    enum                ESExpResultType;
    struct              ESExpResult;
    enum                ESExpTermType;
    struct              ESExpSymbol;
    struct              ESExpTerm;
    struct              ESExp;
    struct              ESExpClass;
    ESExp *             e_sexp_new                          (void);
    #define             e_sexp_ref                          (f)
    #define             e_sexp_unref                        (f)
    void                e_sexp_add_function                 (ESExp *f,
                                                             gint scope,
                                                             const gchar *name,
                                                             ESExpFunc *func,
                                                             gpointer data);
    void                e_sexp_add_ifunction                (ESExp *f,
                                                             gint scope,
                                                             const gchar *name,
                                                             ESExpIFunc *func,
                                                             gpointer data);
    void                e_sexp_add_variable                 (ESExp *f,
                                                             gint scope,
                                                             gchar *name,
                                                             ESExpTerm *value);
    void                e_sexp_remove_symbol                (ESExp *f,
                                                             gint scope,
                                                             const gchar *name);
    gint                e_sexp_set_scope                    (ESExp *f,
                                                             gint scope);
    void                e_sexp_input_text                   (ESExp *f,
                                                             const gchar *text,
                                                             gint len);
    void                e_sexp_input_file                   (ESExp *f,
                                                             gint fd);
    gint                e_sexp_parse                        (ESExp *f);
    ESExpResult *       e_sexp_eval                         (ESExp *f);
    ESExpResult *       e_sexp_term_eval                    (struct _ESExp *f,
                                                             struct _ESExpTerm *t);
    ESExpResult *       e_sexp_result_new                   (struct _ESExp *f,
                                                             gint type);
    void                e_sexp_result_free                  (struct _ESExp *f,
                                                             struct _ESExpResult *t);
    void                e_sexp_resultv_free                 (struct _ESExp *f,
                                                             gint argc,
                                                             struct _ESExpResult **argv);
    void                e_sexp_encode_bool                  (GString *s,
                                                             gboolean state);
    void                e_sexp_encode_string                (GString *s,
                                                             const gchar *string);
    void                e_sexp_fatal_error                  (struct _ESExp *f,
                                                             const gchar *why,
                                                             ...);
    const gchar *       e_sexp_error                        (struct _ESExp *f);
    ESExpTerm *         e_sexp_parse_value                  (ESExp *f);
    gboolean            e_sexp_evaluate_occur_times         (ESExp *f,
                                                             time_t *start,
                                                             time_t *end);

## Description

## Details

### enum ESExpResultType

    typedef enum {
    	ESEXP_RES_ARRAY_PTR=0, /* type is a ptrarray, what it points to is implementation dependant */
    	ESEXP_RES_INT,		/* type is a number */
    	ESEXP_RES_STRING, /* type is a pointer to a single string */
    	ESEXP_RES_BOOL,		/* boolean type */
    	ESEXP_RES_TIME,		/* time_t type */
    	ESEXP_RES_UNDEFINED /* unknown type */
    } ESExpResultType;

`ESEXP_RES_ARRAY_PTR` |
`ESEXP_RES_INT` |
`ESEXP_RES_STRING` |
`ESEXP_RES_BOOL` |
`ESEXP_RES_TIME` |
`ESEXP_RES_UNDEFINED` |

### struct ESExpResult

    struct ESExpResult {
    	ESExpResultType type;
    	union {
    		GPtrArray *ptrarray;
    		gint number;
    		gchar *string;
    		gint boolean;
    		time_t time;
    	} value;
    	gboolean time_generator;
    	time_t occuring_start;
    	time_t occuring_end;
    };

### enum ESExpTermType

    typedef enum {
    	ESEXP_TERM_INT = 0, /* integer literal */
    	ESEXP_TERM_BOOL, /* boolean literal */
    	ESEXP_TERM_STRING, /* string literal */
    	ESEXP_TERM_TIME, /* time_t literal (number of seconds past the epoch) */
    	ESEXP_TERM_FUNC, /* normal function, arguments are evaluated before calling */
    	ESEXP_TERM_IFUNC, /* immediate function, raw terms are arguments */
    	ESEXP_TERM_VAR		/* variable reference */
    } ESExpTermType;

`ESEXP_TERM_INT` |
`ESEXP_TERM_BOOL` |
`ESEXP_TERM_STRING` |
`ESEXP_TERM_TIME` |
`ESEXP_TERM_FUNC` |
`ESEXP_TERM_IFUNC` |
`ESEXP_TERM_VAR` |

### struct ESExpSymbol

    struct ESExpSymbol {
    	gint type;		/* ESEXP_TERM_FUNC or ESEXP_TERM_VAR */
    	gchar *name;
    	gpointer data;
    	union {
    		ESExpFunc *func;
    		ESExpIFunc *ifunc;
    	} f;
    };

### struct ESExpTerm

    struct ESExpTerm {
    	ESExpTermType type;
    	union {
    		gchar *string;
    		gint number;
    		gint boolean;
    		time_t time;
    		struct {
    			struct _ESExpSymbol *sym;
    			struct _ESExpTerm **terms;
    			gint termcount;
    		} func;
    		struct _ESExpSymbol *var;
    	} value;
    };

### struct ESExp

    struct ESExp {
    #ifdef E_SEXP_IS_G_OBJECT
    	GObject parent_object;
    #else
    	gint refcount;
    #endif
    	GScanner *scanner; /* for parsing text version */
    	ESExpTerm *tree; /* root of expression tree */

    	/* private stuff */
    	jmp_buf failenv;
    	gchar *error;
    	GSList *operators;

    	/* TODO: may also need a pool allocator for term strings, so we dont lose them
    	 * in error conditions? */
    	struct _EMemChunk *term_chunks;
    	struct _EMemChunk *result_chunks;
    };

### struct ESExpClass

    struct ESExpClass {
    #ifdef E_SEXP_IS_G_OBJECT
    	GObjectClass parent_class;
    #else
    	gint dummy;
    #endif
    };

### e_sexp_new ()

    ESExp *             e_sexp_new                          (void);

### e_sexp_ref()

    #define         e_sexp_ref(f)           g_object_ref (f)

### e_sexp_unref()

    #define         e_sexp_unref(f)         g_object_unref (f)

### e_sexp_add_function ()

    void                e_sexp_add_function                 (ESExp *f,
                                                             gint scope,
                                                             const gchar *name,
                                                             ESExpFunc *func,
                                                             gpointer data);

### e_sexp_add_ifunction ()

    void                e_sexp_add_ifunction                (ESExp *f,
                                                             gint scope,
                                                             const gchar *name,
                                                             ESExpIFunc *func,
                                                             gpointer data);

### e_sexp_add_variable ()

    void                e_sexp_add_variable                 (ESExp *f,
                                                             gint scope,
                                                             gchar *name,
                                                             ESExpTerm *value);

### e_sexp_remove_symbol ()

    void                e_sexp_remove_symbol                (ESExp *f,
                                                             gint scope,
                                                             const gchar *name);

### e_sexp_set_scope ()

    gint                e_sexp_set_scope                    (ESExp *f,
                                                             gint scope);

### e_sexp_input_text ()

    void                e_sexp_input_text                   (ESExp *f,
                                                             const gchar *text,
                                                             gint len);

### e_sexp_input_file ()

    void                e_sexp_input_file                   (ESExp *f,
                                                             gint fd);

### e_sexp_parse ()

    gint                e_sexp_parse                        (ESExp *f);

### e_sexp_eval ()

    ESExpResult *       e_sexp_eval                         (ESExp *f);

### e_sexp_term_eval ()

    ESExpResult *       e_sexp_term_eval                    (struct _ESExp *f,
                                                             struct _ESExpTerm *t);

### e_sexp_result_new ()

    ESExpResult *       e_sexp_result_new                   (struct _ESExp *f,
                                                             gint type);

### e_sexp_result_free ()

    void                e_sexp_result_free                  (struct _ESExp *f,
                                                             struct _ESExpResult *t);

### e_sexp_resultv_free ()

    void                e_sexp_resultv_free                 (struct _ESExp *f,
                                                             gint argc,
                                                             struct _ESExpResult **argv);

### e_sexp_encode_bool ()

    void                e_sexp_encode_bool                  (GString *s,
                                                             gboolean state);

Encode a bool into an s-expression `s`. Bools are encoded using #t #f syntax.

`s` : | A GString to append to
`state` : | The boolean value

### e_sexp_encode_string ()

    void                e_sexp_encode_string                (GString *s,
                                                             const gchar *string);

Add a c string `string` to the s-expression stored in the gstring `s`. Quotes are added, and special characters are escaped appropriately.

`s` : | Destination string.
`string` : | String expression.

### e_sexp_fatal_error ()

    void                e_sexp_fatal_error                  (struct _ESExp *f,
                                                             const gchar *why,
                                                             ...);

### e_sexp_error ()

    const gchar *       e_sexp_error                        (struct _ESExp *f);

### e_sexp_parse_value ()

    ESExpTerm *         e_sexp_parse_value                  (ESExp *f);

Since 2.28

### e_sexp_evaluate_occur_times ()

    gboolean            e_sexp_evaluate_occur_times         (ESExp *f,
                                                             time_t *start,
                                                             time_t *end);