Add support for enum.Flag in ReprHighlighter

enum.Flag allows more than one bit to be set, and its repr will show
something like <Permission.READ|WRITE: 3>.

For this to display correctly, we need to add the pipe symbol to the
tag regex.
This commit is contained in:
Dennis Brakhane 2022-02-05 19:12:21 +01:00
parent 880693db5b
commit eb6b5ef87a
2 changed files with 11 additions and 1 deletions

View File

@ -81,7 +81,7 @@ class ReprHighlighter(RegexHighlighter):
base_style = "repr."
highlights = [
r"(?P<tag_start>\<)(?P<tag_name>[\w\-\.\:]*)(?P<tag_contents>[\w\W]*?)(?P<tag_end>\>)",
r"(?P<tag_start>\<)(?P<tag_name>[\w\-\.\:\|]*)(?P<tag_contents>[\w\W]*?)(?P<tag_end>\>)",
r"(?P<attrib_name>[\w_]{1,50})=(?P<attrib_value>\"?[\w_]+\"?)?",
r"(?P<brace>[\{\[\(\)\]\}])",
_combine_regex(

View File

@ -40,6 +40,16 @@ highlight_tests = [
Span(4, 9, "repr.str"),
],
),
(
"<Permission.WRITE|READ: 3>",
[
Span(0, 1, "repr.tag_start"),
Span(1, 23, "repr.tag_name"),
Span(23, 25, "repr.tag_contents"),
Span(25, 26, "repr.tag_end"),
Span(24, 25, "repr.number"),
],
),
("( )", [Span(0, 1, "repr.brace"), Span(2, 3, "repr.brace")]),
("[ ]", [Span(0, 1, "repr.brace"), Span(2, 3, "repr.brace")]),
("{ }", [Span(0, 1, "repr.brace"), Span(2, 3, "repr.brace")]),