Skip to content

Commit b790655

Browse files
pablukalecthomas
authored andcommitted
Fix PromQL lexer to support values enclosed within single quotes
Values for labels could now be enclosed within single or double quotes.
1 parent d11bdac commit b790655

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

Diff for: lexers/p/promql.go

+1-1
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)},

Diff for: lexers/testdata/promql.actual

+3
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ label_replace(
2828
"instance",
2929
".*"
3030
)
31+
32+
# Values for labels enclosed within single quotes
33+
metric_test_app{app='turtle',proc='web'}

Diff for: lexers/testdata/promql.expected

+15
Original file line numberDiff line numberDiff line change
@@ -165,5 +165,20 @@
165165
{"type":"Punctuation","value":"\""},
166166
{"type":"TextWhitespace","value":"\n"},
167167
{"type":"Operator","value":")"},
168+
{"type":"TextWhitespace","value":"\n\n"},
169+
{"type":"CommentSingle","value":"# Values for labels enclosed within single quotes"},
170+
{"type":"TextWhitespace","value":"\n"},
171+
{"type":"NameVariable","value":"metric_test_app"},
172+
{"type":"Punctuation","value":"{"},
173+
{"type":"NameLabel","value":"app"},
174+
{"type":"Operator","value":"="},
175+
{"type":"Punctuation","value":"'"},
176+
{"type":"LiteralString","value":"turtle"},
177+
{"type":"Punctuation","value":"',"},
178+
{"type":"NameLabel","value":"proc"},
179+
{"type":"Operator","value":"="},
180+
{"type":"Punctuation","value":"'"},
181+
{"type":"LiteralString","value":"web"},
182+
{"type":"Punctuation","value":"'}"},
168183
{"type":"TextWhitespace","value":"\n"}
169184
]

0 commit comments

Comments
 (0)