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
30 #include "lc_opts_t.h"
31 #include "lc_parser_t.h"
33 static void group_open(void);
34 static void group_close(void);
35 static void lc_opt_set(void);
36 static void path_push(text_t text);
38 void PMANGLE(error)(const char *str);
65 group: path { group_open(); } '{' dseq '}' { group_close(); } ;
67 option: path DATA { lc_opt_set(); } ;
69 path: path SEP IDENT { path_push($3); }
70 | IDENT { path_push($1); }
75 static lc_opt_error_handler_t *handler;
76 static struct obstack obst;
77 const char *optfilename = "";
79 void PMANGLE(error)(const char *str)
81 fprintf(stderr, "At line %d: %s\n", PMANGLE(linenr), str);
84 static const char *path_stack[128];
85 static int path_sp = 0;
87 static lc_opt_entry_t *grp_stack[128];
88 static int grp_sp = 0;
89 #define CURR_GRP (grp_stack[grp_sp - 1])
91 void lc_opt_init_parser(const char *filename, lc_opt_error_handler_t *err_handler)
95 handler = err_handler;
96 optfilename = filename;
97 grp_stack[grp_sp++] = lc_opt_root_grp();
100 void _lc_opt_add_to_data_char(char c)
102 obstack_1grow(&obst, c);
105 static void path_push(text_t text)
107 obstack_grow0(&obst, text.str, text.len);
108 path_stack[path_sp++] = obstack_finish(&obst);
111 static void path_free(void)
113 obstack_free(&obst, (void *) path_stack[0]);
117 static void group_open(void)
119 lc_opt_err_info_t err;
120 lc_opt_entry_t *grp = lc_opt_resolve_grp(CURR_GRP, path_stack, path_sp, &err);
124 grp_stack[grp_sp++] = grp;
127 static void group_close(void)
132 static void lc_opt_set(void)
134 char *str = obstack_finish(&obst);
136 lc_opt_err_info_t err;
137 lc_opt_entry_t *opt = lc_opt_resolve_opt(CURR_GRP, path_stack, path_sp, &err);
138 lc_opt_raise_error(&err, handler, "At %s(%d): ", optfilename, PMANGLE(linenr));
140 lc_opt_occurs(opt, str, &err);
141 lc_opt_raise_error(&err, handler, "At %s(%d): ", optfilename, PMANGLE(linenr));
143 obstack_free(&obst, str);