2 * syntax.h: Data types to represent language syntax
4 * Copyright (C) 2007-2016 David Lutterkort
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * Author: David Lutterkort <dlutter@redhat.com>
34 void syntax_error(struct info *info, const char *format, ...)
35 ATTRIBUTE_FORMAT(printf, 2, 3);
37 void fatal_error(struct info *info, const char *format, ...)
38 ATTRIBUTE_FORMAT(printf, 2, 3);
42 A_BIND, /* Module scope binding of a name */
43 A_LET, /* local LET .. IN binding */
57 enum test_result_tag {
73 struct type *type; /* Filled in by the typechecker */
76 struct { /* A_MODULE */
85 struct { /* A_COMPOSE, A_UNION, A_CONCAT, A_APP, A_LET */
89 struct value *value; /* A_VALUE */
90 struct term *brexp; /* A_BRACKET */
91 struct string *ident; /* A_IDENT */
100 struct { /* A_TEST */
101 enum test_result_tag tr_tag;
115 /* The protoype for the implementation of a native/builtin function in the
118 * The arguments are passed as a NULL-terminated array of values.
120 typedef struct value *(*func_impl)(struct info *, struct value *argv[]);
128 /* An exception in the interpreter. Some exceptions are reported directly
129 * into the central struct error; an exception for those is only generated
130 * to follow the control flow for exceptions. Such exceptions have both
131 * seen and error set to 1. They are the only exceptions with error == 1.
132 * When error == 1, none of the other fields in the exn will be usable.
136 unsigned int seen : 1; /* Whether the user has seen this EXN */
137 unsigned int error : 1;
144 * Values in the interpreter
159 #define EXN(v) ((v)->tag == V_EXN)
165 /* Nothing in this union for V_UNIT */
167 struct string *string; /* V_STRING */
168 struct regexp *regexp; /* V_REGEXP */
169 struct lens *lens; /* V_LENS */
170 struct native *native; /* V_NATIVE */
171 struct tree *origin; /* V_TREE */
172 struct filter *filter; /* V_FILTER */
173 struct transform *transform; /* V_TRANSFORM */
174 struct exn *exn; /* V_EXN */
175 struct { /* V_CLOS */
177 struct binding *bindings;
182 /* All types except for T_ARROW (functions) are simple. Subtype relations
183 * for the simple types:
184 * T_STRING <: T_REGEXP
185 * and the usual subtype relation for functions.
201 struct type *dom; /* T_ARROW */
202 struct type *img; /* T_ARROW */
207 struct binding *next;
208 struct string *ident;
213 /* A module maps names to TYPE * VALUE. */
216 struct module *next; /* Only used for the global list of modules */
217 struct transform *autoload;
219 struct binding *bindings;
222 struct type *make_arrow_type(struct type *dom, struct type *img);
223 struct type *make_base_type(enum type_tag tag);
224 /* Do not call this directly. Use unref(t, type) instead */
225 void free_type(struct type *type);
227 /* Constructors for some terms in syntax.c Constructor assumes ownership of
228 * arguments without incrementing. Caller owns returned objects.
230 struct term *make_term(enum term_tag tag, struct info *info);
231 void free_term(struct term *term);
232 struct term *make_param(char *name, struct type *type, struct info *info);
233 struct value *make_value(enum value_tag tag, struct info *info);
234 struct value *make_unit(struct info *info);
235 struct term *make_app_term(struct term *func, struct term *arg,
237 struct term *make_app_ident(char *id, struct term *func, struct info *info);
239 /* Print a tree in the braces style used in modules */
240 void print_tree_braces(FILE *out, int indent, struct tree *tree);
243 * Receive ownership of INFO
245 * FORMAT and following arguments are printed to a new string. Caller must
248 struct value *make_exn_value(struct info *info, const char *format, ...)
249 ATTRIBUTE_FORMAT(printf, 2, 3);
251 /* Add NLINES lines (passed as const char *) to EXN, which must be a
252 * value with tag V_EXN, created by MAKE_EXN_VALUE.
254 * The strings belong to EXN * after the call.
256 void exn_add_lines(struct value *exn, int nlines, ...);
258 void exn_printf_line(struct value *exn, const char *format, ...)
259 ATTRIBUTE_FORMAT(printf, 2, 3);
261 /* Do not call these directly, use UNREF instead */
262 void free_value(struct value *v);
263 void free_module(struct module *module);
265 /* Turn a list of PARAMS (represented as terms tagged as A_FUNC with the
266 * param in PARAM) into nested A_FUNC terms
268 struct term *build_func(struct term *params, struct term *exp);
270 struct module *module_create(const char *name);
272 #define define_native(error, module, name, argc, impl, types ...) \
273 define_native_intl(__FILE__, __LINE__, error, module, name, \
274 argc, impl, ## types)
276 ATTRIBUTE_RETURN_CHECK
277 int define_native_intl(const char *fname, int line,
279 struct module *module, const char *name,
280 int argc, func_impl impl, ...);
282 struct module *builtin_init(struct error *);
284 int load_module_file(struct augeas *aug, const char *filename, const char *name);
286 /* The name of the builtin function that checks recursive lenses */
287 #define LNS_CHECK_REC_NAME "lns_check_rec"
289 int interpreter_init(struct augeas *aug);
291 struct lens *lens_lookup(struct augeas *aug, const char *qname);
297 * indent-tabs-mode: nil