├── .github
└── FUNDING.yml
├── .gitignore
├── LICENSE
├── README.md
├── codecut
├── README
├── __init__.py
├── basicutils_7x.py
├── cc_base.py
├── cc_main.py
├── lfa.py
├── map_read.py
├── maxcut.py
├── modnaming.py
├── module.py
└── snap_cg.py
├── db_support
├── __init__.py
└── schema.py
├── diaphora.py
├── diaphora_config.py
├── diaphora_heuristics.py
├── diaphora_ida.py
├── diaphora_import.py
├── diaphora_load.py
├── diaphora_load_and_import.py
├── doc
├── README.md
├── articles
│ ├── compilation_units.md
│ └── img
│ │ ├── codecut-slide.png
│ │ ├── codecut-slide.xcf
│ │ └── compilation-units-matches.png
├── examples
│ └── hooks
│ │ ├── debug_helper.py
│ │ ├── exclude_heuristics.py
│ │ ├── hooks_example1.py
│ │ └── hooks_example2.py
└── old
│ ├── Tutorial-Analyzing MS15-050 With Diaphora-By Alex Ionescu.pdf
│ ├── diaphora_help.odt
│ ├── heuristics.html
│ ├── images
│ ├── arrow-down.png
│ ├── bg_hr.png
│ ├── blacktocat.png
│ ├── body-bg.jpg
│ ├── download-button.png
│ ├── github-button.png
│ ├── header-bg.jpg
│ ├── highlight-bg.jpg
│ ├── icon_download.png
│ ├── octocat-small.png
│ ├── sidebar-bg.jpg
│ └── sprite_download.png
│ └── stylesheets
│ ├── github-light.css
│ └── stylesheet.css
├── extras
├── README.md
└── diaphora_local.py
├── jkutils
├── IDAMagicStrings.py
├── __init__.py
├── factor.py
├── graph_hashes.py
├── kfuzzy.py
└── threads.py
├── logo
├── diaphora-border.png
├── diaphora-border.svg
└── directed-graph.svg
├── ml
├── __init__.py
├── basic_engine.py
└── diaphora-amalgamation-model.pkl
├── others
├── __init__.py
└── tarjan_sort.py
├── plugin
├── README.md
├── diaphora_plugin.cfg
└── diaphora_plugin.py
├── pygments
├── __init__.py
├── __main__.py
├── cmdline.py
├── console.py
├── filter.py
├── filters
│ └── __init__.py
├── formatter.py
├── formatters
│ ├── __init__.py
│ ├── _mapping.py
│ ├── bbcode.py
│ ├── groff.py
│ ├── html.py
│ ├── img.py
│ ├── irc.py
│ ├── latex.py
│ ├── other.py
│ ├── pangomarkup.py
│ ├── rtf.py
│ ├── svg.py
│ ├── terminal.py
│ └── terminal256.py
├── lexer.py
├── lexers
│ ├── __init__.py
│ ├── _ada_builtins.py
│ ├── _asy_builtins.py
│ ├── _cl_builtins.py
│ ├── _cocoa_builtins.py
│ ├── _csound_builtins.py
│ ├── _css_builtins.py
│ ├── _julia_builtins.py
│ ├── _lasso_builtins.py
│ ├── _lilypond_builtins.py
│ ├── _lua_builtins.py
│ ├── _mapping.py
│ ├── _mql_builtins.py
│ ├── _mysql_builtins.py
│ ├── _openedge_builtins.py
│ ├── _php_builtins.py
│ ├── _postgres_builtins.py
│ ├── _qlik_builtins.py
│ ├── _scheme_builtins.py
│ ├── _scilab_builtins.py
│ ├── _sourcemod_builtins.py
│ ├── _stan_builtins.py
│ ├── _stata_builtins.py
│ ├── _tsql_builtins.py
│ ├── _usd_builtins.py
│ ├── _vbscript_builtins.py
│ ├── _vim_builtins.py
│ ├── actionscript.py
│ ├── ada.py
│ ├── agile.py
│ ├── algebra.py
│ ├── ambient.py
│ ├── amdgpu.py
│ ├── ampl.py
│ ├── apdlexer.py
│ ├── apl.py
│ ├── archetype.py
│ ├── arrow.py
│ ├── asc.py
│ ├── asm.py
│ ├── automation.py
│ ├── bare.py
│ ├── basic.py
│ ├── bdd.py
│ ├── berry.py
│ ├── bibtex.py
│ ├── boa.py
│ ├── business.py
│ ├── c_cpp.py
│ ├── c_like.py
│ ├── capnproto.py
│ ├── cddl.py
│ ├── chapel.py
│ ├── clean.py
│ ├── comal.py
│ ├── compiled.py
│ ├── configs.py
│ ├── console.py
│ ├── cplint.py
│ ├── crystal.py
│ ├── csound.py
│ ├── css.py
│ ├── d.py
│ ├── dalvik.py
│ ├── data.py
│ ├── devicetree.py
│ ├── diff.py
│ ├── dotnet.py
│ ├── dsls.py
│ ├── dylan.py
│ ├── ecl.py
│ ├── eiffel.py
│ ├── elm.py
│ ├── elpi.py
│ ├── email.py
│ ├── erlang.py
│ ├── esoteric.py
│ ├── ezhil.py
│ ├── factor.py
│ ├── fantom.py
│ ├── felix.py
│ ├── floscript.py
│ ├── forth.py
│ ├── fortran.py
│ ├── foxpro.py
│ ├── freefem.py
│ ├── functional.py
│ ├── futhark.py
│ ├── gcodelexer.py
│ ├── gdscript.py
│ ├── go.py
│ ├── grammar_notation.py
│ ├── graph.py
│ ├── graphics.py
│ ├── graphviz.py
│ ├── gsql.py
│ ├── haskell.py
│ ├── haxe.py
│ ├── hdl.py
│ ├── hexdump.py
│ ├── html.py
│ ├── idl.py
│ ├── igor.py
│ ├── inferno.py
│ ├── installers.py
│ ├── int_fiction.py
│ ├── iolang.py
│ ├── j.py
│ ├── javascript.py
│ ├── jmespath.py
│ ├── jslt.py
│ ├── julia.py
│ ├── jvm.py
│ ├── kuin.py
│ ├── lilypond.py
│ ├── lisp.py
│ ├── macaulay2.py
│ ├── make.py
│ ├── markup.py
│ ├── math.py
│ ├── matlab.py
│ ├── maxima.py
│ ├── mcfunction.py
│ ├── meson.py
│ ├── mime.py
│ ├── ml.py
│ ├── modeling.py
│ ├── modula2.py
│ ├── monte.py
│ ├── mosel.py
│ ├── ncl.py
│ ├── nimrod.py
│ ├── nit.py
│ ├── nix.py
│ ├── oberon.py
│ ├── objective.py
│ ├── ooc.py
│ ├── other.py
│ ├── parasail.py
│ ├── parsers.py
│ ├── pascal.py
│ ├── pawn.py
│ ├── perl.py
│ ├── php.py
│ ├── pointless.py
│ ├── pony.py
│ ├── praat.py
│ ├── procfile.py
│ ├── prolog.py
│ ├── promql.py
│ ├── python.py
│ ├── q.py
│ ├── qlik.py
│ ├── qvt.py
│ ├── r.py
│ ├── rdf.py
│ ├── rebol.py
│ ├── resource.py
│ ├── ride.py
│ ├── rita.py
│ ├── rnc.py
│ ├── roboconf.py
│ ├── robotframework.py
│ ├── ruby.py
│ ├── rust.py
│ ├── sas.py
│ ├── savi.py
│ ├── scdoc.py
│ ├── scripting.py
│ ├── sgf.py
│ ├── shell.py
│ ├── sieve.py
│ ├── slash.py
│ ├── smalltalk.py
│ ├── smithy.py
│ ├── smv.py
│ ├── snobol.py
│ ├── solidity.py
│ ├── sophia.py
│ ├── special.py
│ ├── spice.py
│ ├── sql.py
│ ├── srcinfo.py
│ ├── stata.py
│ ├── supercollider.py
│ ├── tal.py
│ ├── tcl.py
│ ├── teal.py
│ ├── templates.py
│ ├── teraterm.py
│ ├── testing.py
│ ├── text.py
│ ├── textedit.py
│ ├── textfmts.py
│ ├── theorem.py
│ ├── thingsdb.py
│ ├── tnt.py
│ ├── trafficscript.py
│ ├── typoscript.py
│ ├── ul4.py
│ ├── unicon.py
│ ├── urbi.py
│ ├── usd.py
│ ├── varnish.py
│ ├── verification.py
│ ├── web.py
│ ├── webassembly.py
│ ├── webidl.py
│ ├── webmisc.py
│ ├── whiley.py
│ ├── x10.py
│ ├── xorg.py
│ ├── yang.py
│ └── zig.py
├── modeline.py
├── plugin.py
├── regexopt.py
├── scanner.py
├── sphinxext.py
├── style.py
├── styles
│ ├── __init__.py
│ ├── abap.py
│ ├── algol.py
│ ├── algol_nu.py
│ ├── arduino.py
│ ├── autumn.py
│ ├── borland.py
│ ├── bw.py
│ ├── colorful.py
│ ├── default.py
│ ├── dracula.py
│ ├── emacs.py
│ ├── friendly.py
│ ├── friendly_grayscale.py
│ ├── fruity.py
│ ├── gh_dark.py
│ ├── gruvbox.py
│ ├── igor.py
│ ├── inkpot.py
│ ├── lilypond.py
│ ├── lovelace.py
│ ├── manni.py
│ ├── material.py
│ ├── monokai.py
│ ├── murphy.py
│ ├── native.py
│ ├── nord.py
│ ├── onedark.py
│ ├── paraiso_dark.py
│ ├── paraiso_light.py
│ ├── pastie.py
│ ├── perldoc.py
│ ├── rainbow_dash.py
│ ├── rrt.py
│ ├── sas.py
│ ├── solarized.py
│ ├── staroffice.py
│ ├── stata_dark.py
│ ├── stata_light.py
│ ├── tango.py
│ ├── trac.py
│ ├── vim.py
│ ├── vs.py
│ ├── xcode.py
│ └── zenburn.py
├── token.py
├── unistring.py
└── util.py
├── scripts
└── patch_diff_vulns.py
└── tester
├── README.md
├── check_indices.py
├── false_positives_checker.py
├── samples
├── add_sample.py
├── ls
├── ls-old
├── ls-old.cfg
└── ls.cfg
├── tester.cfg
└── tester.py
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | liberapay: Diaphora
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.pyc
2 |
--------------------------------------------------------------------------------
/codecut/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joxeankoret/diaphora/d8b898e35750d103cb6a15f7a87910ff6b237427/codecut/__init__.py
--------------------------------------------------------------------------------
/codecut/cc_main.py:
--------------------------------------------------------------------------------
1 | ##############################################################################################
2 | # Copyright 2019 The Johns Hopkins University Applied Physics Laboratory LLC
3 | # All rights reserved.
4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of this
5 | # software and associated documentation files (the "Software"), to deal in the Software
6 | # without restriction, including without limitation the rights to use, copy, modify,
7 | # merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
8 | # permit persons to whom the Software is furnished to do so.
9 | #
10 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
11 | # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
12 | # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
13 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
14 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
15 | # OR OTHER DEALINGS IN THE SOFTWARE.
16 | #
17 | # HAVE A NICE DAY.
18 |
19 | import maxcut
20 | import lfa
21 | import module
22 | import cc_base
23 | import basicutils_7x as basicutils
24 | import snap_cg
25 | import importlib
26 |
27 | try:
28 | import modnaming
29 | except ImportError:
30 | pass
31 |
32 | def go():
33 |
34 | #Do LFA and MaxCut Analysis to find module boundaries
35 | lfa_funclist, lfa_modlist = lfa.analyze()
36 | merge_flist,maxcut_modlist = maxcut.analyze(lfa_funclist)
37 |
38 | #Guess names for the modules using NLP
39 | lfa_modlist = modnaming.guess_module_names(lfa_modlist)
40 | maxcut_modlist = modnaming.guess_module_names(maxcut_modlist)
41 |
42 | #Output all results as .csv
43 | cc_base.print_results(merge_flist, lfa_modlist, maxcut_modlist)
44 |
45 | #Output module-to-module call graph as a Graphviz .gv file
46 | cc_base.gen_mod_graph(lfa_modlist, "lfa")
47 | cc_base.gen_mod_graph(maxcut_modlist, "mc")
48 |
49 | #Output a Python script that will rename modules
50 | cc_base.gen_rename_script(lfa_modlist, "lfa")
51 | cc_base.gen_rename_script(maxcut_modlist, "mc")
52 |
53 | #Output .map file (for comparison against ground truth, when available)
54 | cc_base.gen_map_file(lfa_modlist, "lfa")
55 | cc_base.gen_map_file(maxcut_modlist, "mc")
56 |
57 | return True
58 |
59 | if __name__ == "__main__":
60 | importlib.reload(modnaming)
61 | importlib.reload(module)
62 | importlib.reload(cc_base)
63 | importlib.reload(lfa)
64 | importlib.reload(maxcut)
65 | importlib.reload(snap_cg)
66 | importlib.reload(basicutils)
67 | go()
68 |
69 |
--------------------------------------------------------------------------------
/codecut/module.py:
--------------------------------------------------------------------------------
1 | ##############################################################################################
2 | # Copyright 2019 The Johns Hopkins University Applied Physics Laboratory LLC
3 | # All rights reserved.
4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of this
5 | # software and associated documentation files (the "Software"), to deal in the Software
6 | # without restriction, including without limitation the rights to use, copy, modify,
7 | # merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
8 | # permit persons to whom the Software is furnished to do so.
9 | #
10 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
11 | # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
12 | # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
13 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
14 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
15 | # OR OTHER DEALINGS IN THE SOFTWARE.
16 | #
17 | # HAVE A NICE DAY.
18 |
19 | #This represents the information we want to record about an individual function
20 | #The function lists returned by LFA and MaxCut are made up of these
21 | class func_info():
22 | def __init__(self,loc,score1,score2):
23 | self.loc = loc #the effective address of the function
24 | self.score1=score1 #"Calls from" local function affinity score
25 | self.score2=score2 #"Calls to" local function affinity score
26 | self.total_score=score1+score2
27 | self.lfa_skip=0 #Set to 1 if "skipped" (not scored) by LFA
28 | self.edge=[0,0] #Set by edge_detect() - if 1, this is the start of a new module
29 | #index 0 for LFA, 1 for MaxCut
30 |
31 | def __repr__(self):
32 | return "Function: 0x%08x" % (self.loc)
33 |
34 | def __str__(self):
35 | return self.__repr__()
36 |
37 | #This represents the object files (aka modules) identified by LFA and MaxCut
38 | class bin_module():
39 | def __init__(self,start,end,score,name):
40 | self.start=start
41 | self.end=end
42 | self.score=score #Currently unused
43 | self.name=name
44 |
45 | def __repr__(self):
46 | line = "Module at 0x%08x:0x%08x" % (self.start, self.end)
47 | if self.name != "" and self.name is not None:
48 | line += " (name %s)" % self.name
49 | return line
50 |
51 | def __str__(self):
52 | return self.__repr__()
53 |
--------------------------------------------------------------------------------
/codecut/snap_cg.py:
--------------------------------------------------------------------------------
1 | ##############################################################################################
2 | # Copyright 2019 The Johns Hopkins University Applied Physics Laboratory LLC
3 | # All rights reserved.
4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of this
5 | # software and associated documentation files (the "Software"), to deal in the Software
6 | # without restriction, including without limitation the rights to use, copy, modify,
7 | # merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
8 | # permit persons to whom the Software is furnished to do so.
9 | #
10 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
11 | # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
12 | # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
13 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
14 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
15 | # OR OTHER DEALINGS IN THE SOFTWARE.
16 | #
17 | # HAVE A NICE DAY.
18 |
19 | ## This code creates a Snap PNGraph object that represents the call graph of a binary
20 | ## (the .text section)
21 |
22 | import snap
23 | import sys
24 |
25 | import idc
26 | import struct
27 | import idautils
28 | import basicutils_7x as basicutils
29 |
30 | MAX_DIST = 0
31 |
32 |
33 | UGraph = []
34 |
35 | def add_edge(f, t):
36 | global UGraph
37 | n = basicutils.GetFunctionName(f)
38 | if n != "":
39 | #since we're only doing one edge for each xref, we'll do weight based on distance from the middle of the caller to the callee
40 | f_start = idc.get_func_attr(f, idc.FUNCATTR_START)
41 |
42 | if (not UGraph.IsNode(f_start)):
43 | print("Error: had to add node (to): %08x" % f_start)
44 | UGraph.AddNode(f_start)
45 |
46 | print("%08x -> %08x" % (f_start, t))
47 | UGraph.AddEdge(t,f_start)
48 |
49 | #print "s_%#x -> s_%#x" % (f_start,t)," [len = ",get_weight(func_mid, t), "]"
50 |
51 |
52 | def add_node(f):
53 | basicutils.ForEveryXrefToD(f, add_edge)
54 |
55 | def create_snap_cg():
56 | global UGraph
57 | UGraph= snap.PNGraph.New()
58 |
59 | #Add every function linearly, this makes sure the nodes are in order
60 | basicutils.ForEveryFuncInSeg(".text",UGraph.AddNode)
61 | basicutils.ForEveryFuncInSeg(".text",add_node)
62 |
63 | for NI in UGraph.Nodes():
64 | print("node id 0x%x with out-degree %d and in-degree %d" %(
65 | NI.GetId(), NI.GetOutDeg(), NI.GetInDeg()))
66 |
67 | return UGraph
68 |
--------------------------------------------------------------------------------
/db_support/__init__.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python3
2 |
3 | """
4 | Diaphora database related support
5 | Copyright (c) 2023, Joxean Koret
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU Affero General Public License as
9 | published by the Free Software Foundation, either version 3 of the
10 | License, or (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU Affero General Public License for more details.
16 |
17 | You should have received a copy of the GNU Affero General Public License
18 | along with this program. If not, see .
19 | """
20 |
--------------------------------------------------------------------------------
/diaphora_import.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 |
3 | """
4 | Diaphora, a diffing plugin for IDA
5 | Copyright (c) 2015-2021, Joxean Koret
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU Affero General Public License as
9 | published by the Free Software Foundation, either version 3 of the
10 | License, or (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU Affero General Public License for more details.
16 |
17 | You should have received a copy of the GNU Affero General Public License
18 | along with this program. If not, see .
19 |
20 | """
21 |
22 | import importlib
23 | import diaphora_ida
24 |
25 | from diaphora_ida import import_definitions
26 |
27 | importlib.reload(diaphora_ida)
28 |
29 | #-----------------------------------------------------------------------
30 | def main():
31 | import_definitions()
32 |
33 | if __name__ == "__main__":
34 | main()
35 |
--------------------------------------------------------------------------------
/diaphora_load.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 |
3 | """
4 | Diaphora, a diffing plugin for IDA
5 | Copyright (c) 2015-2021, Joxean Koret
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU Affero General Public License as
9 | published by the Free Software Foundation, either version 3 of the
10 | License, or (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU Affero General Public License for more details.
16 |
17 | You should have received a copy of the GNU Affero General Public License
18 | along with this program. If not, see .
19 |
20 | """
21 |
22 | import importlib
23 | import diaphora_ida
24 |
25 | from diaphora_ida import load_results
26 |
27 | importlib.reload(diaphora_ida)
28 |
29 | #-----------------------------------------------------------------------
30 | def main():
31 | load_results()
32 |
33 | if __name__ == "__main__":
34 | main()
35 |
--------------------------------------------------------------------------------
/diaphora_load_and_import.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 |
3 | """
4 | Diaphora, a diffing plugin for IDA
5 | Copyright (c) 2015, Joxean Koret
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 2 of the License, or
9 | (at your option) any later version.
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .
16 | """
17 |
18 | import idc
19 |
20 | from diaphora_ida import load_and_import_all_results
21 |
22 | #-----------------------------------------------------------------------
23 | def main():
24 | filename = idc.ARGV[1]
25 | main_db = idc.ARGV[2]
26 | diff_db = idc.ARGV[3]
27 |
28 | load_and_import_all_results(filename, main_db, diff_db)
29 |
30 | if __name__ == "__main__":
31 | main()
32 |
--------------------------------------------------------------------------------
/doc/README.md:
--------------------------------------------------------------------------------
1 | ## Documentation
2 |
3 | This directory contains all the existing documentation files for the Diaphora project.
4 |
--------------------------------------------------------------------------------
/doc/articles/img/codecut-slide.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joxeankoret/diaphora/d8b898e35750d103cb6a15f7a87910ff6b237427/doc/articles/img/codecut-slide.png
--------------------------------------------------------------------------------
/doc/articles/img/codecut-slide.xcf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joxeankoret/diaphora/d8b898e35750d103cb6a15f7a87910ff6b237427/doc/articles/img/codecut-slide.xcf
--------------------------------------------------------------------------------
/doc/articles/img/compilation-units-matches.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joxeankoret/diaphora/d8b898e35750d103cb6a15f7a87910ff6b237427/doc/articles/img/compilation-units-matches.png
--------------------------------------------------------------------------------
/doc/examples/hooks/debug_helper.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 |
3 | """
4 | Example Diaphora export hooks script for debugging problems.
5 | Joxean Koret, admin@joxeankoret.com
6 |
7 | Public Domain
8 | """
9 |
10 | #-----------------------------------------------------------------------
11 | class CDebuggingHelper:
12 | def __init__(self, diaphora_obj):
13 | """ @diaphora_obj is the object with all the Diaphora APIs.
14 | """
15 | self.diaphora = diaphora_obj
16 |
17 | self.last_ea = None
18 | self.last_name = None
19 |
20 | def before_export_function(self, ea, func_name):
21 | """ @ea is the address of the function that is going to be read.
22 | Return True for the function to be read, or False to ignore it.
23 | """
24 | self.last_ea = ea
25 | self.last_name = func_name
26 | print("Exporting function 0x%08x: %s" % (ea, func_name))
27 | return True
28 |
29 | def on_export_crash(self):
30 | """ @ea is the address of the function where Diaphora crashed exporting it.
31 | Return True to crash the export process, or False to ignore this error.
32 | """
33 | if self.last_ea is None:
34 | print("Diaphora crashed before exporting a single function!!!")
35 | else:
36 | print("Export crashed at function 0x%08x: %s" % (self.last_ea, self.last_name))
37 | return True
38 |
39 | def after_export_function(self, d):
40 | """ @d is a dictionary with everything that Diaphora exports for the current
41 | function. You can freely modify values here or simply inspect to verify
42 | it didn't do something wrong here or there.
43 |
44 | Check 'create_function_dictionary()' in diaphora_ida.py to get the full
45 | list of fields in the dictionary @d.
46 | """
47 | return d
48 |
49 | HOOKS = {"DiaphoraHooks": CDebuggingHelper}
50 |
--------------------------------------------------------------------------------
/doc/examples/hooks/exclude_heuristics.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 |
3 | """
4 | Script to exclude specific heuristics
5 | Created by Joxean Koret
6 |
7 | Public domain
8 | """
9 |
10 | #-------------------------------------------------------------------------------
11 | EXCLUDE_HEURISTICS = ["pseudo-code fuzzy ast hash"]
12 |
13 | #-------------------------------------------------------------------------------
14 | class CExcludeHeuristicHooks:
15 | def __init__(self, diaphora_obj):
16 | self.diaphora = diaphora_obj
17 |
18 | def get_heuristics(self, category, heuristics):
19 | """
20 | Build a new list with the SQL based heuristics that we want Diaphora to use.
21 | """
22 | new_heurs = []
23 | for heur in heuristics:
24 | name = heur["name"]
25 | if name.lower() not in EXCLUDE_HEURISTICS:
26 | new_heurs.append(heur)
27 | else:
28 | self.diaphora.log(f"Note: Heuristic {name} excluded")
29 | return new_heurs
30 |
31 | def on_special_heuristic(self, heuristic, iteration):
32 | """
33 | We need to use this event too because some special heuristics not based on
34 | SQL queries are handled differently. Basically, we just check the @heuristic
35 | and return True/False if it's allowed or not.
36 | """
37 | if heuristic.lower() in EXCLUDE_HEURISTICS:
38 | self.diaphora.log(f"Note: Special heuristic {heuristic} disabled")
39 | return False
40 | return True
41 |
42 | HOOKS = {"DiaphoraHooks": CExcludeHeuristicHooks}
43 |
44 |
--------------------------------------------------------------------------------
/doc/examples/hooks/hooks_example1.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 |
3 | """
4 | Example Diaphora export hooks script. In this example script the following fake
5 | scenario is considered:
6 |
7 | 1) There is a something-user.i64 database, for user-land stuff.
8 | 2) There is a something-kernel.i64 database, for kernel-land stuff.
9 | 3) We export all functions from the something-user.i64 database.
10 | 4) We only export from something-kernel.i64 the syscall_* or sys_* prefixed
11 | functions.
12 | 5) In both databases there are constants referencing the build identifier but
13 | they are different for both databases: BUILD-1000 in the user-land part and
14 | BUILD-2000 in the kernel-land part. For making a perfect match based on the
15 | constants found in both databases, we change the strings BUILD-XXX to the
16 | generic string "BUILD-ID" for both databases.
17 |
18 | """
19 |
20 | #-----------------------------------------------------------------------
21 | FUNC_PREFIXES = ["syscall_", "sys_"]
22 | BUILD_IDS = ["BUILD-1000", "BUILD-2000"]
23 |
24 | #-----------------------------------------------------------------------
25 | class CMyHooks:
26 | def __init__(self, diaphora_obj):
27 | """ @diaphora_obj is the CIDABinDiff object being used.
28 | """
29 | self.diaphora = diaphora_obj
30 | self.db_name = self.diaphora.db_name
31 |
32 | def before_export_function(self, ea, func_name):
33 | """ @ea is the address of the function that is going to be read.
34 | Return True for the function to be read, or False to ignore it.
35 | """
36 |
37 | # If the IDB name has the word 'user' on it, it's the user-land database for
38 | # which we want to export everything.
39 | if self.db_name.find("user") > -1:
40 | return True
41 |
42 | # Otherwise, it's the kernel-land IDB for which we only want to export the
43 | # syscall functions.
44 | if func_name:
45 | # Is it a syscall?
46 | for prefix in FUNC_PREFIXES:
47 | if func_name.startswith(prefix):
48 | return True
49 |
50 | return False
51 |
52 | def after_export_function(self, d):
53 | """ @d is a dictionary with everything exported by Diaphora for the current
54 | function. Transformations can be applied to the dictionary like changing
55 | some strings or constants or whatever else. The function must return a
56 | new dictionary with the modifications.
57 | """
58 |
59 | # Search if any of the constants in the dictionary has the string "BUILD-*"
60 | # and, if so, change it in the export process to a generic "BUILD-ID" string
61 | # that will match more functions.
62 | for build_id in BUILD_IDS:
63 | for key in d:
64 | if type(d[key]) is str:
65 | if d[key].find(build_id) > -1:
66 | d[key] = d[key].replace(build_id, "GENERIC-BUILD-ID")
67 |
68 | return d
69 |
70 | HOOKS = {"DiaphoraHooks": CMyHooks}
71 |
--------------------------------------------------------------------------------
/doc/old/Tutorial-Analyzing MS15-050 With Diaphora-By Alex Ionescu.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joxeankoret/diaphora/d8b898e35750d103cb6a15f7a87910ff6b237427/doc/old/Tutorial-Analyzing MS15-050 With Diaphora-By Alex Ionescu.pdf
--------------------------------------------------------------------------------
/doc/old/diaphora_help.odt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joxeankoret/diaphora/d8b898e35750d103cb6a15f7a87910ff6b237427/doc/old/diaphora_help.odt
--------------------------------------------------------------------------------
/doc/old/images/arrow-down.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joxeankoret/diaphora/d8b898e35750d103cb6a15f7a87910ff6b237427/doc/old/images/arrow-down.png
--------------------------------------------------------------------------------
/doc/old/images/bg_hr.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joxeankoret/diaphora/d8b898e35750d103cb6a15f7a87910ff6b237427/doc/old/images/bg_hr.png
--------------------------------------------------------------------------------
/doc/old/images/blacktocat.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joxeankoret/diaphora/d8b898e35750d103cb6a15f7a87910ff6b237427/doc/old/images/blacktocat.png
--------------------------------------------------------------------------------
/doc/old/images/body-bg.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joxeankoret/diaphora/d8b898e35750d103cb6a15f7a87910ff6b237427/doc/old/images/body-bg.jpg
--------------------------------------------------------------------------------
/doc/old/images/download-button.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joxeankoret/diaphora/d8b898e35750d103cb6a15f7a87910ff6b237427/doc/old/images/download-button.png
--------------------------------------------------------------------------------
/doc/old/images/github-button.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joxeankoret/diaphora/d8b898e35750d103cb6a15f7a87910ff6b237427/doc/old/images/github-button.png
--------------------------------------------------------------------------------
/doc/old/images/header-bg.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joxeankoret/diaphora/d8b898e35750d103cb6a15f7a87910ff6b237427/doc/old/images/header-bg.jpg
--------------------------------------------------------------------------------
/doc/old/images/highlight-bg.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joxeankoret/diaphora/d8b898e35750d103cb6a15f7a87910ff6b237427/doc/old/images/highlight-bg.jpg
--------------------------------------------------------------------------------
/doc/old/images/icon_download.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joxeankoret/diaphora/d8b898e35750d103cb6a15f7a87910ff6b237427/doc/old/images/icon_download.png
--------------------------------------------------------------------------------
/doc/old/images/octocat-small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joxeankoret/diaphora/d8b898e35750d103cb6a15f7a87910ff6b237427/doc/old/images/octocat-small.png
--------------------------------------------------------------------------------
/doc/old/images/sidebar-bg.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joxeankoret/diaphora/d8b898e35750d103cb6a15f7a87910ff6b237427/doc/old/images/sidebar-bg.jpg
--------------------------------------------------------------------------------
/doc/old/images/sprite_download.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joxeankoret/diaphora/d8b898e35750d103cb6a15f7a87910ff6b237427/doc/old/images/sprite_download.png
--------------------------------------------------------------------------------
/extras/README.md:
--------------------------------------------------------------------------------
1 | # Diaphora local
2 |
3 | This is a pure Python IDA plugin to diff pseudo-codes and assembly for functions inside the current binary, instead of diffing functions in different binaries.
4 |
5 | # Installation
6 |
7 | Simply copy this script in the directory `$IDA_DIR/plugins`.
8 |
9 | # Usage
10 |
11 | Put the cursor in IDA in some function and press Ctrl + Shift + D, choose the function to diff against the current function and 2 choosers (windows) will open showing the differences at pseudo-code and assembly levels.
12 |
13 |
14 |
--------------------------------------------------------------------------------
/jkutils/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joxeankoret/diaphora/d8b898e35750d103cb6a15f7a87910ff6b237427/jkutils/__init__.py
--------------------------------------------------------------------------------
/jkutils/threads.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python3
2 |
3 | """
4 | Threads support
5 | Copyright (c) 2023, Joxean Koret
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU Affero General Public License as
9 | published by the Free Software Foundation, either version 3 of the
10 | License, or (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU Affero General Public License for more details.
16 |
17 | You should have received a copy of the GNU Affero General Public License
18 | along with this program. If not, see .
19 | """
20 |
21 | __all__ = ["threads_apply"]
22 |
23 | import time
24 | import threading
25 |
26 | #-------------------------------------------------------------------------------
27 | def threads_apply(threads, targets, wait_time, log_refresh, timeout):
28 | """
29 | Run a number of @threads calling a function with arguments from @targets,
30 | waiting and checking the threads if they finished every @wait_time seconds,
31 | calling @log_refresh whenever it's required.
32 | """
33 | times = 0
34 | first = True
35 | threads_list = []
36 | while first or len(targets) > 0 or len(threads_list) > 0:
37 | first = False
38 | times += 1
39 | if len(targets) > 0 and len(threads_list) < threads:
40 | item = targets.pop()
41 | target = item["target"]
42 | args = item["args"]
43 |
44 | t = threading.Thread(target=target, args=args)
45 | t.time = time.monotonic()
46 | t.timeout = False
47 |
48 | for key in item.keys():
49 | if key not in ["target", "args"]:
50 | setattr(t, key, item[key])
51 |
52 | t.start()
53 | threads_list.append(t)
54 |
55 | for i, t in enumerate(threads_list):
56 | if not t.is_alive():
57 | if log_refresh:
58 | log_refresh(f"[Parallel] Heuristic '{t.name}' done")
59 | del threads_list[i]
60 | break
61 |
62 | if time.monotonic() - t.time > timeout:
63 | t.timeout = True
64 | t.join(wait_time)
65 |
66 | if times % 50 == 0:
67 | names = []
68 | for x in threads_list:
69 | names.append(x.name)
70 | tmp_names = ", ".join(names)
71 | log_refresh(f"[Parallel] {len(threads_list)} thread(s) still running: {tmp_names}")
72 |
73 |
--------------------------------------------------------------------------------
/logo/diaphora-border.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joxeankoret/diaphora/d8b898e35750d103cb6a15f7a87910ff6b237427/logo/diaphora-border.png
--------------------------------------------------------------------------------
/ml/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joxeankoret/diaphora/d8b898e35750d103cb6a15f7a87910ff6b237427/ml/__init__.py
--------------------------------------------------------------------------------
/ml/diaphora-amalgamation-model.pkl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joxeankoret/diaphora/d8b898e35750d103cb6a15f7a87910ff6b237427/ml/diaphora-amalgamation-model.pkl
--------------------------------------------------------------------------------
/others/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joxeankoret/diaphora/d8b898e35750d103cb6a15f7a87910ff6b237427/others/__init__.py
--------------------------------------------------------------------------------
/others/tarjan_sort.py:
--------------------------------------------------------------------------------
1 |
2 | # Downloaded from http://www.logarithmic.net/pfh-files/blog/01208083168/sort.py
3 |
4 | """
5 |
6 | Tarjan's algorithm and topological sorting implementation in Python
7 |
8 | by Paul Harrison
9 |
10 | Public domain, do with it as you will
11 |
12 | """
13 |
14 | def strongly_connected_components(graph):
15 | """ Find the strongly connected components in a graph using
16 | Tarjan's algorithm.
17 |
18 | graph should be a dictionary mapping node names to
19 | lists of successor nodes.
20 | """
21 |
22 | result = [ ]
23 | stack = [ ]
24 | low = { }
25 |
26 | def visit(node):
27 | if node in low: return
28 | if node not in graph: graph[node] = []
29 |
30 | num = len(low)
31 | low[node] = num
32 | stack_pos = len(stack)
33 | stack.append(node)
34 |
35 | for successor in graph[node]:
36 | visit(successor)
37 | low[node] = min(low[node], low[successor])
38 |
39 | if num == low[node]:
40 | component = tuple(stack[stack_pos:])
41 | del stack[stack_pos:]
42 | result.append(component)
43 | for item in component:
44 | low[item] = len(graph)
45 |
46 | for node in dict(graph):
47 | visit(node)
48 |
49 | return result
50 |
51 |
52 | def topological_sort(graph):
53 | count = { }
54 | for node in graph:
55 | count[node] = 0
56 | for node in graph:
57 | for successor in graph[node]:
58 | count[successor] += 1
59 |
60 | ready = [ node for node in graph if count[node] == 0 ]
61 |
62 | result = [ ]
63 | while ready:
64 | node = ready.pop(-1)
65 | result.append(node)
66 |
67 | for successor in graph[node]:
68 | count[successor] -= 1
69 | if count[successor] == 0:
70 | ready.append(successor)
71 |
72 | return result
73 |
74 |
75 | def robust_topological_sort(graph):
76 | """ First identify strongly connected components,
77 | then perform a topological sort on these components. """
78 |
79 | components = strongly_connected_components(graph)
80 |
81 | node_component = { }
82 | for component in components:
83 | for node in component:
84 | node_component[node] = component
85 |
86 | component_graph = { }
87 | for component in components:
88 | component_graph[component] = [ ]
89 |
90 | for node in graph:
91 | node_c = node_component[node]
92 | for successor in graph[node]:
93 | successor_c = node_component[successor]
94 | if node_c != successor_c:
95 | component_graph[node_c].append(successor_c)
96 |
97 | return topological_sort(component_graph)
98 |
99 |
100 | if __name__ == '__main__':
101 | d = {
102 | 0 : [1],
103 | 1 : [2],
104 | 2 : [1,3],
105 | 3 : [3],
106 | }
107 | #print d
108 | #print robust_topological_sort(d)
109 |
110 | d = {0 : [1, 2, 4], 1 : [3, 4], 2 : [0, 3], 3 : [], 4: [1]}
111 | print(d)
112 | print("scc", strongly_connected_components(d))
113 | print("rts", robust_topological_sort(d))
114 |
115 |
--------------------------------------------------------------------------------
/plugin/README.md:
--------------------------------------------------------------------------------
1 | # Diaphora as an integrated IDA plugin
2 |
3 | This is a very basic wrapper for integrating Diaphora as a plugin in IDA Pro.
4 | In order to install it just do the following:
5 |
6 | * Copy `diaphora_plugin.py` and `diaphora_plugin.cfg` to the IDA's plugins directory.
7 | * Edit `diaphora_plugin.cfg` and set the `path` value to the Diaphora's directory.
8 |
9 | This is a very basic wrapper. It will be enhanced in the future.
10 |
--------------------------------------------------------------------------------
/plugin/diaphora_plugin.cfg:
--------------------------------------------------------------------------------
1 | [Diaphora]
2 | path=/path/to/diaphora/
3 |
--------------------------------------------------------------------------------
/plugin/diaphora_plugin.py:
--------------------------------------------------------------------------------
1 | """
2 | Diaphora, a binary diffing tool
3 | Copyright (c) 2015-2024, Joxean Koret
4 |
5 | This program is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU Affero General Public License as
7 | published by the Free Software Foundation, either version 3 of the
8 | License, or (at your option) any later version.
9 |
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU Affero General Public License for more details.
14 |
15 | You should have received a copy of the GNU Affero General Public License
16 | along with this program. If not, see .
17 | """
18 |
19 | import os
20 | import sys
21 | import configparser
22 |
23 | import idaapi
24 | from idaapi import warning
25 |
26 | #-------------------------------------------------------------------------------
27 | def resolve_diaphora():
28 | config_dir = os.path.dirname(__file__)
29 | config_file = os.path.join(config_dir, "diaphora_plugin.cfg")
30 | if not os.path.exists(config_file):
31 | warning(f"The configuration file {config_file} does not exist.")
32 | return None
33 |
34 | config = configparser.ConfigParser()
35 | config.read(config_file)
36 |
37 | path = config["Diaphora"]["path"]
38 | sys.path.append(path)
39 |
40 | from diaphora_ida import main
41 | return main
42 |
43 | #-------------------------------------------------------------------------------
44 | class DiaphoraPlugin(idaapi.plugin_t):
45 | wanted_name = "Diaphora"
46 | version = "3.2.0"
47 | wanted_hotkey = ""
48 | comment = "Diaphora by joxeankoret"
49 | website = "https://github.com/joxeankoret/diaphora"
50 | help = "Export the current binary or diff against another binary"
51 | flags = 0
52 |
53 | def init(self):
54 | self.diaphora_main = None
55 | return idaapi.PLUGIN_KEEP
56 |
57 | def term(self):
58 | pass
59 |
60 | def run(self, arg):
61 | if self.diaphora_main is None:
62 | self.diaphora_main = resolve_diaphora()
63 |
64 | if self.diaphora_main is not None:
65 | self.diaphora_main()
66 |
67 | return True
68 |
69 | #-------------------------------------------------------------------------------
70 | def PLUGIN_ENTRY():
71 | return DiaphoraPlugin()
72 |
73 |
--------------------------------------------------------------------------------
/pygments/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | Pygments
3 | ~~~~~~~~
4 |
5 | Pygments is a syntax highlighting package written in Python.
6 |
7 | It is a generic syntax highlighter for general use in all kinds of software
8 | such as forum systems, wikis or other applications that need to prettify
9 | source code. Highlights are:
10 |
11 | * a wide range of common languages and markup formats is supported
12 | * special attention is paid to details, increasing quality by a fair amount
13 | * support for new languages and formats are added easily
14 | * a number of output formats, presently HTML, LaTeX, RTF, SVG, all image
15 | formats that PIL supports, and ANSI sequences
16 | * it is usable as a command-line tool and as a library
17 | * ... and it highlights even Brainfuck!
18 |
19 | The `Pygments master branch`_ is installable with ``easy_install Pygments==dev``.
20 |
21 | .. _Pygments master branch:
22 | https://github.com/pygments/pygments/archive/master.zip#egg=Pygments-dev
23 |
24 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
25 | :license: BSD, see LICENSE for details.
26 | """
27 | from io import StringIO, BytesIO
28 |
29 | __version__ = '2.13.0'
30 | __docformat__ = 'restructuredtext'
31 |
32 | __all__ = ['lex', 'format', 'highlight']
33 |
34 |
35 | def lex(code, lexer):
36 | """
37 | Lex ``code`` with ``lexer`` and return an iterable of tokens.
38 | """
39 | try:
40 | return lexer.get_tokens(code)
41 | except TypeError:
42 | # Heuristic to catch a common mistake.
43 | from pygments.lexer import RegexLexer
44 | if isinstance(lexer, type) and issubclass(lexer, RegexLexer):
45 | raise TypeError('lex() argument must be a lexer instance, '
46 | 'not a class')
47 | raise
48 |
49 |
50 | def format(tokens, formatter, outfile=None): # pylint: disable=redefined-builtin
51 | """
52 | Format a tokenlist ``tokens`` with the formatter ``formatter``.
53 |
54 | If ``outfile`` is given and a valid file object (an object
55 | with a ``write`` method), the result will be written to it, otherwise
56 | it is returned as a string.
57 | """
58 | try:
59 | if not outfile:
60 | realoutfile = getattr(formatter, 'encoding', None) and BytesIO() or StringIO()
61 | formatter.format(tokens, realoutfile)
62 | return realoutfile.getvalue()
63 | else:
64 | formatter.format(tokens, outfile)
65 | except TypeError:
66 | # Heuristic to catch a common mistake.
67 | from pygments.formatter import Formatter
68 | if isinstance(formatter, type) and issubclass(formatter, Formatter):
69 | raise TypeError('format() argument must be a formatter instance, '
70 | 'not a class')
71 | raise
72 |
73 |
74 | def highlight(code, lexer, formatter, outfile=None):
75 | """
76 | Lex ``code`` with ``lexer`` and format it with the formatter ``formatter``.
77 |
78 | If ``outfile`` is given and a valid file object (an object
79 | with a ``write`` method), the result will be written to it, otherwise
80 | it is returned as a string.
81 | """
82 | return format(lex(code, lexer), formatter, outfile)
83 |
--------------------------------------------------------------------------------
/pygments/__main__.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.__main__
3 | ~~~~~~~~~~~~~~~~~
4 |
5 | Main entry point for ``python -m pygments``.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | import sys
12 | import pygments.cmdline
13 |
14 | try:
15 | sys.exit(pygments.cmdline.main(sys.argv))
16 | except KeyboardInterrupt:
17 | sys.exit(1)
18 |
--------------------------------------------------------------------------------
/pygments/console.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.console
3 | ~~~~~~~~~~~~~~~~
4 |
5 | Format colored console output.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | esc = "\x1b["
12 |
13 | codes = {}
14 | codes[""] = ""
15 | codes["reset"] = esc + "39;49;00m"
16 |
17 | codes["bold"] = esc + "01m"
18 | codes["faint"] = esc + "02m"
19 | codes["standout"] = esc + "03m"
20 | codes["underline"] = esc + "04m"
21 | codes["blink"] = esc + "05m"
22 | codes["overline"] = esc + "06m"
23 |
24 | dark_colors = ["black", "red", "green", "yellow", "blue",
25 | "magenta", "cyan", "gray"]
26 | light_colors = ["brightblack", "brightred", "brightgreen", "brightyellow", "brightblue",
27 | "brightmagenta", "brightcyan", "white"]
28 |
29 | x = 30
30 | for d, l in zip(dark_colors, light_colors):
31 | codes[d] = esc + "%im" % x
32 | codes[l] = esc + "%im" % (60 + x)
33 | x += 1
34 |
35 | del d, l, x
36 |
37 | codes["white"] = codes["bold"]
38 |
39 |
40 | def reset_color():
41 | return codes["reset"]
42 |
43 |
44 | def colorize(color_key, text):
45 | return codes[color_key] + text + codes["reset"]
46 |
47 |
48 | def ansiformat(attr, text):
49 | """
50 | Format ``text`` with a color and/or some attributes::
51 |
52 | color normal color
53 | *color* bold color
54 | _color_ underlined color
55 | +color+ blinking color
56 | """
57 | result = []
58 | if attr[:1] == attr[-1:] == '+':
59 | result.append(codes['blink'])
60 | attr = attr[1:-1]
61 | if attr[:1] == attr[-1:] == '*':
62 | result.append(codes['bold'])
63 | attr = attr[1:-1]
64 | if attr[:1] == attr[-1:] == '_':
65 | result.append(codes['underline'])
66 | attr = attr[1:-1]
67 | result.append(codes[attr])
68 | result.append(text)
69 | result.append(codes['reset'])
70 | return ''.join(result)
71 |
--------------------------------------------------------------------------------
/pygments/filter.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.filter
3 | ~~~~~~~~~~~~~~~
4 |
5 | Module that implements the default filter.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 |
12 | def apply_filters(stream, filters, lexer=None):
13 | """
14 | Use this method to apply an iterable of filters to
15 | a stream. If lexer is given it's forwarded to the
16 | filter, otherwise the filter receives `None`.
17 | """
18 | def _apply(filter_, stream):
19 | yield from filter_.filter(lexer, stream)
20 | for filter_ in filters:
21 | stream = _apply(filter_, stream)
22 | return stream
23 |
24 |
25 | def simplefilter(f):
26 | """
27 | Decorator that converts a function into a filter::
28 |
29 | @simplefilter
30 | def lowercase(self, lexer, stream, options):
31 | for ttype, value in stream:
32 | yield ttype, value.lower()
33 | """
34 | return type(f.__name__, (FunctionFilter,), {
35 | '__module__': getattr(f, '__module__'),
36 | '__doc__': f.__doc__,
37 | 'function': f,
38 | })
39 |
40 |
41 | class Filter:
42 | """
43 | Default filter. Subclass this class or use the `simplefilter`
44 | decorator to create own filters.
45 | """
46 |
47 | def __init__(self, **options):
48 | self.options = options
49 |
50 | def filter(self, lexer, stream):
51 | raise NotImplementedError()
52 |
53 |
54 | class FunctionFilter(Filter):
55 | """
56 | Abstract class used by `simplefilter` to create simple
57 | function filters on the fly. The `simplefilter` decorator
58 | automatically creates subclasses of this class for
59 | functions passed to it.
60 | """
61 | function = None
62 |
63 | def __init__(self, **options):
64 | if not hasattr(self, 'function'):
65 | raise TypeError('%r used without bound function' %
66 | self.__class__.__name__)
67 | Filter.__init__(self, **options)
68 |
69 | def filter(self, lexer, stream):
70 | # pylint: disable=not-callable
71 | yield from self.function(lexer, stream, self.options)
72 |
--------------------------------------------------------------------------------
/pygments/formatter.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.formatter
3 | ~~~~~~~~~~~~~~~~~~
4 |
5 | Base formatter class.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | import codecs
12 |
13 | from pygments.util import get_bool_opt
14 | from pygments.styles import get_style_by_name
15 |
16 | __all__ = ['Formatter']
17 |
18 |
19 | def _lookup_style(style):
20 | if isinstance(style, str):
21 | return get_style_by_name(style)
22 | return style
23 |
24 |
25 | class Formatter:
26 | """
27 | Converts a token stream to text.
28 |
29 | Options accepted:
30 |
31 | ``style``
32 | The style to use, can be a string or a Style subclass
33 | (default: "default"). Not used by e.g. the
34 | TerminalFormatter.
35 | ``full``
36 | Tells the formatter to output a "full" document, i.e.
37 | a complete self-contained document. This doesn't have
38 | any effect for some formatters (default: false).
39 | ``title``
40 | If ``full`` is true, the title that should be used to
41 | caption the document (default: '').
42 | ``encoding``
43 | If given, must be an encoding name. This will be used to
44 | convert the Unicode token strings to byte strings in the
45 | output. If it is "" or None, Unicode strings will be written
46 | to the output file, which most file-like objects do not
47 | support (default: None).
48 | ``outencoding``
49 | Overrides ``encoding`` if given.
50 | """
51 |
52 | #: Name of the formatter
53 | name = None
54 |
55 | #: Shortcuts for the formatter
56 | aliases = []
57 |
58 | #: fn match rules
59 | filenames = []
60 |
61 | #: If True, this formatter outputs Unicode strings when no encoding
62 | #: option is given.
63 | unicodeoutput = True
64 |
65 | def __init__(self, **options):
66 | self.style = _lookup_style(options.get('style', 'default'))
67 | self.full = get_bool_opt(options, 'full', False)
68 | self.title = options.get('title', '')
69 | self.encoding = options.get('encoding', None) or None
70 | if self.encoding in ('guess', 'chardet'):
71 | # can happen for e.g. pygmentize -O encoding=guess
72 | self.encoding = 'utf-8'
73 | self.encoding = options.get('outencoding') or self.encoding
74 | self.options = options
75 |
76 | def get_style_defs(self, arg=''):
77 | """
78 | Return the style definitions for the current style as a string.
79 |
80 | ``arg`` is an additional argument whose meaning depends on the
81 | formatter used. Note that ``arg`` can also be a list or tuple
82 | for some formatters like the html formatter.
83 | """
84 | return ''
85 |
86 | def format(self, tokensource, outfile):
87 | """
88 | Format ``tokensource``, an iterable of ``(tokentype, tokenstring)``
89 | tuples and write it into ``outfile``.
90 | """
91 | if self.encoding:
92 | # wrap the outfile in a StreamWriter
93 | outfile = codecs.lookup(self.encoding)[3](outfile)
94 | return self.format_unencoded(tokensource, outfile)
95 |
--------------------------------------------------------------------------------
/pygments/formatters/pangomarkup.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.formatters.pangomarkup
3 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Formatter for Pango markup output.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.formatter import Formatter
12 |
13 |
14 | __all__ = ['PangoMarkupFormatter']
15 |
16 |
17 | _escape_table = {
18 | ord('&'): '&',
19 | ord('<'): '<',
20 | }
21 |
22 |
23 | def escape_special_chars(text, table=_escape_table):
24 | """Escape & and < for Pango Markup."""
25 | return text.translate(table)
26 |
27 |
28 | class PangoMarkupFormatter(Formatter):
29 | """
30 | Format tokens as Pango Markup code. It can then be rendered to an SVG.
31 |
32 | .. versionadded:: 2.9
33 | """
34 |
35 | name = 'Pango Markup'
36 | aliases = ['pango', 'pangomarkup']
37 | filenames = []
38 |
39 | def __init__(self, **options):
40 | Formatter.__init__(self, **options)
41 |
42 | self.styles = {}
43 |
44 | for token, style in self.style:
45 | start = ''
46 | end = ''
47 | if style['color']:
48 | start += '' % style['color']
49 | end = '' + end
50 | if style['bold']:
51 | start += ''
52 | end = '' + end
53 | if style['italic']:
54 | start += ''
55 | end = '' + end
56 | if style['underline']:
57 | start += ''
58 | end = '' + end
59 | self.styles[token] = (start, end)
60 |
61 | def format_unencoded(self, tokensource, outfile):
62 | lastval = ''
63 | lasttype = None
64 |
65 | outfile.write('')
66 |
67 | for ttype, value in tokensource:
68 | while ttype not in self.styles:
69 | ttype = ttype.parent
70 | if ttype == lasttype:
71 | lastval += escape_special_chars(value)
72 | else:
73 | if lastval:
74 | stylebegin, styleend = self.styles[lasttype]
75 | outfile.write(stylebegin + lastval + styleend)
76 | lastval = escape_special_chars(value)
77 | lasttype = ttype
78 |
79 | if lastval:
80 | stylebegin, styleend = self.styles[lasttype]
81 | outfile.write(stylebegin + lastval + styleend)
82 |
83 | outfile.write('')
84 |
--------------------------------------------------------------------------------
/pygments/lexers/_ada_builtins.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers._ada_builtins
3 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Ada builtins.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | KEYWORD_LIST = (
12 | 'abort',
13 | 'abs',
14 | 'abstract',
15 | 'accept',
16 | 'access',
17 | 'aliased',
18 | 'all',
19 | 'array',
20 | 'at',
21 | 'begin',
22 | 'body',
23 | 'case',
24 | 'constant',
25 | 'declare',
26 | 'delay',
27 | 'delta',
28 | 'digits',
29 | 'do',
30 | 'else',
31 | 'elsif',
32 | 'end',
33 | 'entry',
34 | 'exception',
35 | 'exit',
36 | 'interface',
37 | 'for',
38 | 'goto',
39 | 'if',
40 | 'is',
41 | 'limited',
42 | 'loop',
43 | 'new',
44 | 'null',
45 | 'of',
46 | 'or',
47 | 'others',
48 | 'out',
49 | 'overriding',
50 | 'pragma',
51 | 'protected',
52 | 'raise',
53 | 'range',
54 | 'record',
55 | 'renames',
56 | 'requeue',
57 | 'return',
58 | 'reverse',
59 | 'select',
60 | 'separate',
61 | 'some',
62 | 'subtype',
63 | 'synchronized',
64 | 'task',
65 | 'tagged',
66 | 'terminate',
67 | 'then',
68 | 'type',
69 | 'until',
70 | 'when',
71 | 'while',
72 | 'xor'
73 | )
74 |
75 | BUILTIN_LIST = (
76 | 'Address',
77 | 'Byte',
78 | 'Boolean',
79 | 'Character',
80 | 'Controlled',
81 | 'Count',
82 | 'Cursor',
83 | 'Duration',
84 | 'File_Mode',
85 | 'File_Type',
86 | 'Float',
87 | 'Generator',
88 | 'Integer',
89 | 'Long_Float',
90 | 'Long_Integer',
91 | 'Long_Long_Float',
92 | 'Long_Long_Integer',
93 | 'Natural',
94 | 'Positive',
95 | 'Reference_Type',
96 | 'Short_Float',
97 | 'Short_Integer',
98 | 'Short_Short_Float',
99 | 'Short_Short_Integer',
100 | 'String',
101 | 'Wide_Character',
102 | 'Wide_String'
103 | )
104 |
--------------------------------------------------------------------------------
/pygments/lexers/_usd_builtins.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers._usd_builtins
3 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | A collection of known USD-related keywords, attributes, and types.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | COMMON_ATTRIBUTES = [
12 | "extent",
13 | "xformOpOrder",
14 | ]
15 |
16 | KEYWORDS = [
17 | "class",
18 | "clips",
19 | "custom",
20 | "customData",
21 | "def",
22 | "dictionary",
23 | "inherits",
24 | "over",
25 | "payload",
26 | "references",
27 | "rel",
28 | "subLayers",
29 | "timeSamples",
30 | "uniform",
31 | "variantSet",
32 | "variantSets",
33 | "variants",
34 | ]
35 |
36 | OPERATORS = [
37 | "add",
38 | "append",
39 | "delete",
40 | "prepend",
41 | "reorder",
42 | ]
43 |
44 | SPECIAL_NAMES = [
45 | "active",
46 | "apiSchemas",
47 | "defaultPrim",
48 | "elementSize",
49 | "endTimeCode",
50 | "hidden",
51 | "instanceable",
52 | "interpolation",
53 | "kind",
54 | "startTimeCode",
55 | "upAxis",
56 | ]
57 |
58 | TYPES = [
59 | "asset",
60 | "bool",
61 | "color3d",
62 | "color3f",
63 | "color3h",
64 | "color4d",
65 | "color4f",
66 | "color4h",
67 | "double",
68 | "double2",
69 | "double3",
70 | "double4",
71 | "float",
72 | "float2",
73 | "float3",
74 | "float4",
75 | "frame4d",
76 | "half",
77 | "half2",
78 | "half3",
79 | "half4",
80 | "int",
81 | "int2",
82 | "int3",
83 | "int4",
84 | "keyword",
85 | "matrix2d",
86 | "matrix3d",
87 | "matrix4d",
88 | "normal3d",
89 | "normal3f",
90 | "normal3h",
91 | "point3d",
92 | "point3f",
93 | "point3h",
94 | "quatd",
95 | "quatf",
96 | "quath",
97 | "string",
98 | "syn",
99 | "token",
100 | "uchar",
101 | "uchar2",
102 | "uchar3",
103 | "uchar4",
104 | "uint",
105 | "uint2",
106 | "uint3",
107 | "uint4",
108 | "usdaType",
109 | "vector3d",
110 | "vector3f",
111 | "vector3h",
112 | ]
113 |
--------------------------------------------------------------------------------
/pygments/lexers/agile.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.agile
3 | ~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Just export lexer classes previously contained in this module.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.lexers.lisp import SchemeLexer
12 | from pygments.lexers.jvm import IokeLexer, ClojureLexer
13 | from pygments.lexers.python import PythonLexer, PythonConsoleLexer, \
14 | PythonTracebackLexer, Python3Lexer, Python3TracebackLexer, DgLexer
15 | from pygments.lexers.ruby import RubyLexer, RubyConsoleLexer, FancyLexer
16 | from pygments.lexers.perl import PerlLexer, Perl6Lexer
17 | from pygments.lexers.d import CrocLexer, MiniDLexer
18 | from pygments.lexers.iolang import IoLexer
19 | from pygments.lexers.tcl import TclLexer
20 | from pygments.lexers.factor import FactorLexer
21 | from pygments.lexers.scripting import LuaLexer, MoonScriptLexer
22 |
23 | __all__ = []
24 |
--------------------------------------------------------------------------------
/pygments/lexers/ambient.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.ambient
3 | ~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexers for AmbientTalk language.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | import re
12 |
13 | from pygments.lexer import RegexLexer, include, words, bygroups
14 | from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
15 | Number, Punctuation, Whitespace
16 |
17 | __all__ = ['AmbientTalkLexer']
18 |
19 |
20 | class AmbientTalkLexer(RegexLexer):
21 | """
22 | Lexer for AmbientTalk source code.
23 |
24 | .. versionadded:: 2.0
25 | """
26 | name = 'AmbientTalk'
27 | url = 'https://code.google.com/p/ambienttalk'
28 | filenames = ['*.at']
29 | aliases = ['ambienttalk', 'ambienttalk/2', 'at']
30 | mimetypes = ['text/x-ambienttalk']
31 |
32 | flags = re.MULTILINE | re.DOTALL
33 |
34 | builtin = words(('if:', 'then:', 'else:', 'when:', 'whenever:', 'discovered:',
35 | 'disconnected:', 'reconnected:', 'takenOffline:', 'becomes:',
36 | 'export:', 'as:', 'object:', 'actor:', 'mirror:', 'taggedAs:',
37 | 'mirroredBy:', 'is:'))
38 | tokens = {
39 | 'root': [
40 | (r'\s+', Whitespace),
41 | (r'//.*?\n', Comment.Single),
42 | (r'/\*.*?\*/', Comment.Multiline),
43 | (r'(def|deftype|import|alias|exclude)\b', Keyword),
44 | (builtin, Name.Builtin),
45 | (r'(true|false|nil)\b', Keyword.Constant),
46 | (r'(~|lobby|jlobby|/)\.', Keyword.Constant, 'namespace'),
47 | (r'"(\\\\|\\[^\\]|[^"\\])*"', String),
48 | (r'\|', Punctuation, 'arglist'),
49 | (r'<:|[*^!%&<>+=,./?-]|:=', Operator),
50 | (r"`[a-zA-Z_]\w*", String.Symbol),
51 | (r"[a-zA-Z_]\w*:", Name.Function),
52 | (r"[{}()\[\];`]", Punctuation),
53 | (r'(self|super)\b', Name.Variable.Instance),
54 | (r"[a-zA-Z_]\w*", Name.Variable),
55 | (r"@[a-zA-Z_]\w*", Name.Class),
56 | (r"@\[", Name.Class, 'annotations'),
57 | include('numbers'),
58 | ],
59 | 'numbers': [
60 | (r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float),
61 | (r'\d+', Number.Integer)
62 | ],
63 | 'namespace': [
64 | (r'[a-zA-Z_]\w*\.', Name.Namespace),
65 | (r'[a-zA-Z_]\w*:', Name.Function, '#pop'),
66 | (r'[a-zA-Z_]\w*(?!\.)', Name.Function, '#pop')
67 | ],
68 | 'annotations': [
69 | (r"(.*?)\]", Name.Class, '#pop')
70 | ],
71 | 'arglist': [
72 | (r'\|', Punctuation, '#pop'),
73 | (r'(\s*)(,)(\s*)', bygroups(Whitespace, Punctuation, Whitespace)),
74 | (r'[a-zA-Z_]\w*', Name.Variable),
75 | ],
76 | }
77 |
--------------------------------------------------------------------------------
/pygments/lexers/amdgpu.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.amdgpu
3 | ~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexers for the AMDGPU ISA assembly.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.lexer import RegexLexer, words
12 | from pygments.token import Name, Text, Keyword, Whitespace, Number, Comment
13 |
14 | import re
15 |
16 | __all__ = ['AMDGPULexer']
17 |
18 |
19 | class AMDGPULexer(RegexLexer):
20 | """
21 | For AMD GPU assembly.
22 |
23 | .. versionadded:: 2.8
24 | """
25 | name = 'AMDGPU'
26 | aliases = ['amdgpu']
27 | filenames = ['*.isa']
28 |
29 | flags = re.IGNORECASE
30 |
31 | tokens = {
32 | 'root': [
33 | (r'\s+', Whitespace),
34 | (r'[\r\n]+', Text),
35 | (r'(([a-z_0-9])*:([a-z_0-9])*)', Name.Attribute),
36 | (r'(\[|\]|\(|\)|,|\:|\&)', Text),
37 | (r'([;#]|//).*?\n', Comment.Single),
38 | (r'((s_)?(ds|buffer|flat|image)_[a-z0-9_]+)', Keyword.Reserved),
39 | (r'(_lo|_hi)', Name.Variable),
40 | (r'(vmcnt|lgkmcnt|expcnt)', Name.Attribute),
41 | (words((
42 | 'op', 'vaddr', 'vdata', 'soffset', 'srsrc', 'format',
43 | 'offset', 'offen', 'idxen', 'glc', 'dlc', 'slc', 'tfe', 'lds',
44 | 'lit', 'unorm'), suffix=r'\b'), Name.Attribute),
45 | (r'(label_[a-z0-9]+)', Keyword),
46 | (r'(_L[0-9]*)', Name.Variable),
47 | (r'(s|v)_[a-z0-9_]+', Keyword),
48 | (r'(v[0-9.]+|vcc|exec|v)', Name.Variable),
49 | (r's[0-9.]+|s', Name.Variable),
50 | (r'[0-9]+\.[^0-9]+', Number.Float),
51 | (r'(0[xX][a-z0-9]+)|([0-9]+)', Number.Integer)
52 | ]
53 | }
54 |
--------------------------------------------------------------------------------
/pygments/lexers/asc.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.asc
3 | ~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexer for various ASCII armored files.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 | import re
11 |
12 | from pygments.lexer import RegexLexer, bygroups
13 | from pygments.token import Comment, Generic, Name, Operator, String, Whitespace
14 |
15 | __all__ = ['AscLexer']
16 |
17 |
18 | class AscLexer(RegexLexer):
19 | """
20 | Lexer for ASCII armored files, containing `-----BEGIN/END ...-----` wrapped base64 data.
21 |
22 | .. versionadded:: 2.10
23 | """
24 | name = 'ASCII armored'
25 | aliases = ['asc', 'pem']
26 | filenames = [
27 | '*.asc', # PGP; *.gpg, *.pgp, and *.sig too, but those can be binary
28 | '*.pem', # X.509; *.cer, *.crt, *.csr, and key etc too, but those can be binary
29 | 'id_dsa', 'id_ecdsa', 'id_ecdsa_sk', 'id_ed25519', 'id_ed25519_sk', 'id_rsa', # SSH private keys
30 | ]
31 | mimetypes = ['application/pgp-keys', 'application/pgp-encrypted', 'application/pgp-signature']
32 |
33 | flags = re.MULTILINE
34 |
35 | tokens = {
36 | 'root': [
37 | (r'\s+', Whitespace),
38 | (r'^-----BEGIN [^\n]+-----$', Generic.Heading, 'data'),
39 | (r'\S+', Comment),
40 | ],
41 | 'data': [
42 | (r'\s+', Whitespace),
43 | (r'^([^:]+)(:)([ \t]+)(.*)', bygroups(Name.Attribute, Operator, Whitespace, String)),
44 | (r'^-----END [^\n]+-----$', Generic.Heading, 'root'),
45 | (r'\S+', String),
46 | ],
47 | }
48 |
49 | def analyse_text(text):
50 | if re.search(r'^-----BEGIN [^\n]+-----\r?\n', text):
51 | return True
52 |
--------------------------------------------------------------------------------
/pygments/lexers/bdd.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.bdd
3 | ~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexer for BDD(Behavior-driven development).
6 | More information: https://en.wikipedia.org/wiki/Behavior-driven_development
7 |
8 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
9 | :license: BSD, see LICENSE for details.
10 | """
11 |
12 | from pygments.lexer import RegexLexer, include
13 | from pygments.token import Comment, Keyword, Name, String, Number, Text, Punctuation, Whitespace
14 |
15 | __all__ = ['BddLexer']
16 |
17 | class BddLexer(RegexLexer):
18 | """
19 | Lexer for BDD(Behavior-driven development), which highlights not only keywords,
20 | but also comments, punctuations, strings, numbers, and variables.
21 |
22 | .. versionadded:: 2.11
23 | """
24 |
25 | name = 'Bdd'
26 | aliases = ['bdd']
27 | filenames = ['*.feature']
28 | mimetypes = ['text/x-bdd']
29 |
30 | step_keywords = r'Given|When|Then|Add|And|Feature|Scenario Outline|Scenario|Background|Examples|But'
31 |
32 | tokens = {
33 | 'comments': [
34 | (r'^\s*#.*$', Comment),
35 | ],
36 | 'miscellaneous': [
37 | (r'(<|>|\[|\]|=|\||:|\(|\)|\{|\}|,|\.|;|-|_|\$)', Punctuation),
38 | (r'((?<=\<)[^\\>]+(?=\>))', Name.Variable),
39 | (r'"([^\"]*)"', String),
40 | (r'^@\S+', Name.Label),
41 | ],
42 | 'numbers': [
43 | (r'(\d+\.?\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number),
44 | ],
45 | 'root': [
46 | (r'\n|\s+', Whitespace),
47 | (step_keywords, Keyword),
48 | include('comments'),
49 | include('miscellaneous'),
50 | include('numbers'),
51 | (r'\S+', Text),
52 | ]
53 | }
54 |
55 | def analyse_text(self, text):
56 | return
57 |
--------------------------------------------------------------------------------
/pygments/lexers/capnproto.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.capnproto
3 | ~~~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexers for the Cap'n Proto schema language.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | import re
12 |
13 | from pygments.lexer import RegexLexer, default
14 | from pygments.token import Text, Comment, Keyword, Name, Literal, Whitespace
15 |
16 | __all__ = ['CapnProtoLexer']
17 |
18 |
19 | class CapnProtoLexer(RegexLexer):
20 | """
21 | For Cap'n Proto source.
22 |
23 | .. versionadded:: 2.2
24 | """
25 | name = 'Cap\'n Proto'
26 | url = 'https://capnproto.org'
27 | filenames = ['*.capnp']
28 | aliases = ['capnp']
29 |
30 | tokens = {
31 | 'root': [
32 | (r'#.*?$', Comment.Single),
33 | (r'@[0-9a-zA-Z]*', Name.Decorator),
34 | (r'=', Literal, 'expression'),
35 | (r':', Name.Class, 'type'),
36 | (r'\$', Name.Attribute, 'annotation'),
37 | (r'(struct|enum|interface|union|import|using|const|annotation|'
38 | r'extends|in|of|on|as|with|from|fixed)\b',
39 | Keyword),
40 | (r'[\w.]+', Name),
41 | (r'[^#@=:$\w\s]+', Text),
42 | (r'\s+', Whitespace),
43 | ],
44 | 'type': [
45 | (r'[^][=;,(){}$]+', Name.Class),
46 | (r'[\[(]', Name.Class, 'parentype'),
47 | default('#pop'),
48 | ],
49 | 'parentype': [
50 | (r'[^][;()]+', Name.Class),
51 | (r'[\[(]', Name.Class, '#push'),
52 | (r'[])]', Name.Class, '#pop'),
53 | default('#pop'),
54 | ],
55 | 'expression': [
56 | (r'[^][;,(){}$]+', Literal),
57 | (r'[\[(]', Literal, 'parenexp'),
58 | default('#pop'),
59 | ],
60 | 'parenexp': [
61 | (r'[^][;()]+', Literal),
62 | (r'[\[(]', Literal, '#push'),
63 | (r'[])]', Literal, '#pop'),
64 | default('#pop'),
65 | ],
66 | 'annotation': [
67 | (r'[^][;,(){}=:]+', Name.Attribute),
68 | (r'[\[(]', Name.Attribute, 'annexp'),
69 | default('#pop'),
70 | ],
71 | 'annexp': [
72 | (r'[^][;()]+', Name.Attribute),
73 | (r'[\[(]', Name.Attribute, '#push'),
74 | (r'[])]', Name.Attribute, '#pop'),
75 | default('#pop'),
76 | ],
77 | }
78 |
--------------------------------------------------------------------------------
/pygments/lexers/compiled.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.compiled
3 | ~~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Just export lexer classes previously contained in this module.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.lexers.jvm import JavaLexer, ScalaLexer
12 | from pygments.lexers.c_cpp import CLexer, CppLexer
13 | from pygments.lexers.d import DLexer
14 | from pygments.lexers.objective import ObjectiveCLexer, \
15 | ObjectiveCppLexer, LogosLexer
16 | from pygments.lexers.go import GoLexer
17 | from pygments.lexers.rust import RustLexer
18 | from pygments.lexers.c_like import ECLexer, ValaLexer, CudaLexer
19 | from pygments.lexers.pascal import DelphiLexer, Modula2Lexer
20 | from pygments.lexers.ada import AdaLexer
21 | from pygments.lexers.business import CobolLexer, CobolFreeformatLexer
22 | from pygments.lexers.fortran import FortranLexer
23 | from pygments.lexers.prolog import PrologLexer
24 | from pygments.lexers.python import CythonLexer
25 | from pygments.lexers.graphics import GLShaderLexer
26 | from pygments.lexers.ml import OcamlLexer
27 | from pygments.lexers.basic import BlitzBasicLexer, BlitzMaxLexer, MonkeyLexer
28 | from pygments.lexers.dylan import DylanLexer, DylanLidLexer, DylanConsoleLexer
29 | from pygments.lexers.ooc import OocLexer
30 | from pygments.lexers.felix import FelixLexer
31 | from pygments.lexers.nimrod import NimrodLexer
32 | from pygments.lexers.crystal import CrystalLexer
33 |
34 | __all__ = []
35 |
--------------------------------------------------------------------------------
/pygments/lexers/cplint.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.cplint
3 | ~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexer for the cplint language
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | import re
12 |
13 | from pygments.lexer import bygroups, inherit, words
14 | from pygments.lexers import PrologLexer
15 | from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
16 | Number, Punctuation
17 |
18 | __all__ = ['CplintLexer']
19 |
20 |
21 | class CplintLexer(PrologLexer):
22 | """
23 | Lexer for cplint files, including CP-logic, Logic Programs with Annotated Disjunctions,
24 | Distributional Clauses syntax, ProbLog, DTProbLog
25 |
26 | .. versionadded:: 2.12
27 | """
28 | name = 'cplint'
29 | url = 'https://cplint.eu'
30 | aliases = ['cplint']
31 | filenames = ['*.ecl', '*.prolog', '*.pro', '*.pl', '*.P', '*.lpad', '*.cpl']
32 | mimetypes = ['text/x-cplint']
33 |
34 | tokens = {
35 | 'root': [
36 | (r'map_query',Keyword),
37 | (words(('gaussian','uniform_dens','dirichlet','gamma','beta','poisson','binomial','geometric',
38 | 'exponential','pascal','multinomial','user','val',
39 | 'uniform','discrete','finite')),Name.Builtin),
40 | (r'([a-z]+)(:)', bygroups(String.Atom, Punctuation)), # annotations of atoms
41 | (r':(-|=)|::?|~=?|=>', Operator),
42 | (r'\?', Name.Builtin),
43 | inherit,
44 | ],
45 | }
46 |
47 |
48 |
--------------------------------------------------------------------------------
/pygments/lexers/eiffel.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.eiffel
3 | ~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexer for the Eiffel language.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.lexer import RegexLexer, include, words, bygroups
12 | from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
13 | Number, Punctuation, Whitespace
14 |
15 | __all__ = ['EiffelLexer']
16 |
17 |
18 | class EiffelLexer(RegexLexer):
19 | """
20 | For Eiffel source code.
21 |
22 | .. versionadded:: 2.0
23 | """
24 | name = 'Eiffel'
25 | url = 'http://www.eiffel.com'
26 | aliases = ['eiffel']
27 | filenames = ['*.e']
28 | mimetypes = ['text/x-eiffel']
29 |
30 | tokens = {
31 | 'root': [
32 | (r'[^\S\n]+', Whitespace),
33 | (r'--.*?$', Comment.Single),
34 | (r'[^\S\n]+', Whitespace),
35 | # Please note that keyword and operator are case insensitive.
36 | (r'(?i)(true|false|void|current|result|precursor)\b', Keyword.Constant),
37 | (r'(?i)(not|xor|implies|or)\b', Operator.Word),
38 | (r'(?i)(and)(?:(\s+)(then))?\b', bygroups(Operator.Word, Whitespace, Operator.Word)),
39 | (r'(?i)(or)(?:(\s+)(else))?\b', bygroups(Operator.Word, Whitespace, Operator.Word)),
40 | (words((
41 | 'across', 'agent', 'alias', 'all', 'as', 'assign', 'attached',
42 | 'attribute', 'check', 'class', 'convert', 'create', 'debug',
43 | 'deferred', 'detachable', 'do', 'else', 'elseif', 'end', 'ensure',
44 | 'expanded', 'export', 'external', 'feature', 'from', 'frozen', 'if',
45 | 'inherit', 'inspect', 'invariant', 'like', 'local', 'loop', 'none',
46 | 'note', 'obsolete', 'old', 'once', 'only', 'redefine', 'rename',
47 | 'require', 'rescue', 'retry', 'select', 'separate', 'then',
48 | 'undefine', 'until', 'variant', 'when'), prefix=r'(?i)\b', suffix=r'\b'),
49 | Keyword.Reserved),
50 | (r'"\[([^\]%]|%(.|\n)|\][^"])*?\]"', String),
51 | (r'"([^"%\n]|%.)*?"', String),
52 | include('numbers'),
53 | (r"'([^'%]|%'|%%)'", String.Char),
54 | (r"(//|\\\\|>=|<=|:=|/=|~|/~|[\\?!#%&@|+/\-=>*$<^\[\]])", Operator),
55 | (r"([{}():;,.])", Punctuation),
56 | (r'([a-z]\w*)|([A-Z][A-Z0-9_]*[a-z]\w*)', Name),
57 | (r'([A-Z][A-Z0-9_]*)', Name.Class),
58 | (r'\n+', Whitespace),
59 | ],
60 | 'numbers': [
61 | (r'0[xX][a-fA-F0-9]+', Number.Hex),
62 | (r'0[bB][01]+', Number.Bin),
63 | (r'0[cC][0-7]+', Number.Oct),
64 | (r'([0-9]+\.[0-9]*)|([0-9]*\.[0-9]+)', Number.Float),
65 | (r'[0-9]+', Number.Integer),
66 | ],
67 | }
68 |
--------------------------------------------------------------------------------
/pygments/lexers/ezhil.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.ezhil
3 | ~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Pygments lexers for Ezhil language.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | import re
12 | from pygments.lexer import RegexLexer, include, words, bygroups
13 | from pygments.token import Keyword, Text, Comment, Name
14 | from pygments.token import String, Number, Punctuation, Operator, Whitespace
15 |
16 | __all__ = ['EzhilLexer']
17 |
18 |
19 | class EzhilLexer(RegexLexer):
20 | """
21 | Lexer for Ezhil, a Tamil script-based programming language.
22 |
23 | .. versionadded:: 2.1
24 | """
25 | name = 'Ezhil'
26 | url = 'http://ezhillang.org'
27 | aliases = ['ezhil']
28 | filenames = ['*.n']
29 | mimetypes = ['text/x-ezhil']
30 | # Refer to tamil.utf8.tamil_letters from open-tamil for a stricter version of this.
31 | # This much simpler version is close enough, and includes combining marks.
32 | _TALETTERS = '[a-zA-Z_]|[\u0b80-\u0bff]'
33 | tokens = {
34 | 'root': [
35 | include('keywords'),
36 | (r'#.*$', Comment.Single),
37 | (r'[@+/*,^\-%]|[!<>=]=?|&&?|\|\|?', Operator),
38 | ('இல்', Operator.Word),
39 | (words(('assert', 'max', 'min',
40 | 'நீளம்', 'சரம்_இடமாற்று', 'சரம்_கண்டுபிடி',
41 | 'பட்டியல்', 'பின்இணை', 'வரிசைப்படுத்து',
42 | 'எடு', 'தலைகீழ்', 'நீட்டிக்க', 'நுழைக்க', 'வை',
43 | 'கோப்பை_திற', 'கோப்பை_எழுது', 'கோப்பை_மூடு',
44 | 'pi', 'sin', 'cos', 'tan', 'sqrt', 'hypot', 'pow',
45 | 'exp', 'log', 'log10', 'exit',
46 | ), suffix=r'\b'), Name.Builtin),
47 | (r'(True|False)\b', Keyword.Constant),
48 | (r'[^\S\n]+', Whitespace),
49 | include('identifier'),
50 | include('literal'),
51 | (r'[(){}\[\]:;.]', Punctuation),
52 | ],
53 | 'keywords': [
54 | ('பதிப்பி|தேர்ந்தெடு|தேர்வு|ஏதேனில்|ஆனால்|இல்லைஆனால்|இல்லை|ஆக|ஒவ்வொன்றாக|இல்|வரை|செய்|முடியேனில்|பின்கொடு|முடி|நிரல்பாகம்|தொடர்|நிறுத்து|நிரல்பாகம்', Keyword),
55 | ],
56 | 'identifier': [
57 | ('(?:'+_TALETTERS+')(?:[0-9]|'+_TALETTERS+')*', Name),
58 | ],
59 | 'literal': [
60 | (r'".*?"', String),
61 | (r'\d+((\.\d*)?[eE][+-]?\d+|\.\d*)', Number.Float),
62 | (r'\d+', Number.Integer),
63 | ]
64 | }
65 |
66 | def analyse_text(text):
67 | """This language uses Tamil-script. We'll assume that if there's a
68 | decent amount of Tamil-characters, it's this language. This assumption
69 | is obviously horribly off if someone uses string literals in tamil
70 | in another language."""
71 | if len(re.findall(r'[\u0b80-\u0bff]', text)) > 10:
72 | return 0.25
73 |
74 | def __init__(self, **options):
75 | super().__init__(**options)
76 | self.encoding = options.get('encoding', 'utf-8')
77 |
--------------------------------------------------------------------------------
/pygments/lexers/floscript.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.floscript
3 | ~~~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexer for FloScript
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.lexer import RegexLexer, include, bygroups
12 | from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
13 | Number, Punctuation, Whitespace
14 |
15 | __all__ = ['FloScriptLexer']
16 |
17 |
18 | class FloScriptLexer(RegexLexer):
19 | """
20 | For FloScript configuration language source code.
21 |
22 | .. versionadded:: 2.4
23 | """
24 |
25 | name = 'FloScript'
26 | url = 'https://github.com/ioflo/ioflo'
27 | aliases = ['floscript', 'flo']
28 | filenames = ['*.flo']
29 |
30 | def innerstring_rules(ttype):
31 | return [
32 | # the old style '%s' % (...) string formatting
33 | (r'%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?'
34 | '[hlL]?[E-GXc-giorsux%]', String.Interpol),
35 | # backslashes, quotes and formatting signs must be parsed one at a time
36 | (r'[^\\\'"%\n]+', ttype),
37 | (r'[\'"\\]', ttype),
38 | # unhandled string formatting sign
39 | (r'%', ttype),
40 | # newlines are an error (use "nl" state)
41 | ]
42 |
43 | tokens = {
44 | 'root': [
45 | (r'\s+', Whitespace),
46 |
47 | (r'[]{}:(),;[]', Punctuation),
48 | (r'(\\)(\n)', bygroups(Text, Whitespace)),
49 | (r'\\', Text),
50 | (r'(to|by|with|from|per|for|cum|qua|via|as|at|in|of|on|re|is|if|be|into|'
51 | r'and|not)\b', Operator.Word),
52 | (r'!=|==|<<|>>|[-~+/*%=<>&^|.]', Operator),
53 | (r'(load|init|server|logger|log|loggee|first|over|under|next|done|timeout|'
54 | r'repeat|native|benter|enter|recur|exit|precur|renter|rexit|print|put|inc|'
55 | r'copy|set|aux|rear|raze|go|let|do|bid|ready|start|stop|run|abort|use|flo|'
56 | r'give|take)\b', Name.Builtin),
57 | (r'(frame|framer|house)\b', Keyword),
58 | ('"', String, 'string'),
59 |
60 | include('name'),
61 | include('numbers'),
62 | (r'#.+$', Comment.Single),
63 | ],
64 | 'string': [
65 | ('[^"]+', String),
66 | ('"', String, '#pop'),
67 | ],
68 | 'numbers': [
69 | (r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?j?', Number.Float),
70 | (r'\d+[eE][+-]?[0-9]+j?', Number.Float),
71 | (r'0[0-7]+j?', Number.Oct),
72 | (r'0[bB][01]+', Number.Bin),
73 | (r'0[xX][a-fA-F0-9]+', Number.Hex),
74 | (r'\d+L', Number.Integer.Long),
75 | (r'\d+j?', Number.Integer)
76 | ],
77 |
78 | 'name': [
79 | (r'@[\w.]+', Name.Decorator),
80 | (r'[a-zA-Z_]\w*', Name),
81 | ],
82 | }
83 |
--------------------------------------------------------------------------------
/pygments/lexers/functional.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.functional
3 | ~~~~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Just export lexer classes previously contained in this module.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.lexers.lisp import SchemeLexer, CommonLispLexer, RacketLexer, \
12 | NewLispLexer, ShenLexer
13 | from pygments.lexers.haskell import HaskellLexer, LiterateHaskellLexer, \
14 | KokaLexer
15 | from pygments.lexers.theorem import CoqLexer
16 | from pygments.lexers.erlang import ErlangLexer, ErlangShellLexer, \
17 | ElixirConsoleLexer, ElixirLexer
18 | from pygments.lexers.ml import SMLLexer, OcamlLexer, OpaLexer
19 |
20 | __all__ = []
21 |
--------------------------------------------------------------------------------
/pygments/lexers/gcodelexer.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.gcodelexer
3 | ~~~~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexers for the G Code Language.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.lexer import RegexLexer, bygroups
12 | from pygments.token import Comment, Name, Text, Keyword, Number
13 |
14 | __all__ = ['GcodeLexer']
15 |
16 |
17 | class GcodeLexer(RegexLexer):
18 | """
19 | For gcode source code.
20 |
21 | .. versionadded:: 2.9
22 | """
23 | name = 'g-code'
24 | aliases = ['gcode']
25 | filenames = ['*.gcode']
26 |
27 | tokens = {
28 | 'root': [
29 | (r';.*\n', Comment),
30 | (r'^[gmGM]\d{1,4}\s', Name.Builtin), # M or G commands
31 | (r'([^gGmM])([+-]?\d*[.]?\d+)', bygroups(Keyword, Number)),
32 | (r'\s', Text.Whitespace),
33 | (r'.*\n', Text),
34 | ]
35 | }
36 |
--------------------------------------------------------------------------------
/pygments/lexers/graphviz.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.graphviz
3 | ~~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexer for the DOT language (graphviz).
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.lexer import RegexLexer, bygroups
12 | from pygments.token import Comment, Keyword, Operator, Name, String, Number, \
13 | Punctuation, Whitespace
14 |
15 |
16 | __all__ = ['GraphvizLexer']
17 |
18 |
19 | class GraphvizLexer(RegexLexer):
20 | """
21 | For graphviz DOT graph description language.
22 |
23 | .. versionadded:: 2.8
24 | """
25 | name = 'Graphviz'
26 | url = 'https://www.graphviz.org/doc/info/lang.html'
27 | aliases = ['graphviz', 'dot']
28 | filenames = ['*.gv', '*.dot']
29 | mimetypes = ['text/x-graphviz', 'text/vnd.graphviz']
30 | tokens = {
31 | 'root': [
32 | (r'\s+', Whitespace),
33 | (r'(#|//).*?$', Comment.Single),
34 | (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
35 | (r'(?i)(node|edge|graph|digraph|subgraph|strict)\b', Keyword),
36 | (r'--|->', Operator),
37 | (r'[{}[\]:;,]', Punctuation),
38 | (r'(\b\D\w*)(\s*)(=)(\s*)',
39 | bygroups(Name.Attribute, Whitespace, Punctuation, Whitespace),
40 | 'attr_id'),
41 | (r'\b(n|ne|e|se|s|sw|w|nw|c|_)\b', Name.Builtin),
42 | (r'\b\D\w*', Name.Tag), # node
43 | (r'[-]?((\.[0-9]+)|([0-9]+(\.[0-9]*)?))', Number),
44 | (r'"(\\"|[^"])*?"', Name.Tag), # quoted node
45 | (r'<', Punctuation, 'xml'),
46 | ],
47 | 'attr_id': [
48 | (r'\b\D\w*', String, '#pop'),
49 | (r'[-]?((\.[0-9]+)|([0-9]+(\.[0-9]*)?))', Number, '#pop'),
50 | (r'"(\\"|[^"])*?"', String.Double, '#pop'),
51 | (r'<', Punctuation, ('#pop', 'xml')),
52 | ],
53 | 'xml': [
54 | (r'<', Punctuation, '#push'),
55 | (r'>', Punctuation, '#pop'),
56 | (r'\s+', Whitespace),
57 | (r'[^<>\s]', Name.Tag),
58 | ]
59 | }
60 |
--------------------------------------------------------------------------------
/pygments/lexers/iolang.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.iolang
3 | ~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexers for the Io language.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.lexer import RegexLexer
12 | from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
13 | Number, Whitespace
14 |
15 | __all__ = ['IoLexer']
16 |
17 |
18 | class IoLexer(RegexLexer):
19 | """
20 | For Io (a small, prototype-based programming language) source.
21 |
22 | .. versionadded:: 0.10
23 | """
24 | name = 'Io'
25 | url = 'http://iolanguage.com/'
26 | filenames = ['*.io']
27 | aliases = ['io']
28 | mimetypes = ['text/x-iosrc']
29 | tokens = {
30 | 'root': [
31 | (r'\n', Whitespace),
32 | (r'\s+', Whitespace),
33 | # Comments
34 | (r'//(.*?)$', Comment.Single),
35 | (r'#(.*?)$', Comment.Single),
36 | (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
37 | (r'/\+', Comment.Multiline, 'nestedcomment'),
38 | # DoubleQuotedString
39 | (r'"(\\\\|\\[^\\]|[^"\\])*"', String),
40 | # Operators
41 | (r'::=|:=|=|\(|\)|;|,|\*|-|\+|>|<|@|!|/|\||\^|\.|%|&|\[|\]|\{|\}',
42 | Operator),
43 | # keywords
44 | (r'(clone|do|doFile|doString|method|for|if|else|elseif|then)\b',
45 | Keyword),
46 | # constants
47 | (r'(nil|false|true)\b', Name.Constant),
48 | # names
49 | (r'(Object|list|List|Map|args|Sequence|Coroutine|File)\b',
50 | Name.Builtin),
51 | (r'[a-zA-Z_]\w*', Name),
52 | # numbers
53 | (r'(\d+\.?\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float),
54 | (r'\d+', Number.Integer)
55 | ],
56 | 'nestedcomment': [
57 | (r'[^+/]+', Comment.Multiline),
58 | (r'/\+', Comment.Multiline, '#push'),
59 | (r'\+/', Comment.Multiline, '#pop'),
60 | (r'[+/]', Comment.Multiline),
61 | ]
62 | }
63 |
--------------------------------------------------------------------------------
/pygments/lexers/jmespath.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.jmespath
3 | ~~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexers for the JMESPath language
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.lexer import RegexLexer, bygroups, include
12 | from pygments.token import String, Punctuation, Whitespace, Name, Operator, \
13 | Number, Literal, Keyword
14 |
15 | __all__ = ['JMESPathLexer']
16 |
17 |
18 | class JMESPathLexer(RegexLexer):
19 | """
20 | For JMESPath queries.
21 | """
22 | name = 'JMESPath'
23 | url = 'https://jmespath.org'
24 | filenames = ['*.jp']
25 | aliases = ['jmespath', 'jp']
26 |
27 | tokens = {
28 | 'string': [
29 | (r"'(\\(.|\n)|[^'\\])*'", String),
30 | ],
31 | 'punctuation': [
32 | (r'(\[\?|[\.\*\[\],:\(\)\{\}\|])', Punctuation),
33 | ],
34 | 'ws': [
35 | (r" |\t|\n|\r", Whitespace)
36 | ],
37 | "dq-identifier": [
38 | (r'[^\\"]+', Name.Variable),
39 | (r'\\"', Name.Variable),
40 | (r'.', Punctuation, '#pop'),
41 | ],
42 | 'identifier': [
43 | (r'(&)?(")', bygroups(Name.Variable, Punctuation), 'dq-identifier'),
44 | (r'(")?(&?[A-Za-z][A-Za-z0-9_-]*)(")?', bygroups(Punctuation, Name.Variable, Punctuation)),
45 | ],
46 | 'root': [
47 | include('ws'),
48 | include('string'),
49 | (r'(==|!=|<=|>=|<|>|&&|\|\||!)', Operator),
50 | include('punctuation'),
51 | (r'@', Name.Variable.Global),
52 | (r'(&?[A-Za-z][A-Za-z0-9_]*)(\()', bygroups(Name.Function, Punctuation)),
53 | (r'(&)(\()', bygroups(Name.Variable, Punctuation)),
54 | include('identifier'),
55 | (r'-?\d+', Number),
56 | (r'`', Literal, 'literal'),
57 | ],
58 | 'literal': [
59 | include('ws'),
60 | include('string'),
61 | include('punctuation'),
62 | (r'(false|true|null)\b', Keyword.Constant),
63 | include('identifier'),
64 | (r'-?\d+\.?\d*([eE][-+]\d+)?', Number),
65 | (r'\\`', Literal),
66 | (r'`', Literal, '#pop'),
67 | ]
68 | }
69 |
--------------------------------------------------------------------------------
/pygments/lexers/math.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.math
3 | ~~~~~~~~~~~~~~~~~~~~
4 |
5 | Just export lexers that were contained in this module.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.lexers.python import NumPyLexer
12 | from pygments.lexers.matlab import MatlabLexer, MatlabSessionLexer, \
13 | OctaveLexer, ScilabLexer
14 | from pygments.lexers.julia import JuliaLexer, JuliaConsoleLexer
15 | from pygments.lexers.r import RConsoleLexer, SLexer, RdLexer
16 | from pygments.lexers.modeling import BugsLexer, JagsLexer, StanLexer
17 | from pygments.lexers.idl import IDLLexer
18 | from pygments.lexers.algebra import MuPADLexer
19 |
20 | __all__ = []
21 |
--------------------------------------------------------------------------------
/pygments/lexers/maxima.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.maxima
3 | ~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexer for the computer algebra system Maxima.
6 |
7 | Derived from pygments/lexers/algebra.py.
8 |
9 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
10 | :license: BSD, see LICENSE for details.
11 | """
12 |
13 | import re
14 |
15 | from pygments.lexer import RegexLexer, bygroups, words
16 | from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
17 | Number, Punctuation
18 |
19 | __all__ = ['MaximaLexer']
20 |
21 | class MaximaLexer(RegexLexer):
22 | """
23 | A Maxima lexer.
24 | Derived from pygments.lexers.MuPADLexer.
25 |
26 | .. versionadded:: 2.11
27 | """
28 | name = 'Maxima'
29 | url = 'http://maxima.sourceforge.net'
30 | aliases = ['maxima', 'macsyma']
31 | filenames = ['*.mac', '*.max']
32 |
33 | keywords = ('if', 'then', 'else', 'elseif',
34 | 'do', 'while', 'repeat', 'until',
35 | 'for', 'from', 'to', 'downto', 'step', 'thru')
36 |
37 | constants = ('%pi', '%e', '%phi', '%gamma', '%i',
38 | 'und', 'ind', 'infinity', 'inf', 'minf',
39 | 'true', 'false', 'unknown', 'done')
40 |
41 | operators = (r'.', r':', r'=', r'#',
42 | r'+', r'-', r'*', r'/', r'^',
43 | r'@', r'>', r'<', r'|', r'!', r"'")
44 |
45 | operator_words = ('and', 'or', 'not')
46 |
47 | tokens = {
48 | 'root': [
49 | (r'/\*', Comment.Multiline, 'comment'),
50 | (r'"(?:[^"\\]|\\.)*"', String),
51 | (r'\(|\)|\[|\]|\{|\}', Punctuation),
52 | (r'[,;$]', Punctuation),
53 | (words (constants), Name.Constant),
54 | (words (keywords), Keyword),
55 | (words (operators), Operator),
56 | (words (operator_words), Operator.Word),
57 | (r'''(?x)
58 | ((?:[a-zA-Z_#][\w#]*|`[^`]*`)
59 | (?:::[a-zA-Z_#][\w#]*|`[^`]*`)*)(\s*)([(])''',
60 | bygroups(Name.Function, Text.Whitespace, Punctuation)),
61 | (r'''(?x)
62 | (?:[a-zA-Z_#%][\w#%]*|`[^`]*`)
63 | (?:::[a-zA-Z_#%][\w#%]*|`[^`]*`)*''', Name.Variable),
64 | (r'[-+]?(\d*\.\d+([bdefls][-+]?\d+)?|\d+(\.\d*)?[bdefls][-+]?\d+)', Number.Float),
65 | (r'[-+]?\d+', Number.Integer),
66 | (r'\s+', Text.Whitespace),
67 | (r'.', Text)
68 | ],
69 | 'comment': [
70 | (r'[^*/]+', Comment.Multiline),
71 | (r'/\*', Comment.Multiline, '#push'),
72 | (r'\*/', Comment.Multiline, '#pop'),
73 | (r'[*/]', Comment.Multiline)
74 | ]
75 | }
76 |
77 | def analyse_text (text):
78 | strength = 0.0
79 | # Input expression terminator.
80 | if re.search (r'\$\s*$', text, re.MULTILINE):
81 | strength += 0.05
82 | # Function definition operator.
83 | if ':=' in text:
84 | strength += 0.02
85 | return strength
86 |
--------------------------------------------------------------------------------
/pygments/lexers/nit.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.nit
3 | ~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexer for the Nit language.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.lexer import RegexLexer, words
12 | from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
13 | Number, Punctuation
14 |
15 | __all__ = ['NitLexer']
16 |
17 |
18 | class NitLexer(RegexLexer):
19 | """
20 | For nit source.
21 |
22 | .. versionadded:: 2.0
23 | """
24 |
25 | name = 'Nit'
26 | url = 'http://nitlanguage.org'
27 | aliases = ['nit']
28 | filenames = ['*.nit']
29 | tokens = {
30 | 'root': [
31 | (r'#.*?$', Comment.Single),
32 | (words((
33 | 'package', 'module', 'import', 'class', 'abstract', 'interface',
34 | 'universal', 'enum', 'end', 'fun', 'type', 'init', 'redef',
35 | 'isa', 'do', 'readable', 'writable', 'var', 'intern', 'extern',
36 | 'public', 'protected', 'private', 'intrude', 'if', 'then',
37 | 'else', 'while', 'loop', 'for', 'in', 'and', 'or', 'not',
38 | 'implies', 'return', 'continue', 'break', 'abort', 'assert',
39 | 'new', 'is', 'once', 'super', 'self', 'true', 'false', 'nullable',
40 | 'null', 'as', 'isset', 'label', '__debug__'), suffix=r'(?=[\r\n\t( ])'),
41 | Keyword),
42 | (r'[A-Z]\w*', Name.Class),
43 | (r'"""(([^\'\\]|\\.)|\\r|\\n)*((\{\{?)?(""?\{\{?)*""""*)', String), # Simple long string
44 | (r'\'\'\'(((\\.|[^\'\\])|\\r|\\n)|\'((\\.|[^\'\\])|\\r|\\n)|'
45 | r'\'\'((\\.|[^\'\\])|\\r|\\n))*\'\'\'', String), # Simple long string alt
46 | (r'"""(([^\'\\]|\\.)|\\r|\\n)*((""?)?(\{\{?""?)*\{\{\{\{*)', String), # Start long string
47 | (r'\}\}\}(((\\.|[^\'\\])|\\r|\\n))*(""?)?(\{\{?""?)*\{\{\{\{*', String), # Mid long string
48 | (r'\}\}\}(((\\.|[^\'\\])|\\r|\\n))*(\{\{?)?(""?\{\{?)*""""*', String), # End long string
49 | (r'"(\\.|([^"}{\\]))*"', String), # Simple String
50 | (r'"(\\.|([^"}{\\]))*\{', String), # Start string
51 | (r'\}(\\.|([^"}{\\]))*\{', String), # Mid String
52 | (r'\}(\\.|([^"}{\\]))*"', String), # End String
53 | (r'(\'[^\'\\]\')|(\'\\.\')', String.Char),
54 | (r'[0-9]+', Number.Integer),
55 | (r'[0-9]*.[0-9]+', Number.Float),
56 | (r'0(x|X)[0-9A-Fa-f]+', Number.Hex),
57 | (r'[a-z]\w*', Name),
58 | (r'_\w+', Name.Variable.Instance),
59 | (r'==|!=|<==>|>=|>>|>|<=|<<|<|\+|-|=|/|\*|%|\+=|-=|!|@', Operator),
60 | (r'\(|\)|\[|\]|,|\.\.\.|\.\.|\.|::|:', Punctuation),
61 | (r'`\{[^`]*`\}', Text), # Extern blocks won't be Lexed by Nit
62 | (r'[\r\n\t ]+', Text),
63 | ],
64 | }
65 |
--------------------------------------------------------------------------------
/pygments/lexers/ooc.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.ooc
3 | ~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexers for the Ooc language.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.lexer import RegexLexer, bygroups, words
12 | from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
13 | Number, Punctuation
14 |
15 | __all__ = ['OocLexer']
16 |
17 |
18 | class OocLexer(RegexLexer):
19 | """
20 | For Ooc source code
21 |
22 | .. versionadded:: 1.2
23 | """
24 | name = 'Ooc'
25 | url = 'http://ooc-lang.org/'
26 | aliases = ['ooc']
27 | filenames = ['*.ooc']
28 | mimetypes = ['text/x-ooc']
29 |
30 | tokens = {
31 | 'root': [
32 | (words((
33 | 'class', 'interface', 'implement', 'abstract', 'extends', 'from',
34 | 'this', 'super', 'new', 'const', 'final', 'static', 'import',
35 | 'use', 'extern', 'inline', 'proto', 'break', 'continue',
36 | 'fallthrough', 'operator', 'if', 'else', 'for', 'while', 'do',
37 | 'switch', 'case', 'as', 'in', 'version', 'return', 'true',
38 | 'false', 'null'), prefix=r'\b', suffix=r'\b'),
39 | Keyword),
40 | (r'include\b', Keyword, 'include'),
41 | (r'(cover)([ \t]+)(from)([ \t]+)(\w+[*@]?)',
42 | bygroups(Keyword, Text, Keyword, Text, Name.Class)),
43 | (r'(func)((?:[ \t]|\\\n)+)(~[a-z_]\w*)',
44 | bygroups(Keyword, Text, Name.Function)),
45 | (r'\bfunc\b', Keyword),
46 | # Note: %= and ^= not listed on http://ooc-lang.org/syntax
47 | (r'//.*', Comment),
48 | (r'(?s)/\*.*?\*/', Comment.Multiline),
49 | (r'(==?|\+=?|-[=>]?|\*=?|/=?|:=|!=?|%=?|\?|>{1,3}=?|<{1,3}=?|\.\.|'
50 | r'&&?|\|\|?|\^=?)', Operator),
51 | (r'(\.)([ \t]*)([a-z]\w*)', bygroups(Operator, Text,
52 | Name.Function)),
53 | (r'[A-Z][A-Z0-9_]+', Name.Constant),
54 | (r'[A-Z]\w*([@*]|\[[ \t]*\])?', Name.Class),
55 |
56 | (r'([a-z]\w*(?:~[a-z]\w*)?)((?:[ \t]|\\\n)*)(?=\()',
57 | bygroups(Name.Function, Text)),
58 | (r'[a-z]\w*', Name.Variable),
59 |
60 | # : introduces types
61 | (r'[:(){}\[\];,]', Punctuation),
62 |
63 | (r'0x[0-9a-fA-F]+', Number.Hex),
64 | (r'0c[0-9]+', Number.Oct),
65 | (r'0b[01]+', Number.Bin),
66 | (r'[0-9_]\.[0-9_]*(?!\.)', Number.Float),
67 | (r'[0-9_]+', Number.Decimal),
68 |
69 | (r'"(?:\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\"])*"',
70 | String.Double),
71 | (r"'(?:\\.|\\[0-9]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'",
72 | String.Char),
73 | (r'@', Punctuation), # pointer dereference
74 | (r'\.', Punctuation), # imports or chain operator
75 |
76 | (r'\\[ \t\n]', Text),
77 | (r'[ \t]+', Text),
78 | ],
79 | 'include': [
80 | (r'[\w/]+', Name),
81 | (r',', Punctuation),
82 | (r'[ \t]', Text),
83 | (r'[;\n]', Text, '#pop'),
84 | ],
85 | }
86 |
--------------------------------------------------------------------------------
/pygments/lexers/other.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.other
3 | ~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Just export lexer classes previously contained in this module.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.lexers.sql import SqlLexer, MySqlLexer, SqliteConsoleLexer
12 | from pygments.lexers.shell import BashLexer, BashSessionLexer, BatchLexer, \
13 | TcshLexer
14 | from pygments.lexers.robotframework import RobotFrameworkLexer
15 | from pygments.lexers.testing import GherkinLexer
16 | from pygments.lexers.esoteric import BrainfuckLexer, BefungeLexer, RedcodeLexer
17 | from pygments.lexers.prolog import LogtalkLexer
18 | from pygments.lexers.snobol import SnobolLexer
19 | from pygments.lexers.rebol import RebolLexer
20 | from pygments.lexers.configs import KconfigLexer, Cfengine3Lexer
21 | from pygments.lexers.modeling import ModelicaLexer
22 | from pygments.lexers.scripting import AppleScriptLexer, MOOCodeLexer, \
23 | HybrisLexer
24 | from pygments.lexers.graphics import PostScriptLexer, GnuplotLexer, \
25 | AsymptoteLexer, PovrayLexer
26 | from pygments.lexers.business import ABAPLexer, OpenEdgeLexer, \
27 | GoodDataCLLexer, MaqlLexer
28 | from pygments.lexers.automation import AutoItLexer, AutohotkeyLexer
29 | from pygments.lexers.dsls import ProtoBufLexer, BroLexer, PuppetLexer, \
30 | MscgenLexer, VGLLexer
31 | from pygments.lexers.basic import CbmBasicV2Lexer
32 | from pygments.lexers.pawn import SourcePawnLexer, PawnLexer
33 | from pygments.lexers.ecl import ECLLexer
34 | from pygments.lexers.urbi import UrbiscriptLexer
35 | from pygments.lexers.smalltalk import SmalltalkLexer, NewspeakLexer
36 | from pygments.lexers.installers import NSISLexer, RPMSpecLexer
37 | from pygments.lexers.textedit import AwkLexer
38 | from pygments.lexers.smv import NuSMVLexer
39 |
40 | __all__ = []
41 |
--------------------------------------------------------------------------------
/pygments/lexers/parasail.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.parasail
3 | ~~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexer for ParaSail.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | import re
12 |
13 | from pygments.lexer import RegexLexer, include
14 | from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
15 | Number, Punctuation, Literal
16 |
17 | __all__ = ['ParaSailLexer']
18 |
19 |
20 | class ParaSailLexer(RegexLexer):
21 | """
22 | For ParaSail source code.
23 |
24 | .. versionadded:: 2.1
25 | """
26 |
27 | name = 'ParaSail'
28 | url = 'http://www.parasail-lang.org'
29 | aliases = ['parasail']
30 | filenames = ['*.psi', '*.psl']
31 | mimetypes = ['text/x-parasail']
32 |
33 | flags = re.MULTILINE
34 |
35 | tokens = {
36 | 'root': [
37 | (r'[^\S\n]+', Text),
38 | (r'//.*?\n', Comment.Single),
39 | (r'\b(and|or|xor)=', Operator.Word),
40 | (r'\b(and(\s+then)?|or(\s+else)?|xor|rem|mod|'
41 | r'(is|not)\s+null)\b',
42 | Operator.Word),
43 | # Keywords
44 | (r'\b(abs|abstract|all|block|class|concurrent|const|continue|'
45 | r'each|end|exit|extends|exports|forward|func|global|implements|'
46 | r'import|in|interface|is|lambda|locked|new|not|null|of|op|'
47 | r'optional|private|queued|ref|return|reverse|separate|some|'
48 | r'type|until|var|with|'
49 | # Control flow
50 | r'if|then|else|elsif|case|for|while|loop)\b',
51 | Keyword.Reserved),
52 | (r'(abstract\s+)?(interface|class|op|func|type)',
53 | Keyword.Declaration),
54 | # Literals
55 | (r'"[^"]*"', String),
56 | (r'\\[\'ntrf"0]', String.Escape),
57 | (r'#[a-zA-Z]\w*', Literal), # Enumeration
58 | include('numbers'),
59 | (r"'[^']'", String.Char),
60 | (r'[a-zA-Z]\w*', Name),
61 | # Operators and Punctuation
62 | (r'(<==|==>|<=>|\*\*=|<\|=|<<=|>>=|==|!=|=\?|<=|>=|'
63 | r'\*\*|<<|>>|=>|:=|\+=|-=|\*=|\|=|\||/=|\+|-|\*|/|'
64 | r'\.\.|<\.\.|\.\.<|<\.\.<)',
65 | Operator),
66 | (r'(<|>|\[|\]|\(|\)|\||:|;|,|.|\{|\}|->)',
67 | Punctuation),
68 | (r'\n+', Text),
69 | ],
70 | 'numbers': [
71 | (r'\d[0-9_]*#[0-9a-fA-F][0-9a-fA-F_]*#', Number.Hex), # any base
72 | (r'0[xX][0-9a-fA-F][0-9a-fA-F_]*', Number.Hex), # C-like hex
73 | (r'0[bB][01][01_]*', Number.Bin), # C-like bin
74 | (r'\d[0-9_]*\.\d[0-9_]*[eE][+-]\d[0-9_]*', # float exp
75 | Number.Float),
76 | (r'\d[0-9_]*\.\d[0-9_]*', Number.Float), # float
77 | (r'\d[0-9_]*', Number.Integer), # integer
78 | ],
79 | }
80 |
--------------------------------------------------------------------------------
/pygments/lexers/pointless.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.pointless
3 | ~~~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexers for Pointless.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.lexer import RegexLexer, words
12 | from pygments.token import Comment, Error, Keyword, Name, Number, Operator, \
13 | Punctuation, String, Text
14 |
15 | __all__ = ['PointlessLexer']
16 |
17 |
18 | class PointlessLexer(RegexLexer):
19 | """
20 | For Pointless source code.
21 |
22 | .. versionadded:: 2.7
23 | """
24 |
25 | name = 'Pointless'
26 | url = 'https://ptls.dev'
27 | aliases = ['pointless']
28 | filenames = ['*.ptls']
29 |
30 | ops = words([
31 | "+", "-", "*", "/", "**", "%", "+=", "-=", "*=",
32 | "/=", "**=", "%=", "|>", "=", "==", "!=", "<", ">",
33 | "<=", ">=", "=>", "$", "++",
34 | ])
35 |
36 | keywords = words([
37 | "if", "then", "else", "where", "with", "cond",
38 | "case", "and", "or", "not", "in", "as", "for",
39 | "requires", "throw", "try", "catch", "when",
40 | "yield", "upval",
41 | ], suffix=r'\b')
42 |
43 | tokens = {
44 | 'root': [
45 | (r'[ \n\r]+', Text),
46 | (r'--.*$', Comment.Single),
47 | (r'"""', String, 'multiString'),
48 | (r'"', String, 'string'),
49 | (r'[\[\](){}:;,.]', Punctuation),
50 | (ops, Operator),
51 | (keywords, Keyword),
52 | (r'\d+|\d*\.\d+', Number),
53 | (r'(true|false)\b', Name.Builtin),
54 | (r'[A-Z][a-zA-Z0-9]*\b', String.Symbol),
55 | (r'output\b', Name.Variable.Magic),
56 | (r'(export|import)\b', Keyword.Namespace),
57 | (r'[a-z][a-zA-Z0-9]*\b', Name.Variable)
58 | ],
59 | 'multiString': [
60 | (r'\\.', String.Escape),
61 | (r'"""', String, '#pop'),
62 | (r'"', String),
63 | (r'[^\\"]+', String),
64 | ],
65 | 'string': [
66 | (r'\\.', String.Escape),
67 | (r'"', String, '#pop'),
68 | (r'\n', Error),
69 | (r'[^\\"]+', String),
70 | ],
71 | }
72 |
--------------------------------------------------------------------------------
/pygments/lexers/procfile.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.procfile
3 | ~~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexer for Procfile file format.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.lexer import RegexLexer, bygroups
12 | from pygments.token import Name, Number, String, Text, Punctuation
13 |
14 | __all__ = ["ProcfileLexer"]
15 |
16 |
17 | class ProcfileLexer(RegexLexer):
18 | """
19 | Lexer for Procfile file format.
20 |
21 | The format is used to run processes on Heroku or is used by Foreman or
22 | Honcho tools.
23 |
24 | .. versionadded:: 2.10
25 | """
26 | name = 'Procfile'
27 | url = 'https://devcenter.heroku.com/articles/procfile#procfile-format'
28 | aliases = ['procfile']
29 | filenames = ['Procfile']
30 |
31 | tokens = {
32 | 'root': [
33 | (r'^([a-z]+)(:)', bygroups(Name.Label, Punctuation)),
34 | (r'\s+', Text.Whitespace),
35 | (r'"[^"]*"', String),
36 | (r"'[^']*'", String),
37 | (r'[0-9]+', Number.Integer),
38 | (r'\$[a-zA-Z_][\w]*', Name.Variable),
39 | (r'(\w+)(=)(\w+)', bygroups(Name.Variable, Punctuation, String)),
40 | (r'([\w\-\./]+)', Text),
41 | ],
42 | }
43 |
--------------------------------------------------------------------------------
/pygments/lexers/resource.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.resource
3 | ~~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexer for resource definition files.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | import re
12 |
13 | from pygments.lexer import RegexLexer, bygroups, words
14 | from pygments.token import Comment, String, Number, Operator, Text, \
15 | Keyword, Name
16 |
17 | __all__ = ['ResourceLexer']
18 |
19 |
20 | class ResourceLexer(RegexLexer):
21 | """Lexer for `ICU Resource bundles
22 | `_.
23 |
24 | .. versionadded:: 2.0
25 | """
26 | name = 'ResourceBundle'
27 | aliases = ['resourcebundle', 'resource']
28 | filenames = []
29 |
30 | _types = (':table', ':array', ':string', ':bin', ':import', ':intvector',
31 | ':int', ':alias')
32 |
33 | flags = re.MULTILINE | re.IGNORECASE
34 | tokens = {
35 | 'root': [
36 | (r'//.*?$', Comment),
37 | (r'"', String, 'string'),
38 | (r'-?\d+', Number.Integer),
39 | (r'[,{}]', Operator),
40 | (r'([^\s{:]+)(\s*)(%s?)' % '|'.join(_types),
41 | bygroups(Name, Text, Keyword)),
42 | (r'\s+', Text),
43 | (words(_types), Keyword),
44 | ],
45 | 'string': [
46 | (r'(\\x[0-9a-f]{2}|\\u[0-9a-f]{4}|\\U00[0-9a-f]{6}|'
47 | r'\\[0-7]{1,3}|\\c.|\\[abtnvfre\'"?\\]|\\\{|[^"{\\])+', String),
48 | (r'\{', String.Escape, 'msgname'),
49 | (r'"', String, '#pop')
50 | ],
51 | 'msgname': [
52 | (r'([^{},]+)(\s*)', bygroups(Name, String.Escape), ('#pop', 'message'))
53 | ],
54 | 'message': [
55 | (r'\{', String.Escape, 'msgname'),
56 | (r'\}', String.Escape, '#pop'),
57 | (r'(,)(\s*)([a-z]+)(\s*\})',
58 | bygroups(Operator, String.Escape, Keyword, String.Escape), '#pop'),
59 | (r'(,)(\s*)([a-z]+)(\s*)(,)(\s*)(offset)(\s*)(:)(\s*)(-?\d+)(\s*)',
60 | bygroups(Operator, String.Escape, Keyword, String.Escape, Operator,
61 | String.Escape, Operator.Word, String.Escape, Operator,
62 | String.Escape, Number.Integer, String.Escape), 'choice'),
63 | (r'(,)(\s*)([a-z]+)(\s*)(,)(\s*)',
64 | bygroups(Operator, String.Escape, Keyword, String.Escape, Operator,
65 | String.Escape), 'choice'),
66 | (r'\s+', String.Escape)
67 | ],
68 | 'choice': [
69 | (r'(=|<|>|<=|>=|!=)(-?\d+)(\s*\{)',
70 | bygroups(Operator, Number.Integer, String.Escape), 'message'),
71 | (r'([a-z]+)(\s*\{)', bygroups(Keyword.Type, String.Escape), 'str'),
72 | (r'\}', String.Escape, ('#pop', '#pop')),
73 | (r'\s+', String.Escape)
74 | ],
75 | 'str': [
76 | (r'\}', String.Escape, '#pop'),
77 | (r'\{', String.Escape, 'msgname'),
78 | (r'[^{}]+', String)
79 | ]
80 | }
81 |
82 | def analyse_text(text):
83 | if text.startswith('root:table'):
84 | return 1.0
85 |
--------------------------------------------------------------------------------
/pygments/lexers/rita.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.rita
3 | ~~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexers for RITA language
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | import re
12 |
13 | from pygments.lexer import RegexLexer, include, bygroups, using, this, \
14 | inherit, words
15 | from pygments.token import Comment, Operator, Keyword, Name, Literal, Punctuation, Text, Whitespace
16 |
17 | __all__ = ['RitaLexer']
18 |
19 |
20 | class RitaLexer(RegexLexer):
21 | """
22 | Lexer for RITA.
23 |
24 | .. versionadded:: 2.11
25 | """
26 | name = 'Rita'
27 | url = 'https://github.com/zaibacu/rita-dsl'
28 | filenames = ['*.rita']
29 | aliases = ['rita']
30 | mimetypes = ['text/rita']
31 |
32 | tokens = {
33 | 'root': [
34 | (r'\n', Whitespace),
35 | (r'\s+', Whitespace),
36 | (r'#(.*?)\n', Comment.Single),
37 | (r'@(.*?)\n', Operator), # Yes, whole line as an operator
38 | (r'"(\w|\d|\s|(\\")|[\'_\-./,\?\!])+?"', Literal),
39 | (r'\'(\w|\d|\s|(\\\')|["_\-./,\?\!])+?\'', Literal),
40 | (r'([A-Z_]+)', Keyword),
41 | (r'([a-z0-9_]+)', Name),
42 | (r'((->)|[!?+*|=])', Operator),
43 | (r'[\(\),\{\}]', Punctuation)
44 | ]
45 | }
46 |
--------------------------------------------------------------------------------
/pygments/lexers/rnc.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.rnc
3 | ~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexer for Relax-NG Compact syntax
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.lexer import RegexLexer
12 | from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
13 | Punctuation
14 |
15 | __all__ = ['RNCCompactLexer']
16 |
17 |
18 | class RNCCompactLexer(RegexLexer):
19 | """
20 | For RelaxNG-compact syntax.
21 |
22 | .. versionadded:: 2.2
23 | """
24 |
25 | name = 'Relax-NG Compact'
26 | url = 'http://relaxng.org'
27 | aliases = ['rng-compact', 'rnc']
28 | filenames = ['*.rnc']
29 |
30 | tokens = {
31 | 'root': [
32 | (r'namespace\b', Keyword.Namespace),
33 | (r'(?:default|datatypes)\b', Keyword.Declaration),
34 | (r'##.*$', Comment.Preproc),
35 | (r'#.*$', Comment.Single),
36 | (r'"[^"]*"', String.Double),
37 | # TODO single quoted strings and escape sequences outside of
38 | # double-quoted strings
39 | (r'(?:element|attribute|mixed)\b', Keyword.Declaration, 'variable'),
40 | (r'(text\b|xsd:[^ ]+)', Keyword.Type, 'maybe_xsdattributes'),
41 | (r'[,?&*=|~]|>>', Operator),
42 | (r'[(){}]', Punctuation),
43 | (r'.', Text),
44 | ],
45 |
46 | # a variable has been declared using `element` or `attribute`
47 | 'variable': [
48 | (r'[^{]+', Name.Variable),
49 | (r'\{', Punctuation, '#pop'),
50 | ],
51 |
52 | # after an xsd: declaration there may be attributes
53 | 'maybe_xsdattributes': [
54 | (r'\{', Punctuation, 'xsdattributes'),
55 | (r'\}', Punctuation, '#pop'),
56 | (r'.', Text),
57 | ],
58 |
59 | # attributes take the form { key1 = value1 key2 = value2 ... }
60 | 'xsdattributes': [
61 | (r'[^ =}]', Name.Attribute),
62 | (r'=', Operator),
63 | (r'"[^"]*"', String.Double),
64 | (r'\}', Punctuation, '#pop'),
65 | (r'.', Text),
66 | ],
67 | }
68 |
--------------------------------------------------------------------------------
/pygments/lexers/roboconf.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.roboconf
3 | ~~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexers for Roboconf DSL.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.lexer import RegexLexer, words, re
12 | from pygments.token import Text, Operator, Keyword, Name, Comment
13 |
14 | __all__ = ['RoboconfGraphLexer', 'RoboconfInstancesLexer']
15 |
16 |
17 | class RoboconfGraphLexer(RegexLexer):
18 | """
19 | Lexer for Roboconf graph files.
20 |
21 | .. versionadded:: 2.1
22 | """
23 | name = 'Roboconf Graph'
24 | aliases = ['roboconf-graph']
25 | filenames = ['*.graph']
26 |
27 | flags = re.IGNORECASE | re.MULTILINE
28 | tokens = {
29 | 'root': [
30 | # Skip white spaces
31 | (r'\s+', Text),
32 |
33 | # There is one operator
34 | (r'=', Operator),
35 |
36 | # Keywords
37 | (words(('facet', 'import'), suffix=r'\s*\b', prefix=r'\b'), Keyword),
38 | (words((
39 | 'installer', 'extends', 'exports', 'imports', 'facets',
40 | 'children'), suffix=r'\s*:?', prefix=r'\b'), Name),
41 |
42 | # Comments
43 | (r'#.*\n', Comment),
44 |
45 | # Default
46 | (r'[^#]', Text),
47 | (r'.*\n', Text)
48 | ]
49 | }
50 |
51 |
52 | class RoboconfInstancesLexer(RegexLexer):
53 | """
54 | Lexer for Roboconf instances files.
55 |
56 | .. versionadded:: 2.1
57 | """
58 | name = 'Roboconf Instances'
59 | aliases = ['roboconf-instances']
60 | filenames = ['*.instances']
61 |
62 | flags = re.IGNORECASE | re.MULTILINE
63 | tokens = {
64 | 'root': [
65 |
66 | # Skip white spaces
67 | (r'\s+', Text),
68 |
69 | # Keywords
70 | (words(('instance of', 'import'), suffix=r'\s*\b', prefix=r'\b'), Keyword),
71 | (words(('name', 'count'), suffix=r's*:?', prefix=r'\b'), Name),
72 | (r'\s*[\w.-]+\s*:', Name),
73 |
74 | # Comments
75 | (r'#.*\n', Comment),
76 |
77 | # Default
78 | (r'[^#]', Text),
79 | (r'.*\n', Text)
80 | ]
81 | }
82 |
--------------------------------------------------------------------------------
/pygments/lexers/scdoc.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.scdoc
3 | ~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexer for scdoc, a simple man page generator.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | import re
12 |
13 | from pygments.lexer import RegexLexer, include, bygroups, \
14 | using, this
15 | from pygments.token import Text, Comment, Keyword, String, \
16 | Generic
17 |
18 |
19 | __all__ = ['ScdocLexer']
20 |
21 |
22 | class ScdocLexer(RegexLexer):
23 | """
24 | `scdoc` is a simple man page generator for POSIX systems written in C99.
25 |
26 | .. versionadded:: 2.5
27 | """
28 | name = 'scdoc'
29 | url = 'https://git.sr.ht/~sircmpwn/scdoc'
30 | aliases = ['scdoc', 'scd']
31 | filenames = ['*.scd', '*.scdoc']
32 | flags = re.MULTILINE
33 |
34 | tokens = {
35 | 'root': [
36 | # comment
37 | (r'^(;.+\n)', bygroups(Comment)),
38 |
39 | # heading with pound prefix
40 | (r'^(#)([^#].+\n)', bygroups(Generic.Heading, Text)),
41 | (r'^(#{2})(.+\n)', bygroups(Generic.Subheading, Text)),
42 | # bulleted lists
43 | (r'^(\s*)([*-])(\s)(.+\n)',
44 | bygroups(Text, Keyword, Text, using(this, state='inline'))),
45 | # numbered lists
46 | (r'^(\s*)(\.+\.)( .+\n)',
47 | bygroups(Text, Keyword, using(this, state='inline'))),
48 | # quote
49 | (r'^(\s*>\s)(.+\n)', bygroups(Keyword, Generic.Emph)),
50 | # text block
51 | (r'^(```\n)([\w\W]*?)(^```$)', bygroups(String, Text, String)),
52 |
53 | include('inline'),
54 | ],
55 | 'inline': [
56 | # escape
57 | (r'\\.', Text),
58 | # underlines
59 | (r'(\s)(_[^_]+_)(\W|\n)', bygroups(Text, Generic.Emph, Text)),
60 | # bold
61 | (r'(\s)(\*[^*]+\*)(\W|\n)', bygroups(Text, Generic.Strong, Text)),
62 | # inline code
63 | (r'`[^`]+`', String.Backtick),
64 |
65 | # general text, must come last!
66 | (r'[^\\\s]+', Text),
67 | (r'.', Text),
68 | ],
69 | }
70 |
71 | def analyse_text(text):
72 | """This is very similar to markdown, save for the escape characters
73 | needed for * and _."""
74 | result = 0
75 |
76 | if '\\*' in text:
77 | result += 0.01
78 |
79 | if '\\_' in text:
80 | result += 0.01
81 |
82 | return result
83 |
--------------------------------------------------------------------------------
/pygments/lexers/sgf.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.sgf
3 | ~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexer for Smart Game Format (sgf) file format.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.lexer import RegexLexer, bygroups
12 | from pygments.token import Name, Literal, String, Text, Punctuation, Whitespace
13 |
14 | __all__ = ["SmartGameFormatLexer"]
15 |
16 |
17 | class SmartGameFormatLexer(RegexLexer):
18 | """
19 | Lexer for Smart Game Format (sgf) file format.
20 |
21 | The format is used to store game records of board games for two players
22 | (mainly Go game).
23 |
24 | .. versionadded:: 2.4
25 | """
26 | name = 'SmartGameFormat'
27 | url = 'https://www.red-bean.com/sgf/'
28 | aliases = ['sgf']
29 | filenames = ['*.sgf']
30 |
31 | tokens = {
32 | 'root': [
33 | (r'[():;]+', Punctuation),
34 | # tokens:
35 | (r'(A[BW]|AE|AN|AP|AR|AS|[BW]L|BM|[BW]R|[BW]S|[BW]T|CA|CH|CP|CR|'
36 | r'DD|DM|DO|DT|EL|EV|EX|FF|FG|G[BW]|GC|GM|GN|HA|HO|ID|IP|IT|IY|KM|'
37 | r'KO|LB|LN|LT|L|MA|MN|M|N|OB|OM|ON|OP|OT|OV|P[BW]|PC|PL|PM|RE|RG|'
38 | r'RO|RU|SO|SC|SE|SI|SL|SO|SQ|ST|SU|SZ|T[BW]|TC|TE|TM|TR|UC|US|VW|'
39 | r'V|[BW]|C)',
40 | Name.Builtin),
41 | # number:
42 | (r'(\[)([0-9.]+)(\])',
43 | bygroups(Punctuation, Literal.Number, Punctuation)),
44 | # date:
45 | (r'(\[)([0-9]{4}-[0-9]{2}-[0-9]{2})(\])',
46 | bygroups(Punctuation, Literal.Date, Punctuation)),
47 | # point:
48 | (r'(\[)([a-z]{2})(\])',
49 | bygroups(Punctuation, String, Punctuation)),
50 | # double points:
51 | (r'(\[)([a-z]{2})(:)([a-z]{2})(\])',
52 | bygroups(Punctuation, String, Punctuation, String, Punctuation)),
53 |
54 | (r'(\[)([\w\s#()+,\-.:?]+)(\])',
55 | bygroups(Punctuation, String, Punctuation)),
56 | (r'(\[)(\s.*)(\])',
57 | bygroups(Punctuation, Whitespace, Punctuation)),
58 | (r'\s+', Whitespace)
59 | ],
60 | }
61 |
--------------------------------------------------------------------------------
/pygments/lexers/sieve.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.sieve
3 | ~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexer for Sieve file format.
6 |
7 | https://tools.ietf.org/html/rfc5228
8 | https://tools.ietf.org/html/rfc5173
9 | https://tools.ietf.org/html/rfc5229
10 | https://tools.ietf.org/html/rfc5230
11 | https://tools.ietf.org/html/rfc5232
12 | https://tools.ietf.org/html/rfc5235
13 | https://tools.ietf.org/html/rfc5429
14 | https://tools.ietf.org/html/rfc8580
15 |
16 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
17 | :license: BSD, see LICENSE for details.
18 | """
19 |
20 | from pygments.lexer import RegexLexer, bygroups
21 | from pygments.token import Comment, Name, Literal, String, Text, Punctuation, Keyword
22 |
23 | __all__ = ["SieveLexer"]
24 |
25 |
26 | class SieveLexer(RegexLexer):
27 | """
28 | Lexer for sieve format.
29 | """
30 | name = 'Sieve'
31 | filenames = ['*.siv', '*.sieve']
32 | aliases = ['sieve']
33 |
34 | tokens = {
35 | 'root': [
36 | (r'\s+', Text),
37 | (r'[();,{}\[\]]', Punctuation),
38 | # import:
39 | (r'(?i)require',
40 | Keyword.Namespace),
41 | # tags:
42 | (r'(?i)(:)(addresses|all|contains|content|create|copy|comparator|count|days|detail|domain|fcc|flags|from|handle|importance|is|localpart|length|lowerfirst|lower|matches|message|mime|options|over|percent|quotewildcard|raw|regex|specialuse|subject|text|under|upperfirst|upper|value)',
43 | bygroups(Name.Tag, Name.Tag)),
44 | # tokens:
45 | (r'(?i)(address|addflag|allof|anyof|body|discard|elsif|else|envelope|ereject|exists|false|fileinto|if|hasflag|header|keep|notify_method_capability|notify|not|redirect|reject|removeflag|setflag|size|spamtest|stop|string|true|vacation|virustest)',
46 | Name.Builtin),
47 | (r'(?i)set',
48 | Keyword.Declaration),
49 | # number:
50 | (r'([0-9.]+)([kmgKMG])?',
51 | bygroups(Literal.Number, Literal.Number)),
52 | # comment:
53 | (r'#.*$',
54 | Comment.Single),
55 | (r'/\*.*\*/',
56 | Comment.Multiline),
57 | # string:
58 | (r'"[^"]*?"',
59 | String),
60 | # text block:
61 | (r'text:',
62 | Name.Tag, 'text'),
63 | ],
64 | 'text': [
65 | (r'[^.].*?\n', String),
66 | (r'^\.', Punctuation, "#pop"),
67 | ]
68 | }
69 |
--------------------------------------------------------------------------------
/pygments/lexers/smithy.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.smithy
3 | ~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexers for the Smithy IDL.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | import re
12 |
13 | from pygments.lexer import RegexLexer, bygroups, words
14 | from pygments.token import Text, Comment, Keyword, Name, String, \
15 | Number, Whitespace, Punctuation
16 |
17 | __all__ = ['SmithyLexer']
18 |
19 |
20 | class SmithyLexer(RegexLexer):
21 | """
22 | For Smithy IDL
23 |
24 | .. versionadded:: 2.10
25 | """
26 | name = 'Smithy'
27 | url = 'https://awslabs.github.io/smithy/'
28 | filenames = ['*.smithy']
29 | aliases = ['smithy']
30 |
31 | unquoted = r'[A-Za-z0-9_\.#$-]+'
32 | identifier = r"[A-Za-z0-9_\.#$-]+"
33 |
34 | simple_shapes = (
35 | 'use', 'byte', 'short', 'integer', 'long', 'float', 'document',
36 | 'double', 'bigInteger', 'bigDecimal', 'boolean', 'blob', 'string',
37 | 'timestamp',
38 | )
39 |
40 | aggregate_shapes = (
41 | 'apply', 'list', 'map', 'set', 'structure', 'union', 'resource',
42 | 'operation', 'service', 'trait'
43 | )
44 |
45 | tokens = {
46 | 'root': [
47 | (r'///.*$', Comment.Multiline),
48 | (r'//.*$', Comment),
49 | (r'@[0-9a-zA-Z\.#-]*', Name.Decorator),
50 | (r'(=)', Name.Decorator),
51 | (r'^(\$version)(:)(.+)',
52 | bygroups(Keyword.Declaration, Name.Decorator, Name.Class)),
53 | (r'^(namespace)(\s+' + identifier + r')\b',
54 | bygroups(Keyword.Declaration, Name.Class)),
55 | (words(simple_shapes,
56 | prefix=r'^', suffix=r'(\s+' + identifier + r')\b'),
57 | bygroups(Keyword.Declaration, Name.Class)),
58 | (words(aggregate_shapes,
59 | prefix=r'^', suffix=r'(\s+' + identifier + r')'),
60 | bygroups(Keyword.Declaration, Name.Class)),
61 | (r'^(metadata)(\s+.+)(\s*)(=)',
62 | bygroups(Keyword.Declaration, Name.Class, Whitespace, Name.Decorator)),
63 | (r"(true|false|null)", Keyword.Constant),
64 | (r"(-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?)", Number),
65 | (identifier + ":", Name.Label),
66 | (identifier, Name.Variable.Class),
67 | (r'\[', Text, "#push"),
68 | (r'\]', Text, "#pop"),
69 | (r'\(', Text, "#push"),
70 | (r'\)', Text, "#pop"),
71 | (r'\{', Text, "#push"),
72 | (r'\}', Text, "#pop"),
73 | (r'"{3}(\\\\|\n|\\")*"{3}', String.Doc),
74 | (r'"(\\\\|\n|\\"|[^"])*"', String.Double),
75 | (r"'(\\\\|\n|\\'|[^'])*'", String.Single),
76 | (r'[:,]+', Punctuation),
77 | (r'\s+', Whitespace),
78 | ]
79 | }
80 |
--------------------------------------------------------------------------------
/pygments/lexers/smv.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.smv
3 | ~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexers for the SMV languages.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.lexer import RegexLexer, words
12 | from pygments.token import Comment, Keyword, Name, Number, Operator, \
13 | Punctuation, Text
14 |
15 | __all__ = ['NuSMVLexer']
16 |
17 |
18 | class NuSMVLexer(RegexLexer):
19 | """
20 | Lexer for the NuSMV language.
21 |
22 | .. versionadded:: 2.2
23 | """
24 |
25 | name = 'NuSMV'
26 | aliases = ['nusmv']
27 | filenames = ['*.smv']
28 | mimetypes = []
29 |
30 | tokens = {
31 | 'root': [
32 | # Comments
33 | (r'(?s)\/\-\-.*?\-\-/', Comment),
34 | (r'--.*\n', Comment),
35 |
36 | # Reserved
37 | (words(('MODULE', 'DEFINE', 'MDEFINE', 'CONSTANTS', 'VAR', 'IVAR',
38 | 'FROZENVAR', 'INIT', 'TRANS', 'INVAR', 'SPEC', 'CTLSPEC',
39 | 'LTLSPEC', 'PSLSPEC', 'COMPUTE', 'NAME', 'INVARSPEC',
40 | 'FAIRNESS', 'JUSTICE', 'COMPASSION', 'ISA', 'ASSIGN',
41 | 'CONSTRAINT', 'SIMPWFF', 'CTLWFF', 'LTLWFF', 'PSLWFF',
42 | 'COMPWFF', 'IN', 'MIN', 'MAX', 'MIRROR', 'PRED',
43 | 'PREDICATES'), suffix=r'(?![\w$#-])'),
44 | Keyword.Declaration),
45 | (r'process(?![\w$#-])', Keyword),
46 | (words(('array', 'of', 'boolean', 'integer', 'real', 'word'),
47 | suffix=r'(?![\w$#-])'), Keyword.Type),
48 | (words(('case', 'esac'), suffix=r'(?![\w$#-])'), Keyword),
49 | (words(('word1', 'bool', 'signed', 'unsigned', 'extend', 'resize',
50 | 'sizeof', 'uwconst', 'swconst', 'init', 'self', 'count',
51 | 'abs', 'max', 'min'), suffix=r'(?![\w$#-])'),
52 | Name.Builtin),
53 | (words(('EX', 'AX', 'EF', 'AF', 'EG', 'AG', 'E', 'F', 'O', 'G',
54 | 'H', 'X', 'Y', 'Z', 'A', 'U', 'S', 'V', 'T', 'BU', 'EBF',
55 | 'ABF', 'EBG', 'ABG', 'next', 'mod', 'union', 'in', 'xor',
56 | 'xnor'), suffix=r'(?![\w$#-])'),
57 | Operator.Word),
58 | (words(('TRUE', 'FALSE'), suffix=r'(?![\w$#-])'), Keyword.Constant),
59 |
60 | # Names
61 | (r'[a-zA-Z_][\w$#-]*', Name.Variable),
62 |
63 | # Operators
64 | (r':=', Operator),
65 | (r'[-&|+*/<>!=]', Operator),
66 |
67 | # Literals
68 | (r'\-?\d+\b', Number.Integer),
69 | (r'0[su][bB]\d*_[01_]+', Number.Bin),
70 | (r'0[su][oO]\d*_[0-7_]+', Number.Oct),
71 | (r'0[su][dD]\d*_[\d_]+', Number.Decimal),
72 | (r'0[su][hH]\d*_[\da-fA-F_]+', Number.Hex),
73 |
74 | # Whitespace, punctuation and the rest
75 | (r'\s+', Text.Whitespace),
76 | (r'[()\[\]{};?:.,]', Punctuation),
77 | ],
78 | }
79 |
--------------------------------------------------------------------------------
/pygments/lexers/snobol.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.snobol
3 | ~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexers for the SNOBOL language.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.lexer import RegexLexer, bygroups
12 | from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
13 | Number, Punctuation
14 |
15 | __all__ = ['SnobolLexer']
16 |
17 |
18 | class SnobolLexer(RegexLexer):
19 | """
20 | Lexer for the SNOBOL4 programming language.
21 |
22 | Recognizes the common ASCII equivalents of the original SNOBOL4 operators.
23 | Does not require spaces around binary operators.
24 |
25 | .. versionadded:: 1.5
26 | """
27 |
28 | name = "Snobol"
29 | aliases = ["snobol"]
30 | filenames = ['*.snobol']
31 | mimetypes = ['text/x-snobol']
32 |
33 | tokens = {
34 | # root state, start of line
35 | # comments, continuation lines, and directives start in column 1
36 | # as do labels
37 | 'root': [
38 | (r'\*.*\n', Comment),
39 | (r'[+.] ', Punctuation, 'statement'),
40 | (r'-.*\n', Comment),
41 | (r'END\s*\n', Name.Label, 'heredoc'),
42 | (r'[A-Za-z$][\w$]*', Name.Label, 'statement'),
43 | (r'\s+', Text, 'statement'),
44 | ],
45 | # statement state, line after continuation or label
46 | 'statement': [
47 | (r'\s*\n', Text, '#pop'),
48 | (r'\s+', Text),
49 | (r'(?<=[^\w.])(LT|LE|EQ|NE|GE|GT|INTEGER|IDENT|DIFFER|LGT|SIZE|'
50 | r'REPLACE|TRIM|DUPL|REMDR|DATE|TIME|EVAL|APPLY|OPSYN|LOAD|UNLOAD|'
51 | r'LEN|SPAN|BREAK|ANY|NOTANY|TAB|RTAB|REM|POS|RPOS|FAIL|FENCE|'
52 | r'ABORT|ARB|ARBNO|BAL|SUCCEED|INPUT|OUTPUT|TERMINAL)(?=[^\w.])',
53 | Name.Builtin),
54 | (r'[A-Za-z][\w.]*', Name),
55 | # ASCII equivalents of original operators
56 | # | for the EBCDIC equivalent, ! likewise
57 | # \ for EBCDIC negation
58 | (r'\*\*|[?$.!%*/#+\-@|&\\=]', Operator),
59 | (r'"[^"]*"', String),
60 | (r"'[^']*'", String),
61 | # Accept SPITBOL syntax for real numbers
62 | # as well as Macro SNOBOL4
63 | (r'[0-9]+(?=[^.EeDd])', Number.Integer),
64 | (r'[0-9]+(\.[0-9]*)?([EDed][-+]?[0-9]+)?', Number.Float),
65 | # Goto
66 | (r':', Punctuation, 'goto'),
67 | (r'[()<>,;]', Punctuation),
68 | ],
69 | # Goto block
70 | 'goto': [
71 | (r'\s*\n', Text, "#pop:2"),
72 | (r'\s+', Text),
73 | (r'F|S', Keyword),
74 | (r'(\()([A-Za-z][\w.]*)(\))',
75 | bygroups(Punctuation, Name.Label, Punctuation))
76 | ],
77 | # everything after the END statement is basically one
78 | # big heredoc.
79 | 'heredoc': [
80 | (r'.*\n', String.Heredoc)
81 | ]
82 | }
83 |
--------------------------------------------------------------------------------
/pygments/lexers/spice.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.spice
3 | ~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexers for the Spice programming language.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | import re
12 |
13 | from pygments.lexer import RegexLexer, bygroups, words
14 | from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
15 | Number, Punctuation, Whitespace
16 |
17 | __all__ = ['SpiceLexer']
18 |
19 |
20 | class SpiceLexer(RegexLexer):
21 | """
22 | For Spice source.
23 |
24 | .. versionadded:: 2.11
25 | """
26 | name = 'Spice'
27 | url = 'https://www.spicelang.com'
28 | filenames = ['*.spice']
29 | aliases = ['spice', 'spicelang']
30 | mimetypes = ['text/x-spice']
31 |
32 | tokens = {
33 | 'root': [
34 | (r'\n', Whitespace),
35 | (r'\s+', Whitespace),
36 | (r'\\\n', Text),
37 | # comments
38 | (r'//(.*?)\n', Comment.Single),
39 | (r'/(\\\n)?[*]{2}(.|\n)*?[*](\\\n)?/', String.Doc),
40 | (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
41 | # keywords
42 | (r'(import|as)\b', Keyword.Namespace),
43 | (r'(f|p|type|struct)\b', Keyword.Declaration),
44 | (words(('if', 'else', 'for', 'foreach', 'while', 'break', 'continue', 'return', 'assert', 'thread', 'unsafe', 'ext', 'dll'), suffix=r'\b'), Keyword),
45 | (words(('const', 'signed', 'unsigned', 'inline', 'public'), suffix=r'\b'), Keyword.Pseudo),
46 | (words(('new', 'switch', 'case', 'yield', 'stash', 'pick', 'sync'), suffix=r'\b'), Keyword.Reserved),
47 | (r'(true|false|nil)\b', Keyword.Constant),
48 | (words(('double', 'int', 'short', 'long', 'byte', 'char', 'string', 'bool', 'dyn'), suffix=r'\b'), Keyword.Type),
49 | (words(('printf', 'sizeof', 'len', 'tid', 'join'), suffix=r'\b(\()'), bygroups(Name.Builtin, Punctuation)),
50 | # numeric literals
51 | (r'([0-9]*[.][0-9]+)', Number.Double),
52 | (r'((0[dD])?[0-9]+[sl]?)', Number.Integer),
53 | (r'(0[bB][01]+[sl]?)', Number.Bin),
54 | (r'(0[oO][0-7]+[sl]?)', Number.Oct),
55 | (r'(0[xXhH][0-9a-fA-F]+[sl]?)', Number.Hex),
56 | # string literal
57 | (r'"(\\\\|\\[^\\]|[^"\\])*"', String),
58 | # char literal
59 | (r'\'(\\\\|\\[^\\]|[^\'\\])\'', String.Char),
60 | # tokens
61 | (r'(<<=|>>=|<<|>>|<=|>=|\+=|-=|\*=|/=|\%=|\|=|&=|\^=|&&|\|\||&|\||\+\+|--|\%|\^|\~|==|!=|[.]{3}|[+\-*/&])', Operator),
62 | (r'[|<>=!()\[\]{}.,;:\?]', Punctuation),
63 | # identifiers
64 | (r'[^\W\d]\w*', Name.Other),
65 | ]
66 | }
67 |
--------------------------------------------------------------------------------
/pygments/lexers/srcinfo.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.srcinfo
3 | ~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexers for .SRCINFO files used by Arch Linux Packages.
6 |
7 | The description of the format can be found in the wiki: https://wiki.archlinux.org/title/.SRCINFO
8 |
9 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
10 | :license: BSD, see LICENSE for details.
11 | """
12 |
13 | from pygments.lexer import RegexLexer, words
14 | from pygments.token import Text, Comment, Keyword, Name, Operator, Whitespace
15 |
16 | __all__ = ['SrcinfoLexer']
17 |
18 | keywords = (
19 | 'pkgbase', 'pkgname',
20 | 'pkgver', 'pkgrel', 'epoch',
21 | 'pkgdesc', 'url', 'install', 'changelog',
22 | 'arch', 'groups', 'license', 'noextract', 'options', 'backup', 'validpgpkeys',
23 | )
24 |
25 | architecture_dependent_keywords = (
26 | 'source', 'depends', 'checkdepends', 'makedepends', 'optdepends',
27 | 'provides', 'conflicts', 'replaces',
28 | 'md5sums', 'sha1sums', 'sha224sums', 'sha256sums', 'sha384sums', 'sha512sums'
29 | )
30 |
31 | class SrcinfoLexer(RegexLexer):
32 | """Lexer for .SRCINFO files used by Arch Linux Packages.
33 |
34 | .. versionadded:: 2.11
35 | """
36 |
37 | name = 'Srcinfo'
38 | aliases = ['srcinfo']
39 | filenames = ['.SRCINFO']
40 |
41 | tokens = {
42 | 'root': [
43 | (r'\s+', Whitespace),
44 | (r'#.*', Comment.Single),
45 | (words(keywords), Keyword, 'assignment'),
46 | (words(architecture_dependent_keywords, suffix=r'_\w+'), Keyword, 'assignment'),
47 | (r'\w+', Name.Variable, 'assignment'),
48 | ],
49 | 'assignment': [
50 | (r' +', Whitespace),
51 | (r'=', Operator, 'value'),
52 | ],
53 | 'value': [
54 | (r' +', Whitespace),
55 | (r'.*', Text, '#pop:2'),
56 | ],
57 | }
58 |
--------------------------------------------------------------------------------
/pygments/lexers/tal.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.tal
3 | ~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexer for Uxntal
6 |
7 | .. versionadded:: 2.12
8 |
9 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
10 | :license: BSD, see LICENSE for details.
11 | """
12 |
13 | import re
14 |
15 | from pygments.lexer import RegexLexer, words
16 | from pygments.token import Comment, Keyword, Name, String, Number, Punctuation, Whitespace, Literal
17 |
18 | __all__ = ['TalLexer']
19 |
20 | class TalLexer(RegexLexer):
21 | """
22 | For `Uxntal `_ source code.
23 |
24 | .. versionadded:: 2.12
25 | """
26 |
27 | name = 'Tal'
28 | aliases = ['tal', 'uxntal']
29 | filenames = ['*.tal']
30 | mimetypes = ['text/x-uxntal']
31 |
32 | instructions = [
33 | 'BRK', 'LIT', 'INC', 'POP', 'DUP', 'NIP', 'SWP', 'OVR', 'ROT',
34 | 'EQU', 'NEQ', 'GTH', 'LTH', 'JMP', 'JCN', 'JSR', 'STH',
35 | 'LDZ', 'STZ', 'LDR', 'STR', 'LDA', 'STA', 'DEI', 'DEO',
36 | 'ADD', 'SUB', 'MUL', 'DIV', 'AND', 'ORA', 'EOR', 'SFT'
37 | ]
38 |
39 | tokens = {
40 | # the comment delimiters must not be adjacent to non-space characters.
41 | # this means ( foo ) is a valid comment but (foo) is not. this also
42 | # applies to nested comments.
43 | 'comment': [
44 | (r'(?^.!~|&\[\]\?\:]', Operator),
37 | (r'(>=|<=|==|!=|'
38 | r'&&|\|\||'
39 | r'\+=|.=|-=|\*=|/=|%=|<<=|>>=|&=|\|=|\^=|'
40 | r'>>|<<|'
41 | r'\+\+|--|=>)', Operator),
42 | (r'[ \t\r]+', Text),
43 | (r'#[^\n]*', Comment),
44 | ],
45 | 'escapable-string' : [
46 | (r'\\[tsn]', String.Escape),
47 | (r'[^"]', String),
48 | (r'"', String, '#pop'),
49 | ],
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/pygments/lexers/web.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.web
3 | ~~~~~~~~~~~~~~~~~~~
4 |
5 | Just export previously exported lexers.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.lexers.html import HtmlLexer, DtdLexer, XmlLexer, XsltLexer, \
12 | HamlLexer, ScamlLexer, JadeLexer
13 | from pygments.lexers.css import CssLexer, SassLexer, ScssLexer
14 | from pygments.lexers.javascript import JavascriptLexer, LiveScriptLexer, \
15 | DartLexer, TypeScriptLexer, LassoLexer, ObjectiveJLexer, CoffeeScriptLexer
16 | from pygments.lexers.actionscript import ActionScriptLexer, \
17 | ActionScript3Lexer, MxmlLexer
18 | from pygments.lexers.php import PhpLexer
19 | from pygments.lexers.webmisc import DuelLexer, XQueryLexer, SlimLexer, QmlLexer
20 | from pygments.lexers.data import JsonLexer
21 | JSONLexer = JsonLexer # for backwards compatibility with Pygments 1.5
22 |
23 | __all__ = []
24 |
--------------------------------------------------------------------------------
/pygments/lexers/x10.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.x10
3 | ~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexers for the X10 programming language.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.lexer import RegexLexer
12 | from pygments.token import Text, Comment, Keyword, String
13 |
14 | __all__ = ['X10Lexer']
15 |
16 | class X10Lexer(RegexLexer):
17 | """
18 | For the X10 language.
19 |
20 | .. versionadded:: 0.1
21 | """
22 |
23 | name = 'X10'
24 | url = 'http://x10-lang.org/'
25 | aliases = ['x10', 'xten']
26 | filenames = ['*.x10']
27 | mimetypes = ['text/x-x10']
28 |
29 | keywords = (
30 | 'as', 'assert', 'async', 'at', 'athome', 'ateach', 'atomic',
31 | 'break', 'case', 'catch', 'class', 'clocked', 'continue',
32 | 'def', 'default', 'do', 'else', 'final', 'finally', 'finish',
33 | 'for', 'goto', 'haszero', 'here', 'if', 'import', 'in',
34 | 'instanceof', 'interface', 'isref', 'new', 'offer',
35 | 'operator', 'package', 'return', 'struct', 'switch', 'throw',
36 | 'try', 'type', 'val', 'var', 'when', 'while'
37 | )
38 |
39 | types = (
40 | 'void'
41 | )
42 |
43 | values = (
44 | 'false', 'null', 'self', 'super', 'this', 'true'
45 | )
46 |
47 | modifiers = (
48 | 'abstract', 'extends', 'implements', 'native', 'offers',
49 | 'private', 'property', 'protected', 'public', 'static',
50 | 'throws', 'transient'
51 | )
52 |
53 | tokens = {
54 | 'root': [
55 | (r'[^\S\n]+', Text),
56 | (r'//.*?\n', Comment.Single),
57 | (r'/\*(.|\n)*?\*/', Comment.Multiline),
58 | (r'\b(%s)\b' % '|'.join(keywords), Keyword),
59 | (r'\b(%s)\b' % '|'.join(types), Keyword.Type),
60 | (r'\b(%s)\b' % '|'.join(values), Keyword.Constant),
61 | (r'\b(%s)\b' % '|'.join(modifiers), Keyword.Declaration),
62 | (r'"(\\\\|\\[^\\]|[^"\\])*"', String),
63 | (r"'\\.'|'[^\\]'|'\\u[0-9a-fA-F]{4}'", String.Char),
64 | (r'.', Text)
65 | ],
66 | }
67 |
--------------------------------------------------------------------------------
/pygments/lexers/xorg.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.lexers.xorg
3 | ~~~~~~~~~~~~~~~~~~~~
4 |
5 | Lexers for Xorg configs.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.lexer import RegexLexer, bygroups
12 | from pygments.token import Comment, String, Name, Text
13 |
14 | __all__ = ['XorgLexer']
15 |
16 |
17 | class XorgLexer(RegexLexer):
18 | """Lexer for xorg.conf file."""
19 | name = 'Xorg'
20 | url = 'https://www.x.org/wiki/'
21 | aliases = ['xorg.conf']
22 | filenames = ['xorg.conf']
23 | mimetypes = []
24 |
25 | tokens = {
26 | 'root': [
27 | (r'\s+', Text),
28 | (r'#.*$', Comment),
29 |
30 | (r'((?:Sub)?Section)(\s+)("\w+")',
31 | bygroups(String.Escape, Text, String.Escape)),
32 | (r'(End(?:Sub)?Section)', String.Escape),
33 |
34 | (r'(\w+)(\s+)([^\n#]+)',
35 | bygroups(Name.Builtin, Text, Name.Constant)),
36 | ],
37 | }
38 |
--------------------------------------------------------------------------------
/pygments/modeline.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.modeline
3 | ~~~~~~~~~~~~~~~~~
4 |
5 | A simple modeline parser (based on pymodeline).
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | import re
12 |
13 | __all__ = ['get_filetype_from_buffer']
14 |
15 |
16 | modeline_re = re.compile(r'''
17 | (?: vi | vim | ex ) (?: [<=>]? \d* )? :
18 | .* (?: ft | filetype | syn | syntax ) = ( [^:\s]+ )
19 | ''', re.VERBOSE)
20 |
21 |
22 | def get_filetype_from_line(l):
23 | m = modeline_re.search(l)
24 | if m:
25 | return m.group(1)
26 |
27 |
28 | def get_filetype_from_buffer(buf, max_lines=5):
29 | """
30 | Scan the buffer for modelines and return filetype if one is found.
31 | """
32 | lines = buf.splitlines()
33 | for l in lines[-1:-max_lines-1:-1]:
34 | ret = get_filetype_from_line(l)
35 | if ret:
36 | return ret
37 | for i in range(max_lines, -1, -1):
38 | if i < len(lines):
39 | ret = get_filetype_from_line(lines[i])
40 | if ret:
41 | return ret
42 |
43 | return None
44 |
--------------------------------------------------------------------------------
/pygments/plugin.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.plugin
3 | ~~~~~~~~~~~~~~~
4 |
5 | Pygments plugin interface. By default, this tries to use
6 | ``importlib.metadata``, which is in the Python standard
7 | library since Python 3.8, or its ``importlib_metadata``
8 | backport for earlier versions of Python. It falls back on
9 | ``pkg_resources`` if not found. Finally, if ``pkg_resources``
10 | is not found either, no plugins are loaded at all.
11 |
12 | lexer plugins::
13 |
14 | [pygments.lexers]
15 | yourlexer = yourmodule:YourLexer
16 |
17 | formatter plugins::
18 |
19 | [pygments.formatters]
20 | yourformatter = yourformatter:YourFormatter
21 | /.ext = yourformatter:YourFormatter
22 |
23 | As you can see, you can define extensions for the formatter
24 | with a leading slash.
25 |
26 | syntax plugins::
27 |
28 | [pygments.styles]
29 | yourstyle = yourstyle:YourStyle
30 |
31 | filter plugin::
32 |
33 | [pygments.filter]
34 | yourfilter = yourfilter:YourFilter
35 |
36 |
37 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
38 | :license: BSD, see LICENSE for details.
39 | """
40 |
41 | LEXER_ENTRY_POINT = 'pygments.lexers'
42 | FORMATTER_ENTRY_POINT = 'pygments.formatters'
43 | STYLE_ENTRY_POINT = 'pygments.styles'
44 | FILTER_ENTRY_POINT = 'pygments.filters'
45 |
46 |
47 | def iter_entry_points(group_name):
48 | try:
49 | from importlib.metadata import entry_points
50 | except ImportError:
51 | try:
52 | from importlib_metadata import entry_points
53 | except ImportError:
54 | try:
55 | from pkg_resources import iter_entry_points
56 | except (ImportError, OSError):
57 | return []
58 | else:
59 | return iter_entry_points(group_name)
60 | groups = entry_points()
61 | if hasattr(groups, 'select'):
62 | # New interface in Python 3.10 and newer versions of the
63 | # importlib_metadata backport.
64 | return groups.select(group=group_name)
65 | else:
66 | # Older interface, deprecated in Python 3.10 and recent
67 | # importlib_metadata, but we need it in Python 3.8 and 3.9.
68 | return groups.get(group_name, [])
69 |
70 |
71 | def find_plugin_lexers():
72 | for entrypoint in iter_entry_points(LEXER_ENTRY_POINT):
73 | yield entrypoint.load()
74 |
75 |
76 | def find_plugin_formatters():
77 | for entrypoint in iter_entry_points(FORMATTER_ENTRY_POINT):
78 | yield entrypoint.name, entrypoint.load()
79 |
80 |
81 | def find_plugin_styles():
82 | for entrypoint in iter_entry_points(STYLE_ENTRY_POINT):
83 | yield entrypoint.name, entrypoint.load()
84 |
85 |
86 | def find_plugin_filters():
87 | for entrypoint in iter_entry_points(FILTER_ENTRY_POINT):
88 | yield entrypoint.name, entrypoint.load()
89 |
--------------------------------------------------------------------------------
/pygments/styles/abap.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.abap
3 | ~~~~~~~~~~~~~~~~~~~~
4 |
5 | ABAP workbench like style.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.style import Style
12 | from pygments.token import Keyword, Name, Comment, String, Error, \
13 | Number, Operator
14 |
15 |
16 | class AbapStyle(Style):
17 |
18 | styles = {
19 | Comment: 'italic #888',
20 | Comment.Special: '#888',
21 | Keyword: '#00f',
22 | Operator.Word: '#00f',
23 | Name: '#000',
24 | Number: '#3af',
25 | String: '#5a2',
26 |
27 | Error: '#F00',
28 | }
29 |
--------------------------------------------------------------------------------
/pygments/styles/algol.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.algol
3 | ~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Algol publication style.
6 |
7 | This style renders source code for publication of algorithms in
8 | scientific papers and academic texts, where its format is frequently used.
9 |
10 | It is based on the style of the revised Algol-60 language report[1].
11 |
12 | o No colours, only black, white and shades of grey are used.
13 | o Keywords are rendered in lowercase underline boldface.
14 | o Builtins are rendered in lowercase boldface italic.
15 | o Docstrings and pragmas are rendered in dark grey boldface.
16 | o Library identifiers are rendered in dark grey boldface italic.
17 | o Comments are rendered in grey italic.
18 |
19 | To render keywords without underlining, refer to the `Algol_Nu` style.
20 |
21 | For lowercase conversion of keywords and builtins in languages where
22 | these are not or might not be lowercase, a supporting lexer is required.
23 | The Algol and Modula-2 lexers automatically convert to lowercase whenever
24 | this style is selected.
25 |
26 | [1] `Revised Report on the Algorithmic Language Algol-60 `
27 |
28 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
29 | :license: BSD, see LICENSE for details.
30 | """
31 |
32 | from pygments.style import Style
33 | from pygments.token import Keyword, Name, Comment, String, Error, Operator
34 |
35 |
36 | class AlgolStyle(Style):
37 |
38 | background_color = "#ffffff"
39 |
40 | styles = {
41 | Comment: "italic #888",
42 | Comment.Preproc: "bold noitalic #888",
43 | Comment.Special: "bold noitalic #888",
44 |
45 | Keyword: "underline bold",
46 | Keyword.Declaration: "italic",
47 |
48 | Name.Builtin: "bold italic",
49 | Name.Builtin.Pseudo: "bold italic",
50 | Name.Namespace: "bold italic #666",
51 | Name.Class: "bold italic #666",
52 | Name.Function: "bold italic #666",
53 | Name.Variable: "bold italic #666",
54 | Name.Constant: "bold italic #666",
55 |
56 | Operator.Word: "bold",
57 |
58 | String: "italic #666",
59 |
60 | Error: "border:#FF0000"
61 | }
62 |
--------------------------------------------------------------------------------
/pygments/styles/algol_nu.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.algol_nu
3 | ~~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Algol publication style without underlining of keywords.
6 |
7 | This style renders source code for publication of algorithms in
8 | scientific papers and academic texts, where its format is frequently used.
9 |
10 | It is based on the style of the revised Algol-60 language report[1].
11 |
12 | o No colours, only black, white and shades of grey are used.
13 | o Keywords are rendered in lowercase boldface.
14 | o Builtins are rendered in lowercase boldface italic.
15 | o Docstrings and pragmas are rendered in dark grey boldface.
16 | o Library identifiers are rendered in dark grey boldface italic.
17 | o Comments are rendered in grey italic.
18 |
19 | To render keywords with underlining, refer to the `Algol` style.
20 |
21 | For lowercase conversion of keywords and builtins in languages where
22 | these are not or might not be lowercase, a supporting lexer is required.
23 | The Algol and Modula-2 lexers automatically convert to lowercase whenever
24 | this style is selected.
25 |
26 | [1] `Revised Report on the Algorithmic Language Algol-60 `
27 |
28 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
29 | :license: BSD, see LICENSE for details.
30 | """
31 |
32 | from pygments.style import Style
33 | from pygments.token import Keyword, Name, Comment, String, Error, Operator
34 |
35 |
36 | class Algol_NuStyle(Style):
37 |
38 | background_color = "#ffffff"
39 |
40 | styles = {
41 | Comment: "italic #888",
42 | Comment.Preproc: "bold noitalic #888",
43 | Comment.Special: "bold noitalic #888",
44 |
45 | Keyword: "bold",
46 | Keyword.Declaration: "italic",
47 |
48 | Name.Builtin: "bold italic",
49 | Name.Builtin.Pseudo: "bold italic",
50 | Name.Namespace: "bold italic #666",
51 | Name.Class: "bold italic #666",
52 | Name.Function: "bold italic #666",
53 | Name.Variable: "bold italic #666",
54 | Name.Constant: "bold italic #666",
55 |
56 | Operator.Word: "bold",
57 |
58 | String: "italic #666",
59 |
60 | Error: "border:#FF0000"
61 | }
62 |
--------------------------------------------------------------------------------
/pygments/styles/autumn.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.autumn
3 | ~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | A colorful style, inspired by the terminal highlighting style.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.style import Style
12 | from pygments.token import Keyword, Name, Comment, String, Error, \
13 | Number, Operator, Generic, Whitespace
14 |
15 |
16 | class AutumnStyle(Style):
17 | """
18 | A colorful style, inspired by the terminal highlighting style.
19 | """
20 |
21 | styles = {
22 | Whitespace: '#bbbbbb',
23 |
24 | Comment: 'italic #aaaaaa',
25 | Comment.Preproc: 'noitalic #4c8317',
26 | Comment.Special: 'italic #0000aa',
27 |
28 | Keyword: '#0000aa',
29 | Keyword.Type: '#00aaaa',
30 |
31 | Operator.Word: '#0000aa',
32 |
33 | Name.Builtin: '#00aaaa',
34 | Name.Function: '#00aa00',
35 | Name.Class: 'underline #00aa00',
36 | Name.Namespace: 'underline #00aaaa',
37 | Name.Variable: '#aa0000',
38 | Name.Constant: '#aa0000',
39 | Name.Entity: 'bold #800',
40 | Name.Attribute: '#1e90ff',
41 | Name.Tag: 'bold #1e90ff',
42 | Name.Decorator: '#888888',
43 |
44 | String: '#aa5500',
45 | String.Symbol: '#0000aa',
46 | String.Regex: '#009999',
47 |
48 | Number: '#009999',
49 |
50 | Generic.Heading: 'bold #000080',
51 | Generic.Subheading: 'bold #800080',
52 | Generic.Deleted: '#aa0000',
53 | Generic.Inserted: '#00aa00',
54 | Generic.Error: '#aa0000',
55 | Generic.Emph: 'italic',
56 | Generic.Strong: 'bold',
57 | Generic.Prompt: '#555555',
58 | Generic.Output: '#888888',
59 | Generic.Traceback: '#aa0000',
60 |
61 | Error: '#F00 bg:#FAA'
62 | }
63 |
--------------------------------------------------------------------------------
/pygments/styles/borland.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.borland
3 | ~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Style similar to the style used in the Borland IDEs.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.style import Style
12 | from pygments.token import Keyword, Name, Comment, String, Error, \
13 | Number, Operator, Generic, Whitespace
14 |
15 |
16 | class BorlandStyle(Style):
17 | """
18 | Style similar to the style used in the borland IDEs.
19 | """
20 |
21 | styles = {
22 | Whitespace: '#bbbbbb',
23 |
24 | Comment: 'italic #008800',
25 | Comment.Preproc: 'noitalic #008080',
26 | Comment.Special: 'noitalic bold',
27 |
28 | String: '#0000FF',
29 | String.Char: '#800080',
30 | Number: '#0000FF',
31 | Keyword: 'bold #000080',
32 | Operator.Word: 'bold',
33 | Name.Tag: 'bold #000080',
34 | Name.Attribute: '#FF0000',
35 |
36 | Generic.Heading: '#999999',
37 | Generic.Subheading: '#aaaaaa',
38 | Generic.Deleted: 'bg:#ffdddd #000000',
39 | Generic.Inserted: 'bg:#ddffdd #000000',
40 | Generic.Error: '#aa0000',
41 | Generic.Emph: 'italic',
42 | Generic.Strong: 'bold',
43 | Generic.Prompt: '#555555',
44 | Generic.Output: '#888888',
45 | Generic.Traceback: '#aa0000',
46 |
47 | Error: 'bg:#e3d2d2 #a61717'
48 | }
49 |
--------------------------------------------------------------------------------
/pygments/styles/bw.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.bw
3 | ~~~~~~~~~~~~~~~~~~
4 |
5 | Simple black/white only style.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.style import Style
12 | from pygments.token import Keyword, Name, Comment, String, Error, \
13 | Operator, Generic
14 |
15 |
16 | class BlackWhiteStyle(Style):
17 |
18 | background_color = "#ffffff"
19 |
20 | styles = {
21 | Comment: "italic",
22 | Comment.Preproc: "noitalic",
23 |
24 | Keyword: "bold",
25 | Keyword.Pseudo: "nobold",
26 | Keyword.Type: "nobold",
27 |
28 | Operator.Word: "bold",
29 |
30 | Name.Class: "bold",
31 | Name.Namespace: "bold",
32 | Name.Exception: "bold",
33 | Name.Entity: "bold",
34 | Name.Tag: "bold",
35 |
36 | String: "italic",
37 | String.Interpol: "bold",
38 | String.Escape: "bold",
39 |
40 | Generic.Heading: "bold",
41 | Generic.Subheading: "bold",
42 | Generic.Emph: "italic",
43 | Generic.Strong: "bold",
44 | Generic.Prompt: "bold",
45 |
46 | Error: "border:#FF0000"
47 | }
48 |
--------------------------------------------------------------------------------
/pygments/styles/colorful.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.colorful
3 | ~~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | A colorful style, inspired by CodeRay.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.style import Style
12 | from pygments.token import Keyword, Name, Comment, String, Error, \
13 | Number, Operator, Generic, Whitespace
14 |
15 |
16 | class ColorfulStyle(Style):
17 | """
18 | A colorful style, inspired by CodeRay.
19 | """
20 |
21 | styles = {
22 | Whitespace: "#bbbbbb",
23 |
24 | Comment: "#888",
25 | Comment.Preproc: "#579",
26 | Comment.Special: "bold #cc0000",
27 |
28 | Keyword: "bold #080",
29 | Keyword.Pseudo: "#038",
30 | Keyword.Type: "#339",
31 |
32 | Operator: "#333",
33 | Operator.Word: "bold #000",
34 |
35 | Name.Builtin: "#007020",
36 | Name.Function: "bold #06B",
37 | Name.Class: "bold #B06",
38 | Name.Namespace: "bold #0e84b5",
39 | Name.Exception: "bold #F00",
40 | Name.Variable: "#963",
41 | Name.Variable.Instance: "#33B",
42 | Name.Variable.Class: "#369",
43 | Name.Variable.Global: "bold #d70",
44 | Name.Constant: "bold #036",
45 | Name.Label: "bold #970",
46 | Name.Entity: "bold #800",
47 | Name.Attribute: "#00C",
48 | Name.Tag: "#070",
49 | Name.Decorator: "bold #555",
50 |
51 | String: "bg:#fff0f0",
52 | String.Char: "#04D bg:",
53 | String.Doc: "#D42 bg:",
54 | String.Interpol: "bg:#eee",
55 | String.Escape: "bold #666",
56 | String.Regex: "bg:#fff0ff #000",
57 | String.Symbol: "#A60 bg:",
58 | String.Other: "#D20",
59 |
60 | Number: "bold #60E",
61 | Number.Integer: "bold #00D",
62 | Number.Float: "bold #60E",
63 | Number.Hex: "bold #058",
64 | Number.Oct: "bold #40E",
65 |
66 | Generic.Heading: "bold #000080",
67 | Generic.Subheading: "bold #800080",
68 | Generic.Deleted: "#A00000",
69 | Generic.Inserted: "#00A000",
70 | Generic.Error: "#FF0000",
71 | Generic.Emph: "italic",
72 | Generic.Strong: "bold",
73 | Generic.Prompt: "bold #c65d09",
74 | Generic.Output: "#888",
75 | Generic.Traceback: "#04D",
76 |
77 | Error: "#F00 bg:#FAA"
78 | }
79 |
--------------------------------------------------------------------------------
/pygments/styles/default.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.default
3 | ~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | The default highlighting style.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.style import Style
12 | from pygments.token import Keyword, Name, Comment, String, Error, \
13 | Number, Operator, Generic, Whitespace
14 |
15 |
16 | class DefaultStyle(Style):
17 | """
18 | The default style (inspired by Emacs 22).
19 | """
20 |
21 | background_color = "#f8f8f8"
22 |
23 | styles = {
24 | Whitespace: "#bbbbbb",
25 | Comment: "italic #3D7B7B",
26 | Comment.Preproc: "noitalic #9C6500",
27 |
28 | #Keyword: "bold #AA22FF",
29 | Keyword: "bold #008000",
30 | Keyword.Pseudo: "nobold",
31 | Keyword.Type: "nobold #B00040",
32 |
33 | Operator: "#666666",
34 | Operator.Word: "bold #AA22FF",
35 |
36 | Name.Builtin: "#008000",
37 | Name.Function: "#0000FF",
38 | Name.Class: "bold #0000FF",
39 | Name.Namespace: "bold #0000FF",
40 | Name.Exception: "bold #CB3F38",
41 | Name.Variable: "#19177C",
42 | Name.Constant: "#880000",
43 | Name.Label: "#767600",
44 | Name.Entity: "bold #717171",
45 | Name.Attribute: "#687822",
46 | Name.Tag: "bold #008000",
47 | Name.Decorator: "#AA22FF",
48 |
49 | String: "#BA2121",
50 | String.Doc: "italic",
51 | String.Interpol: "bold #A45A77",
52 | String.Escape: "bold #AA5D1F",
53 | String.Regex: "#A45A77",
54 | #String.Symbol: "#B8860B",
55 | String.Symbol: "#19177C",
56 | String.Other: "#008000",
57 | Number: "#666666",
58 |
59 | Generic.Heading: "bold #000080",
60 | Generic.Subheading: "bold #800080",
61 | Generic.Deleted: "#A00000",
62 | Generic.Inserted: "#008400",
63 | Generic.Error: "#E40000",
64 | Generic.Emph: "italic",
65 | Generic.Strong: "bold",
66 | Generic.Prompt: "bold #000080",
67 | Generic.Output: "#717171",
68 | Generic.Traceback: "#04D",
69 |
70 | Error: "border:#FF0000"
71 | }
72 |
--------------------------------------------------------------------------------
/pygments/styles/emacs.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.emacs
3 | ~~~~~~~~~~~~~~~~~~~~~
4 |
5 | A highlighting style for Pygments, inspired by Emacs.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.style import Style
12 | from pygments.token import Keyword, Name, Comment, String, Error, \
13 | Number, Operator, Generic, Whitespace
14 |
15 |
16 | class EmacsStyle(Style):
17 | """
18 | The default style (inspired by Emacs 22).
19 | """
20 |
21 | background_color = "#f8f8f8"
22 |
23 | styles = {
24 | Whitespace: "#bbbbbb",
25 | Comment: "italic #008800",
26 | Comment.Preproc: "noitalic",
27 | Comment.Special: "noitalic bold",
28 |
29 | Keyword: "bold #AA22FF",
30 | Keyword.Pseudo: "nobold",
31 | Keyword.Type: "bold #00BB00",
32 |
33 | Operator: "#666666",
34 | Operator.Word: "bold #AA22FF",
35 |
36 | Name.Builtin: "#AA22FF",
37 | Name.Function: "#00A000",
38 | Name.Class: "#0000FF",
39 | Name.Namespace: "bold #0000FF",
40 | Name.Exception: "bold #D2413A",
41 | Name.Variable: "#B8860B",
42 | Name.Constant: "#880000",
43 | Name.Label: "#A0A000",
44 | Name.Entity: "bold #999999",
45 | Name.Attribute: "#BB4444",
46 | Name.Tag: "bold #008000",
47 | Name.Decorator: "#AA22FF",
48 |
49 | String: "#BB4444",
50 | String.Doc: "italic",
51 | String.Interpol: "bold #BB6688",
52 | String.Escape: "bold #BB6622",
53 | String.Regex: "#BB6688",
54 | String.Symbol: "#B8860B",
55 | String.Other: "#008000",
56 | Number: "#666666",
57 |
58 | Generic.Heading: "bold #000080",
59 | Generic.Subheading: "bold #800080",
60 | Generic.Deleted: "#A00000",
61 | Generic.Inserted: "#00A000",
62 | Generic.Error: "#FF0000",
63 | Generic.Emph: "italic",
64 | Generic.Strong: "bold",
65 | Generic.Prompt: "bold #000080",
66 | Generic.Output: "#888",
67 | Generic.Traceback: "#04D",
68 |
69 | Error: "border:#FF0000"
70 | }
71 |
--------------------------------------------------------------------------------
/pygments/styles/friendly.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.friendly
3 | ~~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | A modern style based on the VIM pyte theme.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.style import Style
12 | from pygments.token import Keyword, Name, Comment, String, Error, \
13 | Number, Operator, Generic, Whitespace
14 |
15 |
16 | class FriendlyStyle(Style):
17 | """
18 | A modern style based on the VIM pyte theme.
19 | """
20 |
21 | background_color = "#f0f0f0"
22 | line_number_color = "#666666"
23 |
24 | styles = {
25 | Whitespace: "#bbbbbb",
26 | Comment: "italic #60a0b0",
27 | Comment.Preproc: "noitalic #007020",
28 | Comment.Special: "noitalic bg:#fff0f0",
29 |
30 | Keyword: "bold #007020",
31 | Keyword.Pseudo: "nobold",
32 | Keyword.Type: "nobold #902000",
33 |
34 | Operator: "#666666",
35 | Operator.Word: "bold #007020",
36 |
37 | Name.Builtin: "#007020",
38 | Name.Function: "#06287e",
39 | Name.Class: "bold #0e84b5",
40 | Name.Namespace: "bold #0e84b5",
41 | Name.Exception: "#007020",
42 | Name.Variable: "#bb60d5",
43 | Name.Constant: "#60add5",
44 | Name.Label: "bold #002070",
45 | Name.Entity: "bold #d55537",
46 | Name.Attribute: "#4070a0",
47 | Name.Tag: "bold #062873",
48 | Name.Decorator: "bold #555555",
49 |
50 | String: "#4070a0",
51 | String.Doc: "italic",
52 | String.Interpol: "italic #70a0d0",
53 | String.Escape: "bold #4070a0",
54 | String.Regex: "#235388",
55 | String.Symbol: "#517918",
56 | String.Other: "#c65d09",
57 | Number: "#40a070",
58 |
59 | Generic.Heading: "bold #000080",
60 | Generic.Subheading: "bold #800080",
61 | Generic.Deleted: "#A00000",
62 | Generic.Inserted: "#00A000",
63 | Generic.Error: "#FF0000",
64 | Generic.Emph: "italic",
65 | Generic.Strong: "bold",
66 | Generic.Prompt: "bold #c65d09",
67 | Generic.Output: "#888",
68 | Generic.Traceback: "#04D",
69 |
70 | Error: "border:#FF0000"
71 | }
72 |
--------------------------------------------------------------------------------
/pygments/styles/friendly_grayscale.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.friendly_grayscale
3 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | A style based on friendly style.
6 | The color values of the friendly style have been converted to grayscale
7 | using the luminosity value calculated by
8 | http://www.workwithcolor.com/color-converter-01.htm
9 |
10 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
11 | :license: BSD, see LICENSE for details.
12 | """
13 |
14 | from pygments.style import Style
15 | from pygments.token import Keyword, Name, Comment, String, Error, \
16 | Number, Operator, Generic, Whitespace
17 |
18 |
19 | class FriendlyGrayscaleStyle(Style):
20 | """
21 | A modern grayscale style based on the friendly style.
22 |
23 | .. versionadded:: 2.11
24 | """
25 |
26 | background_color = "#f0f0f0"
27 |
28 | styles = {
29 | Whitespace: "#bbbbbb",
30 | Comment: "italic #959595",
31 | Comment.Preproc: "noitalic #575757",
32 | Comment.Special: "noitalic bg:#F4F4F4",
33 |
34 | Keyword: "bold #575757",
35 | Keyword.Pseudo: "nobold",
36 | Keyword.Type: "nobold #4F4F4F",
37 |
38 | Operator: "#666666",
39 | Operator.Word: "bold #575757",
40 |
41 | Name.Builtin: "#575757",
42 | Name.Function: "#3F3F3F",
43 | Name.Class: "bold #7E7E7E",
44 | Name.Namespace: "bold #7E7E7E",
45 | Name.Exception: "#575757",
46 | Name.Variable: "#9A9A9A",
47 | Name.Constant: "#A5A5A5",
48 | Name.Label: "bold #363636",
49 | Name.Entity: "bold #848484",
50 | Name.Attribute: "#707070",
51 | Name.Tag: "bold #3B3B3B",
52 | Name.Decorator: "bold #555555",
53 |
54 | String: "#717171",
55 | String.Doc: "italic",
56 | String.Interpol: "italic #9F9F9F",
57 | String.Escape: "bold #717171",
58 | String.Regex: "#575757",
59 | String.Symbol: "#676767",
60 | String.Other: "#7E7E7E",
61 | Number: "#888888",
62 |
63 | Generic.Heading: "bold #373737",
64 | Generic.Subheading: "bold #5A5A5A",
65 | Generic.Deleted: "#545454",
66 | Generic.Inserted: "#7D7D7D",
67 | Generic.Error: "#898989",
68 | Generic.Emph: "italic",
69 | Generic.Strong: "bold",
70 | Generic.Prompt: "bold #7E7E7E",
71 | Generic.Output: "#888888",
72 | Generic.Traceback: "#6D6D6D",
73 |
74 | Error: "border:#898989"
75 | }
76 |
--------------------------------------------------------------------------------
/pygments/styles/fruity.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.fruity
3 | ~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | pygments version of my "fruity" vim theme.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.style import Style
12 | from pygments.token import Token, Comment, Name, Keyword, \
13 | Generic, Number, String, Whitespace
14 |
15 | class FruityStyle(Style):
16 | """
17 | Pygments version of the "native" vim theme.
18 | """
19 |
20 | background_color = '#111111'
21 | highlight_color = '#333333'
22 |
23 | styles = {
24 | Whitespace: '#888888',
25 | Token: '#ffffff',
26 | Generic.Output: '#444444 bg:#222222',
27 | Keyword: '#fb660a bold',
28 | Keyword.Pseudo: 'nobold',
29 | Number: '#0086f7 bold',
30 | Name.Tag: '#fb660a bold',
31 | Name.Variable: '#fb660a',
32 | Comment: '#008800 bg:#0f140f italic',
33 | Name.Attribute: '#ff0086 bold',
34 | String: '#0086d2',
35 | Name.Function: '#ff0086 bold',
36 | Generic.Heading: '#ffffff bold',
37 | Keyword.Type: '#cdcaa9 bold',
38 | Generic.Subheading: '#ffffff bold',
39 | Name.Constant: '#0086d2',
40 | Comment.Preproc: '#ff0007 bold'
41 | }
42 |
--------------------------------------------------------------------------------
/pygments/styles/igor.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.igor
3 | ~~~~~~~~~~~~~~~~~~~~
4 |
5 | Igor Pro default style.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.style import Style
12 | from pygments.token import Keyword, Name, Comment, String
13 |
14 |
15 | class IgorStyle(Style):
16 | """
17 | Pygments version of the official colors for Igor Pro procedures.
18 | """
19 |
20 | styles = {
21 | Comment: 'italic #FF0000',
22 | Keyword: '#0000FF',
23 | Name.Function: '#C34E00',
24 | Name.Decorator: '#CC00A3',
25 | Name.Class: '#007575',
26 | String: '#009C00'
27 | }
28 |
--------------------------------------------------------------------------------
/pygments/styles/inkpot.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.inkpot
3 | ~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | A highlighting style for Pygments, inspired by the Inkpot theme for VIM.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.style import Style
12 | from pygments.token import Text, Other, Keyword, Name, Comment, String, \
13 | Error, Number, Operator, Generic, Whitespace, Punctuation
14 |
15 |
16 | class InkPotStyle(Style):
17 |
18 | background_color = "#1e1e27"
19 |
20 | styles = {
21 | Text: "#cfbfad",
22 | Other: "#cfbfad",
23 | Whitespace: "#434357",
24 | Comment: "#cd8b00",
25 | Comment.Preproc: "#409090",
26 | Comment.PreprocFile: "bg:#404040 #ffcd8b",
27 | Comment.Special: "#808bed",
28 |
29 | Keyword: "#808bed",
30 | Keyword.Pseudo: "nobold",
31 | Keyword.Type: "#ff8bff",
32 |
33 | Operator: "#666666",
34 |
35 | Punctuation: "#cfbfad",
36 |
37 | Name: "#cfbfad",
38 | Name.Attribute: "#cfbfad",
39 | Name.Builtin.Pseudo: '#ffff00',
40 | Name.Builtin: "#808bed",
41 | Name.Class: "#ff8bff",
42 | Name.Constant: "#409090",
43 | Name.Decorator: "#409090",
44 | Name.Exception: "#ff0000",
45 | Name.Function: "#c080d0",
46 | Name.Label: "#808bed",
47 | Name.Namespace: "#ff0000",
48 | Name.Variable: "#cfbfad",
49 |
50 | String: "bg:#404040 #ffcd8b",
51 | String.Doc: "#808bed",
52 |
53 | Number: "#f0ad6d",
54 |
55 | Generic.Heading: "bold #000080",
56 | Generic.Subheading: "bold #800080",
57 | Generic.Deleted: "#A00000",
58 | Generic.Inserted: "#00A000",
59 | Generic.Error: "#FF0000",
60 | Generic.Emph: "italic",
61 | Generic.Strong: "bold",
62 | Generic.Prompt: "bold #000080",
63 | Generic.Output: "#888",
64 | Generic.Traceback: "#04D",
65 |
66 | Error: "bg:#6e2e2e #ffffff"
67 | }
68 |
--------------------------------------------------------------------------------
/pygments/styles/lilypond.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.lilypond
3 | ~~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | LilyPond-specific style.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.style import Style
12 | from pygments.token import Token
13 |
14 | class LilyPondStyle(Style):
15 | """
16 | Style for the LilyPond language.
17 |
18 | .. versionadded:: 2.11
19 | """
20 |
21 | # Don't show it in the gallery, it's intended for LilyPond
22 | # input only and doesn't show good output on Python code.
23 | web_style_gallery_exclude = True
24 |
25 | styles = {
26 | Token.Text: "",
27 | Token.Keyword: "bold",
28 | Token.Comment: "italic #A3AAB2",
29 | Token.String: "#AB0909",
30 | Token.String.Escape: "#C46C6C",
31 | Token.String.Symbol: "noinherit",
32 | Token.Pitch: "", #"#911520",
33 | Token.Number: "#976806", # includes durations
34 | # A bare 11 is not distinguishable from a number, so we highlight
35 | # the same.
36 | Token.ChordModifier: "#976806",
37 | Token.Name.Lvalue: "#08547A",
38 | Token.Name.BackslashReference: "#08547A",
39 | Token.Name.Builtin.MusicCommand: "bold #08547A",
40 | Token.Name.Builtin.PaperVariable: "bold #6C5A05",
41 | Token.Name.Builtin.HeaderVariable: "bold #6C5A05",
42 | Token.Name.Builtin.MusicFunction: "bold #08547A",
43 | Token.Name.Builtin.Clef: "bold #08547A",
44 | Token.Name.Builtin.Scale: "bold #08547A",
45 | Token.Name.Builtin.RepeatType: "#08547A",
46 | Token.Name.Builtin.Dynamic: "#68175A",
47 | Token.Name.Builtin.Articulation: "#68175A",
48 | Token.Name.Builtin.SchemeFunction: "bold #A83401",
49 | Token.Name.Builtin.SchemeBuiltin: "bold",
50 | Token.Name.Builtin.MarkupCommand: "bold #831E71",
51 | Token.Name.Builtin.Context: "bold #038B8B",
52 | Token.Name.Builtin.ContextProperty: "#038B8B",
53 | Token.Name.Builtin.Grob: "bold #0C7441",
54 | Token.Name.Builtin.GrobProperty: "#0C7441",
55 | Token.Name.Builtin.Translator: "bold #6200A4",
56 | }
57 |
--------------------------------------------------------------------------------
/pygments/styles/manni.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.manni
3 | ~~~~~~~~~~~~~~~~~~~~~
4 |
5 | A colorful style, inspired by the terminal highlighting style.
6 |
7 | This is a port of the style used in the `php port`_ of pygments
8 | by Manni. The style is called 'default' there.
9 |
10 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
11 | :license: BSD, see LICENSE for details.
12 | """
13 |
14 | from pygments.style import Style
15 | from pygments.token import Keyword, Name, Comment, String, Error, \
16 | Number, Operator, Generic, Whitespace
17 |
18 |
19 | class ManniStyle(Style):
20 | """
21 | A colorful style, inspired by the terminal highlighting style.
22 | """
23 |
24 | background_color = '#f0f3f3'
25 |
26 | styles = {
27 | Whitespace: '#bbbbbb',
28 | Comment: 'italic #0099FF',
29 | Comment.Preproc: 'noitalic #009999',
30 | Comment.Special: 'bold',
31 |
32 | Keyword: 'bold #006699',
33 | Keyword.Pseudo: 'nobold',
34 | Keyword.Type: '#007788',
35 |
36 | Operator: '#555555',
37 | Operator.Word: 'bold #000000',
38 |
39 | Name.Builtin: '#336666',
40 | Name.Function: '#CC00FF',
41 | Name.Class: 'bold #00AA88',
42 | Name.Namespace: 'bold #00CCFF',
43 | Name.Exception: 'bold #CC0000',
44 | Name.Variable: '#003333',
45 | Name.Constant: '#336600',
46 | Name.Label: '#9999FF',
47 | Name.Entity: 'bold #999999',
48 | Name.Attribute: '#330099',
49 | Name.Tag: 'bold #330099',
50 | Name.Decorator: '#9999FF',
51 |
52 | String: '#CC3300',
53 | String.Doc: 'italic',
54 | String.Interpol: '#AA0000',
55 | String.Escape: 'bold #CC3300',
56 | String.Regex: '#33AAAA',
57 | String.Symbol: '#FFCC33',
58 | String.Other: '#CC3300',
59 |
60 | Number: '#FF6600',
61 |
62 | Generic.Heading: 'bold #003300',
63 | Generic.Subheading: 'bold #003300',
64 | Generic.Deleted: 'border:#CC0000 bg:#FFCCCC',
65 | Generic.Inserted: 'border:#00CC00 bg:#CCFFCC',
66 | Generic.Error: '#FF0000',
67 | Generic.Emph: 'italic',
68 | Generic.Strong: 'bold',
69 | Generic.Prompt: 'bold #000099',
70 | Generic.Output: '#AAAAAA',
71 | Generic.Traceback: '#99CC66',
72 |
73 | Error: 'bg:#FFAAAA #AA0000'
74 | }
75 |
--------------------------------------------------------------------------------
/pygments/styles/murphy.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.murphy
3 | ~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Murphy's style from CodeRay.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.style import Style
12 | from pygments.token import Keyword, Name, Comment, String, Error, \
13 | Number, Operator, Generic, Whitespace
14 |
15 |
16 | class MurphyStyle(Style):
17 | """
18 | Murphy's style from CodeRay.
19 | """
20 |
21 | styles = {
22 | Whitespace: "#bbbbbb",
23 | Comment: "#666 italic",
24 | Comment.Preproc: "#579 noitalic",
25 | Comment.Special: "#c00 bold",
26 |
27 | Keyword: "bold #289",
28 | Keyword.Pseudo: "#08f",
29 | Keyword.Type: "#66f",
30 |
31 | Operator: "#333",
32 | Operator.Word: "bold #000",
33 |
34 | Name.Builtin: "#072",
35 | Name.Function: "bold #5ed",
36 | Name.Class: "bold #e9e",
37 | Name.Namespace: "bold #0e84b5",
38 | Name.Exception: "bold #F00",
39 | Name.Variable: "#036",
40 | Name.Variable.Instance: "#aaf",
41 | Name.Variable.Class: "#ccf",
42 | Name.Variable.Global: "#f84",
43 | Name.Constant: "bold #5ed",
44 | Name.Label: "bold #970",
45 | Name.Entity: "#800",
46 | Name.Attribute: "#007",
47 | Name.Tag: "#070",
48 | Name.Decorator: "bold #555",
49 |
50 | String: "bg:#e0e0ff",
51 | String.Char: "#88F bg:",
52 | String.Doc: "#D42 bg:",
53 | String.Interpol: "bg:#eee",
54 | String.Escape: "bold #666",
55 | String.Regex: "bg:#e0e0ff #000",
56 | String.Symbol: "#fc8 bg:",
57 | String.Other: "#f88",
58 |
59 | Number: "bold #60E",
60 | Number.Integer: "bold #66f",
61 | Number.Float: "bold #60E",
62 | Number.Hex: "bold #058",
63 | Number.Oct: "bold #40E",
64 |
65 | Generic.Heading: "bold #000080",
66 | Generic.Subheading: "bold #800080",
67 | Generic.Deleted: "#A00000",
68 | Generic.Inserted: "#00A000",
69 | Generic.Error: "#FF0000",
70 | Generic.Emph: "italic",
71 | Generic.Strong: "bold",
72 | Generic.Prompt: "bold #c65d09",
73 | Generic.Output: "#888",
74 | Generic.Traceback: "#04D",
75 |
76 | Error: "#F00 bg:#FAA"
77 | }
78 |
--------------------------------------------------------------------------------
/pygments/styles/native.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.native
3 | ~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | pygments version of my "native" vim theme.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.style import Style
12 | from pygments.token import Keyword, Name, Comment, String, Error, \
13 | Number, Operator, Generic, Token, Whitespace
14 |
15 |
16 | class NativeStyle(Style):
17 | """
18 | Pygments version of the "native" vim theme.
19 | """
20 |
21 | background_color = '#202020'
22 | highlight_color = '#404040'
23 | line_number_color = '#aaaaaa'
24 |
25 | styles = {
26 | Token: '#d0d0d0',
27 | Whitespace: '#666666',
28 |
29 | Comment: 'italic #ababab',
30 | Comment.Preproc: 'noitalic bold #cd2828',
31 | Comment.Special: 'noitalic bold #e50808 bg:#520000',
32 |
33 | Keyword: 'bold #6ebf26',
34 | Keyword.Pseudo: 'nobold',
35 | Operator.Word: 'bold #6ebf26',
36 |
37 | String: '#ed9d13',
38 | String.Other: '#ffa500',
39 |
40 | Number: '#51b2fd',
41 |
42 | Name.Builtin: '#2fbccd',
43 | Name.Variable: '#40ffff',
44 | Name.Constant: '#40ffff',
45 | Name.Class: 'underline #71adff',
46 | Name.Function: '#71adff',
47 | Name.Namespace: 'underline #71adff',
48 | Name.Exception: '#bbbbbb',
49 | Name.Tag: 'bold #6ebf26',
50 | Name.Attribute: '#bbbbbb',
51 | Name.Decorator: '#ffa500',
52 |
53 | Generic.Heading: 'bold #ffffff',
54 | Generic.Subheading: 'underline #ffffff',
55 | Generic.Deleted: '#d22323',
56 | Generic.Inserted: '#589819',
57 | Generic.Error: '#d22323',
58 | Generic.Emph: 'italic',
59 | Generic.Strong: 'bold',
60 | Generic.Prompt: '#aaaaaa',
61 | Generic.Output: '#cccccc',
62 | Generic.Traceback: '#d22323',
63 |
64 | Error: 'bg:#e3d2d2 #a61717'
65 | }
66 |
--------------------------------------------------------------------------------
/pygments/styles/onedark.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.onedark
3 | ~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | One Dark Theme for Pygments by Tobias Zoghaib (https://github.com/TobiZog)
6 |
7 | Inspired by one-dark-ui for the code editor Atom
8 | (https://atom.io/themes/one-dark-ui).
9 |
10 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
11 | :license: BSD, see LICENSE for details.
12 | """
13 |
14 | from pygments.style import Style
15 | from pygments.token import (Comment, Generic, Keyword, Name, Number, Operator,
16 | Punctuation, String, Token, Whitespace)
17 |
18 |
19 | class OneDarkStyle(Style):
20 | """
21 | Theme inspired by One Dark Pro for Atom
22 |
23 | .. versionadded:: 2.11
24 | """
25 |
26 | background_color = '#282C34'
27 |
28 | styles = {
29 | Token: '#ABB2BF',
30 |
31 | Punctuation: '#ABB2BF',
32 | Punctuation.Marker: '#ABB2BF',
33 |
34 | Keyword: '#C678DD',
35 | Keyword.Constant: '#E5C07B',
36 | Keyword.Declaration: '#C678DD',
37 | Keyword.Namespace: '#C678DD',
38 | Keyword.Reserved: '#C678DD',
39 | Keyword.Type: '#E5C07B',
40 |
41 | Name: '#E06C75',
42 | Name.Attribute: '#E06C75',
43 | Name.Builtin: '#E5C07B',
44 | Name.Class: '#E5C07B',
45 | Name.Function: 'bold #61AFEF',
46 | Name.Function.Magic: 'bold #56B6C2',
47 | Name.Other: '#E06C75',
48 | Name.Tag: '#E06C75',
49 | Name.Decorator: '#61AFEF',
50 | Name.Variable.Class: '',
51 |
52 | String: '#98C379',
53 |
54 | Number: '#D19A66',
55 |
56 | Operator: '#56B6C2',
57 |
58 | Comment: '#7F848E'
59 | }
60 |
--------------------------------------------------------------------------------
/pygments/styles/pastie.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.pastie
3 | ~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Style similar to the `pastie`_ default style.
6 |
7 | .. _pastie: http://pastie.caboo.se/
8 |
9 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
10 | :license: BSD, see LICENSE for details.
11 | """
12 |
13 | from pygments.style import Style
14 | from pygments.token import Keyword, Name, Comment, String, Error, \
15 | Number, Operator, Generic, Whitespace
16 |
17 |
18 | class PastieStyle(Style):
19 | """
20 | Style similar to the pastie default style.
21 | """
22 |
23 | styles = {
24 | Whitespace: '#bbbbbb',
25 | Comment: '#888888',
26 | Comment.Preproc: 'bold #cc0000',
27 | Comment.Special: 'bg:#fff0f0 bold #cc0000',
28 |
29 | String: 'bg:#fff0f0 #dd2200',
30 | String.Regex: 'bg:#fff0ff #008800',
31 | String.Other: 'bg:#f0fff0 #22bb22',
32 | String.Symbol: '#aa6600',
33 | String.Interpol: '#3333bb',
34 | String.Escape: '#0044dd',
35 |
36 | Operator.Word: '#008800',
37 |
38 | Keyword: 'bold #008800',
39 | Keyword.Pseudo: 'nobold',
40 | Keyword.Type: '#888888',
41 |
42 | Name.Class: 'bold #bb0066',
43 | Name.Exception: 'bold #bb0066',
44 | Name.Function: 'bold #0066bb',
45 | Name.Property: 'bold #336699',
46 | Name.Namespace: 'bold #bb0066',
47 | Name.Builtin: '#003388',
48 | Name.Variable: '#336699',
49 | Name.Variable.Class: '#336699',
50 | Name.Variable.Instance: '#3333bb',
51 | Name.Variable.Global: '#dd7700',
52 | Name.Constant: 'bold #003366',
53 | Name.Tag: 'bold #bb0066',
54 | Name.Attribute: '#336699',
55 | Name.Decorator: '#555555',
56 | Name.Label: 'italic #336699',
57 |
58 | Number: 'bold #0000DD',
59 |
60 | Generic.Heading: '#333',
61 | Generic.Subheading: '#666',
62 | Generic.Deleted: 'bg:#ffdddd #000000',
63 | Generic.Inserted: 'bg:#ddffdd #000000',
64 | Generic.Error: '#aa0000',
65 | Generic.Emph: 'italic',
66 | Generic.Strong: 'bold',
67 | Generic.Prompt: '#555555',
68 | Generic.Output: '#888888',
69 | Generic.Traceback: '#aa0000',
70 |
71 | Error: 'bg:#e3d2d2 #a61717'
72 | }
73 |
--------------------------------------------------------------------------------
/pygments/styles/perldoc.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.perldoc
3 | ~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Style similar to the style used in the `perldoc`_ code blocks.
6 |
7 | .. _perldoc: http://perldoc.perl.org/
8 |
9 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
10 | :license: BSD, see LICENSE for details.
11 | """
12 |
13 | from pygments.style import Style
14 | from pygments.token import Keyword, Name, Comment, String, Error, \
15 | Number, Operator, Generic, Whitespace
16 |
17 |
18 | class PerldocStyle(Style):
19 | """
20 | Style similar to the style used in the perldoc code blocks.
21 | """
22 |
23 | background_color = '#eeeedd'
24 |
25 | styles = {
26 | Whitespace: '#bbbbbb',
27 | Comment: '#228B22',
28 | Comment.Preproc: '#1e889b',
29 | Comment.Special: '#8B008B bold',
30 |
31 | String: '#CD5555',
32 | String.Heredoc: '#1c7e71 italic',
33 | String.Regex: '#B452CD',
34 | String.Other: '#cb6c20',
35 | String.Regex: '#1c7e71',
36 |
37 | Number: '#B452CD',
38 |
39 | Operator.Word: '#8B008B',
40 |
41 | Keyword: '#8B008B bold',
42 | Keyword.Type: '#00688B',
43 |
44 | Name.Class: '#008b45 bold',
45 | Name.Exception: '#008b45 bold',
46 | Name.Function: '#008b45',
47 | Name.Namespace: '#008b45 underline',
48 | Name.Variable: '#00688B',
49 | Name.Constant: '#00688B',
50 | Name.Decorator: '#707a7c',
51 | Name.Tag: '#8B008B bold',
52 | Name.Attribute: '#658b00',
53 | Name.Builtin: '#658b00',
54 |
55 | Generic.Heading: 'bold #000080',
56 | Generic.Subheading: 'bold #800080',
57 | Generic.Deleted: '#aa0000',
58 | Generic.Inserted: '#00aa00',
59 | Generic.Error: '#aa0000',
60 | Generic.Emph: 'italic',
61 | Generic.Strong: 'bold',
62 | Generic.Prompt: '#555555',
63 | Generic.Output: '#888888',
64 | Generic.Traceback: '#aa0000',
65 |
66 | Error: 'bg:#e3d2d2 #a61717'
67 | }
68 |
--------------------------------------------------------------------------------
/pygments/styles/rainbow_dash.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.rainbow_dash
3 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | A bright and colorful syntax highlighting `theme`.
6 |
7 | .. _theme: http://sanssecours.github.io/Rainbow-Dash.tmbundle
8 |
9 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
10 | :license: BSD, see LICENSE for details.
11 | """
12 |
13 | from pygments.style import Style
14 | from pygments.token import (Comment, Error, Generic, Name, Number, Operator,
15 | String, Text, Whitespace, Keyword)
16 |
17 | BLUE_LIGHT = '#0080ff'
18 | BLUE = '#2c5dcd'
19 | GREEN = '#00cc66'
20 | GREEN_LIGHT = '#ccffcc'
21 | GREEN_NEON = '#00cc00'
22 | GREY = '#aaaaaa'
23 | GREY_LIGHT = '#cbcbcb'
24 | GREY_DARK = '#4d4d4d'
25 | PURPLE = '#5918bb'
26 | RED = '#cc0000'
27 | RED_DARK = '#c5060b'
28 | RED_LIGHT = '#ffcccc'
29 | RED_BRIGHT = '#ff0000'
30 | WHITE = '#ffffff'
31 | TURQUOISE = '#318495'
32 | ORANGE = '#ff8000'
33 |
34 |
35 | class RainbowDashStyle(Style):
36 | """
37 | A bright and colorful syntax highlighting theme.
38 | """
39 |
40 | background_color = WHITE
41 |
42 | styles = {
43 | Comment: 'italic {}'.format(BLUE_LIGHT),
44 | Comment.Preproc: 'noitalic',
45 | Comment.Special: 'bold',
46 |
47 | Error: 'bg:{} {}'.format(RED, WHITE),
48 |
49 | Generic.Deleted: 'border:{} bg:{}'.format(RED_DARK, RED_LIGHT),
50 | Generic.Emph: 'italic',
51 | Generic.Error: RED_BRIGHT,
52 | Generic.Heading: 'bold {}'.format(BLUE),
53 | Generic.Inserted: 'border:{} bg:{}'.format(GREEN_NEON, GREEN_LIGHT),
54 | Generic.Output: GREY,
55 | Generic.Prompt: 'bold {}'.format(BLUE),
56 | Generic.Strong: 'bold',
57 | Generic.Subheading: 'bold {}'.format(BLUE),
58 | Generic.Traceback: RED_DARK,
59 |
60 | Keyword: 'bold {}'.format(BLUE),
61 | Keyword.Pseudo: 'nobold',
62 | Keyword.Type: PURPLE,
63 |
64 | Name.Attribute: 'italic {}'.format(BLUE),
65 | Name.Builtin: 'bold {}'.format(PURPLE),
66 | Name.Class: 'underline',
67 | Name.Constant: TURQUOISE,
68 | Name.Decorator: 'bold {}'.format(ORANGE),
69 | Name.Entity: 'bold {}'.format(PURPLE),
70 | Name.Exception: 'bold {}'.format(PURPLE),
71 | Name.Function: 'bold {}'.format(ORANGE),
72 | Name.Tag: 'bold {}'.format(BLUE),
73 |
74 | Number: 'bold {}'.format(PURPLE),
75 |
76 | Operator: BLUE,
77 | Operator.Word: 'bold',
78 |
79 | String: GREEN,
80 | String.Doc: 'italic',
81 | String.Escape: 'bold {}'.format(RED_DARK),
82 | String.Other: TURQUOISE,
83 | String.Symbol: 'bold {}'.format(RED_DARK),
84 |
85 | Text: GREY_DARK,
86 |
87 | Whitespace: GREY_LIGHT
88 | }
89 |
--------------------------------------------------------------------------------
/pygments/styles/rrt.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.rrt
3 | ~~~~~~~~~~~~~~~~~~~
4 |
5 | pygments "rrt" theme, based on Zap and Emacs defaults.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.style import Style
12 | from pygments.token import Token, Comment, Name, Keyword, String
13 |
14 |
15 | class RrtStyle(Style):
16 | """
17 | Minimalistic "rrt" theme, based on Zap and Emacs defaults.
18 | """
19 |
20 | background_color = '#000000'
21 | highlight_color = '#0000ff'
22 |
23 | styles = {
24 | Token: '#dddddd',
25 | Comment: '#00ff00',
26 | Name.Function: '#ffff00',
27 | Name.Variable: '#eedd82',
28 | Name.Constant: '#7fffd4',
29 | Keyword: '#ff0000',
30 | Comment.Preproc: '#e5e5e5',
31 | String: '#87ceeb',
32 | Keyword.Type: '#ee82ee',
33 | }
34 |
--------------------------------------------------------------------------------
/pygments/styles/sas.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.sas
3 | ~~~~~~~~~~~~~~~~~~~
4 |
5 | Style inspired by SAS' enhanced program editor. Note This is not
6 | meant to be a complete style. It's merely meant to mimic SAS'
7 | program editor syntax highlighting.
8 |
9 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
10 | :license: BSD, see LICENSE for details.
11 | """
12 |
13 | from pygments.style import Style
14 | from pygments.token import Keyword, Name, Comment, String, Error, \
15 | Number, Other, Whitespace, Generic
16 |
17 |
18 | class SasStyle(Style):
19 | """
20 | Style inspired by SAS' enhanced program editor. Note This is not
21 | meant to be a complete style. It's merely meant to mimic SAS'
22 | program editor syntax highlighting.
23 | """
24 |
25 | styles = {
26 | Whitespace: '#bbbbbb',
27 | Comment: 'italic #008800',
28 | String: '#800080',
29 | Number: 'bold #2c8553',
30 | Other: 'bg:#ffffe0',
31 | Keyword: '#2c2cff',
32 | Keyword.Reserved: 'bold #353580',
33 | Keyword.Constant: 'bold',
34 | Name.Builtin: '#2c2cff',
35 | Name.Function: 'bold italic',
36 | Name.Variable: 'bold #2c2cff',
37 | Generic: '#2c2cff',
38 | Generic.Emph: '#008800',
39 | Generic.Error: '#d30202',
40 | Error: 'bg:#e3d2d2 #a61717'
41 | }
42 |
--------------------------------------------------------------------------------
/pygments/styles/staroffice.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.staroffice
3 | ~~~~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Style similar to StarOffice style, also in OpenOffice and LibreOffice.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.style import Style
12 | from pygments.token import Comment, Error, Literal, Name, Token
13 |
14 |
15 | class StarofficeStyle(Style):
16 | """
17 | Style similar to StarOffice style, also in OpenOffice and LibreOffice.
18 | """
19 |
20 | styles = {
21 | Token: '#000080', # Blue
22 | Comment: '#696969', # DimGray
23 | Error: '#800000', # Maroon
24 | Literal: '#EE0000', # Red
25 | Name: '#008000', # Green
26 | }
27 |
--------------------------------------------------------------------------------
/pygments/styles/stata_dark.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.stata_dark
3 | ~~~~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Dark style inspired by Stata's do-file editor. Note this is not
6 | meant to be a complete style, just for Stata's file formats.
7 |
8 |
9 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
10 | :license: BSD, see LICENSE for details.
11 | """
12 |
13 | from pygments.style import Style
14 | from pygments.token import Token, Keyword, Name, Comment, String, Error, \
15 | Number, Operator, Whitespace, Generic
16 |
17 |
18 | class StataDarkStyle(Style):
19 |
20 | background_color = "#232629"
21 | highlight_color = "#49483e"
22 |
23 | styles = {
24 | Token: '#cccccc',
25 | Whitespace: '#bbbbbb',
26 | Error: 'bg:#e3d2d2 #a61717',
27 | String: '#51cc99',
28 | Number: '#4FB8CC',
29 | Operator: '',
30 | Name.Function: '#6a6aff',
31 | Name.Other: '#e2828e',
32 | Keyword: 'bold #7686bb',
33 | Keyword.Constant: '',
34 | Comment: 'italic #777777',
35 | Name.Variable: 'bold #7AB4DB',
36 | Name.Variable.Global: 'bold #BE646C',
37 | Generic.Prompt: '#ffffff',
38 | }
39 |
--------------------------------------------------------------------------------
/pygments/styles/stata_light.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.stata_light
3 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Light Style inspired by Stata's do-file editor. Note this is not
6 | meant to be a complete style, just for Stata's file formats.
7 |
8 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
9 | :license: BSD, see LICENSE for details.
10 | """
11 |
12 | from pygments.style import Style
13 | from pygments.token import Keyword, Name, Comment, String, Error, \
14 | Number, Operator, Whitespace, Text
15 |
16 |
17 | class StataLightStyle(Style):
18 | """
19 | Light mode style inspired by Stata's do-file editor. This is not
20 | meant to be a complete style, just for use with Stata.
21 | """
22 |
23 | styles = {
24 | Text: '#111111',
25 | Whitespace: '#bbbbbb',
26 | Error: 'bg:#e3d2d2 #a61717',
27 | String: '#7a2424',
28 | Number: '#2c2cff',
29 | Operator: '',
30 | Name.Function: '#2c2cff',
31 | Name.Other: '#be646c',
32 | Keyword: 'bold #353580',
33 | Keyword.Constant: '',
34 | Comment: 'italic #008800',
35 | Name.Variable: 'bold #35baba',
36 | Name.Variable.Global: 'bold #b5565e',
37 | }
38 |
--------------------------------------------------------------------------------
/pygments/styles/trac.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.trac
3 | ~~~~~~~~~~~~~~~~~~~~
4 |
5 | Port of the default trac highlighter design.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.style import Style
12 | from pygments.token import Keyword, Name, Comment, String, Error, \
13 | Number, Operator, Generic, Whitespace
14 |
15 |
16 | class TracStyle(Style):
17 | """
18 | Port of the default trac highlighter design.
19 | """
20 |
21 | styles = {
22 | Whitespace: '#bbbbbb',
23 | Comment: 'italic #999988',
24 | Comment.Preproc: 'bold noitalic #999999',
25 | Comment.Special: 'bold #999999',
26 |
27 | Operator: 'bold',
28 |
29 | String: '#bb8844',
30 | String.Regex: '#808000',
31 |
32 | Number: '#009999',
33 |
34 | Keyword: 'bold',
35 | Keyword.Type: '#445588',
36 |
37 | Name.Builtin: '#999999',
38 | Name.Function: 'bold #990000',
39 | Name.Class: 'bold #445588',
40 | Name.Exception: 'bold #990000',
41 | Name.Namespace: '#555555',
42 | Name.Variable: '#008080',
43 | Name.Constant: '#008080',
44 | Name.Tag: '#000080',
45 | Name.Attribute: '#008080',
46 | Name.Entity: '#800080',
47 |
48 | Generic.Heading: '#999999',
49 | Generic.Subheading: '#aaaaaa',
50 | Generic.Deleted: 'bg:#ffdddd #000000',
51 | Generic.Inserted: 'bg:#ddffdd #000000',
52 | Generic.Error: '#aa0000',
53 | Generic.Emph: 'italic',
54 | Generic.Strong: 'bold',
55 | Generic.Prompt: '#555555',
56 | Generic.Output: '#888888',
57 | Generic.Traceback: '#aa0000',
58 |
59 | Error: 'bg:#e3d2d2 #a61717'
60 | }
61 |
--------------------------------------------------------------------------------
/pygments/styles/vim.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.vim
3 | ~~~~~~~~~~~~~~~~~~~
4 |
5 | A highlighting style for Pygments, inspired by vim.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.style import Style
12 | from pygments.token import Keyword, Name, Comment, String, Error, \
13 | Number, Operator, Generic, Whitespace, Token
14 |
15 |
16 | class VimStyle(Style):
17 | """
18 | Styles somewhat like vim 7.0
19 | """
20 |
21 | background_color = "#000000"
22 | highlight_color = "#222222"
23 |
24 | styles = {
25 | Token: "#cccccc",
26 | Whitespace: "",
27 | Comment: "#000080",
28 | Comment.Preproc: "",
29 | Comment.Special: "bold #cd0000",
30 |
31 | Keyword: "#cdcd00",
32 | Keyword.Declaration: "#00cd00",
33 | Keyword.Namespace: "#cd00cd",
34 | Keyword.Pseudo: "",
35 | Keyword.Type: "#00cd00",
36 |
37 | Operator: "#3399cc",
38 | Operator.Word: "#cdcd00",
39 |
40 | Name: "",
41 | Name.Class: "#00cdcd",
42 | Name.Builtin: "#cd00cd",
43 | Name.Exception: "bold #666699",
44 | Name.Variable: "#00cdcd",
45 |
46 | String: "#cd0000",
47 | Number: "#cd00cd",
48 |
49 | Generic.Heading: "bold #000080",
50 | Generic.Subheading: "bold #800080",
51 | Generic.Deleted: "#cd0000",
52 | Generic.Inserted: "#00cd00",
53 | Generic.Error: "#FF0000",
54 | Generic.Emph: "italic",
55 | Generic.Strong: "bold",
56 | Generic.Prompt: "bold #000080",
57 | Generic.Output: "#888",
58 | Generic.Traceback: "#04D",
59 |
60 | Error: "border:#FF0000"
61 | }
62 |
--------------------------------------------------------------------------------
/pygments/styles/vs.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.vs
3 | ~~~~~~~~~~~~~~~~~~
4 |
5 | Simple style with MS Visual Studio colors.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.style import Style
12 | from pygments.token import Keyword, Name, Comment, String, Error, \
13 | Operator, Generic
14 |
15 |
16 | class VisualStudioStyle(Style):
17 |
18 | background_color = "#ffffff"
19 |
20 | styles = {
21 | Comment: "#008000",
22 | Comment.Preproc: "#0000ff",
23 | Keyword: "#0000ff",
24 | Operator.Word: "#0000ff",
25 | Keyword.Type: "#2b91af",
26 | Name.Class: "#2b91af",
27 | String: "#a31515",
28 |
29 | Generic.Heading: "bold",
30 | Generic.Subheading: "bold",
31 | Generic.Emph: "italic",
32 | Generic.Strong: "bold",
33 | Generic.Prompt: "bold",
34 |
35 | Error: "border:#FF0000"
36 | }
37 |
--------------------------------------------------------------------------------
/pygments/styles/xcode.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.xcode
3 | ~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Style similar to the `Xcode` default theme.
6 |
7 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 | :license: BSD, see LICENSE for details.
9 | """
10 |
11 | from pygments.style import Style
12 | from pygments.token import Keyword, Name, Comment, String, Error, \
13 | Number, Operator, Literal
14 |
15 |
16 | class XcodeStyle(Style):
17 | """
18 | Style similar to the Xcode default colouring theme.
19 | """
20 |
21 | styles = {
22 | Comment: '#177500',
23 | Comment.Preproc: '#633820',
24 |
25 | String: '#C41A16',
26 | String.Char: '#2300CE',
27 |
28 | Operator: '#000000',
29 |
30 | Keyword: '#A90D91',
31 |
32 | Name: '#000000',
33 | Name.Attribute: '#836C28',
34 | Name.Class: '#3F6E75',
35 | Name.Function: '#000000',
36 | Name.Builtin: '#A90D91',
37 | # In Obj-C code this token is used to colour Cocoa types
38 | Name.Builtin.Pseudo: '#5B269A',
39 | Name.Variable: '#000000',
40 | Name.Tag: '#000000',
41 | Name.Decorator: '#000000',
42 | # Workaround for a BUG here: lexer treats multiline method signatres as labels
43 | Name.Label: '#000000',
44 |
45 | Literal: '#1C01CE',
46 | Number: '#1C01CE',
47 | Error: '#000000',
48 | }
49 |
--------------------------------------------------------------------------------
/pygments/styles/zenburn.py:
--------------------------------------------------------------------------------
1 | """
2 | pygments.styles.zenburn
3 | ~~~~~~~~~~~~~~~~~~~~~~~
4 |
5 | Low contrast color scheme Zenburn.
6 |
7 | See: https://kippura.org/zenburnpage/
8 | https://github.com/jnurmine/Zenburn
9 |
10 | :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
11 | :license: BSD, see LICENSE for details.
12 | """
13 |
14 | from pygments.style import Style
15 | from pygments.token import (
16 | Token, Name, Operator, Keyword, Generic, Comment, Number, String, Literal,
17 | Punctuation, Error,
18 | )
19 |
20 |
21 | class ZenburnStyle(Style):
22 | """
23 | Low contrast Zenburn style.
24 | """
25 |
26 | background_color = '#3f3f3f'
27 | highlight_color = '#484848'
28 | line_number_color = '#5d6262'
29 | line_number_background_color = '#353535'
30 | line_number_special_color = '#7a8080'
31 | line_number_special_background_color = '#353535'
32 |
33 | styles = {
34 | Token: '#dcdccc',
35 | Error: '#e37170 bold',
36 |
37 | Keyword: '#efdcbc',
38 | Keyword.Type: '#dfdfbf bold',
39 | Keyword.Constant: '#dca3a3',
40 | Keyword.Declaration: '#f0dfaf',
41 | Keyword.Namespace: '#f0dfaf',
42 |
43 | Name: '#dcdccc',
44 | Name.Tag: '#e89393 bold',
45 | Name.Entity: '#cfbfaf',
46 | Name.Constant: '#dca3a3',
47 | Name.Class: '#efef8f',
48 | Name.Function: '#efef8f',
49 | Name.Builtin: '#efef8f',
50 | Name.Builtin.Pseudo: '#dcdccc',
51 | Name.Attribute: '#efef8f',
52 | Name.Exception: '#c3bf9f bold',
53 |
54 | Literal: '#9fafaf',
55 |
56 | String: '#cc9393',
57 | String.Doc: '#7f9f7f',
58 | String.Interpol: '#dca3a3 bold',
59 |
60 | Number: '#8cd0d3',
61 | Number.Float: '#c0bed1',
62 |
63 | Operator: '#f0efd0',
64 |
65 | Punctuation: '#f0efd0',
66 |
67 | Comment: '#7f9f7f italic',
68 | Comment.Preproc: '#dfaf8f bold',
69 | Comment.PreprocFile: '#cc9393',
70 | Comment.Special: '#dfdfdf bold',
71 |
72 | Generic: '#ecbcbc bold',
73 | Generic.Emph: '#ffffff bold',
74 | Generic.Output: '#5b605e bold',
75 | Generic.Heading: '#efefef bold',
76 | Generic.Deleted: '#c3bf9f bg:#313c36',
77 | Generic.Inserted: '#709080 bg:#313c36 bold',
78 | Generic.Traceback: '#80d4aa bg:#2f2f2f bold',
79 | Generic.Subheading: '#efefef bold',
80 | }
81 |
--------------------------------------------------------------------------------
/tester/check_indices.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python3
2 |
3 | import sys
4 | import time
5 | import sqlite3
6 |
7 | from diaphora_heuristics import HEURISTICS
8 |
9 | #-------------------------------------------------------------------------------
10 | def log(msg):
11 | print("[%s] %s" % (time.asctime(), msg))
12 |
13 | #-------------------------------------------------------------------------------
14 | class CIndicesChecker:
15 | def __init__(self):
16 | self.db = None
17 | self.indices = []
18 |
19 | def __del__(self):
20 | if self.db is not None:
21 | self.db.close()
22 |
23 | def sqlite3_connect(self, db_name):
24 | self.db = sqlite3.connect(db_name, check_same_thread=False)
25 | self.db.text_factory = str
26 | self.db.row_factory = sqlite3.Row
27 |
28 | def connect(self, db1, db2):
29 | self.sqlite3_connect(db1)
30 | cur = self.db.cursor()
31 | try:
32 | cur.execute('attach "%s" as diff' % db2)
33 | finally:
34 | cur.close()
35 |
36 | def check_one(self, name, sql):
37 | log("Checking index for heuristic '%s'" % name)
38 | sql = sql.replace("%POSTFIX%", "")
39 | sql = "EXPLAIN QUERY PLAN\n%s" % sql
40 | cur = self.db.cursor()
41 | try:
42 | cur.execute(sql)
43 | for row in cur.fetchall():
44 | print(dict(row))
45 | finally:
46 | cur.close()
47 |
48 | def check(self, db1, db2):
49 | self.connect(db1, db2)
50 | for heur in HEURISTICS:
51 | name = heur["name"]
52 | sql = heur["sql"]
53 | self.check_one(name, sql)
54 |
55 | #-------------------------------------------------------------------------------
56 | def main(db1, db2):
57 | checker = CIndicesChecker()
58 | checker.check(db1, db2)
59 |
60 | if __name__ == "__main__":
61 | main("../samples/ls.sqlite", "../samples/ls-old.sqlite")
62 |
63 |
--------------------------------------------------------------------------------
/tester/samples/add_sample.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python3
2 |
3 | """
4 |
5 | Script used to create a skeleton .cfg file needed by the testing suite
6 |
7 | Diaphora testing suite
8 | Copyright (c) 2015-2022, Joxean Koret
9 |
10 | This program is free software: you can redistribute it and/or modify
11 | it under the terms of the GNU Affero General Public License as
12 | published by the Free Software Foundation, either version 3 of the
13 | License, or (at your option) any later version.
14 |
15 | This program is distributed in the hope that it will be useful,
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | GNU Affero General Public License for more details.
19 |
20 | You should have received a copy of the GNU Affero General Public License
21 | along with this program. If not, see .
22 | """
23 |
24 | import os
25 |
26 | #-------------------------------------------------------------------------------
27 | EXCLUDED_EXTENSIONS = [".idb", ".i64", ".sqlite", ".til", ".nam", ".id0",
28 | ".id1", ".id2", ".cfg", ".log", ".db", ".py", ".sqlite-crash",
29 | ".sqlite-journal", ".cpp", ".asm"]
30 |
31 | BASE_CFG = """
32 | [Testcase]
33 | filename=%s
34 | export=%s.sqlite
35 | ida-binary=idat64
36 | decompiler=1
37 | slow=0
38 | script=
39 |
40 | [Export]
41 | total basic blocks=0
42 | total bblocks instructions=0
43 | total bblocks relations=0
44 | total call graph items=0
45 | total constants=0
46 | total functions bblocks=0
47 | total functions=0
48 | total instructions=0
49 | total program items=0
50 | total program data items=0
51 | call graph primes=0
52 | compilation units=0
53 | named compilation units=0
54 | total microcode basic blocks=0
55 | total microcode instructions=0
56 | """
57 |
58 | #-------------------------------------------------------------------------------
59 | def add_sample(filename):
60 | with open("%s.cfg" % filename, "w") as f:
61 | basename = os.path.basename(filename)
62 | f.write(BASE_CFG % (basename, basename))
63 | print("Created %s.cfg" % filename)
64 |
65 | #-------------------------------------------------------------------------------
66 | def is_excluded(filename):
67 | for extension in EXCLUDED_EXTENSIONS:
68 | if filename.endswith(extension):
69 | return True
70 | return False
71 |
72 | #-------------------------------------------------------------------------------
73 | def main():
74 | for f in os.listdir("."):
75 | if os.path.isfile(f) and not is_excluded(f):
76 | if not os.path.exists("%s.cfg" % f):
77 | print("New sample found: %s" % f)
78 | add_sample(f)
79 |
80 | if __name__ == "__main__":
81 | main()
82 |
--------------------------------------------------------------------------------
/tester/samples/ls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joxeankoret/diaphora/d8b898e35750d103cb6a15f7a87910ff6b237427/tester/samples/ls
--------------------------------------------------------------------------------
/tester/samples/ls-old:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joxeankoret/diaphora/d8b898e35750d103cb6a15f7a87910ff6b237427/tester/samples/ls-old
--------------------------------------------------------------------------------
/tester/samples/ls-old.cfg:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # Test-case for some Linux ELF x64 'ls' program
3 | ################################################################################
4 |
5 | [Testcase]
6 | filename=ls-old
7 | export=ls-old.sqlite
8 | ida-binary=idat64
9 | decompiler=1
10 | script=
11 |
12 | [Export]
13 | total basic blocks=3208
14 | total bblocks instructions=79759
15 | total bblocks relations=14098
16 | total call graph items=886
17 | total constants=361
18 | total functions bblocks=7616
19 | total functions=304
20 | total instructions=14457
21 | total program items=1
22 | total program data items=63
23 | call graph primes=8.982755699525025869382360381E+354
24 | compilation units=14
25 | named compilation units=1
26 | total microcode basic blocks=4339
27 | total microcode instructions=65302
28 |
29 | [Diff]
30 | against=ls.sqlite
31 | output=ls-ls-old.db
32 | best=132
33 | partial=109
34 | unreliable=0
35 | multimatches=3
36 |
--------------------------------------------------------------------------------
/tester/samples/ls.cfg:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # Test-case for some Linux ELF x64 'ls' program
3 | ################################################################################
4 |
5 | [Testcase]
6 | filename=ls
7 | export=ls.sqlite
8 | ida-binary=idat64
9 | decompiler=1
10 | script=
11 |
12 | [Export]
13 | total basic blocks=3635
14 | total bblocks instructions=86208
15 | total bblocks relations=15831
16 | total call graph items=1004
17 | total constants=358
18 | total functions bblocks=8562
19 | total functions=318
20 | total instructions=16225
21 | total program items=1
22 | total program data items=43
23 | call graph primes=9.983313005596550880312916944E+365
24 | compilation units=11
25 | named compilation units=2
26 | total microcode basic blocks=4875
27 | total microcode instructions=69983
28 |
29 | [Diff]
30 | against=ls-old.sqlite
31 | output=ls-vs-ls-old.db
32 | best=132
33 | partial=101
34 | unreliable=0
35 | multimatches=3
36 |
--------------------------------------------------------------------------------
/tester/tester.cfg:
--------------------------------------------------------------------------------
1 | [General]
2 | samples-directory=samples/
3 | diaphora-script=../diaphora.py
4 | cpus=1
5 |
6 | [IDA]
7 | path=/path/to/ida_dir
8 |
9 | [Python]
10 | path=/usr/bin/python3.10
11 |
12 |
--------------------------------------------------------------------------------