# -*- coding: utf-8 -*- """ pygments.lexers.data ~~~~~~~~~~~~~~~~~~~~ Lexers for data file format. :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ import re from pygments.lexer import RegexLexer, ExtendedRegexLexer, LexerContext, \ include, bygroups, inherit from pygments.token import Text, Comment, Keyword, Name, String, Number, \ Punctuation, Literal, Error __all__ = ['YamlLexer', 'JsonLexer', 'JsonBareObjectLexer', 'JsonLdLexer'] class YamlLexerContext(LexerContext): """Indentation context for the YAML lexer.""" def __init__(self, *args, **kwds): super(YamlLexerContext, self).__init__(*args, **kwds) self.indent_stack = [] self.indent = -1 self.next_indent = 0 self.block_scalar_indent = None class YamlLexer(ExtendedRegexLexer): """ Lexer for `YAML <http://yaml.org/>`_, a human-friendly data serialization language. .. versionadded:: 0.11 """ name = 'YAML' aliases = ['yaml'] filenames = ['*.yaml', '*.yml'] mimetypes = ['text/x-yaml'] def something(token_class): """Do not produce empty tokens.""" def callback(lexer, match, context): text = match.group() if not text: return yield match.start(), token_class, text context.pos = match.end() return callback def reset_indent(token_class): """Reset the indentation levels.""" def callback(lexer, match, context): text = match.group() context.indent_stack = [] context.indent = -1 context.next_indent = 0 context.block_scalar_indent = None yield match.start(), token_class, text context.pos = match.end() return callback def save_indent(token_class, start=False): """Save a possible indentation level.""" def callback(lexer, match, context): text = match.group() extra = '' if start: context.next_indent = len(text) if context.next_indent < context.indent: while context.next_indent < context.indent: context.indent = context.indent_stack.pop() if context.next_indent > context.indent: extra = text[context.indent:] text = text[:context.indent] else: context.next_indent += len(text) if text: yield match.start(), token_class, text if extra: yield match.start()+len(text), token_class.Error, extra context.pos = match.end() return callback def set_indent(token_class, implicit=False): """Set the previously saved indentation level.""" def callback(lexer, match, context): text = match.group() if context.indent < context.next_indent: context.indent_stack.append(context.indent) context.indent = context.next_indent if not implicit: context.next_indent += len(text) yield match.start(), token_class, text context.pos = match.end() return callback def set_block_scalar_indent(token_class): """Set an explicit indentation level for a block scalar.""" def callback(lexer, match, context): text = match.group() context.block_scalar_indent = None if not text: return increment = match.group(1) if increment: current_indent = max(context.indent, 0) increment = int(increment) context.block_scalar_indent = current_indent + increment if text: yield match.start(), token_class, text context.pos = match.end() return callback def parse_block_scalar_empty_line(indent_token_class, content_token_class): """Process an empty line in a block scalar.""" def callback(lexer, match, context): text = match.group() if (context.block_scalar_indent is None or len(text) <= context.block_scalar_indent): if text: yield match.start(), indent_token_class, text else: indentation = text[:context.block_scalar_indent] content = text[context.block_scalar_indent:] yield match.start(), indent_token_class, indentation yield (match.start()+context.block_scalar_indent, content_token_class, content) context.pos = match.end() return callback def parse_block_scalar_indent(token_class): """Process indentation spaces in a block scalar.""" def callback(lexer, match, context): text = match.group() if context.block_scalar_indent is None: if len(text) <= max(context.indent, 0): context.stack.pop() context.stack.pop() return context.block_scalar_indent = len(text) else: if len(text) < context.block_scalar_indent: context.stack.pop() context.stack.pop() return if text: yield match.start(), token_class, text context.pos = match.end() return callback def parse_plain_scalar_indent(token_class): """Process indentation spaces in a plain scalar.""" def callback(lexer, match, context): text = match.group() if len(text) <= context.indent: context.stack.pop() context.stack.pop() return if text: yield match.start(), token_class, text context.pos = match.end() return callback tokens = { # the root rules 'root': [ # ignored whitespaces (r'[ ]+(?=#|$)', Text), # line breaks (r'\n+', Text), # a comment (r'#[^\n]*', Comment.Single), # the '%YAML' directive (r'^%YAML(?=[ ]|$)', reset_indent(Name.Tag), 'yaml-directive'), # the %TAG directive (r'^%TAG(?=[ ]|$)', reset_indent(Name.Tag), 'tag-directive'), # document start and document end indicators (r'^(?:---|\.\.\.)(?=[ ]|$)', reset_indent(Name.Namespace), 'block-line'), # indentation spaces (r'[ ]*(?!\s|$)', save_indent(Text, start=True), ('block-line', 'indentation')), ], # trailing whitespaces after directives or a block scalar indicator 'ignored-line': [ # ignored whitespaces (r'[ ]+(?=#|$)', Text), # a comment (r'#[^\n]*', Comment.Single), # line break (r'\n', Text, '#pop:2'), ], # the %YAML directive 'yaml-directive': [ # the version number (r'([ ]+)([0-9]+\.[0-9]+)', bygroups(Text, Number), 'ignored-line'), ], # the %YAG directive 'tag-directive': [ # a tag handle and the corresponding prefix (r'([ ]+)(!|![\w-]*!)' r'([ ]+)(!|!?[\w;/?:@&=+$,.!~*\'()\[\]%-]+)', bygroups(Text, Keyword.Type, Text, Keyword.Type), 'ignored-line'), ], # block scalar indicators and indentation spaces 'indentation': [ # trailing whitespaces are ignored (r'[ ]*$', something(Text), '#pop:2'), # whitespaces preceeding block collection indicators (r'[ ]+(?=[?:-](?:[ ]|$))', save_indent(Text)), # block collection indicators (r'[?:-](?=[ ]|$)', set_indent(Punctuation.Indicator)), # the beginning a block line (r'[ ]*', save_indent(Text), '#pop'), ], # an indented line in the block context 'block-line': [ # the line end (r'[ ]*(?=#|$)', something(Text), '#pop'), # whitespaces separating tokens (r'[ ]+', Text), # tags, anchors and aliases, include('descriptors'), # block collections and scalars include('block-nodes'), # flow collections and quoted scalars include('flow-nodes'), # a plain scalar (r'(?=[^\s?:,\[\]{}#&*!|>\'"%@`-]|[?:-]\S)', something(Name.Variable), 'plain-scalar-in-block-context'), ], # tags, anchors, aliases 'descriptors': [ # a full-form tag (r'!<[\w#;/?:@&=+$,.!~*\'()\[\]%-]+>', Keyword.Type), # a tag in the form '!', '!suffix' or '!handle!suffix' (r'!(?:[\w-]+!)?' r'[\w#;/?:@&=+$,.!~*\'()\[\]%-]+', Keyword.Type), # an anchor (r'&[\w-]+', Name.Label), # an alias (r'\*[\w-]+', Name.Variable), ], # block collections and scalars 'block-nodes': [ # implicit key (r':(?=[ ]|$)', set_indent(Punctuation.Indicator, implicit=True)), # literal and folded scalars (r'[|>]', Punctuation.Indicator, ('block-scalar-content', 'block-scalar-header')), ], # flow collections and quoted scalars 'flow-nodes': [ # a flow sequence (r'\[', Punctuation.Indicator, 'flow-sequence'), # a flow mapping (r'\{', Punctuation.Indicator, 'flow-mapping'), # a single-quoted scalar (r'\'', String, 'single-quoted-scalar'), # a double-quoted scalar (r'\"', String, 'double-quoted-scalar'), ], # the content of a flow collection 'flow-collection': [ # whitespaces (r'[ ]+', Text), # line breaks (r'\n+', Text), # a comment (r'#[^\n]*', Comment.Single), # simple indicators (r'[?:,]', Punctuation.Indicator), # tags, anchors and aliases include('descriptors'), # nested collections and quoted scalars include('flow-nodes'), # a plain scalar (r'(?=[^\s?:,\[\]{}#&*!|>\'"%@`])', something(Name.Variable), 'plain-scalar-in-flow-context'), ], # a flow sequence indicated by '[' and ']' 'flow-sequence': [ # include flow collection rules include('flow-collection'), # the closing indicator (r'\]', Punctuation.Indicator, '#pop'), ], # a flow mapping indicated by '{' and '}' 'flow-mapping': [ # include flow collection rules include('flow-collection'), # the closing indicator (r'\}', Punctuation.Indicator, '#pop'), ], # block scalar lines 'block-scalar-content': [ # line break (r'\n', Text), # empty line (r'^[ ]+$', parse_block_scalar_empty_line(Text, Name.Constant)), # indentation spaces (we may leave the state here) (r'^[ ]*', parse_block_scalar_indent(Text)), # line content (r'[\S\t ]+', Name.Constant), ], # the content of a literal or folded scalar 'block-scalar-header': [ # indentation indicator followed by chomping flag (r'([1-9])?[+-]?(?=[ ]|$)', set_block_scalar_indent(Punctuation.Indicator), 'ignored-line'), # chomping flag followed by indentation indicator (r'[+-]?([1-9])?(?=[ ]|$)', set_block_scalar_indent(Punctuation.Indicator), 'ignored-line'), ], # ignored and regular whitespaces in quoted scalars 'quoted-scalar-whitespaces': [ # leading and trailing whitespaces are ignored (r'^[ ]+', Text), (r'[ ]+$', Text), # line breaks are ignored (r'\n+', Text), # other whitespaces are a part of the value (r'[ ]+', Name.Variable), ], # single-quoted scalars 'single-quoted-scalar': [ # include whitespace and line break rules include('quoted-scalar-whitespaces'), # escaping of the quote character (r'\'\'', String.Escape), # regular non-whitespace characters (r'[^\s\']+', String), # the closing quote (r'\'', String, '#pop'), ], # double-quoted scalars 'double-quoted-scalar': [ # include whitespace and line break rules include('quoted-scalar-whitespaces'), # escaping of special characters (r'\\[0abt\tn\nvfre "\\N_LP]', String), # escape codes (r'\\(?:x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})', String.Escape), # regular non-whitespace characters (r'[^\s"\\]+', String), # the closing quote (r'"', String, '#pop'), ], # the beginning of a new line while scanning a plain scalar 'plain-scalar-in-block-context-new-line': [ # empty lines (r'^[ ]+$', Text), # line breaks (r'\n+', Text), # document start and document end indicators (r'^(?=---|\.\.\.)', something(Name.Namespace), '#pop:3'), # indentation spaces (we may leave the block line state here) (r'^[ ]*', parse_plain_scalar_indent(Text), '#pop'), ], # a plain scalar in the block context 'plain-scalar-in-block-context': [ # the scalar ends with the ':' indicator (r'[ ]*(?=:[ ]|:$)', something(Text), '#pop'), # the scalar ends with whitespaces followed by a comment (r'[ ]+(?=#)', Text, '#pop'), # trailing whitespaces are ignored (r'[ ]+$', Text), # line breaks are ignored (r'\n+', Text, 'plain-scalar-in-block-context-new-line'), # other whitespaces are a part of the value (r'[ ]+', Literal.Scalar.Plain), # regular non-whitespace characters (r'(?::(?!\s)|[^\s:])+', Literal.Scalar.Plain), ], # a plain scalar is the flow context 'plain-scalar-in-flow-context': [ # the scalar ends with an indicator character (r'[ ]*(?=[,:?\[\]{}])', something(Text), '#pop'), # the scalar ends with a comment (r'[ ]+(?=#)', Text, '#pop'), # leading and trailing whitespaces are ignored (r'^[ ]+', Text), (r'[ ]+$', Text), # line breaks are ignored (r'\n+', Text), # other whitespaces are a part of the value (r'[ ]+', Name.Variable), # regular non-whitespace characters (r'[^\s,:?\[\]{}]+', Name.Variable), ], } def get_tokens_unprocessed(self, text=None, context=None): if context is None: context = YamlLexerContext(text, 0) return super(YamlLexer, self).get_tokens_unprocessed(text, context) class JsonLexer(RegexLexer): """ For JSON data structures. .. versionadded:: 1.5 """ name = 'JSON' aliases = ['json'] filenames = ['*.json'] mimetypes = ['application/json'] flags = re.DOTALL # integer part of a number int_part = r'-?(0|[1-9]\d*)' # fractional part of a number frac_part = r'\.\d+' # exponential part of a number exp_part = r'[eE](\+|-)?\d+' tokens = { 'whitespace': [ (r'\s+', Text), ], # represents a simple terminal value 'simplevalue': [ (r'(true|false|null)\b', Keyword.Constant), (('%(int_part)s(%(frac_part)s%(exp_part)s|' '%(exp_part)s|%(frac_part)s)') % vars(), Number.Float), (int_part, Number.Integer), (r'"(\\\\|\\"|[^"])*"', String.Double), ], # the right hand side of an object, after the attribute name 'objectattribute': [ include('value'), (r':', Punctuation), # comma terminates the attribute but expects more (r',', Punctuation, '#pop'), # a closing bracket terminates the entire object, so pop twice (r'\}', Punctuation, '#pop:2'), ], # a json object - { attr, attr, ... } 'objectvalue': [ include('whitespace'), (r'"(\\\\|\\"|[^"])*"', Name.Tag, 'objectattribute'), (r'\}', Punctuation, '#pop'), ], # json array - [ value, value, ... } 'arrayvalue': [ include('whitespace'), include('value'), (r',', Punctuation), (r'\]', Punctuation, '#pop'), ], # a json value - either a simple value or a complex value (object or array) 'value': [ include('whitespace'), include('simplevalue'), (r'\{', Punctuation, 'objectvalue'), (r'\[', Punctuation, 'arrayvalue'), ], # the root of a json document whould be a value 'root': [ include('value'), ], } 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. .. versionadded:: 2.0 """ name = 'JSON-LD' aliases = ['jsonld', 'json-ld'] filenames = ['*.jsonld'] mimetypes = ['application/ld+json'] tokens = { 'objectvalue': [ (r'"@(context|id|value|language|type|container|list|set|' r'reverse|index|base|vocab|graph)"', Name.Decorator, 'objectattribute'), inherit, ], }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
__pycache__ | Folder | 0755 |
|
|
__init__.py | File | 10.65 KB | 0644 |
|
_asy_builtins.py | File | 26.68 KB | 0644 |
|
_cl_builtins.py | File | 13.72 KB | 0644 |
|
_cocoa_builtins.py | File | 39.04 KB | 0644 |
|
_csound_builtins.py | File | 21.14 KB | 0644 |
|
_lasso_builtins.py | File | 131.38 KB | 0644 |
|
_lua_builtins.py | File | 8.14 KB | 0644 |
|
_mapping.py | File | 53.43 KB | 0644 |
|
_mql_builtins.py | File | 24.16 KB | 0644 |
|
_openedge_builtins.py | File | 47.23 KB | 0644 |
|
_php_builtins.py | File | 150.75 KB | 0644 |
|
_postgres_builtins.py | File | 10.95 KB | 0644 |
|
_scilab_builtins.py | File | 51.18 KB | 0644 |
|
_sourcemod_builtins.py | File | 26.48 KB | 0644 |
|
_stan_builtins.py | File | 9.88 KB | 0644 |
|
_stata_builtins.py | File | 24.55 KB | 0644 |
|
_tsql_builtins.py | File | 15.12 KB | 0644 |
|
_vim_builtins.py | File | 55.75 KB | 0644 |
|
actionscript.py | File | 10.92 KB | 0644 |
|
agile.py | File | 900 B | 0644 |
|
algebra.py | File | 7.03 KB | 0644 |
|
ambient.py | File | 2.5 KB | 0644 |
|
ampl.py | File | 4.02 KB | 0644 |
|
apl.py | File | 3.09 KB | 0644 |
|
archetype.py | File | 10.87 KB | 0644 |
|
asm.py | File | 24.67 KB | 0644 |
|
automation.py | File | 19.19 KB | 0644 |
|
basic.py | File | 19.83 KB | 0644 |
|
bibtex.py | File | 4.61 KB | 0644 |
|
business.py | File | 27.02 KB | 0644 |
|
c_cpp.py | File | 10.28 KB | 0644 |
|
c_like.py | File | 23.56 KB | 0644 |
|
capnproto.py | File | 2.14 KB | 0644 |
|
chapel.py | File | 3.43 KB | 0644 |
|
clean.py | File | 10.16 KB | 0644 |
|
compiled.py | File | 1.35 KB | 0644 |
|
configs.py | File | 27.6 KB | 0644 |
|
console.py | File | 4.02 KB | 0644 |
|
crystal.py | File | 16.45 KB | 0644 |
|
csound.py | File | 12.25 KB | 0644 |
|
css.py | File | 30.77 KB | 0644 |
|
d.py | File | 9.31 KB | 0644 |
|
dalvik.py | File | 4.32 KB | 0644 |
|
data.py | File | 18.33 KB | 0644 |
|
diff.py | File | 4.76 KB | 0644 |
|
dotnet.py | File | 27.02 KB | 0644 |
|
dsls.py | File | 32.55 KB | 0644 |
|
dylan.py | File | 10.18 KB | 0644 |
|
ecl.py | File | 5.74 KB | 0644 |
|
eiffel.py | File | 2.42 KB | 0644 |
|
elm.py | File | 2.93 KB | 0644 |
|
erlang.py | File | 18.49 KB | 0644 |
|
esoteric.py | File | 9.27 KB | 0644 |
|
ezhil.py | File | 2.95 KB | 0644 |
|
factor.py | File | 17.44 KB | 0644 |
|
fantom.py | File | 9.75 KB | 0644 |
|
felix.py | File | 9.19 KB | 0644 |
|
forth.py | File | 6.98 KB | 0644 |
|
fortran.py | File | 9.54 KB | 0644 |
|
foxpro.py | File | 25.62 KB | 0644 |
|
functional.py | File | 698 B | 0644 |
|
go.py | File | 3.61 KB | 0644 |
|
grammar_notation.py | File | 6.18 KB | 0644 |
|
graph.py | File | 2.31 KB | 0644 |
|
graphics.py | File | 25.23 KB | 0644 |
|
haskell.py | File | 30.49 KB | 0644 |
|
haxe.py | File | 30.23 KB | 0644 |
|
hdl.py | File | 18.26 KB | 0644 |
|
hexdump.py | File | 3.42 KB | 0644 |
|
html.py | File | 18.82 KB | 0644 |
|
idl.py | File | 14.63 KB | 0644 |
|
igor.py | File | 19.53 KB | 0644 |
|
inferno.py | File | 3.04 KB | 0644 |
|
installers.py | File | 12.56 KB | 0644 |
|
int_fiction.py | File | 54.47 KB | 0644 |
|
iolang.py | File | 1.86 KB | 0644 |
|
j.py | File | 4.42 KB | 0644 |
|
javascript.py | File | 58.72 KB | 0644 |
|
julia.py | File | 13.76 KB | 0644 |
|
jvm.py | File | 65.18 KB | 0644 |
|
lisp.py | File | 137.38 KB | 0644 |
|
make.py | File | 7.16 KB | 0644 |
|
markup.py | File | 19.97 KB | 0644 |
|
math.py | File | 700 B | 0644 |
|
matlab.py | File | 28.47 KB | 0644 |
|
ml.py | File | 27.23 KB | 0644 |
|
modeling.py | File | 12.53 KB | 0644 |
|
modula2.py | File | 51.33 KB | 0644 |
|
monte.py | File | 6.16 KB | 0644 |
|
ncl.py | File | 62.49 KB | 0644 |
|
nimrod.py | File | 5.05 KB | 0644 |
|
nit.py | File | 2.68 KB | 0644 |
|
nix.py | File | 3.94 KB | 0644 |
|
oberon.py | File | 3.65 KB | 0644 |
|
objective.py | File | 22.22 KB | 0644 |
|
ooc.py | File | 2.93 KB | 0644 |
|
other.py | File | 1.73 KB | 0644 |
|
parasail.py | File | 2.67 KB | 0644 |
|
parsers.py | File | 26.94 KB | 0644 |
|
pascal.py | File | 31.88 KB | 0644 |
|
pawn.py | File | 7.9 KB | 0644 |
|
perl.py | File | 31.26 KB | 0644 |
|
php.py | File | 10.48 KB | 0644 |
|
praat.py | File | 12.26 KB | 0644 |
|
prolog.py | File | 11.78 KB | 0644 |
|
python.py | File | 41.39 KB | 0644 |
|
qvt.py | File | 5.97 KB | 0644 |
|
r.py | File | 23.2 KB | 0644 |
|
rdf.py | File | 9.18 KB | 0644 |
|
rebol.py | File | 18.18 KB | 0644 |
|
resource.py | File | 2.86 KB | 0644 |
|
rnc.py | File | 1.94 KB | 0644 |
|
roboconf.py | File | 2.02 KB | 0644 |
|
robotframework.py | File | 18.3 KB | 0644 |
|
ruby.py | File | 21.62 KB | 0644 |
|
rust.py | File | 7.51 KB | 0644 |
|
sas.py | File | 9.23 KB | 0644 |
|
scripting.py | File | 66.17 KB | 0644 |
|
shell.py | File | 30.69 KB | 0644 |
|
smalltalk.py | File | 7.05 KB | 0644 |
|
smv.py | File | 2.74 KB | 0644 |
|
snobol.py | File | 2.69 KB | 0644 |
|
special.py | File | 3.08 KB | 0644 |
|
sql.py | File | 28.75 KB | 0644 |
|
stata.py | File | 3.54 KB | 0644 |
|
supercollider.py | File | 3.43 KB | 0644 |
|
tcl.py | File | 5.27 KB | 0644 |
|
templates.py | File | 71.73 KB | 0644 |
|
testing.py | File | 10.5 KB | 0644 |
|
text.py | File | 977 B | 0644 |
|
textedit.py | File | 5.92 KB | 0644 |
|
textfmts.py | File | 10.6 KB | 0644 |
|
theorem.py | File | 18.59 KB | 0644 |
|
trafficscript.py | File | 1.51 KB | 0644 |
|
typoscript.py | File | 8.2 KB | 0644 |
|
urbi.py | File | 5.62 KB | 0644 |
|
varnish.py | File | 7.1 KB | 0644 |
|
verification.py | File | 3.62 KB | 0644 |
|
web.py | File | 918 B | 0644 |
|
webmisc.py | File | 38.96 KB | 0644 |
|
whiley.py | File | 3.92 KB | 0644 |
|
x10.py | File | 1.92 KB | 0644 |
|