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.py31
1 files changed, 28 insertions, 3 deletions
diff --git a/pygments/lexers/data.py b/pygments/lexers/data.py
index 84d02f49..4c39db64 100644
--- a/pygments/lexers/data.py
+++ b/pygments/lexers/data.py
@@ -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):
@@ -476,7 +476,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 +508,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.