File: csvparser-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 (169 lines) | stat: -rw-r--r-- 5,527 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
/*
 * Copyright (c) 2002-2015 Balabit
 * Copyright (c) 1998-2015 Balázs Scheidler
 *
 * 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 top {
#include "csvparser-parser.h"

}


%code {

#include "csvparser.h"
#include "cfg-parser.h"
#include "cfg-grammar-internal.h"
#include "syslog-names.h"
#include "messages.h"

}

%define api.prefix {csvparser_}

/* this parameter is needed in order to instruct bison to use a complete
 * argument list for yylex/yyerror */

%lex-param {CfgLexer *lexer}
%parse-param {CfgLexer *lexer}
%parse-param {LogParser **instance}
%parse-param {gpointer arg}

/* INCLUDE_DECLS */

%token KW_CSV_PARSER
%token KW_DIALECT
%token KW_PREFIX
%token KW_COLUMNS
%token KW_DELIMITERS
%token KW_QUOTES
%token KW_QUOTE_PAIRS
%token KW_NULL
%token KW_CHARS
%token KW_STRINGS
%token KW_DROP_INVALID
%token KW_ON_TYPE_ERROR

%type	<ptr> parser_expr_csv
%type   <ptr> parser_csv_columns
%type   <ptr> parser_csv_column
%type   <cptr> parser_csv_flag
%type   <num> parser_csv_flags
%type   <num> parser_csv_dialect

%%

start
        : LL_CONTEXT_PARSER parser_expr_csv                  { YYACCEPT; }
        ;


parser_expr_csv
        : KW_CSV_PARSER '('
          {
            last_parser = *instance = csv_parser_new(configuration);
          }
          parser_csv_opts
          ')'					{ $$ = last_parser; }
        ;


parser_csv_opts
        : parser_csv_opt parser_csv_opts
        |
        ;

parser_csv_opt
        /* CSVParser related options */
        : KW_FLAGS '(' parser_csv_flags ')'     { CHECK_ERROR(csv_parser_set_flags(last_parser, $3), @3, "only one escape style can be used in the flags argument"); }
        | KW_PREFIX '(' string ')'              { csv_parser_set_prefix(last_parser, $3); free($3); }
	| KW_DROP_INVALID '(' yesno ')'         { csv_parser_set_drop_invalid(last_parser, $3); }
        /* CSVScanner related options */
        | KW_DIALECT '(' parser_csv_dialect ')' { csv_scanner_options_set_dialect(csv_parser_get_scanner_options(last_parser), $3); }
        | KW_DELIMITERS '(' parser_csv_delimiters ')'
        | KW_QUOTES '(' string ')'              { csv_scanner_options_set_quotes(csv_parser_get_scanner_options(last_parser), $3); free($3); }
        | KW_QUOTE_PAIRS '(' string ')'         { csv_scanner_options_set_quote_pairs(csv_parser_get_scanner_options(last_parser), $3); free($3); }
        | KW_NULL '(' string ')'                { csv_scanner_options_set_null_value(csv_parser_get_scanner_options(last_parser), $3); free($3); }
        | KW_COLUMNS '(' parser_csv_columns ')'        { csv_parser_set_columns(last_parser, $3); }
        | KW_ON_TYPE_ERROR '(' string ')'
        {
          gint on_error;

          CHECK_ERROR(on_error_parse($3, &on_error), @3, "Invalid on-type-error() setting \"%s\"", $3);
          free($3);

          csv_parser_set_on_error(last_parser, on_error);
        }
        | parser_opt
        ;

parser_csv_delimiters
        : string                                {  csv_scanner_options_set_delimiters(csv_parser_get_scanner_options(last_parser), $1); free($1);  }
        | parser_csv_delimiters_opts
        ;

parser_csv_delimiters_opts
        : parser_csv_delimiters_opt parser_csv_delimiters_opts
        |
        ;

parser_csv_delimiters_opt
        : KW_CHARS '(' string ')'               { csv_scanner_options_set_delimiters(csv_parser_get_scanner_options(last_parser), $3); free($3); }
        | KW_STRINGS '('  string_list  ')'	{ csv_scanner_options_set_string_delimiters(csv_parser_get_scanner_options(last_parser), $3); }
        ;

parser_csv_flags
        : parser_csv_flag parser_csv_flags
          {
            guint32 flag = csv_parser_lookup_flag($1);
            CHECK_ERROR(flag != 0, @1, "unknown csv-parser() flag %s", $1);
            $$ = flag | $2;
            free($1);
          }
        |					{ $$ = 0; }
        ;

parser_csv_flag
        : normalized_flag			{ $$ = $1; }
	| KW_DROP_INVALID			{ $$ = strdup(lexer->token_text->str); };
	;

parser_csv_dialect
        : normalized_flag                       {
                                                  gint mode = csv_parser_lookup_dialect($1);
                                                  CHECK_ERROR(mode >= 0, @1, "unknown dialect() argument for csv-parser()");
                                                  free($1);
						  $$ = mode;
                                                }

parser_csv_columns
	: parser_csv_column parser_csv_columns		{ $$ = g_list_prepend($2, $1); }
	|						{ $$ = NULL; }
	;

parser_csv_column
	: string					{ $$ = csv_parser_column_new($1, LM_VT_STRING); }
	| type_hint '(' string ')'			{ $$ = csv_parser_column_new($3, $1); }
	;

/* INCLUDE_RULES */

%%