2 * syntax.h: Data types to represent language syntax
4 * Copyright (C) 2007-2011 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;
118 struct value *(*impl)(void);
121 /* An exception in the interpreter. Some exceptions are reported directly
122 * into the central struct error; an exception for those is only generated
123 * to follow the control flow for exceptions. Such exceptions have both
124 * seen and error set to 1. They are the only exceptions with error == 1.
125 * When error == 1, none of the other fields in the exn will be usable.
129 unsigned int seen : 1; /* Whether the user has seen this EXN */
130 unsigned int error : 1;
137 * Values in the interpreter
152 #define EXN(v) ((v)->tag == V_EXN)
158 /* Nothing in this union for V_UNIT */
160 struct string *string; /* V_STRING */
161 struct regexp *regexp; /* V_REGEXP */
162 struct lens *lens; /* V_LENS */
163 struct native *native; /* V_NATIVE */
164 struct tree *origin; /* V_TREE */
165 struct filter *filter; /* V_FILTER */
166 struct transform *transform; /* V_TRANSFORM */
167 struct exn *exn; /* V_EXN */
168 struct { /* V_CLOS */
170 struct binding *bindings;
175 /* All types except for T_ARROW (functions) are simple. Subtype relations
176 * for the simple types:
177 * T_STRING <: T_REGEXP
178 * and the usual subtype relation for functions.
194 struct type *dom; /* T_ARROW */
195 struct type *img; /* T_ARROW */
200 struct binding *next;
201 struct string *ident;
206 /* A module maps names to TYPE * VALUE. */
209 struct module *next; /* Only used for the global list of modules */
210 struct transform *autoload;
212 struct binding *bindings;
215 struct type *make_arrow_type(struct type *dom, struct type *img);
216 struct type *make_base_type(enum type_tag tag);
217 /* Do not call this directly. Use unref(t, type) instead */
218 void free_type(struct type *type);
220 /* Constructors for some terms in syntax.c Constructor assumes ownership of
221 * arguments without incrementing. Caller owns returned objects.
223 struct term *make_term(enum term_tag tag, struct info *info);
224 void free_term(struct term *term);
225 struct term *make_param(char *name, struct type *type, struct info *info);
226 struct value *make_value(enum value_tag tag, struct info *info);
227 struct value *make_unit(struct info *info);
228 struct term *make_app_term(struct term *func, struct term *arg,
230 struct term *make_app_ident(char *id, struct term *func, struct info *info);
232 /* Print a tree in the braces style used in modules */
233 void print_tree_braces(FILE *out, int indent, struct tree *tree);
236 * Receive ownership of INFO
238 * FORMAT and following arguments are printed to a new string. Caller must
241 struct value *make_exn_value(struct info *info, const char *format, ...)
242 ATTRIBUTE_FORMAT(printf, 2, 3);
244 /* Add NLINES lines (passed as const char *) to EXN, which must be a
245 * value with tag V_EXN, created by MAKE_EXN_VALUE.
247 * The strings belong to EXN * after the call.
249 void exn_add_lines(struct value *exn, int nlines, ...);
251 void exn_printf_line(struct value *exn, const char *format, ...)
252 ATTRIBUTE_FORMAT(printf, 2, 3);
254 /* Do not call these directly, use UNREF instead */
255 void free_value(struct value *v);
256 void free_module(struct module *module);
258 /* Turn a list of PARAMS (represented as terms tagged as A_FUNC with the
259 * param in PARAM) into nested A_FUNC terms
261 struct term *build_func(struct term *params, struct term *exp);
263 struct module *module_create(const char *name);
265 #define define_native(error, module, name, argc, impl, types ...) \
266 define_native_intl(__FILE__, __LINE__, error, module, name, \
267 argc, impl, ## types)
269 ATTRIBUTE_RETURN_CHECK
270 int define_native_intl(const char *fname, int line,
272 struct module *module, const char *name,
273 int argc, void *impl, ...);
275 struct module *builtin_init(struct error *);
277 int load_module_file(struct augeas *aug, const char *filename, const char *name);
279 /* The name of the builtin function that checks recursive lenses */
280 #define LNS_CHECK_REC_NAME "lns_check_rec"
282 int interpreter_init(struct augeas *aug);
284 struct lens *lens_lookup(struct augeas *aug, const char *qname);
290 * indent-tabs-mode: nil