diff --git a/pygments/lexers/data.py b/pygments/lexers/data.py index e7d0a8436d..d1887304c7 100644 --- a/pygments/lexers/data.py +++ b/pygments/lexers/data.py @@ -231,7 +231,7 @@ def callback(lexer, match, context): # whitespaces separating tokens (r'[ ]+', Whitespace), # key with colon - (r'''([^#,:?\[\]{}"'\n]+)(:)(?=[ ]|$)''', + (r'''([^#,?\[\]{}"'\n]+)(:)(?=[ ]|$)''', bygroups(Name.Tag, set_indent(Punctuation, implicit=True))), # tags, anchors and aliases, include('descriptors'), diff --git a/tests/snippets/yaml/test_yaml_colon_in_key.txt b/tests/snippets/yaml/test_yaml_colon_in_key.txt new file mode 100644 index 0000000000..9f3d313666 --- /dev/null +++ b/tests/snippets/yaml/test_yaml_colon_in_key.txt @@ -0,0 +1,11 @@ +# Colon in the key name is accepted by the YAML specs too + +---input--- +foo:bar: value + +---tokens--- +'foo:bar' Name.Tag +':' Punctuation +' ' Text.Whitespace +'value' Literal.Scalar.Plain +'\n' Text.Whitespace diff --git a/tests/snippets/yaml/test_yaml_colon_in_key_double.txt b/tests/snippets/yaml/test_yaml_colon_in_key_double.txt new file mode 100644 index 0000000000..6f68b6d37e --- /dev/null +++ b/tests/snippets/yaml/test_yaml_colon_in_key_double.txt @@ -0,0 +1,11 @@ +# Colons in the key name is accepted by the YAML specs too + +---input--- +foo::bar: value + +---tokens--- +'foo::bar' Name.Tag +':' Punctuation +' ' Text.Whitespace +'value' Literal.Scalar.Plain +'\n' Text.Whitespace diff --git a/tests/snippets/yaml/test_yaml_colon_in_key_start.txt b/tests/snippets/yaml/test_yaml_colon_in_key_start.txt new file mode 100644 index 0000000000..60d4e2349a --- /dev/null +++ b/tests/snippets/yaml/test_yaml_colon_in_key_start.txt @@ -0,0 +1,11 @@ +# Colon at the beginning of the key name is accepted by the YAML specs too + +---input--- +:foo: value + +---tokens--- +':foo' Name.Tag +':' Punctuation +' ' Text.Whitespace +'value' Literal.Scalar.Plain +'\n' Text.Whitespace