2 %name-prefix="_lc_opt_"
7 libcore: library for basic data structures and algorithms.
8 Copyright (C) 2005 IPD Goos, Universit"at Karlsruhe, Germany
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 2.1 of the License, or (at your option) any later version.
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public
21 License along with this library; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 #include "lc_opts_t.h"
28 #include "lc_parser_t.h"
30 static void group_open(void);
31 static void group_close(void);
32 static void lc_opt_set(void);
33 static void path_push(text_t text);
35 void PMANGLE(error)(const char *str);
62 group: path { group_open(); } '{' dseq '}' { group_close(); } ;
64 option: path DATA { lc_opt_set(); } ;
66 path: path SEP IDENT { path_push($3); }
67 | IDENT { path_push($1); }
72 static lc_opt_error_handler_t *handler;
73 static struct obstack obst;
74 const char *optfilename = "";
76 void PMANGLE(error)(const char *str)
78 fprintf(stderr, "At line %d: %s\n", PMANGLE(linenr), str);
81 static const char *path_stack[128];
82 static int path_sp = 0;
84 static lc_opt_entry_t *grp_stack[128];
85 static int grp_sp = 0;
86 #define CURR_GRP (grp_stack[grp_sp - 1])
88 void lc_opt_init_parser(const char *filename, lc_opt_error_handler_t *err_handler)
92 handler = err_handler;
93 optfilename = filename;
94 grp_stack[grp_sp++] = lc_opt_root_grp();
97 void _lc_opt_add_to_data_char(char c)
99 obstack_1grow(&obst, c);
102 static void path_push(text_t text)
104 obstack_grow0(&obst, text.str, text.len);
105 path_stack[path_sp++] = obstack_finish(&obst);
108 static void path_free(void)
110 obstack_free(&obst, (void *) path_stack[0]);
114 static void group_open(void)
116 lc_opt_err_info_t err;
117 lc_opt_entry_t *grp = lc_opt_resolve_grp(CURR_GRP, path_stack, path_sp, &err);
121 grp_stack[grp_sp++] = grp;
124 static void group_close(void)
129 static void lc_opt_set(void)
131 char *str = obstack_finish(&obst);
133 lc_opt_err_info_t err;
134 lc_opt_entry_t *opt = lc_opt_resolve_opt(CURR_GRP, path_stack, path_sp, &err);
135 lc_opt_raise_error(&err, handler, "At %s(%d): ", optfilename, PMANGLE(linenr));
137 lc_opt_occurs(opt, str, &err);
138 lc_opt_raise_error(&err, handler, "At %s(%d): ", optfilename, PMANGLE(linenr));
140 obstack_free(&obst, str);