1 package p
2
3 import (
4 . "github.com/alecthomas/chroma"
5 "github.com/alecthomas/chroma/lexers/internal"
6 )
7
8
9 var Promql = internal.Register(MustNewLazyLexer(
10 &Config{
11 Name: "PromQL",
12 Aliases: []string{"promql"},
13 Filenames: []string{"*.promql"},
14 MimeTypes: []string{},
15 },
16 promqlRules,
17 ))
18
19 func promqlRules() Rules {
20 return Rules{
21 "root": {
22 {`\n`, TextWhitespace, nil},
23 {`\s+`, TextWhitespace, nil},
24 {`,`, Punctuation, nil},
25 {Words(``, `\b`, `bool`, `by`, `group_left`, `group_right`, `ignoring`, `offset`, `on`, `without`), Keyword, nil},
26 {Words(``, `\b`, `sum`, `min`, `max`, `avg`, `group`, `stddev`, `stdvar`, `count`, `count_values`, `bottomk`, `topk`, `quantile`), Keyword, nil},
27 {Words(``, `\b`, `abs`, `absent`, `absent_over_time`, `avg_over_time`, `ceil`, `changes`, `clamp_max`, `clamp_min`, `count_over_time`, `day_of_month`, `day_of_week`, `days_in_month`, `delta`, `deriv`, `exp`, `floor`, `histogram_quantile`, `holt_winters`, `hour`, `idelta`, `increase`, `irate`, `label_join`, `label_replace`, `ln`, `log10`, `log2`, `max_over_time`, `min_over_time`, `minute`, `month`, `predict_linear`, `quantile_over_time`, `rate`, `resets`, `round`, `scalar`, `sort`, `sort_desc`, `sqrt`, `stddev_over_time`, `stdvar_over_time`, `sum_over_time`, `time`, `timestamp`, `vector`, `year`), KeywordReserved, nil},
28 {`[1-9][0-9]*[smhdwy]`, LiteralString, nil},
29 {`-?[0-9]+\.[0-9]+`, LiteralNumberFloat, nil},
30 {`-?[0-9]+`, LiteralNumberInteger, nil},
31 {`#.*?$`, CommentSingle, nil},
32 {`(\+|\-|\*|\/|\%|\^)`, Operator, nil},
33 {`==|!=|>=|<=|<|>`, Operator, nil},
34 {`and|or|unless`, OperatorWord, nil},
35 {`[_a-zA-Z][a-zA-Z0-9_]+`, NameVariable, nil},
36 {`(["\'])(.*?)(["\'])`, ByGroups(Punctuation, LiteralString, Punctuation), nil},
37 {`\(`, Operator, Push("function")},
38 {`\)`, Operator, nil},
39 {`\{`, Punctuation, Push("labels")},
40 {`\[`, Punctuation, Push("range")},
41 },
42 "labels": {
43 {`\}`, Punctuation, Pop(1)},
44 {`\n`, TextWhitespace, nil},
45 {`\s+`, TextWhitespace, nil},
46 {`,`, Punctuation, nil},
47 {`([_a-zA-Z][a-zA-Z0-9_]*?)(\s*?)(=~|!=|=|!~)(\s*?)("|')(.*?)("|')`, ByGroups(NameLabel, TextWhitespace, Operator, TextWhitespace, Punctuation, LiteralString, Punctuation), nil},
48 },
49 "range": {
50 {`\]`, Punctuation, Pop(1)},
51 {`[1-9][0-9]*[smhdwy]`, LiteralString, nil},
52 },
53 "function": {
54 {`\)`, Operator, Pop(1)},
55 {`\(`, Operator, Push()},
56 Default(Pop(1)),
57 },
58 }
59 }
60
View as plain text