File: pragma-grammar.ym

package info (click to toggle)
syslog-ng 4.8.1-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,456 kB
  • sloc: ansic: 177,631; python: 13,035; cpp: 11,611; makefile: 7,012; sh: 5,147; java: 3,651; xml: 3,344; yacc: 1,377; lex: 599; perl: 193; awk: 190; objc: 162
file content (223 lines) | stat: -rw-r--r-- 6,133 bytes parent folder | download | duplicates (2)
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
/*
 * Copyright (c) 2002-2011 Balabit
 * Copyright (c) 1998-2011 Balázs Scheidler
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; 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 {

#pragma GCC diagnostic ignored "-Wswitch-default"

#include "pragma-parser.h"
#include "plugin.h"
#include "cfg.h"
#include "messages.h"

#include <string.h>

}

%define api.prefix {pragma_}
%lex-param {CfgLexer *lexer}
%parse-param {CfgLexer *lexer}
%parse-param {gpointer *result}
%parse-param {gpointer arg}

/* INCLUDE_DECLS */

%token KW_VERSION
%token KW_VERSION_CURRENT
%token KW_DEFINE
%token KW_MODULE
%token KW_REQUIRES
%token KW_LINE
%token KW_CONFIG_ID

%code {

#include <stdlib.h>

#define PRAGMA_BEGIN() ({ lexer->tokenize_eol++; })
#define PRAGMA_END() ({ lexer->tokenize_eol--; })
#define PRAGMA_ERROR() ({ PRAGMA_END(); YYERROR; })

CfgArgs *last_module_args = NULL;

static void
_report_define_deprecations(const gchar *name, const gchar *value)
{
  if (strcmp(name, "autoload-compiled-modules") == 0 && atoi(value) == 0)
    msg_warning("WARNING: disabling plugin discovery via the autoload-compiled-modules "
                "@define has become unsupported in " VERSION_3_37
                ", use the syslog-ng command line option --no-module-discovery instead");
  else if (strcmp(name, "module-path") == 0)
    msg_warning("WARNING: changing the path to runtime loaded modules via the module-path "
                "@define has become unsupported in " VERSION_3_37
                ", use the command line option --module-path instead");
}

static void
pragma_define_global(GlobalConfig *cfg, const gchar *name, const gchar *value)
{
  msg_debug("Global value changed",
            evt_tag_str("define", name),
            evt_tag_str("value", value));

  _report_define_deprecations(name, value);
  cfg_args_set(cfg->globals, name, value);
}

}

%type   <cptr> requires_message

%%


start
        : { PRAGMA_BEGIN(); }
          stmt                                  { if (yychar != PRAGMA_EMPTY) { cfg_lexer_unput_token(lexer, &yylval); } PRAGMA_END(); YYACCEPT; }

stmt
	: stmt_without_eol LL_EOL
	| stmt_with_eol
	;

stmt_without_eol
        : version_stmt
        | define_stmt
        | module_stmt
        | config_id_stmt
        ;

	/* LL_EOL as a token needs to be consumed by the rules below, as they can
	 * change the lexer buffer by the time they return to the grammar. */
stmt_with_eol
        : include_stmt
        | requires_stmt
        | line_stmt
        ;

version_stmt
        : KW_VERSION ':' KW_VERSION_CURRENT
        {
          if (!cfg_set_current_version(configuration))
            PRAGMA_ERROR();
        }
        | KW_VERSION ':' string_or_number
          {
            guint parsed_version = process_version_string($3);
            free($3);
            if (parsed_version == 0)
                PRAGMA_ERROR();
            if (!cfg_set_version(configuration, parsed_version))
                PRAGMA_ERROR();
          }

define_stmt
	: KW_DEFINE LL_IDENTIFIER string_or_number
          {
            pragma_define_global(configuration, $2, $3);
            free($2);
            free($3);
          }

module_stmt
	: KW_MODULE string { last_module_args = cfg_args_new(); } module_params
          {
            gboolean success = cfg_load_module_with_args(configuration, $2, last_module_args);
            free($2);

            cfg_args_unref(last_module_args);
            last_module_args = NULL;

            if (!success)
              PRAGMA_ERROR();
          }
	;

module_params
	: module_param module_params
	|
	;

module_param
	: LL_IDENTIFIER '(' string_or_number ')'		{ cfg_args_set(last_module_args, $1, $3); free($1); free($3); }
	;

config_id_stmt
  : KW_CONFIG_ID ':' string_or_number
    {
      cfg_set_user_config_id(configuration, $3);
      free($3);
    }

include_stmt
        : KW_INCLUDE string LL_EOL
          {
            CHECK_ERROR(cfg_lexer_include_file(lexer, $2), @2, "Error including %s", $2);
            free($2);
          }
        ;

requires_stmt
	: KW_REQUIRES string requires_message LL_EOL
          {
            if (!cfg_is_module_available(configuration, $2))
              {
                if (0 == lexer->include_depth || $3)
                  {
                    msg_error("Cannot load required module",
                              evt_tag_str("module", $2),
                              evt_tag_str("details", $3 ? : "none"),
                              cfg_lexer_format_location_tag(lexer,&@1));
                    free($2);
                    free($3);
                    PRAGMA_ERROR();
                  }
                else
                  {
                    msg_debug("Included file was skipped because of a missing module",
                              evt_tag_str("module", $2),
                              cfg_lexer_format_location_tag(lexer,&@1));
                    cfg_lexer_start_next_include(lexer);
                  }
              }
            free($2);
            free($3);
          }
	;

requires_message
	: string		{ $$ = $1; }
	| 			{ $$ = NULL; }
	;

line_stmt
	: KW_LINE string positive_integer positive_integer LL_EOL
          {
            cfg_lexer_set_file_location(lexer, $2, $3, $4);
            free($2);
          }

/* INCLUDE_RULES */

%%