From fdbd4b8fda9db85caab00c7734a9decd3a72e8f0 Mon Sep 17 00:00:00 2001 From: "Erik M. Bray" Date: Thu, 14 Apr 2016 12:03:32 +0200 Subject: Fixes two issues: Allows special characters in tag names (but not in named tag handles, which are still just limited to [\w-]). Also allows the # character in tag names, which technically should be allowed. Adds a regression test which previously caused an error due to the foo/bar tag being parsed as just foo, resulting an in rest of the line being parsed as an invalid scalar. --- pygments/lexers/data.py | 6 +++--- tests/examplefiles/example.yaml | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/pygments/lexers/data.py b/pygments/lexers/data.py index c88375d5..84d02f49 100644 --- a/pygments/lexers/data.py +++ b/pygments/lexers/data.py @@ -247,10 +247,10 @@ class YamlLexer(ExtendedRegexLexer): # tags, anchors, aliases 'descriptors': [ # a full-form tag - (r'!<[\w;/?:@&=+$,.!~*\'()\[\]%-]+>', Keyword.Type), + (r'!<[\w#;/?:@&=+$,.!~*\'()\[\]%-]+>', Keyword.Type), # a tag in the form '!', '!suffix' or '!handle!suffix' - (r'!(?:[\w-]+)?' - r'(?:![\w;/?:@&=+$,.!~*\'()\[\]%-]+)?', Keyword.Type), + (r'!(?:[\w-]+!)?' + r'[\w#;/?:@&=+$,.!~*\'()\[\]%-]+', Keyword.Type), # an anchor (r'&[\w-]+', Name.Label), # an alias diff --git a/tests/examplefiles/example.yaml b/tests/examplefiles/example.yaml index 9c0ed9d0..17544c02 100644 --- a/tests/examplefiles/example.yaml +++ b/tests/examplefiles/example.yaml @@ -1,3 +1,12 @@ +# +# Regression tests +# + +%TAG ! tag:example.com:foo/ +--- +test: !foo/bar {a: 'asdf'} +test2: fred +... # # Examples from the Preview section of the YAML specification -- cgit v1.2.1