File: python-grammar.ym

package info (click to toggle)
syslog-ng 3.19.1-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 13,176 kB
  • sloc: ansic: 114,472; makefile: 4,697; sh: 4,391; python: 4,282; java: 4,047; xml: 2,435; yacc: 1,108; lex: 426; perl: 193; awk: 184
file content (252 lines) | stat: -rw-r--r-- 6,376 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
/*
 * Copyright (c) 2014 Balabit
 * Copyright (c) 2014 Gergely Nagy <algernon@balabit.hu>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published
 * by the Free Software Foundation, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * As an additional exemption you are allowed to compile & link against the
 * OpenSSL libraries as published by the OpenSSL project. See the file
 * COPYING for details.
 *
 */

%code requires {

#include "python-parser.h"
#include "python-dest.h"
#include "python-source.h"
#include "python-fetcher.h"
#include "python-logparser.h"
#include "python-main.h"
#include "value-pairs/value-pairs.h"
#include "logthrsource/logthrsourcedrv.h"

}

%code {

#include "cfg-grammar.h"
#include "cfg-parser.h"
#include "plugin.h"
#include "syslog-names.h"
}

%name-prefix "python_"
%lex-param {CfgLexer *lexer}
%parse-param {CfgLexer *lexer}
%parse-param {void **instance}
%parse-param {gpointer arg}

/* INCLUDE_DECLS */

%token KW_PYTHON
%token KW_PYTHON_FETCHER
%token KW_CLASS
%token KW_IMPORTS
%token KW_LOADERS

%%

start
        : LL_CONTEXT_DESTINATION KW_PYTHON
          {
            last_driver = *instance = python_dd_new(configuration);
          }
          '(' python_dd_options ')'         { YYACCEPT; }
        | LL_CONTEXT_PARSER KW_PYTHON
	  {
	    last_parser = *instance = python_parser_new(configuration);
          }
          '(' python_parser_options ')' { YYACCEPT; }
        | LL_CONTEXT_SOURCE KW_PYTHON
          {
            last_driver = *instance = python_sd_new(configuration);
          }
          '(' python_sd_options ')'         { YYACCEPT; }
        | LL_CONTEXT_SOURCE KW_PYTHON_FETCHER
          {
            last_driver = *instance = python_fetcher_new(configuration);
          }
          '(' python_fetcher_options ')'         { YYACCEPT; }
	| LL_CONTEXT_ROOT KW_PYTHON
          { cfg_lexer_push_context(lexer, LL_CONTEXT_BLOCK_CONTENT, NULL, "Python code"); }
          LL_BLOCK
          { cfg_lexer_pop_context(lexer); }
          {
            gboolean result;

	    result = python_evaluate_global_code(configuration, $4, &@2);
	    free($4);
            CHECK_ERROR(result, @1, "Error processing global python block");
            *instance = (void *) 1;
            YYACCEPT;
          }
        ;

python_dd_options
        : python_dd_option python_dd_options
        |
        ;

python_dd_option
        : KW_CLASS '(' string ')'
          {
            python_dd_set_class(last_driver, $3);
            free($3);
          }
        | KW_LOADERS python_dd_loaders
        | KW_IMPORTS python_dd_loaders
        | KW_OPTIONS '(' python_dd_custom_options ')'
        | threaded_dest_driver_option
        | value_pair_option
          {
            python_dd_set_value_pairs(last_driver, $1);
          }
        | { last_template_options = python_dd_get_template_options(last_driver); } template_option
        ;

python_dd_custom_options
        : python_dd_custom_option python_dd_custom_options
        |
        ;

python_dd_custom_option
        : string string_or_number
        {
          python_dd_set_option(last_driver, $1, $2);
          free($1);
          free($2);
        }
        ;


python_sd_options
        : python_sd_option python_sd_options
        |
        ;

python_sd_option
        : KW_CLASS '(' string ')'
          {
            python_sd_set_class(last_driver, $3);
            free($3);
          }
        | KW_LOADERS python_sd_loaders
        | KW_OPTIONS '(' python_sd_custom_options ')'
        | threaded_source_driver_option
        ;

python_sd_custom_options
        : python_sd_custom_option python_sd_custom_options
        |
        ;

python_sd_custom_option
        : string string_or_number
        {
          python_sd_set_option(last_driver, $1, $2);
          free($1);
          free($2);
        }
        ;


python_fetcher_options
        : python_fetcher_option python_fetcher_options
        |
        ;

python_fetcher_option
        : KW_CLASS '(' string ')'
          {
            python_fetcher_set_class(last_driver, $3);
            free($3);
          }
        | KW_LOADERS python_fetcher_loaders
        | KW_OPTIONS '(' python_fetcher_custom_options ')'
        | threaded_source_driver_option
        ;

python_fetcher_custom_options
        : python_fetcher_custom_option python_fetcher_custom_options
        |
        ;

python_fetcher_custom_option
        : string string_or_number
        {
          python_fetcher_set_option(last_driver, $1, $2);
          free($1);
          free($2);
        }
        ;


python_parser_options
        : python_parser_option python_parser_options
        |
        ;

python_parser_option
        : KW_CLASS '(' string ')'
          {
            python_parser_set_class(last_parser, $3);
            free($3);
          }
        | KW_LOADERS python_parser_loaders
        | KW_IMPORTS python_parser_loaders
        | KW_OPTIONS '(' python_parser_custom_options ')'
        ;

python_parser_custom_options
        : python_parser_custom_option python_parser_custom_options
        |
        ;

python_parser_custom_option
        : string string_or_number
        {
          python_parser_set_option(last_parser, $1, $2);
          free($1);
          free($2);
        }


python_dd_loaders
          : '(' string_list ')'
          {
            python_dd_set_loaders(last_driver, $2);
          }

python_sd_loaders
          : '(' string_list ')'
          {
            python_sd_set_loaders(last_driver, $2);
          }

python_fetcher_loaders
          : '(' string_list ')'
          {
            python_fetcher_set_loaders(last_driver, $2);
          }

python_parser_loaders
          : '(' string_list ')'
          {
            python_parser_set_loaders(last_parser, $2);
          }

/* INCLUDE_RULES */

%%