2 * generic s-exp evaluator class
5 #if !defined (__LIBEDATASERVER_H_INSIDE__) && !defined (LIBEDATASERVER_COMPILATION)
6 #error "Only <libedataserver/libedataserver.h> should be included directly."
16 /* Don't define E_SEXP_IS_G_OBJECT as this object is now used by camel */
18 #ifdef E_SEXP_IS_G_OBJECT
19 #include <glib-object.h>
22 #ifdef E_SEXP_IS_G_OBJECT
23 #define E_TYPE_SEXP (e_sexp_get_type ())
24 #define E_SEXP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), E_TYPE_SEXP, ESExp))
25 #define E_SEXP_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST ((cls), E_TYPE_SEXP, ESExpClass))
26 #define IS_E_SEXP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), E_TYPE_SEXP))
27 #define IS_E_SEXP_CLASS(cls) (G_TYPE_CHECK_CLASS_TYPE ((cls), E_TYPE_SEXP))
28 #define E_SEXP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), E_TYPE_SEXP, ESExpClass))
30 #define E_TYPE_SEXP (0)
31 #define E_SEXP(obj) ((struct _ESExp *) (obj))
32 #define E_SEXP_CLASS(cls) ((struct _ESExpClass *) (cls))
33 #define IS_E_SEXP(obj) (1)
34 #define IS_E_SEXP_CLASS(obj) (1)
35 #define E_SEXP_GET_CLASS(obj) (NULL)
40 typedef struct _ESExp ESExp;
41 typedef struct _ESExpClass ESExpClass;
43 typedef struct _ESExpSymbol ESExpSymbol;
44 typedef struct _ESExpResult ESExpResult;
45 typedef struct _ESExpTerm ESExpTerm;
48 ESEXP_RES_ARRAY_PTR=0, /* type is a ptrarray, what it points to is implementation dependant */
49 ESEXP_RES_INT, /* type is a number */
50 ESEXP_RES_STRING, /* type is a pointer to a single string */
51 ESEXP_RES_BOOL, /* boolean type */
52 ESEXP_RES_TIME, /* time_t type */
53 ESEXP_RES_UNDEFINED /* unknown type */
65 gboolean time_generator;
66 time_t occuring_start;
70 typedef struct _ESExpResult *(ESExpFunc)(struct _ESExp *sexp, gint argc,
71 struct _ESExpResult **argv,
74 typedef struct _ESExpResult *(ESExpIFunc)(struct _ESExp *sexp, gint argc,
75 struct _ESExpTerm **argv,
79 ESEXP_TERM_INT = 0, /* integer literal */
80 ESEXP_TERM_BOOL, /* boolean literal */
81 ESEXP_TERM_STRING, /* string literal */
82 ESEXP_TERM_TIME, /* time_t literal (number of seconds past the epoch) */
83 ESEXP_TERM_FUNC, /* normal function, arguments are evaluated before calling */
84 ESEXP_TERM_IFUNC, /* immediate function, raw terms are arguments */
85 ESEXP_TERM_VAR /* variable reference */
89 gint type; /* ESEXP_TERM_FUNC or ESEXP_TERM_VAR */
106 struct _ESExpSymbol *sym;
107 struct _ESExpTerm **terms;
110 struct _ESExpSymbol *var;
115 #ifdef E_SEXP_IS_G_OBJECT
116 GObject parent_object;
120 GScanner *scanner; /* for parsing text version */
121 ESExpTerm *tree; /* root of expression tree */
128 /* TODO: may also need a pool allocator for term strings, so we dont lose them
129 * in error conditions? */
130 struct _EMemChunk *term_chunks;
131 struct _EMemChunk *result_chunks;
135 #ifdef E_SEXP_IS_G_OBJECT
136 GObjectClass parent_class;
142 #ifdef E_SEXP_IS_G_OBJECT
143 GType e_sexp_get_type (void);
145 ESExp *e_sexp_new (void);
146 #ifdef E_SEXP_IS_G_OBJECT
147 #define e_sexp_ref(f) g_object_ref (f)
148 #define e_sexp_unref(f) g_object_unref (f)
150 void e_sexp_ref (ESExp *f);
151 void e_sexp_unref (ESExp *f);
153 void e_sexp_add_function (ESExp *f, gint scope, const gchar *name, ESExpFunc *func, gpointer data);
154 void e_sexp_add_ifunction (ESExp *f, gint scope, const gchar *name, ESExpIFunc *func, gpointer data);
155 void e_sexp_add_variable (ESExp *f, gint scope, gchar *name, ESExpTerm *value);
156 void e_sexp_remove_symbol (ESExp *f, gint scope, const gchar *name);
157 gint e_sexp_set_scope (ESExp *f, gint scope);
159 void e_sexp_input_text (ESExp *f, const gchar *text, gint len);
160 void e_sexp_input_file (ESExp *f, gint fd);
162 gint e_sexp_parse (ESExp *f);
163 ESExpResult *e_sexp_eval (ESExp *f);
165 ESExpResult *e_sexp_term_eval (struct _ESExp *f, struct _ESExpTerm *t);
166 ESExpResult *e_sexp_result_new (struct _ESExp *f, gint type);
167 void e_sexp_result_free (struct _ESExp *f, struct _ESExpResult *t);
169 /* used in normal functions if they have to abort, to free their arguments */
170 void e_sexp_resultv_free (struct _ESExp *f, gint argc, struct _ESExpResult **argv);
172 /* utility functions for creating s-exp strings. */
173 void e_sexp_encode_bool (GString *s, gboolean state);
174 void e_sexp_encode_string (GString *s, const gchar *string);
176 /* only to be called from inside a callback to signal a fatal execution error */
177 void e_sexp_fatal_error (struct _ESExp *f, const gchar *why, ...) G_GNUC_NORETURN;
179 /* return the error string */
180 const gchar *e_sexp_error (struct _ESExp *f);
182 ESExpTerm * e_sexp_parse_value (ESExp *f);
184 gboolean e_sexp_evaluate_occur_times (ESExp *f, time_t *start, time_t *end);
187 #endif /* _E_SEXP_H */