forked from jordansissel/grok
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conf.y
138 lines (107 loc) · 4.04 KB
/
conf.y
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
%{
#include <stdio.h>
#include <string.h>
#include "conf.tab.h"
#include "grok_config.h"
#include "grok_input.h"
#include "grok_matchconf.h"
int yylineno;
void yyerror (YYLTYPE *loc, struct config *conf, char const *s) {
fprintf (stderr, "Syntax error: %s\n", s);
}
#define DEBUGMASK(val) ((val > 0) ? ~0 : 0)
%}
%union{
char *str;
int num;
}
%token <str> QUOTEDSTRING
%token <num> INTEGER
%token CONF_DEBUG "debug"
%token PROGRAM "program"
%token PROG_FILE "file"
%token PROG_EXEC "exec"
%token PROG_MATCH "match"
%token PROG_NOMATCH "no-match"
%token PROG_LOADPATTERNS "load-patterns"
%token FILE_FOLLOW "follow"
%token EXEC_RESTARTONEXIT "restart-on-exit"
%token EXEC_MINRESTARTDELAY "minimum-restart-delay"
%token EXEC_RUNINTERVAL "run-interval"
%token EXEC_READSTDERR "read-stderr"
%token MATCH_PATTERN "pattern"
%token MATCH_REACTION "reaction"
%token MATCH_SHELL "shell"
%token MATCH_FLUSH "flush"
%token MATCH_BREAK_IF_MATCH "break-if-match"
%token SHELL_STDOUT "stdout"
%token LITERAL_NONE "none"
%token '{' '}' ';' ':' '\n'
%pure-parser
%parse-param {struct config *conf}
%error-verbose
%locations
%start config
%%
config: config root
| root
| error {
/* Errors are unrecoverable, so let's return nonzero from the parser */
return 1;
}
root: root_program
| "debug" ':' INTEGER { conf->logmask = DEBUGMASK($3); }
root_program: PROGRAM '{' { conf_new_program(conf); }
program_block
'}'
program_block: program_block program_block_statement
| program_block_statement
program_block_statement: program_file
| program_exec
| program_match
| program_nomatch
| program_load_patterns
| "debug" ':' INTEGER { CURPROGRAM.logmask = DEBUGMASK($3); }
program_load_patterns: "load-patterns" ':' QUOTEDSTRING
{ conf_new_patternfile(conf); CURPATTERNFILE = $3; }
program_file: "file" QUOTEDSTRING { conf_new_input_file(conf, $2); }
program_file_optional_block
program_file_optional_block: /*empty*/ | '{' file_block '}'
program_exec: "exec" QUOTEDSTRING { conf_new_input_process(conf, $2); }
program_exec_optional_block
program_exec_optional_block: /* empty */ | '{' exec_block '}'
program_match: "match" '{' { conf_new_matchconf(conf); }
match_block
'}'
program_nomatch: "no-match" '{'
{ conf_new_matchconf(conf); CURMATCH.is_nomatch = 1; }
match_block
'}'
file_block: file_block file_block_statement
| file_block_statement
file_block_statement: /*empty*/
| "follow" ':' INTEGER { CURINPUT.source.file.follow = $3; }
| "debug" ':' INTEGER { CURINPUT.logmask = DEBUGMASK($3); }
exec_block: exec_block exec_block_statement
| exec_block_statement
exec_block_statement: /* empty */
| "restart-on-exit" ':' INTEGER
{ CURINPUT.source.process.restart_on_death = $3; }
| "minimum-restart-delay" ':' INTEGER
{ CURINPUT.source.process.min_restart_delay = $3; }
| "run-interval" ':' INTEGER
{ CURINPUT.source.process.run_interval = $3; }
| "read-stderr" ':' INTEGER
{ CURINPUT.source.process.read_stderr = $3; }
| "debug" ':' INTEGER { CURINPUT.logmask = DEBUGMASK($3); }
match_block: match_block match_block_statement
| match_block_statement
match_block_statement: /* empty */
| "pattern" ':' QUOTEDSTRING { conf_new_match_pattern(conf, $3) }
| "reaction" ':' QUOTEDSTRING { CURMATCH.reaction = $3; }
| "reaction" ':' "none" { CURMATCH.no_reaction = 1; }
| "shell" ':' QUOTEDSTRING { CURMATCH.shell = $3; }
| "shell" ':' "stdout" { CURMATCH.shell = "stdout"; }
| "flush" ':' INTEGER { CURMATCH.flush = $3; }
| "break-if-match" ':' INTEGER { CURMATCH.break_if_match = $3; }
| "debug" ':' INTEGER { conf_match_set_debug(conf, DEBUGMASK($3)); }