/
usr
/
lib
/
rads
/
venv
/
lib
/
python3.13
/
site-packages
/
pygments
/
lexers
/
/usr/lib/rads/venv/lib/python3.13/site-packages/pygments/lexers
mkdir
upload
Name
Size
Mode
Actions
__pycache__/
-
0755
rm
actionscript.py
11727
0644
edit
dl
rm
ada.py
5353
0644
edit
dl
rm
agile.py
896
0644
edit
dl
rm
algebra.py
9952
0644
edit
dl
rm
ambient.py
2605
0644
edit
dl
rm
amdgpu.py
1723
0644
edit
dl
rm
ampl.py
4176
0644
edit
dl
rm
apdlexer.py
30800
0644
edit
dl
rm
apl.py
3404
0644
edit
dl
rm
archetype.py
11538
0644
edit
dl
rm
arrow.py
3564
0644
edit
dl
rm
arturo.py
11414
0644
edit
dl
rm
asc.py
1693
0644
edit
dl
rm
asm.py
41967
0644
edit
dl
rm
asn1.py
4262
0644
edit
dl
rm
automation.py
19831
0644
edit
dl
rm
bare.py
3020
0644
edit
dl
rm
basic.py
27989
0644
edit
dl
rm
bdd.py
1641
0644
edit
dl
rm
berry.py
3209
0644
edit
dl
rm
bibtex.py
4811
0644
edit
dl
rm
blueprint.py
6188
0644
edit
dl
rm
boa.py
3921
0644
edit
dl
rm
bqn.py
3671
0644
edit
dl
rm
business.py
28345
0644
edit
dl
rm
capnproto.py
2174
0644
edit
dl
rm
carbon.py
3211
0644
edit
dl
rm
cddl.py
5076
0644
edit
dl
rm
chapel.py
5156
0644
edit
dl
rm
clean.py
6418
0644
edit
dl
rm
codeql.py
2576
0644
edit
dl
rm
comal.py
3179
0644
edit
dl
rm
compiled.py
1426
0644
edit
dl
rm
configs.py
50913
0644
edit
dl
rm
console.py
4180
0644
edit
dl
rm
cplint.py
1389
0644
edit
dl
rm
crystal.py
15754
0644
edit
dl
rm
csound.py
16998
0644
edit
dl
rm
css.py
25376
0644
edit
dl
rm
c_cpp.py
18059
0644
edit
dl
rm
c_like.py
32021
0644
edit
dl
rm
d.py
9920
0644
edit
dl
rm
dalvik.py
4606
0644
edit
dl
rm
data.py
27026
0644
edit
dl
rm
dax.py
8098
0644
edit
dl
rm
devicetree.py
4019
0644
edit
dl
rm
diff.py
5382
0644
edit
dl
rm
dns.py
3891
0644
edit
dl
rm
dotnet.py
39441
0644
edit
dl
rm
dsls.py
36746
0644
edit
dl
rm
dylan.py
10409
0644
edit
dl
rm
ecl.py
6371
0644
edit
dl
rm
eiffel.py
2690
0644
edit
dl
rm
elm.py
3152
0644
edit
dl
rm
elpi.py
6877
0644
edit
dl
rm
email.py
4804
0644
edit
dl
rm
erlang.py
19147
0644
edit
dl
rm
esoteric.py
10500
0644
edit
dl
rm
ezhil.py
3272
0644
edit
dl
rm
factor.py
19530
0644
edit
dl
rm
fantom.py
10231
0644
edit
dl
rm
felix.py
9655
0644
edit
dl
rm
fift.py
1644
0644
edit
dl
rm
floscript.py
2667
0644
edit
dl
rm
forth.py
7193
0644
edit
dl
rm
fortran.py
10382
0644
edit
dl
rm
foxpro.py
26295
0644
edit
dl
rm
freefem.py
26913
0644
edit
dl
rm
func.py
3700
0644
edit
dl
rm
functional.py
693
0644
edit
dl
rm
futhark.py
3743
0644
edit
dl
rm
gcodelexer.py
874
0644
edit
dl
rm
gdscript.py
7566
0644
edit
dl
rm
gleam.py
2392
0644
edit
dl
rm
go.py
3783
0644
edit
dl
rm
grammar_notation.py
8043
0644
edit
dl
rm
graph.py
4108
0644
edit
dl
rm
graphics.py
39145
0644
edit
dl
rm
graphql.py
5601
0644
edit
dl
rm
graphviz.py
1934
0644
edit
dl
rm
gsql.py
3990
0644
edit
dl
rm
hare.py
2649
0644
edit
dl
rm
haskell.py
33262
0644
edit
dl
rm
haxe.py
30974
0644
edit
dl
rm
hdl.py
22738
0644
edit
dl
rm
hexdump.py
3653
0644
edit
dl
rm
html.py
21977
0644
edit
dl
rm
idl.py
15449
0644
edit
dl
rm
igor.py
31633
0644
edit
dl
rm
inferno.py
3135
0644
edit
dl
rm
installers.py
14435
0644
edit
dl
rm
int_fiction.py
56544
0644
edit
dl
rm
iolang.py
1905
0644
edit
dl
rm
j.py
4853
0644
edit
dl
rm
javascript.py
63243
0644
edit
dl
rm
jmespath.py
2082
0644
edit
dl
rm
jslt.py
3700
0644
edit
dl
rm
json5.py
2502
0644
edit
dl
rm
jsonnet.py
5636
0644
edit
dl
rm
jsx.py
2693
0644
edit
dl
rm
julia.py
11710
0644
edit
dl
rm
jvm.py
72667
0644
edit
dl
rm
kuin.py
11405
0644
edit
dl
rm
kusto.py
3477
0644
edit
dl
rm
ldap.py
6551
0644
edit
dl
rm
lean.py
8570
0644
edit
dl
rm
lilypond.py
9752
0644
edit
dl
rm
lisp.py
157668
0644
edit
dl
rm
macaulay2.py
33366
0644
edit
dl
rm
make.py
7831
0644
edit
dl
rm
maple.py
7960
0644
edit
dl
rm
markup.py
65088
0644
edit
dl
rm
math.py
695
0644
edit
dl
rm
matlab.py
133027
0644
edit
dl
rm
maxima.py
2715
0644
edit
dl
rm
meson.py
4336
0644
edit
dl
rm
mime.py
7582
0644
edit
dl
rm
minecraft.py
13696
0644
edit
dl
rm
mips.py
4656
0644
edit
dl
rm
ml.py
35390
0644
edit
dl
rm
modeling.py
13683
0644
edit
dl
rm
modula2.py
53072
0644
edit
dl
rm
mojo.py
24233
0644
edit
dl
rm
monte.py
6289
0644
edit
dl
rm
mosel.py
9297
0644
edit
dl
rm
ncl.py
63999
0644
edit
dl
rm
nimrod.py
6413
0644
edit
dl
rm
nit.py
2725
0644
edit
dl
rm
nix.py
4421
0644
edit
dl
rm
numbair.py
1758
0644
edit
dl
rm
oberon.py
4210
0644
edit
dl
rm
objective.py
23297
0644
edit
dl
rm
ooc.py
3002
0644
edit
dl
rm
openscad.py
3700
0644
edit
dl
rm
other.py
1763
0644
edit
dl
rm
parasail.py
2719
0644
edit
dl
rm
parsers.py
26596
0644
edit
dl
rm
pascal.py
30989
0644
edit
dl
rm
pawn.py
8253
0644
edit
dl
rm
pddl.py
2989
0644
edit
dl
rm
perl.py
39192
0644
edit
dl
rm
phix.py
23249
0644
edit
dl
rm
php.py
13061
0644
edit
dl
rm
pointless.py
1974
0644
edit
dl
rm
pony.py
3279
0644
edit
dl
rm
praat.py
12676
0644
edit
dl
rm
procfile.py
1155
0644
edit
dl
rm
prolog.py
12866
0644
edit
dl
rm
promql.py
4738
0644
edit
dl
rm
prql.py
8747
0644
edit
dl
rm
ptx.py
4501
0644
edit
dl
rm
python.py
53805
0644
edit
dl
rm
q.py
6936
0644
edit
dl
rm
qlik.py
3693
0644
edit
dl
rm
qvt.py
6103
0644
edit
dl
rm
r.py
6474
0644
edit
dl
rm
rdf.py
16056
0644
edit
dl
rm
rebol.py
18259
0644
edit
dl
rm
rego.py
1748
0644
edit
dl
rm
resource.py
2927
0644
edit
dl
rm
ride.py
5035
0644
edit
dl
rm
rita.py
1127
0644
edit
dl
rm
rnc.py
1972
0644
edit
dl
rm
roboconf.py
2074
0644
edit
dl
rm
robotframework.py
18448
0644
edit
dl
rm
ruby.py
22753
0644
edit
dl
rm
rust.py
8260
0644
edit
dl
rm
sas.py
9456
0644
edit
dl
rm
savi.py
4878
0644
edit
dl
rm
scdoc.py
2524
0644
edit
dl
rm
scripting.py
81814
0644
edit
dl
rm
sgf.py
1985
0644
edit
dl
rm
shell.py
36381
0644
edit
dl
rm
sieve.py
2514
0644
edit
dl
rm
slash.py
8484
0644
edit
dl
rm
smalltalk.py
7204
0644
edit
dl
rm
smithy.py
2659
0644
edit
dl
rm
smv.py
2805
0644
edit
dl
rm
snobol.py
2778
0644
edit
dl
rm
solidity.py
3163
0644
edit
dl
rm
soong.py
2339
0644
edit
dl
rm
sophia.py
3376
0644
edit
dl
rm
special.py
3585
0644
edit
dl
rm
spice.py
2790
0644
edit
dl
rm
sql.py
41476
0644
edit
dl
rm
srcinfo.py
1746
0644
edit
dl
rm
stata.py
6415
0644
edit
dl
rm
supercollider.py
3697
0644
edit
dl
rm
tablegen.py
3987
0644
edit
dl
rm
tact.py
10809
0644
edit
dl
rm
tal.py
2904
0644
edit
dl
rm
tcl.py
5512
0644
edit
dl
rm
teal.py
3522
0644
edit
dl
rm
templates.py
75731
0644
edit
dl
rm
teraterm.py
9718
0644
edit
dl
rm
testing.py
10810
0644
edit
dl
rm
text.py
1068
0644
edit
dl
rm
textedit.py
7760
0644
edit
dl
rm
textfmts.py
15524
0644
edit
dl
rm
theorem.py
17855
0644
edit
dl
rm
thingsdb.py
6017
0644
edit
dl
rm
tlb.py
1450
0644
edit
dl
rm
tls.py
1540
0644
edit
dl
rm
tnt.py
10456
0644
edit
dl
rm
trafficscript.py
1506
0644
edit
dl
rm
typoscript.py
8332
0644
edit
dl
rm
typst.py
7167
0644
edit
dl
rm
ul4.py
10499
0644
edit
dl
rm
unicon.py
18625
0644
edit
dl
rm
urbi.py
6082
0644
edit
dl
rm
usd.py
3304
0644
edit
dl
rm
varnish.py
7473
0644
edit
dl
rm
verification.py
3934
0644
edit
dl
rm
verifpal.py
2661
0644
edit
dl
rm
vip.py
5711
0644
edit
dl
rm
vyper.py
5615
0644
edit
dl
rm
web.py
913
0644
edit
dl
rm
webassembly.py
5698
0644
edit
dl
rm
webidl.py
10516
0644
edit
dl
rm
webmisc.py
40564
0644
edit
dl
rm
wgsl.py
11880
0644
edit
dl
rm
whiley.py
4017
0644
edit
dl
rm
wowtoc.py
4076
0644
edit
dl
rm
wren.py
3229
0644
edit
dl
rm
x10.py
1943
0644
edit
dl
rm
xorg.py
925
0644
edit
dl
rm
yang.py
4499
0644
edit
dl
rm
yara.py
2427
0644
edit
dl
rm
zig.py
3976
0644
edit
dl
rm
_ada_builtins.py
1543
0644
edit
dl
rm
_asy_builtins.py
27287
0644
edit
dl
rm
_cl_builtins.py
13994
0644
edit
dl
rm
_cocoa_builtins.py
105173
0644
edit
dl
rm
_csound_builtins.py
18414
0644
edit
dl
rm
_css_builtins.py
12446
0644
edit
dl
rm
_googlesql_builtins.py
16132
0644
edit
dl
rm
_julia_builtins.py
11883
0644
edit
dl
rm
_lasso_builtins.py
134510
0644
edit
dl
rm
_lilypond_builtins.py
108094
0644
edit
dl
rm
_luau_builtins.py
955
0644
edit
dl
rm
_lua_builtins.py
8108
0644
edit
dl
rm
_mapping.py
70438
0644
edit
dl
rm
_mql_builtins.py
24713
0644
edit
dl
rm
_mysql_builtins.py
25838
0644
edit
dl
rm
_openedge_builtins.py
49398
0644
edit
dl
rm
_php_builtins.py
107922
0644
edit
dl
rm
_postgres_builtins.py
13343
0644
edit
dl
rm
_qlik_builtins.py
12595
0644
edit
dl
rm
_scheme_builtins.py
32564
0644
edit
dl
rm
_scilab_builtins.py
52411
0644
edit
dl
rm
_sourcemod_builtins.py
26777
0644
edit
dl
rm
_sql_builtins.py
6767
0644
edit
dl
rm
_stan_builtins.py
13445
0644
edit
dl
rm
_stata_builtins.py
27227
0644
edit
dl
rm
_tsql_builtins.py
15460
0644
edit
dl
rm
_usd_builtins.py
1658
0644
edit
dl
rm
_vbscript_builtins.py
4225
0644
edit
dl
rm
_vim_builtins.py
57066
0644
edit
dl
rm
__init__.py
12067
0644
edit
dl
rm
Edit:
/usr/lib/rads/venv/lib/python3.13/site-packages/pygments/lexers/data.py
(27026B)
""" pygments.lexers.data ~~~~~~~~~~~~~~~~~~~~ Lexers for data file format. :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ from pygments.lexer import Lexer, ExtendedRegexLexer, LexerContext, \ include, bygroups from pygments.token import Comment, Error, Keyword, Literal, Name, Number, \ Punctuation, String, Whitespace __all__ = ['YamlLexer', 'JsonLexer', 'JsonBareObjectLexer', 'JsonLdLexer'] class YamlLexerContext(LexerContext): """Indentation context for the YAML lexer.""" def __init__(self, *args, **kwds): super().__init__(*args, **kwds) self.indent_stack = [] self.indent = -1 self.next_indent = 0 self.block_scalar_indent = None class YamlLexer(ExtendedRegexLexer): """ Lexer for YAML, a human-friendly data serialization language. """ name = 'YAML' url = 'http://yaml.org/' aliases = ['yaml'] filenames = ['*.yaml', '*.yml'] mimetypes = ['text/x-yaml'] version_added = '0.11' 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'[ ]+(?=#|$)', Whitespace), # line breaks (r'\n+', Whitespace), # 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(Whitespace, start=True), ('block-line', 'indentation')), ], # trailing whitespaces after directives or a block scalar indicator 'ignored-line': [ # ignored whitespaces (r'[ ]+(?=#|$)', Whitespace), # a comment (r'#[^\n]*', Comment.Single), # line break (r'\n', Whitespace, '#pop:2'), ], # the %YAML directive 'yaml-directive': [ # the version number (r'([ ]+)([0-9]+\.[0-9]+)', bygroups(Whitespace, Number), 'ignored-line'), ], # the %TAG directive 'tag-directive': [ # a tag handle and the corresponding prefix (r'([ ]+)(!|![\w-]*!)' r'([ ]+)(!|!?[\w;/?:@&=+$,.!~*\'()\[\]%-]+)', bygroups(Whitespace, Keyword.Type, Whitespace, Keyword.Type), 'ignored-line'), ], # block scalar indicators and indentation spaces 'indentation': [ # trailing whitespaces are ignored (r'[ ]*$', something(Whitespace), '#pop:2'), # whitespaces preceding block collection indicators (r'[ ]+(?=[?:-](?:[ ]|$))', save_indent(Whitespace)), # block collection indicators (r'[?:-](?=[ ]|$)', set_indent(Punctuation.Indicator)), # the beginning a block line (r'[ ]*', save_indent(Whitespace), '#pop'), ], # an indented line in the block context 'block-line': [ # the line end (r'[ ]*(?=#|$)', something(Whitespace), '#pop'), # whitespaces separating tokens (r'[ ]+', Whitespace), # key with colon (r'''([^#,?\[\]{}"'\n]+)(:)(?=[ ]|$)''', bygroups(Name.Tag, set_indent(Punctuation, implicit=True))), # 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'[ ]+', Whitespace), # line breaks (r'\n+', Whitespace), # 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': [ # key with colon (r'''([^,:?\[\]{}"'\n]+)(:)(?=[ ]|$)''', bygroups(Name.Tag, Punctuation)), # include flow collection rules include('flow-collection'), # the closing indicator (r'\}', Punctuation.Indicator, '#pop'), ], # block scalar lines 'block-scalar-content': [ # line break (r'\n', Whitespace), # empty line (r'^[ ]+$', parse_block_scalar_empty_line(Whitespace, Name.Constant)), # indentation spaces (we may leave the state here) (r'^[ ]*', parse_block_scalar_indent(Whitespace)), # 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'^[ ]+', Whitespace), (r'[ ]+$', Whitespace), # line breaks are ignored (r'\n+', Whitespace), # 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'^[ ]+$', Whitespace), # line breaks (r'\n+', Whitespace), # 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(Whitespace), '#pop'), ], # a plain scalar in the block context 'plain-scalar-in-block-context': [ # the scalar ends with the ':' indicator (r'[ ]*(?=:[ ]|:$)', something(Whitespace), '#pop'), # the scalar ends with whitespaces followed by a comment (r'[ ]+(?=#)', Whitespace, '#pop'), # trailing whitespaces are ignored (r'[ ]+$', Whitespace), # line breaks are ignored (r'\n+', Whitespace, '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(Whitespace), '#pop'), # the scalar ends with a comment (r'[ ]+(?=#)', Whitespace, '#pop'), # leading and trailing whitespaces are ignored (r'^[ ]+', Whitespace), (r'[ ]+$', Whitespace), # line breaks are ignored (r'\n+', Whitespace), # 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().get_tokens_unprocessed(text, context) class JsonLexer(Lexer): """ For JSON data structures. Javascript-style comments are supported (like ``/* */`` and ``//``), though comments are not part of the JSON specification. This allows users to highlight JSON as it is used in the wild. No validation is performed on the input JSON document. """ name = 'JSON' url = 'https://www.json.org' aliases = ['json', 'json-object'] filenames = ['*.json', '*.jsonl', '*.ndjson', 'Pipfile.lock'] mimetypes = ['application/json', 'application/json-object', 'application/x-ndjson', 'application/jsonl', 'application/json-seq'] version_added = '1.5' # No validation of integers, floats, or constants is done. # As long as the characters are members of the following # sets, the token will be considered valid. For example, # # "--1--" is parsed as an integer # "1...eee" is parsed as a float # "trustful" is parsed as a constant # integers = set('-0123456789') floats = set('.eE+') constants = set('truefalsenull') # true|false|null hexadecimals = set('0123456789abcdefABCDEF') punctuations = set('{}[],') whitespaces = {'\u0020', '\u000a', '\u000d', '\u0009'} def get_tokens_unprocessed(self, text): """Parse JSON data.""" in_string = False in_escape = False in_unicode_escape = 0 in_whitespace = False in_constant = False in_number = False in_float = False in_punctuation = False in_comment_single = False in_comment_multiline = False expecting_second_comment_opener = False # // or /* expecting_second_comment_closer = False # */ start = 0 # The queue is used to store data that may need to be tokenized # differently based on what follows. In particular, JSON object # keys are tokenized differently than string values, but cannot # be distinguished until punctuation is encountered outside the # string. # # A ":" character after the string indicates that the string is # an object key; any other character indicates the string is a # regular string value. # # The queue holds tuples that contain the following data: # # (start_index, token_type, text) # # By default the token type of text in double quotes is # String.Double. The token type will be replaced if a colon # is encountered after the string closes. # queue = [] for stop, character in enumerate(text): if in_string: if in_unicode_escape: if character in self.hexadecimals: in_unicode_escape -= 1 if not in_unicode_escape: in_escape = False else: in_unicode_escape = 0 in_escape = False elif in_escape: if character == 'u': in_unicode_escape = 4 else: in_escape = False elif character == '\\': in_escape = True elif character == '"': queue.append((start, String.Double, text[start:stop + 1])) in_string = False in_escape = False in_unicode_escape = 0 continue elif in_whitespace: if character in self.whitespaces: continue if queue: queue.append((start, Whitespace, text[start:stop])) else: yield start, Whitespace, text[start:stop] in_whitespace = False # Fall through so the new character can be evaluated. elif in_constant: if character in self.constants: continue yield start, Keyword.Constant, text[start:stop] in_constant = False # Fall through so the new character can be evaluated. elif in_number: if character in self.integers: continue elif character in self.floats: in_float = True continue if in_float: yield start, Number.Float, text[start:stop] else: yield start, Number.Integer, text[start:stop] in_number = False in_float = False # Fall through so the new character can be evaluated. elif in_punctuation: if character in self.punctuations: continue yield start, Punctuation, text[start:stop] in_punctuation = False # Fall through so the new character can be evaluated. elif in_comment_single: if character != '\n': continue if queue: queue.append((start, Comment.Single, text[start:stop])) else: yield start, Comment.Single, text[start:stop] in_comment_single = False # Fall through so the new character can be evaluated. elif in_comment_multiline: if character == '*': expecting_second_comment_closer = True elif expecting_second_comment_closer: expecting_second_comment_closer = False if character == '/': if queue: queue.append((start, Comment.Multiline, text[start:stop + 1])) else: yield start, Comment.Multiline, text[start:stop + 1] in_comment_multiline = False continue elif expecting_second_comment_opener: expecting_second_comment_opener = False if character == '/': in_comment_single = True continue elif character == '*': in_comment_multiline = True continue # Exhaust the queue. Accept the existing token types. yield from queue queue.clear() yield start, Error, text[start:stop] # Fall through so the new character can be evaluated. start = stop if character == '"': in_string = True elif character in self.whitespaces: in_whitespace = True elif character in {'f', 'n', 't'}: # The first letters of true|false|null # Exhaust the queue. Accept the existing token types. yield from queue queue.clear() in_constant = True elif character in self.integers: # Exhaust the queue. Accept the existing token types. yield from queue queue.clear() in_number = True elif character == ':': # Yield from the queue. Replace string token types. for _start, _token, _text in queue: # There can be only three types of tokens before a ':': # Whitespace, Comment, or a quoted string. # # If it's a quoted string we emit Name.Tag. # Otherwise, we yield the original token. # # In all other cases this would be invalid JSON, # but this is not a validating JSON lexer, so it's OK. if _token is String.Double: yield _start, Name.Tag, _text else: yield _start, _token, _text queue.clear() in_punctuation = True elif character in self.punctuations: # Exhaust the queue. Accept the existing token types. yield from queue queue.clear() in_punctuation = True elif character == '/': # This is the beginning of a comment. expecting_second_comment_opener = True else: # Exhaust the queue. Accept the existing token types. yield from queue queue.clear() yield start, Error, character # Yield any remaining text. yield from queue if in_string: yield start, Error, text[start:] elif in_float: yield start, Number.Float, text[start:] elif in_number: yield start, Number.Integer, text[start:] elif in_constant: yield start, Keyword.Constant, text[start:] elif in_whitespace: yield start, Whitespace, text[start:] elif in_punctuation: yield start, Punctuation, text[start:] elif in_comment_single: yield start, Comment.Single, text[start:] elif in_comment_multiline: yield start, Error, text[start:] elif expecting_second_comment_opener: yield start, Error, text[start:] class JsonBareObjectLexer(JsonLexer): """ For JSON data structures (with missing object curly braces). .. deprecated:: 2.8.0 Behaves the same as `JsonLexer` now. """ name = 'JSONBareObject' aliases = [] filenames = [] mimetypes = [] version_added = '2.2' class JsonLdLexer(JsonLexer): """ For JSON-LD linked data. """ name = 'JSON-LD' url = 'https://json-ld.org/' aliases = ['jsonld', 'json-ld'] filenames = ['*.jsonld'] mimetypes = ['application/ld+json'] version_added = '2.0' json_ld_keywords = { f'"@{keyword}"' for keyword in ( 'base', 'container', 'context', 'direction', 'graph', 'id', 'import', 'included', 'index', 'json', 'language', 'list', 'nest', 'none', 'prefix', 'propagate', 'protected', 'reverse', 'set', 'type', 'value', 'version', 'vocab', ) } def get_tokens_unprocessed(self, text): for start, token, value in super().get_tokens_unprocessed(text): if token is Name.Tag and value in self.json_ld_keywords: yield start, Name.Decorator, value else: yield start, token, value
Save
cmd:
run