diff options
author | Tim Hatch <tim@timhatch.com> | 2016-05-31 22:06:40 -0700 |
---|---|---|
committer | Tim Hatch <tim@timhatch.com> | 2016-05-31 22:06:40 -0700 |
commit | 11f5df043d36049fb066e41178c31c2e64410c7b (patch) | |
tree | ec6db7986fc8a1c98094c218c46c273979dcc5ec /pygments | |
parent | d352bbdf4d2f6265d4ee934799775b044eb47678 (diff) | |
download | pygments-11f5df043d36049fb066e41178c31c2e64410c7b.tar.gz |
Add a new lexer that assumes json object is already open.
Fixes #884
Diffstat (limited to 'pygments')
-rw-r--r-- | pygments/lexers/_mapping.py | 1 | ||||
-rw-r--r-- | pygments/lexers/data.py | 25 |
2 files changed, 24 insertions, 2 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index 8243d344..46948d8d 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -212,6 +212,7 @@ LEXERS = { 'JavascriptSmartyLexer': ('pygments.lexers.templates', 'JavaScript+Smarty', ('js+smarty', 'javascript+smarty'), (), ('application/x-javascript+smarty', 'text/x-javascript+smarty', 'text/javascript+smarty')), 'JclLexer': ('pygments.lexers.scripting', 'JCL', ('jcl',), ('*.jcl',), ('text/x-jcl',)), 'JsgfLexer': ('pygments.lexers.grammar_notation', 'JSGF', ('jsgf',), ('*.jsgf',), ('application/jsgf', 'application/x-jsgf', 'text/jsgf')), + 'JsonBareObjectLexer': ('pygments.lexers.data', 'JSONBareObject', ('json-object',), (), ('application/json-object',)), 'JsonLdLexer': ('pygments.lexers.data', 'JSON-LD', ('jsonld', 'json-ld'), ('*.jsonld',), ('application/ld+json',)), 'JsonLexer': ('pygments.lexers.data', 'JSON', ('json',), ('*.json',), ('application/json',)), 'JspLexer': ('pygments.lexers.templates', 'Java Server Page', ('jsp',), ('*.jsp',), ('application/x-jsp',)), diff --git a/pygments/lexers/data.py b/pygments/lexers/data.py index 84d02f49..fbc25bf2 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): @@ -508,6 +508,27 @@ 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'), + ], + } + + class JsonLdLexer(JsonLexer): """ For `JSON-LD <http://json-ld.org/>`_ linked data. |