Imported Upstream version 1.5.0
[platform/upstream/augeas.git] / src / jmt.h
1 /*
2  * jmt.h: Earley parser for lenses based on Jim/Mandelbaum transducers
3  *
4  * Copyright (C) 2009-2015 David Lutterkort
5  *
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.
10  *
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.
15  *
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
19  *
20  * Author: David Lutterkort <lutter@redhat.com>
21  */
22
23 #ifndef EARLEY_H_
24 #define EARLEY_H_
25
26 #include <stdlib.h>
27 #include <stdint.h>
28 #include "lens.h"
29
30 struct jmt;
31 struct jmt_parse;
32
33 typedef uint32_t ind_t;
34
35 struct lens;
36
37 typedef void (*jmt_traverser)(struct lens *l, size_t start, size_t end,
38                               void *data);
39
40 typedef void (*jmt_error)(struct lens *lens, void *data, size_t pos,
41                           const char *format, ...);
42
43 struct jmt_visitor {
44     struct jmt_parse *parse;
45     jmt_traverser    terminal;
46     jmt_traverser    enter;
47     jmt_traverser    exit;
48     jmt_error        error;
49     void             *data;
50 };
51
52 struct jmt *jmt_build(struct lens *l);
53
54 struct jmt_parse *jmt_parse(struct jmt *jmt, const char *text, size_t text_len);
55
56 void jmt_free_parse(struct jmt_parse *);
57
58 /* Returns -1 on internal error, 0 on syntax error, 1 on a successful
59  * parse.
60  */
61 int jmt_visit(struct jmt_visitor *visitor, size_t *len);
62
63 void jmt_free(struct jmt *jmt);
64
65 void jmt_dot(struct jmt *jmt, const char *fname);
66 #endif
67
68 /*
69  * Local variables:
70  *  indent-tabs-mode: nil
71  *  c-indent-level: 4
72  *  c-basic-offset: 4
73  *  tab-width: 4
74  * End:
75  */