3 pygments.lexers.data |
3 pygments.lexers.data |
4 ~~~~~~~~~~~~~~~~~~~~ |
4 ~~~~~~~~~~~~~~~~~~~~ |
5 |
5 |
6 Lexers for data file format. |
6 Lexers for data file format. |
7 |
7 |
8 :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. |
8 :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. |
9 :license: BSD, see LICENSE for details. |
9 :license: BSD, see LICENSE for details. |
10 """ |
10 """ |
11 |
11 |
12 import re |
12 import re |
13 |
13 |
14 from pygments.lexer import RegexLexer, ExtendedRegexLexer, LexerContext, \ |
14 from pygments.lexer import RegexLexer, ExtendedRegexLexer, LexerContext, \ |
15 include, bygroups, inherit |
15 include, bygroups, inherit |
16 from pygments.token import Text, Comment, Keyword, Name, String, Number, \ |
16 from pygments.token import Text, Comment, Keyword, Name, String, Number, \ |
17 Punctuation, Literal |
17 Punctuation, Literal, Error |
18 |
18 |
19 __all__ = ['YamlLexer', 'JsonLexer', 'JsonLdLexer'] |
19 __all__ = ['YamlLexer', 'JsonLexer', 'JsonBareObjectLexer', 'JsonLdLexer'] |
20 |
20 |
21 |
21 |
22 class YamlLexerContext(LexerContext): |
22 class YamlLexerContext(LexerContext): |
23 """Indentation context for the YAML lexer.""" |
23 """Indentation context for the YAML lexer.""" |
24 |
24 |
245 ], |
245 ], |
246 |
246 |
247 # tags, anchors, aliases |
247 # tags, anchors, aliases |
248 'descriptors': [ |
248 'descriptors': [ |
249 # a full-form tag |
249 # a full-form tag |
250 (r'!<[\w;/?:@&=+$,.!~*\'()\[\]%-]+>', Keyword.Type), |
250 (r'!<[\w#;/?:@&=+$,.!~*\'()\[\]%-]+>', Keyword.Type), |
251 # a tag in the form '!', '!suffix' or '!handle!suffix' |
251 # a tag in the form '!', '!suffix' or '!handle!suffix' |
252 (r'!(?:[\w-]+)?' |
252 (r'!(?:[\w-]+!)?' |
253 r'(?:![\w;/?:@&=+$,.!~*\'()\[\]%-]+)?', Keyword.Type), |
253 r'[\w#;/?:@&=+$,.!~*\'()\[\]%-]+', Keyword.Type), |
254 # an anchor |
254 # an anchor |
255 (r'&[\w-]+', Name.Label), |
255 (r'&[\w-]+', Name.Label), |
256 # an alias |
256 # an alias |
257 (r'\*[\w-]+', Name.Variable), |
257 (r'\*[\w-]+', Name.Variable), |
258 ], |
258 ], |
474 include('value'), |
474 include('value'), |
475 (r':', Punctuation), |
475 (r':', Punctuation), |
476 # comma terminates the attribute but expects more |
476 # comma terminates the attribute but expects more |
477 (r',', Punctuation, '#pop'), |
477 (r',', Punctuation, '#pop'), |
478 # a closing bracket terminates the entire object, so pop twice |
478 # a closing bracket terminates the entire object, so pop twice |
479 (r'\}', Punctuation, ('#pop', '#pop')), |
479 (r'\}', Punctuation, '#pop:2'), |
480 ], |
480 ], |
481 |
481 |
482 # a json object - { attr, attr, ... } |
482 # a json object - { attr, attr, ... } |
483 'objectvalue': [ |
483 'objectvalue': [ |
484 include('whitespace'), |
484 include('whitespace'), |
506 'root': [ |
506 'root': [ |
507 include('value'), |
507 include('value'), |
508 ], |
508 ], |
509 } |
509 } |
510 |
510 |
|
511 |
|
512 class JsonBareObjectLexer(JsonLexer): |
|
513 """ |
|
514 For JSON data structures (with missing object curly braces). |
|
515 |
|
516 .. versionadded:: 2.2 |
|
517 """ |
|
518 |
|
519 name = 'JSONBareObject' |
|
520 aliases = ['json-object'] |
|
521 filenames = [] |
|
522 mimetypes = ['application/json-object'] |
|
523 |
|
524 tokens = { |
|
525 'root': [ |
|
526 (r'\}', Error), |
|
527 include('objectvalue'), |
|
528 ], |
|
529 'objectattribute': [ |
|
530 (r'\}', Error), |
|
531 inherit, |
|
532 ], |
|
533 } |
|
534 |
|
535 |
511 class JsonLdLexer(JsonLexer): |
536 class JsonLdLexer(JsonLexer): |
512 """ |
537 """ |
513 For `JSON-LD <http://json-ld.org/>`_ linked data. |
538 For `JSON-LD <http://json-ld.org/>`_ linked data. |
514 |
539 |
515 .. versionadded:: 2.0 |
540 .. versionadded:: 2.0 |