2
* Copyright (c) 2002-2010 BalaBit IT Ltd, Budapest, Hungary
3
* Copyright (c) 1998-2010 Balázs Scheidler
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2.1 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
* As an additional exemption you are allowed to compile & link against the
20
* OpenSSL libraries as published by the OpenSSL project. See the file
21
* COPYING for details.
25
#ifndef CFG_PARSER_H_INCLUDED
26
#define CFG_PARSER_H_INCLUDED
28
#include "syslog-ng.h"
29
#include "cfg-lexer.h"
31
/* high level interface to a configuration file parser, it encapsulates the
32
* grammar/lexer pair. */
33
typedef struct _CfgParser
35
/* how to enable bison debug in the parser */
40
/* parser specific keywords to be pushed to the lexer */
41
CfgLexerKeyword *keywords;
43
/* the parser entry point, returns the parsed object in *instance */
44
gint (*parse)(CfgLexer *lexer, gpointer *instance);
46
/* in case of parse failure and instance != NULL, this should free instance */
47
void (*cleanup)(gpointer instance);
56
typedef struct _CfgFlagHandler
65
cfg_process_flag(CfgFlagHandler *handlers, gpointer base, gchar *flag);
67
/* the debug flag for the main parser will be used for all parsers */
68
extern int cfg_parser_debug;
70
static inline gboolean
71
cfg_parser_parse(CfgParser *self, CfgLexer *lexer, gpointer *instance)
77
fprintf(stderr, "\n\nStarting parser %s\n", self->name);
80
(*self->debug_flag) = cfg_parser_debug;
81
cfg_lexer_push_context(lexer, self->context, self->keywords, self->name);
82
success = (self->parse(lexer, instance) == 0);
83
cfg_lexer_pop_context(lexer);
86
fprintf(stderr, "\nStopping parser %s, result: %d\n", self->name, success);
92
cfg_parser_cleanup(CfgParser *self, gpointer instance)
94
if (instance && self->cleanup)
95
self->cleanup(instance);
98
extern CfgParser main_parser;
100
#define CFG_PARSER_DECLARE_LEXER_BINDING(parser_prefix, root_type) \
102
parser_prefix ## lex(YYSTYPE *yylval, YYLTYPE *yylloc, CfgLexer *lexer); \
105
parser_prefix ## error(YYLTYPE *yylloc, CfgLexer *lexer, root_type instance, const char *msg);
108
#define CFG_PARSER_IMPLEMENT_LEXER_BINDING(parser_prefix, root_type) \
110
parser_prefix ## lex(YYSTYPE *yylval, YYLTYPE *yylloc, CfgLexer *lexer) \
114
token = cfg_lexer_lex(lexer, yylval, yylloc); \
119
parser_prefix ## error(YYLTYPE *yylloc, CfgLexer *lexer, root_type instance, const char *msg) \
121
report_syntax_error(lexer, yylloc, cfg_lexer_get_context_description(lexer), msg); \
124
void report_syntax_error(CfgLexer *lexer, YYLTYPE *yylloc, const char *what, const char *msg);
126
CFG_PARSER_DECLARE_LEXER_BINDING(main_, gpointer *)