-
Notifications
You must be signed in to change notification settings - Fork 10
/
grammar.treetop
241 lines (195 loc) · 4.4 KB
/
grammar.treetop
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
require "treetop"
require "logstash/config/config_ast"
grammar LogStashConfig
rule config
_ plugin_section _ (_ plugin_section)* _ <LogStash::Config::AST::Config>
end
rule comment
(whitespace? "#" [^\r\n]* "\r"? "\n")+ <LogStash::Config::AST::Comment>
end
rule _
(comment / whitespace)* <LogStash::Config::AST::Whitespace>
end
rule whitespace
[ \t\r\n]+ <LogStash::Config::AST::Whitespace>
end
rule plugin_section
plugin_type _ "{"
_ (branch_or_plugin _)*
"}"
<LogStash::Config::AST::PluginSection>
end
rule branch_or_plugin
branch / plugin
end
rule plugin_type
("input" / "filter" / "output")
end
rule plugins
(plugin (_ plugin)*)?
<LogStash::Config::AST::Plugins>
end
rule plugin
name _ "{"
_
attributes:( attribute (whitespace _ attribute)*)?
_
"}"
<LogStash::Config::AST::Plugin>
end
rule name
(
([A-Za-z0-9_-]+ <LogStash::Config::AST::Name>)
/ string
)
end
rule attribute
name _ "=>" _ value
<LogStash::Config::AST::Attribute>
end
rule value
plugin / bareword / string / number / array / hash
end
rule array_value
bareword / string / number / array / hash
end
rule bareword
[A-Za-z_] [A-Za-z0-9_]+
<LogStash::Config::AST::Bareword>
end
rule double_quoted_string
( '"' ( '\"' / !'"' . )* '"' <LogStash::Config::AST::String>)
end
rule single_quoted_string
( "'" ( "\\'" / !"'" . )* "'" <LogStash::Config::AST::String>)
end
rule string
double_quoted_string / single_quoted_string
end
rule regexp
( '/' ( '\/' / !'/' . )* '/' <LogStash::Config::AST::RegExp>)
end
rule number
"-"? [0-9]+ ("." [0-9]*)?
<LogStash::Config::AST::Number>
end
rule array
"["
_
(
value (_ "," _ value)*
)?
_
"]"
<LogStash::Config::AST::Array>
end
rule hash
"{"
_
hashentries?
_
"}"
<LogStash::Config::AST::Hash>
end
rule hashentries
hashentry (whitespace hashentry)*
<LogStash::Config::AST::HashEntries>
end
rule hashentry
name:(number / bareword / string) _ "=>" _ value
<LogStash::Config::AST::HashEntry>
end
# Conditions
rule branch
if (_ else_if)* (_ else)?
<LogStash::Config::AST::Branch>
end
rule if
"if" _ condition _ "{" _ (branch_or_plugin _)* "}"
<LogStash::Config::AST::If>
end
rule else_if
"else" _ "if" _ condition _ "{" _ ( branch_or_plugin _)* "}"
<LogStash::Config::AST::Elsif>
end
rule else
"else" _ "{" _ (branch_or_plugin _)* "}"
<LogStash::Config::AST::Else>
end
rule condition
expression (_ boolean_operator _ expression)*
<LogStash::Config::AST::Condition>
end
rule expression
(
("(" _ condition _ ")")
/ negative_expression
/ in_expression
/ not_in_expression
/ compare_expression
/ regexp_expression
/ rvalue
) <LogStash::Config::AST::Expression>
end
rule negative_expression
(
("!" _ "(" _ condition _ ")")
/ ("!" _ selector)
) <LogStash::Config::AST::NegativeExpression>
end
rule in_expression
rvalue _ in_operator _ rvalue
<LogStash::Config::AST::InExpression>
end
rule not_in_expression
rvalue _ not_in_operator _ rvalue
<LogStash::Config::AST::NotInExpression>
end
rule in_operator
"in"
end
rule not_in_operator
"not " _ "in"
end
rule rvalue
string / number / selector / array / method_call / regexp
end
rule method_call
method _ "(" _
(
rvalue ( _ "," _ rvalue )*
)?
_ ")"
<LogStash::Config::AST::MethodCall>
end
rule method
bareword
end
rule compare_expression
rvalue _ compare_operator _ rvalue
<LogStash::Config::AST::ComparisonExpression>
end
rule compare_operator
("==" / "!=" / "<=" / ">=" / "<" / ">")
<LogStash::Config::AST::ComparisonOperator>
end
rule regexp_expression
rvalue _ regexp_operator _ (string / regexp)
<LogStash::Config::AST::RegexpExpression>
end
rule regexp_operator
("=~" / "!~") <LogStash::Config::AST::RegExpOperator>
end
rule boolean_operator
("and" / "or" / "xor" / "nand")
<LogStash::Config::AST::BooleanOperator>
end
rule selector
selector_element+
<LogStash::Config::AST::Selector>
end
rule selector_element
"[" [^\],]+ "]"
<LogStash::Config::AST::SelectorElement>
end
end