1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-03-19 21:10:15 +02:00

Fix PromQL lexer to support values enclosed within single quotes

Values for labels could now be enclosed within single or double quotes.
This commit is contained in:
Pablo Seminario 2021-04-24 21:33:58 +02:00 committed by Alec Thomas
parent d11bdacff4
commit b790655195
3 changed files with 19 additions and 1 deletions

View File

@ -44,7 +44,7 @@ func promqlRules() Rules {
{`\n`, TextWhitespace, nil}, {`\n`, TextWhitespace, nil},
{`\s+`, TextWhitespace, nil}, {`\s+`, TextWhitespace, nil},
{`,`, Punctuation, 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": { "range": {
{`\]`, Punctuation, Pop(1)}, {`\]`, Punctuation, Pop(1)},

View File

@ -28,3 +28,6 @@ label_replace(
"instance", "instance",
".*" ".*"
) )
# Values for labels enclosed within single quotes
metric_test_app{app='turtle',proc='web'}

View File

@ -165,5 +165,20 @@
{"type":"Punctuation","value":"\""}, {"type":"Punctuation","value":"\""},
{"type":"TextWhitespace","value":"\n"}, {"type":"TextWhitespace","value":"\n"},
{"type":"Operator","value":")"}, {"type":"Operator","value":")"},
{"type":"TextWhitespace","value":"\n\n"},
{"type":"CommentSingle","value":"# Values for labels enclosed within single quotes"},
{"type":"TextWhitespace","value":"\n"},
{"type":"NameVariable","value":"metric_test_app"},
{"type":"Punctuation","value":"{"},
{"type":"NameLabel","value":"app"},
{"type":"Operator","value":"="},
{"type":"Punctuation","value":"'"},
{"type":"LiteralString","value":"turtle"},
{"type":"Punctuation","value":"',"},
{"type":"NameLabel","value":"proc"},
{"type":"Operator","value":"="},
{"type":"Punctuation","value":"'"},
{"type":"LiteralString","value":"web"},
{"type":"Punctuation","value":"'}"},
{"type":"TextWhitespace","value":"\n"} {"type":"TextWhitespace","value":"\n"}
] ]