-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprom.py
32 lines (28 loc) · 904 Bytes
/
prom.py
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
# Based on pygments documentation
from pygments.lexer import RegexLexer, bygroups
from pygments.token import *
__all__ = ['PrometheusLexer']
class PrometheusLexer(RegexLexer):
name = 'Prometheus'
aliases = ['prom', 'prometheus']
filenames = ['*.prom']
tokens = {
'root': [
(r'^#.*$', Comment),
(r'[a-zA-Z0-9_]+', Name.Tag, ('maybe_dimensions')),
],
'value': [
(r'[0-9]+(\.[0-9]+(e[-+][0-9]+)?)?$', Number.Float),
],
'maybe_dimensions': [
(r'\s+', Text, ('#pop', 'value')),
(r'\{', Punctuation, 'dimensions'),
(r'\}', Punctuation, '#pop'),
],
'dimensions': [
(r',', Punctuation),
(r'\}', Punctuation, '#pop'),
(r'([^=}]+)(=)("[^"]*")',
bygroups(Name.Attribute, Operator, String.Double)),
],
}