Skip to content

Commit 9866a75

Browse files
pablukalecthomas
authored andcommitted
Fix a typo into the lables regex for PromQL lexer
The correct label matching operator is `!~` instead of `~!`.
1 parent b790655 commit 9866a75

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

lexers/p/promql.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func promqlRules() Rules {
4444
{`\n`, TextWhitespace, nil},
4545
{`\s+`, TextWhitespace, nil},
4646
{`,`, Punctuation, nil},
47-
{`([_a-zA-Z][a-zA-Z0-9_]*?)(\s*?)(=~|!=|=|~!)(\s*?)("|')(.*?)("|')`, ByGroups(NameLabel, TextWhitespace, Operator, TextWhitespace, Punctuation, LiteralString, Punctuation), nil},
47+
{`([_a-zA-Z][a-zA-Z0-9_]*?)(\s*?)(=~|!=|=|!~)(\s*?)("|')(.*?)("|')`, ByGroups(NameLabel, TextWhitespace, Operator, TextWhitespace, Punctuation, LiteralString, Punctuation), nil},
4848
},
4949
"range": {
5050
{`\]`, Punctuation, Pop(1)},

lexers/testdata/promql.actual

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ label_replace(
3131

3232
# Values for labels enclosed within single quotes
3333
metric_test_app{app='turtle',proc='web'}
34+
35+
# Use label matching operator `!~`
36+
metric_test_app{status!~'(4|5)..'}

lexers/testdata/promql.expected

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,5 +180,15 @@
180180
{"type":"Punctuation","value":"'"},
181181
{"type":"LiteralString","value":"web"},
182182
{"type":"Punctuation","value":"'}"},
183+
{"type":"TextWhitespace","value":"\n\n"},
184+
{"type":"CommentSingle","value":"# Use label matching operator `!~`"},
185+
{"type":"TextWhitespace","value":"\n"},
186+
{"type":"NameVariable","value":"metric_test_app"},
187+
{"type":"Punctuation","value":"{"},
188+
{"type":"NameLabel","value":"status"},
189+
{"type":"Operator","value":"!~"},
190+
{"type":"Punctuation","value":"'"},
191+
{"type":"LiteralString","value":"(4|5).."},
192+
{"type":"Punctuation","value":"'}"},
183193
{"type":"TextWhitespace","value":"\n"}
184194
]

0 commit comments

Comments
 (0)