Skip to content

Commit

Permalink
Accept colon(s) in YAML key names
Browse files Browse the repository at this point in the history
as it's ok according to the YAML specs and is widely used in the real world,
f.e. in Puppet's Hiera (https://puppet.com/docs/puppet/7/hiera_quick.html#values_common_data)
  • Loading branch information
gdubicki authored and birkenfeld committed Nov 14, 2022
1 parent 8abbd68 commit 9aa5fc0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pygments/lexers/data.py
Expand Up @@ -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'),
Expand Down
11 changes: 11 additions & 0 deletions 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
11 changes: 11 additions & 0 deletions 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
11 changes: 11 additions & 0 deletions 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

0 comments on commit 9aa5fc0

Please sign in to comment.