diff --git a/lexers/p/promql.go b/lexers/p/promql.go index e49ac07..e80b926 100644 --- a/lexers/p/promql.go +++ b/lexers/p/promql.go @@ -44,7 +44,7 @@ func promqlRules() Rules { {`\n`, TextWhitespace, nil}, {`\s+`, TextWhitespace, nil}, {`,`, Punctuation, nil}, - {`([_a-zA-Z][a-zA-Z0-9_]*?)(\s*?)(=~|!=|=|~!)(\s*?)("|')(.*?)("|')`, ByGroups(NameLabel, TextWhitespace, Operator, TextWhitespace, Punctuation, LiteralString, Punctuation), nil}, + {`([_a-zA-Z][a-zA-Z0-9_]*?)(\s*?)(=~|!=|=|!~)(\s*?)("|')(.*?)("|')`, ByGroups(NameLabel, TextWhitespace, Operator, TextWhitespace, Punctuation, LiteralString, Punctuation), nil}, }, "range": { {`\]`, Punctuation, Pop(1)}, diff --git a/lexers/testdata/promql.actual b/lexers/testdata/promql.actual index ebf99f6..9392bb2 100644 --- a/lexers/testdata/promql.actual +++ b/lexers/testdata/promql.actual @@ -31,3 +31,6 @@ label_replace( # Values for labels enclosed within single quotes metric_test_app{app='turtle',proc='web'} + +# Use label matching operator `!~` +metric_test_app{status!~'(4|5)..'} diff --git a/lexers/testdata/promql.expected b/lexers/testdata/promql.expected index 1537c43..9d572e6 100644 --- a/lexers/testdata/promql.expected +++ b/lexers/testdata/promql.expected @@ -180,5 +180,15 @@ {"type":"Punctuation","value":"'"}, {"type":"LiteralString","value":"web"}, {"type":"Punctuation","value":"'}"}, + {"type":"TextWhitespace","value":"\n\n"}, + {"type":"CommentSingle","value":"# Use label matching operator `!~`"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"NameVariable","value":"metric_test_app"}, + {"type":"Punctuation","value":"{"}, + {"type":"NameLabel","value":"status"}, + {"type":"Operator","value":"!~"}, + {"type":"Punctuation","value":"'"}, + {"type":"LiteralString","value":"(4|5).."}, + {"type":"Punctuation","value":"'}"}, {"type":"TextWhitespace","value":"\n"} ]