-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammar.js
181 lines (154 loc) · 3.22 KB
/
grammar.js
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
// TODO: better way to handle string quotes (singel and double)?
// TODO: check for regexp correctness wrt what Logstash accepts
const integer_literal = /[+-]?(0|[1-9](_?[0-9])*)/;
module.exports = grammar({
name: 'logstash_pipeline',
extras: $ => [
$.comment,
/\s/,
/\\\r?\n/
],
rules: {
source_file: $ => repeat($._section_definition),
_section_definition: $ => choice(
$.input_definition,
$.filter_definition,
$.output_definition,
),
input_definition: $ => seq(
'input',
$.section_block,
),
filter_definition: $ => seq(
'filter',
$.section_block,
),
output_definition: $ => seq(
'output',
$.section_block,
),
section_block: $ => seq(
'{',
repeat($.plugin_definition),
'}',
),
plugin_definition: $ => seq(
$.identifier,
$.plugin_block,
),
plugin_block: $ => seq(
'{',
repeat($.setting_statement),
'}',
),
setting_statement: $ => seq(
$.identifier,
'=>',
$._value,
),
_value: $ => choice(
$.boolean_literal,
$._number_literal,
$.bytes_literal,
$.string_literal,
//$.array,
//$.list,
$.hash,
),
boolean_literal: $ => choice(
'true',
'false',
),
// TODO: leave as hidden? a number is either an integer or float
_number_literal: $ => choice(
$.integer_literal,
$.float_literal,
),
integer_literal: $ => integer_literal,
// TODO: check for regexp correctness wrt what Logstash accepts
float_literal: $ => token(
seq(
integer_literal,
/[.][0-9](_?[0-9])*/,
),
),
// TODO: check for regexp correctness wrt what Logstash accepts
bytes_literal: $ => token(
choice(
seq(
'"',
/[0-9](_?[0-9])*/,
optional(/[\s]?[KkMmGgTtPpEeZzYy][Ii]?[Bb]/),
'"',
),
seq(
"'",
/[0-9](_?[0-9])*/,
optional(/[\s]?[KkMmGgTtPpEeZzYy][Ii]?[Bb]/),
"'",
),
),
),
string_literal: $ => token(
choice(
seq(
'"',
/(\\.|[^\"])*/,
'"',
),
seq(
"'",
/(\\.|[^\'])*/,
"'",
),
),
),
hash: $ => seq(
'{',
repeat($.hash_entry),
'}',
),
hash_entry: $ => seq(
$.hash_key,
'=>',
$.hash_value,
),
// TODO: check if single quotes are allowed for hash keys
hash_key: $ => token(
choice(
seq(
'"',
/[a-z0-9-_]+/,
'"',
),
seq(
"'",
/[a-z0-9-_]+/,
"'",
),
),
),
// TODO: unify with string literal since it is the same?
// TODO: check if single quotes are allowed for hash values
hash_value: $ => token(
choice(
seq(
'"',
/(\\.|[^\"])*/,
'"',
),
seq(
"'",
/(\\.|[^\'])*/,
"'",
),
),
),
// TODO: check for regexp correctness wrt what Logstash accepts
identifier: $ => /[a-z-_]+/,
comment: $ => seq(
'#',
/.*/
),
}
});