-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathebnf.pp2
199 lines (180 loc) · 4.32 KB
/
ebnf.pp2
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
/**
* Prometheus version 2.0 text-based format schema parser.
*/
/**
* --------------------------------------------------------------------------
* Values
* --------------------------------------------------------------------------
*/
%token T_WHITESPACE \s+
%token T_HELP HELP
%token T_TYPE TYPE
%token T_COMMENT ^\#\s[a-zA-Z0-9\s\.\,\!\?\:]+\:
/**
* --------------------------------------------------------------------------
* Numbers
* --------------------------------------------------------------------------
*/
%token T_FLOAT [0-9]+\.[0-9]+(e(\+|\-)?[0-9]+)?
%token T_INF (\+|\-)Inf
%token T_INT (\-)?[0-9]+
%token T_METRIC_TYPE (summary|counter|gauge|histogram|untyped)
%token T_METRIC_NAME [a-z_]+
%token T_COMMA \,
%token T_TEXT [a-zA-Z0-9\s\.\,\!\?\:]+
%token T_QUOTED_STRING \"([a-zA-Z0-9\s\.\,\!\?\:\\\"\+]+)\" // "string"
/**
* --------------------------------------------------------------------------
* Syntax
* --------------------------------------------------------------------------
*/
%token T_EQUAL \=
%token T_HASH \#
%token T_LBRACE {
%token T_RBRACE }
%token T_DOT \.
%token T_EOR \\r
%token T_EOL \\n
/**
* --------------------------------------------------------------------------
* Prometheus Grammar
* --------------------------------------------------------------------------
* @see https://prometheus.io/docs/instrumenting/exposition_formats/
*/
#Document
:
Schema()
;
#Schema -> {
return new \Butschster\Prometheus\Ast\SchemaNode($children);
}
:
MetricData()*
;
#MetricData -> {
return new \Butschster\Prometheus\Ast\MetricDataNode($children);
}
:
(
Comment()*
Help()
Type()
Metric()*
)
/**
* Possible value:
* # A histogram, which has a pretty complex representation in the text format:
*/
#Comment -> {
return new \Butschster\Prometheus\Ast\CommentNode($children);
}
: (
::T_WHITESPACE::*
<T_COMMENT>
Eol()?
)
/**
* Possible value:
* # HELP http_request_duration_seconds A histogram of the request duration.
*/
#Help -> {
return new \Butschster\Prometheus\Ast\HelpNode($children);
}
: (
::T_WHITESPACE::*
::T_HASH::
::T_WHITESPACE::
::T_HELP::
::T_WHITESPACE::
<T_METRIC_NAME>
::T_WHITESPACE::
<T_TEXT>
Eol()?
)
/**
* Possible value:
* # TYPE http_request_duration_seconds histogram
*/
#Type -> {
return new \Butschster\Prometheus\Ast\TypeNode($children);
}
: (
::T_WHITESPACE::*
::T_HASH::
::T_WHITESPACE::
::T_TYPE::
::T_WHITESPACE::
<T_METRIC_NAME>
::T_WHITESPACE::
<T_METRIC_TYPE>
Eol()?
)
/**
* Possible values:
* # Minimalistic line:
* metric_without_timestamp_and_labels 12.47
* http_requests_total{method="post",code="200"} 1027 1395066363000
* http_request_duration_seconds_sum 53423
*/
#Metric -> {
return new \Butschster\Prometheus\Ast\MetricNode($children);
}
: (
Comment()*
::T_WHITESPACE::*<T_METRIC_NAME>Labels()?::T_WHITESPACE::MetricValue()(::T_WHITESPACE::MetricTimestamp())?Eol()?
)
/**
* Possible values:
* 1027
* 3
* +Inf
* 12.47
* 1.7560473e+07
* 1.7560473e-07
* 1.458255915e9
*/
#MetricValue -> {
return new \Butschster\Prometheus\Ast\MetricValueNode($children);
}
: (
(<T_FLOAT>|<T_INT>|<T_INF>)
)
/**
* Possible values:
* 1395066363000
* -3982045
*/
#MetricTimestamp -> {
return new \Butschster\Prometheus\Ast\MetricTimestampNode($children);
}
: (
<T_INT>
)
/**
* Possible values:
* {quantile="0", test="0.25"}
* {problem="division by zero"}
* {path="C:\\DIR\\FILE.TXT",error="Cannot find file:\n\"FILE.TXT\""}
*/
#Labels -> {
return new \Butschster\Prometheus\Ast\LabelsNode($children);
}
: (
::T_LBRACE::(Label()(::T_COMMA::::T_WHITESPACE::*)?)*::T_RBRACE::
)
/**
* Possible values:
* quantile="0"
* problem="division by zero"
* path="C:\\DIR\\FILE.TXT"
* error="Cannot find file:\n\"FILE.TXT\""
*/
#Label -> {
return new \Butschster\Prometheus\Ast\LabelNode($children);
}
: (
<T_METRIC_NAME>::T_EQUAL::<T_QUOTED_STRING>
)
#Eol: (
::T_WHITESPACE::*::T_EOL::
)