12 #include <boost/variant.hpp>
13 #define BOOST_FILESYSTEM_DYN_LINK
14 #include <boost/filesystem.hpp>
15 #include <boost/shared_ptr.hpp>
27 glps_expr_invalid = -1
29 const char *glps_expr_type_name(glps_expr_type);
31 typedef struct parse_context parse_context;
38 typedef struct string_t string_t;
40 typedef struct expr_t expr_t;
42 typedef struct vector_t vector_t;
43 typedef struct kvlist_t kvlist_t;
44 typedef struct strlist_t strlist_t;
51 string_t* glps_string_alloc(
const char *,
size_t);
53 void glps_string_cleanup(string_t*);
54 void glps_expr_cleanup(expr_t*);
55 void glps_vector_cleanup(vector_t*);
56 void glps_kvlist_cleanup(kvlist_t*);
57 void glps_strlist_cleanup(strlist_t*);
59 void glps_expr_debug(FILE *,
const expr_t *);
60 void glps_string_debug(FILE *,
const string_t *);
62 void glps_error(
void *scan, parse_context *ctxt,
const char*, ...) __attribute__((format(printf,3,4)));
63 void glps_verror(
void *scan, parse_context *ctxt, const
char*, va_list);
65 void glps_assign(parse_context*, string_t *, expr_t*);
66 void glps_add_element(parse_context*, string_t *label, string_t *etype, kvlist_t*);
67 void glps_add_line(parse_context*, string_t *label, string_t *etype, strlist_t*);
68 void glps_command(parse_context*, string_t *kw);
69 void glps_call1(parse_context*, string_t*, expr_t*);
71 kvlist_t* glps_append_kv(parse_context *ctxt, kvlist_t*, kv_t*);
72 strlist_t* glps_append_expr(parse_context *ctxt, strlist_t*, expr_t *);
73 vector_t* glps_append_vector(parse_context *ctxt, vector_t*, expr_t *);
75 expr_t *glps_add_value(parse_context *ctxt, glps_expr_type t, ...);
76 expr_t *glps_add_op(parse_context *ctxt, string_t *,
unsigned N, expr_t **);
83 typedef boost::variant<
87 std::vector<std::string>,
88 boost::shared_ptr<Config>
94 string_t(A a) : str(a) {}
95 template<
typename A,
typename B>
96 string_t(A a, B b) : str(a,b) {}
100 glps_expr_type etype;
103 expr_t(): etype(glps_expr_invalid), value(0.0) {}
104 expr_t(glps_expr_type e, expr_value_t v): etype(e), value(v) {}
108 std::vector<double> value;
112 typedef std::map<std::string, expr_t> map_t;
117 typedef std::vector<std::string> list_t;
126 parse_var(
const char* n, expr_t E) :name(n), expr(E) {}
129 struct parse_element {
130 std::string label, etype;
131 kvlist_t::map_t props;
133 parse_element(std::string L, std::string E, kvlist_t::map_t& M);
137 std::string label, etype;
138 strlist_t::list_t names;
140 parse_line(std::string L, std::string E, strlist_t::list_t& N);
144 typedef int (*eval_t)(parse_context*, expr_value_t *,
const expr_t*
const *);
148 glps_expr_type result_type;
149 std::vector<glps_expr_type> arg_types;
151 operation_t(
const char *name, eval_t, glps_expr_type R,
unsigned N, va_list args);
154 struct parse_context {
155 typedef std::vector<parse_var> vars_t;
158 typedef std::vector<parse_element> elements_t;
161 typedef std::vector<parse_line> line_t;
165 typedef std::map<std::string, size_t> map_idx_t;
166 map_idx_t var_idx, element_idx, line_idx;
168 typedef std::multimap<std::string, operation_t> operations_t;
169 typedef std::pair<operations_t::const_iterator, operations_t::const_iterator> operations_iterator_pair;
170 operations_t operations;
172 void addop(
const char *name, operation_t::eval_t, glps_expr_type R,
unsigned N, ...);
174 std::string last_error;
176 std::ostream *printer;
178 std::vector<char> error_scratch;
183 boost::filesystem::path cwd;
186 parse_context(
const char *path=NULL);
189 void parse(FILE *fp);
190 void parse(
const char* s,
size_t len);
191 void parse(
const std::string& s);
Associative configuration container.