summaryrefslogtreecommitdiff
path: root/pygments/lexers/data.py
diff options
context:
space:
mode:
Diffstat (limited to 'pygments/lexers/data.py')
-rw-r--r--pygments/lexers/data.py45
1 files changed, 38 insertions, 7 deletions
diff --git a/pygments/lexers/data.py b/pygments/lexers/data.py
index 84d02f49..7593b487 100644
--- a/pygments/lexers/data.py
+++ b/pygments/lexers/data.py
@@ -5,7 +5,7 @@
Lexers for data file format.
- :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
+ :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -14,9 +14,9 @@ import re
from pygments.lexer import RegexLexer, ExtendedRegexLexer, LexerContext, \
include, bygroups, inherit
from pygments.token import Text, Comment, Keyword, Name, String, Number, \
- Punctuation, Literal
+ Punctuation, Literal, Error
-__all__ = ['YamlLexer', 'JsonLexer', 'JsonLdLexer']
+__all__ = ['YamlLexer', 'JsonLexer', 'JsonBareObjectLexer', 'JsonLdLexer']
class YamlLexerContext(LexerContext):
@@ -205,7 +205,7 @@ class YamlLexer(ExtendedRegexLexer):
bygroups(Text, Number), 'ignored-line'),
],
- # the %YAG directive
+ # the %TAG directive
'tag-directive': [
# a tag handle and the corresponding prefix
(r'([ ]+)(!|![\w-]*!)'
@@ -218,7 +218,7 @@ class YamlLexer(ExtendedRegexLexer):
'indentation': [
# trailing whitespaces are ignored
(r'[ ]*$', something(Text), '#pop:2'),
- # whitespaces preceeding block collection indicators
+ # whitespaces preceding block collection indicators
(r'[ ]+(?=[?:-](?:[ ]|$))', save_indent(Text)),
# block collection indicators
(r'[?:-](?=[ ]|$)', set_indent(Punctuation.Indicator)),
@@ -232,6 +232,9 @@ class YamlLexer(ExtendedRegexLexer):
(r'[ ]*(?=#|$)', something(Text), '#pop'),
# whitespaces separating tokens
(r'[ ]+', Text),
+ # key with colon
+ (r'''([^,:?\[\]{}"'\n]+)(:)(?=[ ]|$)''',
+ bygroups(Name.Tag, set_indent(Punctuation, implicit=True))),
# tags, anchors and aliases,
include('descriptors'),
# block collections and scalars
@@ -250,7 +253,7 @@ class YamlLexer(ExtendedRegexLexer):
(r'!<[\w#;/?:@&=+$,.!~*\'()\[\]%-]+>', Keyword.Type),
# a tag in the form '!', '!suffix' or '!handle!suffix'
(r'!(?:[\w-]+!)?'
- r'[\w#;/?:@&=+$,.!~*\'()\[\]%-]+', Keyword.Type),
+ r'[\w#;/?:@&=+$,.!~*\'()\[\]%-]*', Keyword.Type),
# an anchor
(r'&[\w-]+', Name.Label),
# an alias
@@ -308,6 +311,9 @@ class YamlLexer(ExtendedRegexLexer):
# a flow mapping indicated by '{' and '}'
'flow-mapping': [
+ # key with colon
+ (r'''([^,:?\[\]{}"'\n]+)(:)(?=[ ]|$)''',
+ bygroups(Name.Tag, Punctuation)),
# include flow collection rules
include('flow-collection'),
# the closing indicator
@@ -476,7 +482,7 @@ class JsonLexer(RegexLexer):
# comma terminates the attribute but expects more
(r',', Punctuation, '#pop'),
# a closing bracket terminates the entire object, so pop twice
- (r'\}', Punctuation, ('#pop', '#pop')),
+ (r'\}', Punctuation, '#pop:2'),
],
# a json object - { attr, attr, ... }
@@ -508,6 +514,31 @@ class JsonLexer(RegexLexer):
],
}
+
+class JsonBareObjectLexer(JsonLexer):
+ """
+ For JSON data structures (with missing object curly braces).
+
+ .. versionadded:: 2.2
+ """
+
+ name = 'JSONBareObject'
+ aliases = ['json-object']
+ filenames = []
+ mimetypes = ['application/json-object']
+
+ tokens = {
+ 'root': [
+ (r'\}', Error),
+ include('objectvalue'),
+ ],
+ 'objectattribute': [
+ (r'\}', Error),
+ inherit,
+ ],
+ }
+
+
class JsonLdLexer(JsonLexer):
"""
For `JSON-LD <http://json-ld.org/>`_ linked data.