summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPablo Seminario <pablo@seminar.io>2021-04-24 08:00:37 +0200
committerGitHub <noreply@github.com>2021-04-24 08:00:37 +0200
commit9ea4c265fea25f370585099836f68a22a056c282 (patch)
tree0b80e5a57f740cad8d7ea6f87855b0e76e81a2bf
parent91d9f54bddc01027654b5c1773f65c7cfb184f02 (diff)
downloadpygments-git-9ea4c265fea25f370585099836f68a22a056c282.tar.gz
Improve PromQL lexer with new test cases (#1783)
* Fix PromQL lexer to support values enclosed within single quotes Values for labels could now be enclosed within single or double quotes. * Fix a typo into the lables regex for PromQL lexer The correct label matching operator is `!~` instead of `~!`.
-rw-r--r--pygments/lexers/promql.py2
-rw-r--r--tests/snippets/promql/test_complex_exp_single_quotes.txt35
-rw-r--r--tests/snippets/promql/test_matching_operator_no_regex_match.txt16
3 files changed, 52 insertions, 1 deletions
diff --git a/pygments/lexers/promql.py b/pygments/lexers/promql.py
index e58182c8..b9646d46 100644
--- a/pygments/lexers/promql.py
+++ b/pygments/lexers/promql.py
@@ -166,7 +166,7 @@ class PromQLLexer(RegexLexer):
(r"\n", Whitespace),
(r"\s+", Whitespace),
(r",", Punctuation),
- (r'([_a-zA-Z][a-zA-Z0-9_]*?)(\s*?)(=~|!=|=|~!)(\s*?)(")(.*?)(")',
+ (r'([_a-zA-Z][a-zA-Z0-9_]*?)(\s*?)(=~|!=|=|!~)(\s*?)("|\')(.*?)("|\')',
bygroups(Name.Label, Whitespace, Operator, Whitespace,
Punctuation, String, Punctuation)),
],
diff --git a/tests/snippets/promql/test_complex_exp_single_quotes.txt b/tests/snippets/promql/test_complex_exp_single_quotes.txt
new file mode 100644
index 00000000..cbbde3a6
--- /dev/null
+++ b/tests/snippets/promql/test_complex_exp_single_quotes.txt
@@ -0,0 +1,35 @@
+---input---
+(sum(rate(metric_test_app{app='turtle',proc='web'}[2m])) by(node))
+
+---tokens---
+'(' Operator
+'sum' Keyword
+'(' Operator
+'rate' Keyword.Reserved
+'(' Operator
+'metric_test_app' Name.Variable
+'{' Punctuation
+'app' Name.Label
+'=' Operator
+"'" Punctuation
+'turtle' Literal.String
+"'" Punctuation
+',' Punctuation
+'proc' Name.Label
+'=' Operator
+"'" Punctuation
+'web' Literal.String
+"'" Punctuation
+'}' Punctuation
+'[' Punctuation
+'2m' Literal.String
+']' Punctuation
+')' Operator
+')' Operator
+' ' Text.Whitespace
+'by' Keyword
+'(' Operator
+'node' Name.Variable
+')' Operator
+')' Operator
+'\n' Text.Whitespace
diff --git a/tests/snippets/promql/test_matching_operator_no_regex_match.txt b/tests/snippets/promql/test_matching_operator_no_regex_match.txt
new file mode 100644
index 00000000..98597392
--- /dev/null
+++ b/tests/snippets/promql/test_matching_operator_no_regex_match.txt
@@ -0,0 +1,16 @@
+---input---
+metric_test_app{status!~'(4|5)..'}[2m]
+
+---tokens---
+'metric_test_app' Name.Variable
+'{' Punctuation
+'status' Name.Label
+'!~' Operator
+"'" Punctuation
+'(4|5)..' Literal.String
+"'" Punctuation
+'}' Punctuation
+'[' Punctuation
+'2m' Literal.String
+']' Punctuation
+'\n' Text.Whitespace