├── .editorconfig ├── .gitignore ├── LICENSE ├── README.md ├── datasets ├── README.md ├── dataset.csv.bz2 └── sqlite.script ├── doc └── Hacktivity_2018_presentation.pdf ├── exporters ├── SimpleEval.py ├── __init__.py ├── base_support.py ├── clang_exporter.py ├── kfuzzy.py ├── simple_macro_parser.py └── terminalsize.py ├── hooks └── example1.py ├── ml ├── __init__.py ├── clf.pkl ├── pigaios_create_dataset.py └── pigaios_ml.py ├── others ├── __init__.py ├── py3compat.py └── tarjan_sort.py ├── pygments ├── __init__.py ├── cmdline.py ├── console.py ├── filter.py ├── filters │ └── __init__.py ├── formatter.py ├── formatters │ ├── __init__.py │ ├── _mapping.py │ ├── bbcode.py │ ├── html.py │ ├── img.py │ ├── latex.py │ ├── other.py │ ├── rtf.py │ ├── svg.py │ ├── terminal.py │ └── terminal256.py ├── lexer.py ├── lexers │ ├── __init__.py │ ├── _asy_builtins.py │ ├── _cl_builtins.py │ ├── _cocoa_builtins.py │ ├── _lasso_builtins.py │ ├── _lua_builtins.py │ ├── _mapping.py │ ├── _mql_builtins.py │ ├── _openedge_builtins.py │ ├── _php_builtins.py │ ├── _postgres_builtins.py │ ├── _scilab_builtins.py │ ├── _sourcemod_builtins.py │ ├── _stan_builtins.py │ ├── _vim_builtins.py │ ├── actionscript.py │ ├── agile.py │ ├── algebra.py │ ├── ambient.py │ ├── apl.py │ ├── asm.py │ ├── automation.py │ ├── basic.py │ ├── business.py │ ├── c_cpp.py │ ├── c_like.py │ ├── chapel.py │ ├── compiled.py │ ├── configs.py │ ├── console.py │ ├── css.py │ ├── d.py │ ├── dalvik.py │ ├── data.py │ ├── diff.py │ ├── dotnet.py │ ├── dsls.py │ ├── dylan.py │ ├── ecl.py │ ├── eiffel.py │ ├── erlang.py │ ├── esoteric.py │ ├── factor.py │ ├── fantom.py │ ├── felix.py │ ├── fortran.py │ ├── foxpro.py │ ├── functional.py │ ├── go.py │ ├── graph.py │ ├── graphics.py │ ├── haskell.py │ ├── haxe.py │ ├── hdl.py │ ├── html.py │ ├── idl.py │ ├── igor.py │ ├── inferno.py │ ├── installers.py │ ├── int_fiction.py │ ├── iolang.py │ ├── javascript.py │ ├── julia.py │ ├── jvm.py │ ├── lisp.py │ ├── make.py │ ├── markup.py │ ├── math.py │ ├── matlab.py │ ├── ml.py │ ├── modeling.py │ ├── nimrod.py │ ├── nit.py │ ├── nix.py │ ├── objective.py │ ├── ooc.py │ ├── other.py │ ├── parsers.py │ ├── pascal.py │ ├── pawn.py │ ├── perl.py │ ├── php.py │ ├── prolog.py │ ├── python.py │ ├── r.py │ ├── rdf.py │ ├── rebol.py │ ├── resource.py │ ├── robotframework.py │ ├── ruby.py │ ├── rust.py │ ├── scripting.py │ ├── shell.py │ ├── smalltalk.py │ ├── snobol.py │ ├── special.py │ ├── sql.py │ ├── tcl.py │ ├── templates.py │ ├── testing.py │ ├── text.py │ ├── textedit.py │ ├── textfmts.py │ ├── theorem.py │ ├── urbi.py │ ├── web.py │ └── webmisc.py ├── modeline.py ├── plugin.py ├── regexopt.py ├── scanner.py ├── sphinxext.py ├── style.py ├── styles │ ├── __init__.py │ ├── arduino.py │ ├── autumn.py │ ├── borland.py │ ├── bw.py │ ├── colorful.py │ ├── default.py │ ├── emacs.py │ ├── friendly.py │ ├── fruity.py │ ├── igor.py │ ├── manni.py │ ├── monokai.py │ ├── murphy.py │ ├── native.py │ ├── paraiso_dark.py │ ├── paraiso_light.py │ ├── pastie.py │ ├── perldoc.py │ ├── rrt.py │ ├── tango.py │ ├── trac.py │ ├── vim.py │ ├── vs.py │ └── xcode.py ├── token.py ├── unistring.py └── util.py ├── sourceimp_core.py ├── sourceimp_ida.py ├── sourcexp_ida.py └── srcbindiff.py /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: https://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | end_of_line = lf 9 | 10 | # 2 space indentation 11 | [*.py] 12 | indent_style = space 13 | indent_size = 2 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | -------------------------------------------------------------------------------- /datasets/README.md: -------------------------------------------------------------------------------- 1 | # Dataset 2 | 3 | The following is a dataset created with the good matches discovered between ZLib 1.2.11, Libxml2, Curl, Busybox, GMP, the whole coreutils and SQLite. 4 | It contains all the positives found between the source code and the binaries as well as a random selection of 1,000,000 negative results, created with the following easy SQLite3 command line tool script: 5 | 6 | ``` 7 | $ sqlite3 dataset.db 8 | sqlite> .headers on 9 | sqlite> .mode csv 10 | sqlite> .output dataset.csv 11 | sqlite> select * from matches where accurate = 1; 12 | sqlite> .headers off 13 | sqlite> select * from matches where accurate = 0 order by random() limit 1000000; 14 | sqlite> .quit 15 | ``` 16 | 17 | ## Results 18 | 19 | The current classifier is based on the results of multiple other classifiers, namely: 20 | 21 | * Decision Tree Classifier. 22 | * RandomForestClassifier. 23 | * Bernoulli Naive Bayes. 24 | * Gradient Boosting Classifier. 25 | 26 | Using this multi-classifier to train an adapted dataset the following initial results were observed and reproduced: 27 | 28 | ``` 29 | $ ml/pigaios_ml.py -multi -v 30 | [Fri Sep 21 11:26:14 2018] Using the Pigaios Multi Classifier 31 | [Fri Sep 21 11:26:14 2018] Loading model and data... 32 | [Fri Sep 21 11:26:14 2018] Predicting... 33 | [Fri Sep 21 11:26:16 2018] Correctly predicted 3840 out of 4392 (true positives 552 -> 87.431694%, false positives 441 -> 4.410000%) 34 | [Fri Sep 21 11:26:16 2018] Total right matches 13399 -> 93.100334% 35 | ``` 36 | 37 | Later on, after refining the dataset and adding more fields, the following results were observed: 38 | 39 | ``` 40 | $ ../ml/pigaios_ml.py -multi -t 41 | [Thu Dec 6 20:50:08 2018] Using the Pigaios Multi Classifier 42 | [Thu Dec 6 20:50:08 2018] Loading data... 43 | [Thu Dec 6 20:50:16 2018] Fitting data with CPigaiosMultiClassifier(None)... 44 | Fitting DecisionTreeClassifier(class_weight=None, criterion='gini', max_depth=None, 45 | max_features=None, max_leaf_nodes=None, 46 | min_impurity_decrease=0.0, min_impurity_split=None, 47 | min_samples_leaf=1, min_samples_split=2, 48 | min_weight_fraction_leaf=0.0, presort=False, random_state=None, 49 | splitter='best') 50 | Fitting BernoulliNB(alpha=1.0, binarize=0.0, class_prior=None, fit_prior=True) 51 | Fitting GradientBoostingClassifier(criterion='friedman_mse', init=None, 52 | learning_rate=0.1, loss='deviance', max_depth=3, 53 | max_features=None, max_leaf_nodes=None, 54 | min_impurity_decrease=0.0, min_impurity_split=None, 55 | min_samples_leaf=1, min_samples_split=2, 56 | min_weight_fraction_leaf=0.0, n_estimators=100, 57 | presort='auto', random_state=None, subsample=1.0, verbose=0, 58 | warm_start=False) 59 | Fitting RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini', 60 | max_depth=None, max_features='auto', max_leaf_nodes=None, 61 | min_impurity_decrease=0.0, min_impurity_split=None, 62 | min_samples_leaf=1, min_samples_split=2, 63 | min_weight_fraction_leaf=0.0, n_estimators=10, n_jobs=1, 64 | oob_score=False, random_state=None, verbose=0, 65 | warm_start=False) 66 | [Thu Dec 6 20:54:26 2018] Predicting... 67 | [Thu Dec 6 21:05:14 2018] Correctly predicted 13813 out of 19075 (false negatives 5262 -> 27.585845%, false positives 832 -> 0.083200%) 68 | [Thu Dec 6 21:05:14 2018] Total right matches 1012981 -> 99.402007% 69 | [Thu Dec 6 21:05:14 2018] Saving model... 70 | ``` 71 | 72 | So, in summary, our model predicts >98% matches from the dataset correctly with ~0.5% of false positives, which is more than acceptable. 73 | 74 | ## How to generate datasets 75 | 76 | If you want to generate your own datasets, export your binary or binaries as well as the source codes and, then, use the script ```ml/pigaios_create_dataset.py``` to create a CSV file. 77 | 78 | ## How to train datasets 79 | 80 | If you want to train the model with your own datasets or using a different classifier, use the script ```ml/pigaios_ml.py```. 81 | -------------------------------------------------------------------------------- /datasets/dataset.csv.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joxeankoret/pigaios/8807972f08d5613f5dd291329306abdfb68d60ec/datasets/dataset.csv.bz2 -------------------------------------------------------------------------------- /datasets/sqlite.script: -------------------------------------------------------------------------------- 1 | .headers on 2 | .mode csv 3 | .output dataset.csv 4 | select * from matches where accurate = 1; 5 | .headers off 6 | select * from matches where accurate = 0 order by random() limit 1000000; 7 | .quit 8 | 9 | -------------------------------------------------------------------------------- /doc/Hacktivity_2018_presentation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joxeankoret/pigaios/8807972f08d5613f5dd291329306abdfb68d60ec/doc/Hacktivity_2018_presentation.pdf -------------------------------------------------------------------------------- /exporters/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joxeankoret/pigaios/8807972f08d5613f5dd291329306abdfb68d60ec/exporters/__init__.py -------------------------------------------------------------------------------- /exporters/simple_macro_parser.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python2.7 2 | 3 | """ 4 | Simple C macro parser. Part of the Pigaios project. 5 | Copyright (c) 2018, Joxean Koret 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (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 General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . 19 | """ 20 | 21 | from __future__ import print_function 22 | import os 23 | import re 24 | import sys 25 | import decimal 26 | 27 | from SimpleEval import SimpleEval 28 | from kfuzzy import CKoretFuzzyHashing 29 | 30 | try: 31 | long # Python 2 32 | except NameError: 33 | long = int # Python 3 34 | 35 | #------------------------------------------------------------------------------- 36 | MACROS_REGEXP = '\W*#\W*define\W+([a-z0-9_]+)\W+([a-z0-9_]+)' 37 | DEFAULT_ENUM = "" 38 | 39 | #------------------------------------------------------------------------------- 40 | class CMacroExtractor: 41 | def __init__(self): 42 | self.filename = None 43 | 44 | def get_file_suffix(self, filename): 45 | _, tail = os.path.split(filename) 46 | tail = tail.replace(".","_") 47 | return "".join([c for c in tail if c.isalpha() or c.isdigit() or c=='_']).rstrip() 48 | 49 | def get_enum_name(self, l): 50 | last_group = 0 51 | for i in range(1, 16): 52 | s = set() 53 | for key in l: 54 | s.add(key[:i]) 55 | 56 | if last_group > 0 and len(s) > last_group: 57 | new_name = key[:i-1] 58 | new_name = new_name.upper() 59 | new_name = new_name.strip("_") 60 | return "%s_%s" % (new_name, self.get_file_suffix(self.filename).upper()) 61 | last_group = len(s) 62 | 63 | return DEFAULT_ENUM 64 | 65 | def create_enums(self, d): 66 | kfh = CKoretFuzzyHashing() 67 | kfh.bsize = 1 68 | kfh.output_size = 8 69 | 70 | fuzzy_hashes = {} 71 | for key in d.keys(): 72 | hash1, hash2, _ = kfh.hash_bytes(key).split(";") 73 | new_key = "%s-%s" % (hash1, hash2) 74 | if new_key in fuzzy_hashes: 75 | fuzzy_hashes[new_key].append(key) 76 | else: 77 | fuzzy_hashes[new_key] = [key] 78 | 79 | enums = {} 80 | enums[DEFAULT_ENUM] = [] 81 | for key in fuzzy_hashes: 82 | l = fuzzy_hashes[key] 83 | if len(l) == 1: 84 | continue 85 | 86 | enum_name = self.get_enum_name(l) 87 | enums[enum_name] = [] 88 | tmp = [] 89 | for element in l: 90 | value = None 91 | if type(d[element]) is decimal.Decimal: 92 | eng_str = d[element].to_eng_string() 93 | if str(eng_str).find(".") == -1: 94 | value = "0x%08x" % long(eng_str) 95 | 96 | if value is None: 97 | value = str(d[element]) 98 | tmp.append(" %s = %s, " % (element, value)) 99 | 100 | tmp.sort() 101 | tmp.insert(0, "enum %s {" % enum_name) 102 | tmp.append("};") 103 | enums[enum_name] = "\n".join(tmp) 104 | 105 | return enums 106 | 107 | def extract(self, filename): 108 | self.filename = filename 109 | return self.extract_from_buffer(open(filename, "rb").read()) 110 | 111 | def extract_from_buffer(self, buf): 112 | ret = {} 113 | evaluator = SimpleEval() 114 | # 1) Find all the simple macros 115 | matches = re.findall(MACROS_REGEXP, buf, re.IGNORECASE) 116 | for match in matches: 117 | name, value = match 118 | try: 119 | # Evaluate all of them as to verify we can resolve the proper values 120 | value = evaluator.eval(value) 121 | ret[name] = value 122 | except: 123 | pass 124 | 125 | # 2) Group them by name 126 | ret = self.create_enums(ret) 127 | return ret 128 | 129 | #------------------------------------------------------------------------------- 130 | def usage(): 131 | print("Usage: %s " % sys.argv[0]) 132 | 133 | #------------------------------------------------------------------------------- 134 | def main(filename): 135 | extractor = CMacroExtractor() 136 | enums = extractor.extract(filename) 137 | for name in enums: 138 | src = enums[name] 139 | print(src) 140 | print() 141 | 142 | if __name__ == "__main__": 143 | if len(sys.argv) == 1: 144 | usage() 145 | else: 146 | main(sys.argv[1]) 147 | -------------------------------------------------------------------------------- /exporters/terminalsize.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python2.7 2 | 3 | from __future__ import print_function 4 | 5 | import os 6 | import shlex 7 | import struct 8 | import platform 9 | import subprocess 10 | 11 | #------------------------------------------------------------------------------- 12 | def get_terminal_size(): 13 | """ getTerminalSize() 14 | - get width and height of console 15 | - works on linux,os x,windows,cygwin(windows) 16 | originally retrieved from: 17 | http://stackoverflow.com/questions/566746/how-to-get-console-window-width-in-python 18 | """ 19 | current_os = platform.system() 20 | tuple_xy = None 21 | if current_os == 'Windows': 22 | tuple_xy = _get_terminal_size_windows() 23 | if tuple_xy is None: 24 | tuple_xy = _get_terminal_size_tput() 25 | # needed for window's python in cygwin's xterm! 26 | if current_os in ['Linux', 'Darwin'] or current_os.startswith('CYGWIN'): 27 | tuple_xy = _get_terminal_size_linux() 28 | if tuple_xy is None: 29 | print("default") 30 | tuple_xy = (80, 25) # default value 31 | return tuple_xy 32 | 33 | #------------------------------------------------------------------------------- 34 | def _get_terminal_size_windows(): 35 | try: 36 | from ctypes import windll, create_string_buffer 37 | # stdin handle is -10 38 | # stdout handle is -11 39 | # stderr handle is -12 40 | h = windll.kernel32.GetStdHandle(-12) 41 | csbi = create_string_buffer(22) 42 | res = windll.kernel32.GetConsoleScreenBufferInfo(h, csbi) 43 | if res: 44 | (bufx, bufy, curx, cury, wattr, 45 | left, top, right, bottom, 46 | maxx, maxy) = struct.unpack("hhhhHhhhhhh", csbi.raw) 47 | sizex = right - left + 1 48 | sizey = bottom - top + 1 49 | return sizex, sizey 50 | except: 51 | pass 52 | 53 | #------------------------------------------------------------------------------- 54 | def _get_terminal_size_tput(): 55 | # get terminal width 56 | # src: http://stackoverflow.com/questions/263890/how-do-i-find-the-width-height-of-a-terminal-window 57 | try: 58 | cols = int(subprocess.check_call(shlex.split('tput cols'))) 59 | rows = int(subprocess.check_call(shlex.split('tput lines'))) 60 | return (cols, rows) 61 | except: 62 | pass 63 | 64 | #------------------------------------------------------------------------------- 65 | def _get_terminal_size_linux(): 66 | def ioctl_GWINSZ(fd): 67 | try: 68 | import fcntl 69 | import termios 70 | cr = struct.unpack('hh', 71 | fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234')) 72 | return cr 73 | except: 74 | pass 75 | cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2) 76 | if not cr: 77 | try: 78 | fd = os.open(os.ctermid(), os.O_RDONLY) 79 | cr = ioctl_GWINSZ(fd) 80 | os.close(fd) 81 | except: 82 | pass 83 | if not cr: 84 | try: 85 | cr = (os.environ['LINES'], os.environ['COLUMNS']) 86 | except: 87 | return None 88 | return int(cr[1]), int(cr[0]) 89 | 90 | if __name__ == "__main__": 91 | sizex, sizey = get_terminal_size() 92 | print('width =', sizex, 'height =', sizey) 93 | -------------------------------------------------------------------------------- /hooks/example1.py: -------------------------------------------------------------------------------- 1 | """ 2 | Example Pigaios hooks script for writing project specific rules. 3 | Copyright (c) 2018, Joxean Koret 4 | """ 5 | 6 | from idc import * 7 | from idaapi import * 8 | from idautils import * 9 | 10 | #------------------------------------------------------------------------------- 11 | class CMyHooks: 12 | def __init__(self, pigaios_obj): 13 | """ 14 | The @pigaios_obj is a CBinaryToSourceExporter or CIDABinaryToSourceImporter 15 | object. 16 | """ 17 | self.pigaios = pigaios_obj 18 | 19 | def get_export_range(self): 20 | """ Return a tuple with (start_address, end_address) to export. """ 21 | segname = ".libopenssl.so.RO" 22 | for s in Segments(): 23 | if SegName(s) == segname: 24 | start_ea, end_ea = get_segm_start(s), get_segm_end(s) 25 | self.pigaios.log("Limiting the export to 0x%08x -> 0x%08x" % (start_ea, end_ea)) 26 | return start_ea, end_ea 27 | 28 | # We didn't find the segment, export the whole database 29 | return inf_get_min_ea(), inf_get_max_ea() 30 | 31 | def before_export_function(self, f, name): 32 | """ 33 | Called before a function is going to be exported. Return False to ignore the 34 | function, return True to export it. 35 | """ 36 | #print("AT before_export_function()") 37 | return True 38 | 39 | def after_export_function(self, d): 40 | """ 41 | Called after a function has been parsed and all information gathered. Return 42 | a new dictionary with whatever modifications you want over the given dict 43 | with all the information extracted from the function in IDA. 44 | """ 45 | #print("AT after_export_function()") 46 | return d 47 | 48 | HOOKS = {"PigaiosHooks": CMyHooks} 49 | -------------------------------------------------------------------------------- /ml/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joxeankoret/pigaios/8807972f08d5613f5dd291329306abdfb68d60ec/ml/__init__.py -------------------------------------------------------------------------------- /ml/clf.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joxeankoret/pigaios/8807972f08d5613f5dd291329306abdfb68d60ec/ml/clf.pkl -------------------------------------------------------------------------------- /others/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joxeankoret/pigaios/8807972f08d5613f5dd291329306abdfb68d60ec/others/__init__.py -------------------------------------------------------------------------------- /others/py3compat.py: -------------------------------------------------------------------------------- 1 | 2 | # Workaround for Python3 compat 3 | try: 4 | INTEGER_TYPES = (int, long) 5 | except NameError: 6 | long = int 7 | INTEGER_TYPES = (int,) 8 | -------------------------------------------------------------------------------- /others/tarjan_sort.py: -------------------------------------------------------------------------------- 1 | """ 2 | Tarjan's algorithm and topological sorting implementation in Python 3 | by Paul Harrison 4 | Public domain, do with it as you will 5 | 6 | Downloaded from http://www.logarithmic.net/pfh-files/blog/01208083168/sort.py 7 | """ 8 | def strongly_connected_components(graph): 9 | """ Find the strongly connected components in a graph using 10 | Tarjan's algorithm. 11 | 12 | graph should be a dictionary mapping node names to 13 | lists of successor nodes. 14 | """ 15 | result = [ ] 16 | stack = [ ] 17 | low = { } 18 | 19 | def visit(node): 20 | if node in low: return 21 | 22 | num = len(low) 23 | low[node] = num 24 | stack_pos = len(stack) 25 | stack.append(node) 26 | 27 | for successor in graph[node]: 28 | visit(successor) 29 | low[node] = min(low[node], low[successor]) 30 | 31 | if num == low[node]: 32 | component = tuple(stack[stack_pos:]) 33 | del stack[stack_pos:] 34 | result.append(component) 35 | for item in component: 36 | low[item] = len(graph) 37 | 38 | for node in graph: 39 | visit(node) 40 | 41 | return result 42 | 43 | def topological_sort(graph): 44 | count = { } 45 | for node in graph: 46 | count[node] = 0 47 | for node in graph: 48 | for successor in graph[node]: 49 | count[successor] += 1 50 | 51 | ready = [ node for node in graph if count[node] == 0 ] 52 | 53 | result = [ ] 54 | while ready: 55 | node = ready.pop(-1) 56 | result.append(node) 57 | 58 | for successor in graph[node]: 59 | count[successor] -= 1 60 | if count[successor] == 0: 61 | ready.append(successor) 62 | 63 | return result 64 | 65 | def robust_topological_sort(graph): 66 | """ First identify strongly connected components, 67 | then perform a topological sort on these components. """ 68 | 69 | components = strongly_connected_components(graph) 70 | 71 | node_component = { } 72 | for component in components: 73 | for node in component: 74 | node_component[node] = component 75 | 76 | component_graph = { } 77 | for component in components: 78 | component_graph[component] = [ ] 79 | 80 | for node in graph: 81 | node_c = node_component[node] 82 | for successor in graph[node]: 83 | successor_c = node_component[successor] 84 | if node_c != successor_c: 85 | component_graph[node_c].append(successor_c) 86 | 87 | return topological_sort(component_graph) 88 | 89 | if __name__ == '__main__': 90 | d = { 91 | 0 : [1], 92 | 1 : [2], 93 | 2 : [1,3], 94 | 3 : [3], 95 | } 96 | #print d 97 | #print robust_topological_sort(d) 98 | 99 | d = {0 : [1, 2, 4], 1 : [3, 4], 2 : [0, 3], 3 : [], 4: [1]} 100 | print(d) 101 | print("scc", strongly_connected_components(d)) 102 | print("rts", robust_topological_sort(d)) 103 | -------------------------------------------------------------------------------- /pygments/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Pygments 4 | ~~~~~~~~ 5 | 6 | Pygments is a syntax highlighting package written in Python. 7 | 8 | It is a generic syntax highlighter for general use in all kinds of software 9 | such as forum systems, wikis or other applications that need to prettify 10 | source code. Highlights are: 11 | 12 | * a wide range of common languages and markup formats is supported 13 | * special attention is paid to details, increasing quality by a fair amount 14 | * support for new languages and formats are added easily 15 | * a number of output formats, presently HTML, LaTeX, RTF, SVG, all image 16 | formats that PIL supports, and ANSI sequences 17 | * it is usable as a command-line tool and as a library 18 | * ... and it highlights even Brainfuck! 19 | 20 | The `Pygments tip`_ is installable with ``easy_install Pygments==dev``. 21 | 22 | .. _Pygments tip: 23 | http://bitbucket.org/birkenfeld/pygments-main/get/tip.zip#egg=Pygments-dev 24 | 25 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 26 | :license: BSD, see LICENSE for details. 27 | """ 28 | 29 | __version__ = '2.1a0' 30 | __docformat__ = 'restructuredtext' 31 | 32 | __all__ = ['lex', 'format', 'highlight'] 33 | 34 | 35 | import sys 36 | 37 | from pygments.util import StringIO, BytesIO 38 | 39 | 40 | def lex(code, lexer): 41 | """ 42 | Lex ``code`` with ``lexer`` and return an iterable of tokens. 43 | """ 44 | try: 45 | return lexer.get_tokens(code) 46 | except TypeError as err: 47 | if isinstance(err.args[0], str) and \ 48 | ('unbound method get_tokens' in err.args[0] or 49 | 'missing 1 required positional argument' in err.args[0]): 50 | raise TypeError('lex() argument must be a lexer instance, ' 51 | 'not a class') 52 | raise 53 | 54 | 55 | def format(tokens, formatter, outfile=None): 56 | """ 57 | Format a tokenlist ``tokens`` with the formatter ``formatter``. 58 | 59 | If ``outfile`` is given and a valid file object (an object 60 | with a ``write`` method), the result will be written to it, otherwise 61 | it is returned as a string. 62 | """ 63 | try: 64 | if not outfile: 65 | realoutfile = getattr(formatter, 'encoding', None) and BytesIO() or StringIO() 66 | formatter.format(tokens, realoutfile) 67 | return realoutfile.getvalue() 68 | else: 69 | formatter.format(tokens, outfile) 70 | except TypeError as err: 71 | if isinstance(err.args[0], str) and \ 72 | ('unbound method format' in err.args[0] or 73 | 'missing 1 required positional argument' in err.args[0]): 74 | raise TypeError('format() argument must be a formatter instance, ' 75 | 'not a class') 76 | raise 77 | 78 | 79 | def highlight(code, lexer, formatter, outfile=None): 80 | """ 81 | Lex ``code`` with ``lexer`` and format it with the formatter ``formatter``. 82 | 83 | If ``outfile`` is given and a valid file object (an object 84 | with a ``write`` method), the result will be written to it, otherwise 85 | it is returned as a string. 86 | """ 87 | return format(lex(code, lexer), formatter, outfile) 88 | 89 | 90 | if __name__ == '__main__': # pragma: no cover 91 | from pygments.cmdline import main 92 | sys.exit(main(sys.argv)) 93 | -------------------------------------------------------------------------------- /pygments/console.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.console 4 | ~~~~~~~~~~~~~~~~ 5 | 6 | Format colored console output. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | esc = "\x1b[" 13 | 14 | codes = {} 15 | codes[""] = "" 16 | codes["reset"] = esc + "39;49;00m" 17 | 18 | codes["bold"] = esc + "01m" 19 | codes["faint"] = esc + "02m" 20 | codes["standout"] = esc + "03m" 21 | codes["underline"] = esc + "04m" 22 | codes["blink"] = esc + "05m" 23 | codes["overline"] = esc + "06m" 24 | 25 | dark_colors = ["black", "darkred", "darkgreen", "brown", "darkblue", 26 | "purple", "teal", "lightgray"] 27 | light_colors = ["darkgray", "red", "green", "yellow", "blue", 28 | "fuchsia", "turquoise", "white"] 29 | 30 | x = 30 31 | for d, l in zip(dark_colors, light_colors): 32 | codes[d] = esc + "%im" % x 33 | codes[l] = esc + "%i;01m" % x 34 | x += 1 35 | 36 | del d, l, x 37 | 38 | codes["darkteal"] = codes["turquoise"] 39 | codes["darkyellow"] = codes["brown"] 40 | codes["fuscia"] = codes["fuchsia"] 41 | codes["white"] = codes["bold"] 42 | 43 | 44 | def reset_color(): 45 | return codes["reset"] 46 | 47 | 48 | def colorize(color_key, text): 49 | return codes[color_key] + text + codes["reset"] 50 | 51 | 52 | def ansiformat(attr, text): 53 | """ 54 | Format ``text`` with a color and/or some attributes:: 55 | 56 | color normal color 57 | *color* bold color 58 | _color_ underlined color 59 | +color+ blinking color 60 | """ 61 | result = [] 62 | if attr[:1] == attr[-1:] == '+': 63 | result.append(codes['blink']) 64 | attr = attr[1:-1] 65 | if attr[:1] == attr[-1:] == '*': 66 | result.append(codes['bold']) 67 | attr = attr[1:-1] 68 | if attr[:1] == attr[-1:] == '_': 69 | result.append(codes['underline']) 70 | attr = attr[1:-1] 71 | result.append(codes[attr]) 72 | result.append(text) 73 | result.append(codes['reset']) 74 | return ''.join(result) 75 | -------------------------------------------------------------------------------- /pygments/filter.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.filter 4 | ~~~~~~~~~~~~~~~ 5 | 6 | Module that implements the default filter. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | 13 | def apply_filters(stream, filters, lexer=None): 14 | """ 15 | Use this method to apply an iterable of filters to 16 | a stream. If lexer is given it's forwarded to the 17 | filter, otherwise the filter receives `None`. 18 | """ 19 | def _apply(filter_, stream): 20 | for token in filter_.filter(lexer, stream): 21 | yield token 22 | for filter_ in filters: 23 | stream = _apply(filter_, stream) 24 | return stream 25 | 26 | 27 | def simplefilter(f): 28 | """ 29 | Decorator that converts a function into a filter:: 30 | 31 | @simplefilter 32 | def lowercase(self, lexer, stream, options): 33 | for ttype, value in stream: 34 | yield ttype, value.lower() 35 | """ 36 | return type(f.__name__, (FunctionFilter,), { 37 | 'function': f, 38 | '__module__': getattr(f, '__module__'), 39 | '__doc__': f.__doc__ 40 | }) 41 | 42 | 43 | class Filter(object): 44 | """ 45 | Default filter. Subclass this class or use the `simplefilter` 46 | decorator to create own filters. 47 | """ 48 | 49 | def __init__(self, **options): 50 | self.options = options 51 | 52 | def filter(self, lexer, stream): 53 | raise NotImplementedError() 54 | 55 | 56 | class FunctionFilter(Filter): 57 | """ 58 | Abstract class used by `simplefilter` to create simple 59 | function filters on the fly. The `simplefilter` decorator 60 | automatically creates subclasses of this class for 61 | functions passed to it. 62 | """ 63 | function = None 64 | 65 | def __init__(self, **options): 66 | if not hasattr(self, 'function'): 67 | raise TypeError('%r used without bound function' % 68 | self.__class__.__name__) 69 | Filter.__init__(self, **options) 70 | 71 | def filter(self, lexer, stream): 72 | # pylint: disable-msg=E1102 73 | for ttype, value in self.function(lexer, stream, self.options): 74 | yield ttype, value 75 | -------------------------------------------------------------------------------- /pygments/formatter.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.formatter 4 | ~~~~~~~~~~~~~~~~~~ 5 | 6 | Base formatter class. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | import codecs 13 | 14 | from pygments.util import get_bool_opt, string_types 15 | from pygments.styles import get_style_by_name 16 | 17 | __all__ = ['Formatter'] 18 | 19 | 20 | def _lookup_style(style): 21 | if isinstance(style, string_types): 22 | return get_style_by_name(style) 23 | return style 24 | 25 | 26 | class Formatter(object): 27 | """ 28 | Converts a token stream to text. 29 | 30 | Options accepted: 31 | 32 | ``style`` 33 | The style to use, can be a string or a Style subclass 34 | (default: "default"). Not used by e.g. the 35 | TerminalFormatter. 36 | ``full`` 37 | Tells the formatter to output a "full" document, i.e. 38 | a complete self-contained document. This doesn't have 39 | any effect for some formatters (default: false). 40 | ``title`` 41 | If ``full`` is true, the title that should be used to 42 | caption the document (default: ''). 43 | ``encoding`` 44 | If given, must be an encoding name. This will be used to 45 | convert the Unicode token strings to byte strings in the 46 | output. If it is "" or None, Unicode strings will be written 47 | to the output file, which most file-like objects do not 48 | support (default: None). 49 | ``outencoding`` 50 | Overrides ``encoding`` if given. 51 | """ 52 | 53 | #: Name of the formatter 54 | name = None 55 | 56 | #: Shortcuts for the formatter 57 | aliases = [] 58 | 59 | #: fn match rules 60 | filenames = [] 61 | 62 | #: If True, this formatter outputs Unicode strings when no encoding 63 | #: option is given. 64 | unicodeoutput = True 65 | 66 | def __init__(self, **options): 67 | self.style = _lookup_style(options.get('style', 'default')) 68 | self.full = get_bool_opt(options, 'full', False) 69 | self.title = options.get('title', '') 70 | self.encoding = options.get('encoding', None) or None 71 | if self.encoding in ('guess', 'chardet'): 72 | # can happen for e.g. pygmentize -O encoding=guess 73 | self.encoding = 'utf-8' 74 | self.encoding = options.get('outencoding') or self.encoding 75 | self.options = options 76 | 77 | def get_style_defs(self, arg=''): 78 | """ 79 | Return the style definitions for the current style as a string. 80 | 81 | ``arg`` is an additional argument whose meaning depends on the 82 | formatter used. Note that ``arg`` can also be a list or tuple 83 | for some formatters like the html formatter. 84 | """ 85 | return '' 86 | 87 | def format(self, tokensource, outfile): 88 | """ 89 | Format ``tokensource``, an iterable of ``(tokentype, tokenstring)`` 90 | tuples and write it into ``outfile``. 91 | """ 92 | if self.encoding: 93 | # wrap the outfile in a StreamWriter 94 | outfile = codecs.lookup(self.encoding)[3](outfile) 95 | return self.format_unencoded(tokensource, outfile) 96 | -------------------------------------------------------------------------------- /pygments/formatters/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.formatters 4 | ~~~~~~~~~~~~~~~~~~~ 5 | 6 | Pygments formatters. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | import re 13 | import sys 14 | import types 15 | import fnmatch 16 | from os.path import basename 17 | 18 | from pygments.formatters._mapping import FORMATTERS 19 | from pygments.plugin import find_plugin_formatters 20 | from pygments.util import ClassNotFound, itervalues 21 | 22 | __all__ = ['get_formatter_by_name', 'get_formatter_for_filename', 23 | 'get_all_formatters'] + list(FORMATTERS) 24 | 25 | _formatter_cache = {} # classes by name 26 | _pattern_cache = {} 27 | 28 | 29 | def _fn_matches(fn, glob): 30 | """Return whether the supplied file name fn matches pattern filename.""" 31 | if glob not in _pattern_cache: 32 | pattern = _pattern_cache[glob] = re.compile(fnmatch.translate(glob)) 33 | return pattern.match(fn) 34 | return _pattern_cache[glob].match(fn) 35 | 36 | 37 | def _load_formatters(module_name): 38 | """Load a formatter (and all others in the module too).""" 39 | mod = __import__(module_name, None, None, ['__all__']) 40 | for formatter_name in mod.__all__: 41 | cls = getattr(mod, formatter_name) 42 | _formatter_cache[cls.name] = cls 43 | 44 | 45 | def get_all_formatters(): 46 | """Return a generator for all formatter classes.""" 47 | # NB: this returns formatter classes, not info like get_all_lexers(). 48 | for info in itervalues(FORMATTERS): 49 | if info[1] not in _formatter_cache: 50 | _load_formatters(info[0]) 51 | yield _formatter_cache[info[1]] 52 | for _, formatter in find_plugin_formatters(): 53 | yield formatter 54 | 55 | 56 | def find_formatter_class(alias): 57 | """Lookup a formatter by alias. 58 | 59 | Returns None if not found. 60 | """ 61 | for module_name, name, aliases, _, _ in itervalues(FORMATTERS): 62 | if alias in aliases: 63 | if name not in _formatter_cache: 64 | _load_formatters(module_name) 65 | return _formatter_cache[name] 66 | for _, cls in find_plugin_formatters(): 67 | if alias in cls.aliases: 68 | return cls 69 | 70 | 71 | def get_formatter_by_name(_alias, **options): 72 | """Lookup and instantiate a formatter by alias. 73 | 74 | Raises ClassNotFound if not found. 75 | """ 76 | cls = find_formatter_class(_alias) 77 | if cls is None: 78 | raise ClassNotFound("no formatter found for name %r" % _alias) 79 | return cls(**options) 80 | 81 | 82 | def get_formatter_for_filename(fn, **options): 83 | """Lookup and instantiate a formatter by filename pattern. 84 | 85 | Raises ClassNotFound if not found. 86 | """ 87 | fn = basename(fn) 88 | for modname, name, _, filenames, _ in itervalues(FORMATTERS): 89 | for filename in filenames: 90 | if _fn_matches(fn, filename): 91 | if name not in _formatter_cache: 92 | _load_formatters(modname) 93 | return _formatter_cache[name](**options) 94 | for cls in find_plugin_formatters(): 95 | for filename in cls.filenames: 96 | if _fn_matches(fn, filename): 97 | return cls(**options) 98 | raise ClassNotFound("no formatter found for file name %r" % fn) 99 | 100 | 101 | class _automodule(types.ModuleType): 102 | """Automatically import formatters.""" 103 | 104 | def __getattr__(self, name): 105 | info = FORMATTERS.get(name) 106 | if info: 107 | _load_formatters(info[0]) 108 | cls = _formatter_cache[info[1]] 109 | setattr(self, name, cls) 110 | return cls 111 | raise AttributeError(name) 112 | 113 | 114 | oldmod = sys.modules[__name__] 115 | newmod = _automodule(__name__) 116 | newmod.__dict__.update(oldmod.__dict__) 117 | sys.modules[__name__] = newmod 118 | del newmod.newmod, newmod.oldmod, newmod.sys, newmod.types 119 | -------------------------------------------------------------------------------- /pygments/formatters/_mapping.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.formatters._mapping 4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Formatter mapping definitions. This file is generated by itself. Everytime 7 | you change something on a builtin formatter definition, run this script from 8 | the formatters folder to update it. 9 | 10 | Do not alter the FORMATTERS dictionary by hand. 11 | 12 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 13 | :license: BSD, see LICENSE for details. 14 | """ 15 | 16 | from __future__ import print_function 17 | 18 | FORMATTERS = { 19 | 'BBCodeFormatter': ('pygments.formatters.bbcode', 'BBCode', ('bbcode', 'bb'), (), 'Format tokens with BBcodes. These formatting codes are used by many bulletin boards, so you can highlight your sourcecode with pygments before posting it there.'), 20 | 'BmpImageFormatter': ('pygments.formatters.img', 'img_bmp', ('bmp', 'bitmap'), ('*.bmp',), 'Create a bitmap image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'), 21 | 'GifImageFormatter': ('pygments.formatters.img', 'img_gif', ('gif',), ('*.gif',), 'Create a GIF image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'), 22 | 'HtmlFormatter': ('pygments.formatters.html', 'HTML', ('html',), ('*.html', '*.htm'), "Format tokens as HTML 4 ```` tags within a ``
`` tag, wrapped in a ``
`` tag. The ``
``'s CSS class can be set by the `cssclass` option."), 23 | 'ImageFormatter': ('pygments.formatters.img', 'img', ('img', 'IMG', 'png'), ('*.png',), 'Create a PNG image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'), 24 | 'JpgImageFormatter': ('pygments.formatters.img', 'img_jpg', ('jpg', 'jpeg'), ('*.jpg',), 'Create a JPEG image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'), 25 | 'LatexFormatter': ('pygments.formatters.latex', 'LaTeX', ('latex', 'tex'), ('*.tex',), 'Format tokens as LaTeX code. This needs the `fancyvrb` and `color` standard packages.'), 26 | 'NullFormatter': ('pygments.formatters.other', 'Text only', ('text', 'null'), ('*.txt',), 'Output the text unchanged without any formatting.'), 27 | 'RawTokenFormatter': ('pygments.formatters.other', 'Raw tokens', ('raw', 'tokens'), ('*.raw',), 'Format tokens as a raw representation for storing token streams.'), 28 | 'RtfFormatter': ('pygments.formatters.rtf', 'RTF', ('rtf',), ('*.rtf',), 'Format tokens as RTF markup. This formatter automatically outputs full RTF documents with color information and other useful stuff. Perfect for Copy and Paste into Microsoft(R) Word(R) documents.'), 29 | 'SvgFormatter': ('pygments.formatters.svg', 'SVG', ('svg',), ('*.svg',), 'Format tokens as an SVG graphics file. This formatter is still experimental. Each line of code is a ```` element with explicit ``x`` and ``y`` coordinates containing ```` elements with the individual token styles.'), 30 | 'Terminal256Formatter': ('pygments.formatters.terminal256', 'Terminal256', ('terminal256', 'console256', '256'), (), 'Format tokens with ANSI color sequences, for output in a 256-color terminal or console. Like in `TerminalFormatter` color sequences are terminated at newlines, so that paging the output works correctly.'), 31 | 'TerminalFormatter': ('pygments.formatters.terminal', 'Terminal', ('terminal', 'console'), (), 'Format tokens with ANSI color sequences, for output in a text console. Color sequences are terminated at newlines, so that paging the output works correctly.'), 32 | 'TestcaseFormatter': ('pygments.formatters.other', 'Testcase', ('testcase',), (), 'Format tokens as appropriate for a new testcase.') 33 | } 34 | 35 | if __name__ == '__main__': # pragma: no cover 36 | import sys 37 | import os 38 | 39 | # lookup formatters 40 | found_formatters = [] 41 | imports = [] 42 | sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..')) 43 | from pygments.util import docstring_headline 44 | 45 | for root, dirs, files in os.walk('.'): 46 | for filename in files: 47 | if filename.endswith('.py') and not filename.startswith('_'): 48 | module_name = 'pygments.formatters%s.%s' % ( 49 | root[1:].replace('/', '.'), filename[:-3]) 50 | print(module_name) 51 | module = __import__(module_name, None, None, ['']) 52 | for formatter_name in module.__all__: 53 | formatter = getattr(module, formatter_name) 54 | found_formatters.append( 55 | '%r: %r' % (formatter_name, 56 | (module_name, 57 | formatter.name, 58 | tuple(formatter.aliases), 59 | tuple(formatter.filenames), 60 | docstring_headline(formatter)))) 61 | # sort them to make the diff minimal 62 | found_formatters.sort() 63 | 64 | # extract useful sourcecode from this file 65 | with open(__file__) as fp: 66 | content = fp.read() 67 | header = content[:content.find('FORMATTERS = {')] 68 | footer = content[content.find("if __name__ == '__main__':"):] 69 | 70 | # write new file 71 | with open(__file__, 'w') as fp: 72 | fp.write(header) 73 | fp.write('FORMATTERS = {\n %s\n}\n\n' % ',\n '.join(found_formatters)) 74 | fp.write(footer) 75 | 76 | print ('=== %d formatters processed.' % len(found_formatters)) 77 | -------------------------------------------------------------------------------- /pygments/formatters/bbcode.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.formatters.bbcode 4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | BBcode formatter. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | 13 | from pygments.formatter import Formatter 14 | from pygments.util import get_bool_opt 15 | 16 | __all__ = ['BBCodeFormatter'] 17 | 18 | 19 | class BBCodeFormatter(Formatter): 20 | """ 21 | Format tokens with BBcodes. These formatting codes are used by many 22 | bulletin boards, so you can highlight your sourcecode with pygments before 23 | posting it there. 24 | 25 | This formatter has no support for background colors and borders, as there 26 | are no common BBcode tags for that. 27 | 28 | Some board systems (e.g. phpBB) don't support colors in their [code] tag, 29 | so you can't use the highlighting together with that tag. 30 | Text in a [code] tag usually is shown with a monospace font (which this 31 | formatter can do with the ``monofont`` option) and no spaces (which you 32 | need for indentation) are removed. 33 | 34 | Additional options accepted: 35 | 36 | `style` 37 | The style to use, can be a string or a Style subclass (default: 38 | ``'default'``). 39 | 40 | `codetag` 41 | If set to true, put the output into ``[code]`` tags (default: 42 | ``false``) 43 | 44 | `monofont` 45 | If set to true, add a tag to show the code with a monospace font 46 | (default: ``false``). 47 | """ 48 | name = 'BBCode' 49 | aliases = ['bbcode', 'bb'] 50 | filenames = [] 51 | 52 | def __init__(self, **options): 53 | Formatter.__init__(self, **options) 54 | self._code = get_bool_opt(options, 'codetag', False) 55 | self._mono = get_bool_opt(options, 'monofont', False) 56 | 57 | self.styles = {} 58 | self._make_styles() 59 | 60 | def _make_styles(self): 61 | for ttype, ndef in self.style: 62 | start = end = '' 63 | if ndef['color']: 64 | start += '[color=#%s]' % ndef['color'] 65 | end = '[/color]' + end 66 | if ndef['bold']: 67 | start += '[b]' 68 | end = '[/b]' + end 69 | if ndef['italic']: 70 | start += '[i]' 71 | end = '[/i]' + end 72 | if ndef['underline']: 73 | start += '[u]' 74 | end = '[/u]' + end 75 | # there are no common BBcodes for background-color and border 76 | 77 | self.styles[ttype] = start, end 78 | 79 | def format_unencoded(self, tokensource, outfile): 80 | if self._code: 81 | outfile.write('[code]') 82 | if self._mono: 83 | outfile.write('[font=monospace]') 84 | 85 | lastval = '' 86 | lasttype = None 87 | 88 | for ttype, value in tokensource: 89 | while ttype not in self.styles: 90 | ttype = ttype.parent 91 | if ttype == lasttype: 92 | lastval += value 93 | else: 94 | if lastval: 95 | start, end = self.styles[lasttype] 96 | outfile.write(''.join((start, lastval, end))) 97 | lastval = value 98 | lasttype = ttype 99 | 100 | if lastval: 101 | start, end = self.styles[lasttype] 102 | outfile.write(''.join((start, lastval, end))) 103 | 104 | if self._mono: 105 | outfile.write('[/font]') 106 | if self._code: 107 | outfile.write('[/code]') 108 | if self._code or self._mono: 109 | outfile.write('\n') 110 | -------------------------------------------------------------------------------- /pygments/formatters/other.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.formatters.other 4 | ~~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Other formatters: NullFormatter, RawTokenFormatter. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | from pygments.formatter import Formatter 13 | from pygments.util import OptionError, get_choice_opt 14 | from pygments.token import Token 15 | from pygments.console import colorize 16 | 17 | __all__ = ['NullFormatter', 'RawTokenFormatter', 'TestcaseFormatter'] 18 | 19 | 20 | class NullFormatter(Formatter): 21 | """ 22 | Output the text unchanged without any formatting. 23 | """ 24 | name = 'Text only' 25 | aliases = ['text', 'null'] 26 | filenames = ['*.txt'] 27 | 28 | def format(self, tokensource, outfile): 29 | enc = self.encoding 30 | for ttype, value in tokensource: 31 | if enc: 32 | outfile.write(value.encode(enc)) 33 | else: 34 | outfile.write(value) 35 | 36 | 37 | class RawTokenFormatter(Formatter): 38 | r""" 39 | Format tokens as a raw representation for storing token streams. 40 | 41 | The format is ``tokentyperepr(tokenstring)\n``. The output can later 42 | be converted to a token stream with the `RawTokenLexer`, described in the 43 | :doc:`lexer list `. 44 | 45 | Only two options are accepted: 46 | 47 | `compress` 48 | If set to ``'gz'`` or ``'bz2'``, compress the output with the given 49 | compression algorithm after encoding (default: ``''``). 50 | `error_color` 51 | If set to a color name, highlight error tokens using that color. If 52 | set but with no value, defaults to ``'red'``. 53 | 54 | .. versionadded:: 0.11 55 | 56 | """ 57 | name = 'Raw tokens' 58 | aliases = ['raw', 'tokens'] 59 | filenames = ['*.raw'] 60 | 61 | unicodeoutput = False 62 | 63 | def __init__(self, **options): 64 | Formatter.__init__(self, **options) 65 | # We ignore self.encoding if it is set, since it gets set for lexer 66 | # and formatter if given with -Oencoding on the command line. 67 | # The RawTokenFormatter outputs only ASCII. Override here. 68 | self.encoding = 'ascii' # let pygments.format() do the right thing 69 | self.compress = get_choice_opt(options, 'compress', 70 | ['', 'none', 'gz', 'bz2'], '') 71 | self.error_color = options.get('error_color', None) 72 | if self.error_color is True: 73 | self.error_color = 'red' 74 | if self.error_color is not None: 75 | try: 76 | colorize(self.error_color, '') 77 | except KeyError: 78 | raise ValueError("Invalid color %r specified" % 79 | self.error_color) 80 | 81 | def format(self, tokensource, outfile): 82 | try: 83 | outfile.write(b'') 84 | except TypeError: 85 | raise TypeError('The raw tokens formatter needs a binary ' 86 | 'output file') 87 | if self.compress == 'gz': 88 | import gzip 89 | outfile = gzip.GzipFile('', 'wb', 9, outfile) 90 | def write(text): 91 | outfile.write(text.encode()) 92 | flush = outfile.flush 93 | elif self.compress == 'bz2': 94 | import bz2 95 | compressor = bz2.BZ2Compressor(9) 96 | def write(text): 97 | outfile.write(compressor.compress(text.encode())) 98 | def flush(): 99 | outfile.write(compressor.flush()) 100 | outfile.flush() 101 | else: 102 | def write(text): 103 | outfile.write(text.encode()) 104 | flush = outfile.flush 105 | 106 | if self.error_color: 107 | for ttype, value in tokensource: 108 | line = "%s\t%r\n" % (ttype, value) 109 | if ttype is Token.Error: 110 | write(colorize(self.error_color, line)) 111 | else: 112 | write(line) 113 | else: 114 | for ttype, value in tokensource: 115 | write("%s\t%r\n" % (ttype, value)) 116 | flush() 117 | 118 | TESTCASE_BEFORE = u'''\ 119 | def testNeedsName(self): 120 | fragment = %r 121 | tokens = [ 122 | ''' 123 | TESTCASE_AFTER = u'''\ 124 | ] 125 | self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) 126 | ''' 127 | 128 | 129 | class TestcaseFormatter(Formatter): 130 | """ 131 | Format tokens as appropriate for a new testcase. 132 | 133 | .. versionadded:: 2.0 134 | """ 135 | name = 'Testcase' 136 | aliases = ['testcase'] 137 | 138 | def __init__(self, **options): 139 | Formatter.__init__(self, **options) 140 | if self.encoding is not None and self.encoding != 'utf-8': 141 | raise ValueError("Only None and utf-8 are allowed encodings.") 142 | 143 | def format(self, tokensource, outfile): 144 | indentation = ' ' * 12 145 | rawbuf = [] 146 | outbuf = [] 147 | for ttype, value in tokensource: 148 | rawbuf.append(value) 149 | outbuf.append('%s(%s, %r),\n' % (indentation, ttype, value)) 150 | 151 | before = TESTCASE_BEFORE % (u''.join(rawbuf),) 152 | during = u''.join(outbuf) 153 | after = TESTCASE_AFTER 154 | if self.encoding is None: 155 | outfile.write(before + during + after) 156 | else: 157 | outfile.write(before.encode('utf-8')) 158 | outfile.write(during.encode('utf-8')) 159 | outfile.write(after.encode('utf-8')) 160 | outfile.flush() 161 | -------------------------------------------------------------------------------- /pygments/formatters/rtf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.formatters.rtf 4 | ~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | A formatter that generates RTF files. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | from pygments.formatter import Formatter 13 | from pygments.util import get_int_opt, _surrogatepair 14 | 15 | 16 | __all__ = ['RtfFormatter'] 17 | 18 | 19 | class RtfFormatter(Formatter): 20 | """ 21 | Format tokens as RTF markup. This formatter automatically outputs full RTF 22 | documents with color information and other useful stuff. Perfect for Copy and 23 | Paste into Microsoft(R) Word(R) documents. 24 | 25 | Please note that ``encoding`` and ``outencoding`` options are ignored. 26 | The RTF format is ASCII natively, but handles unicode characters correctly 27 | thanks to escape sequences. 28 | 29 | .. versionadded:: 0.6 30 | 31 | Additional options accepted: 32 | 33 | `style` 34 | The style to use, can be a string or a Style subclass (default: 35 | ``'default'``). 36 | 37 | `fontface` 38 | The used font famliy, for example ``Bitstream Vera Sans``. Defaults to 39 | some generic font which is supposed to have fixed width. 40 | 41 | `fontsize` 42 | Size of the font used. Size is specified in half points. The 43 | default is 24 half-points, giving a size 12 font. 44 | 45 | .. versionadded:: 2.0 46 | """ 47 | name = 'RTF' 48 | aliases = ['rtf'] 49 | filenames = ['*.rtf'] 50 | 51 | def __init__(self, **options): 52 | r""" 53 | Additional options accepted: 54 | 55 | ``fontface`` 56 | Name of the font used. Could for example be ``'Courier New'`` 57 | to further specify the default which is ``'\fmodern'``. The RTF 58 | specification claims that ``\fmodern`` are "Fixed-pitch serif 59 | and sans serif fonts". Hope every RTF implementation thinks 60 | the same about modern... 61 | 62 | """ 63 | Formatter.__init__(self, **options) 64 | self.fontface = options.get('fontface') or '' 65 | self.fontsize = get_int_opt(options, 'fontsize', 0) 66 | 67 | def _escape(self, text): 68 | return text.replace(u'\\', u'\\\\') \ 69 | .replace(u'{', u'\\{') \ 70 | .replace(u'}', u'\\}') 71 | 72 | def _escape_text(self, text): 73 | # empty strings, should give a small performance improvment 74 | if not text: 75 | return u'' 76 | 77 | # escape text 78 | text = self._escape(text) 79 | 80 | buf = [] 81 | for c in text: 82 | cn = ord(c) 83 | if cn < (2**7): 84 | # ASCII character 85 | buf.append(str(c)) 86 | elif (2**7) <= cn < (2**16): 87 | # single unicode escape sequence 88 | buf.append(u'{\\u%d}' % cn) 89 | elif (2**16) <= cn: 90 | # RTF limits unicode to 16 bits. 91 | # Force surrogate pairs 92 | buf.append(u'{\\u%d}{\\u%d}' % _surrogatepair(cn)) 93 | 94 | return u''.join(buf).replace(u'\n', u'\\par\n') 95 | 96 | def format_unencoded(self, tokensource, outfile): 97 | # rtf 1.8 header 98 | outfile.write(u'{\\rtf1\\ansi\\uc0\\deff0' 99 | u'{\\fonttbl{\\f0\\fmodern\\fprq1\\fcharset0%s;}}' 100 | u'{\\colortbl;' % (self.fontface and 101 | u' ' + self._escape(self.fontface) or 102 | u'')) 103 | 104 | # convert colors and save them in a mapping to access them later. 105 | color_mapping = {} 106 | offset = 1 107 | for _, style in self.style: 108 | for color in style['color'], style['bgcolor'], style['border']: 109 | if color and color not in color_mapping: 110 | color_mapping[color] = offset 111 | outfile.write(u'\\red%d\\green%d\\blue%d;' % ( 112 | int(color[0:2], 16), 113 | int(color[2:4], 16), 114 | int(color[4:6], 16) 115 | )) 116 | offset += 1 117 | outfile.write(u'}\\f0 ') 118 | if self.fontsize: 119 | outfile.write(u'\\fs%d' % (self.fontsize)) 120 | 121 | # highlight stream 122 | for ttype, value in tokensource: 123 | while not self.style.styles_token(ttype) and ttype.parent: 124 | ttype = ttype.parent 125 | style = self.style.style_for_token(ttype) 126 | buf = [] 127 | if style['bgcolor']: 128 | buf.append(u'\\cb%d' % color_mapping[style['bgcolor']]) 129 | if style['color']: 130 | buf.append(u'\\cf%d' % color_mapping[style['color']]) 131 | if style['bold']: 132 | buf.append(u'\\b') 133 | if style['italic']: 134 | buf.append(u'\\i') 135 | if style['underline']: 136 | buf.append(u'\\ul') 137 | if style['border']: 138 | buf.append(u'\\chbrdr\\chcfpat%d' % 139 | color_mapping[style['border']]) 140 | start = u''.join(buf) 141 | if start: 142 | outfile.write(u'{%s ' % start) 143 | outfile.write(self._escape_text(value)) 144 | if start: 145 | outfile.write(u'}') 146 | 147 | outfile.write(u'}') 148 | -------------------------------------------------------------------------------- /pygments/formatters/terminal.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.formatters.terminal 4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Formatter for terminal output with ANSI sequences. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | import sys 13 | 14 | from pygments.formatter import Formatter 15 | from pygments.token import Keyword, Name, Comment, String, Error, \ 16 | Number, Operator, Generic, Token, Whitespace 17 | from pygments.console import ansiformat 18 | from pygments.util import get_choice_opt 19 | 20 | 21 | __all__ = ['TerminalFormatter'] 22 | 23 | 24 | #: Map token types to a tuple of color values for light and dark 25 | #: backgrounds. 26 | TERMINAL_COLORS = { 27 | Token: ('', ''), 28 | 29 | Whitespace: ('lightgray', 'darkgray'), 30 | Comment: ('lightgray', 'darkgray'), 31 | Comment.Preproc: ('teal', 'turquoise'), 32 | Keyword: ('darkblue', 'blue'), 33 | Keyword.Type: ('teal', 'turquoise'), 34 | Operator.Word: ('purple', 'fuchsia'), 35 | Name.Builtin: ('teal', 'turquoise'), 36 | Name.Function: ('darkgreen', 'green'), 37 | Name.Namespace: ('_teal_', '_turquoise_'), 38 | Name.Class: ('_darkgreen_', '_green_'), 39 | Name.Exception: ('teal', 'turquoise'), 40 | Name.Decorator: ('darkgray', 'lightgray'), 41 | Name.Variable: ('darkred', 'red'), 42 | Name.Constant: ('darkred', 'red'), 43 | Name.Attribute: ('teal', 'turquoise'), 44 | Name.Tag: ('blue', 'blue'), 45 | String: ('brown', 'brown'), 46 | Number: ('darkblue', 'blue'), 47 | 48 | Generic.Deleted: ('red', 'red'), 49 | Generic.Inserted: ('darkgreen', 'green'), 50 | Generic.Heading: ('**', '**'), 51 | Generic.Subheading: ('*purple*', '*fuchsia*'), 52 | Generic.Error: ('red', 'red'), 53 | 54 | Error: ('_red_', '_red_'), 55 | } 56 | 57 | 58 | class TerminalFormatter(Formatter): 59 | r""" 60 | Format tokens with ANSI color sequences, for output in a text console. 61 | Color sequences are terminated at newlines, so that paging the output 62 | works correctly. 63 | 64 | The `get_style_defs()` method doesn't do anything special since there is 65 | no support for common styles. 66 | 67 | Options accepted: 68 | 69 | `bg` 70 | Set to ``"light"`` or ``"dark"`` depending on the terminal's background 71 | (default: ``"light"``). 72 | 73 | `colorscheme` 74 | A dictionary mapping token types to (lightbg, darkbg) color names or 75 | ``None`` (default: ``None`` = use builtin colorscheme). 76 | 77 | `linenos` 78 | Set to ``True`` to have line numbers on the terminal output as well 79 | (default: ``False`` = no line numbers). 80 | """ 81 | name = 'Terminal' 82 | aliases = ['terminal', 'console'] 83 | filenames = [] 84 | 85 | def __init__(self, **options): 86 | Formatter.__init__(self, **options) 87 | self.darkbg = get_choice_opt(options, 'bg', 88 | ['light', 'dark'], 'light') == 'dark' 89 | self.colorscheme = options.get('colorscheme', None) or TERMINAL_COLORS 90 | self.linenos = options.get('linenos', False) 91 | self._lineno = 0 92 | 93 | def format(self, tokensource, outfile): 94 | # hack: if the output is a terminal and has an encoding set, 95 | # use that to avoid unicode encode problems 96 | if not self.encoding and hasattr(outfile, "encoding") and \ 97 | hasattr(outfile, "isatty") and outfile.isatty() and \ 98 | sys.version_info < (3,): 99 | self.encoding = outfile.encoding 100 | return Formatter.format(self, tokensource, outfile) 101 | 102 | def _write_lineno(self, outfile): 103 | self._lineno += 1 104 | outfile.write("\n%04d: " % self._lineno) 105 | 106 | def _format_unencoded_with_lineno(self, tokensource, outfile): 107 | self._write_lineno(outfile) 108 | 109 | for ttype, value in tokensource: 110 | if value.endswith("\n"): 111 | self._write_lineno(outfile) 112 | value = value[:-1] 113 | color = self.colorscheme.get(ttype) 114 | while color is None: 115 | ttype = ttype[:-1] 116 | color = self.colorscheme.get(ttype) 117 | if color: 118 | color = color[self.darkbg] 119 | spl = value.split('\n') 120 | for line in spl[:-1]: 121 | self._write_lineno(outfile) 122 | if line: 123 | outfile.write(ansiformat(color, line[:-1])) 124 | if spl[-1]: 125 | outfile.write(ansiformat(color, spl[-1])) 126 | else: 127 | outfile.write(value) 128 | 129 | outfile.write("\n") 130 | 131 | def format_unencoded(self, tokensource, outfile): 132 | if self.linenos: 133 | self._format_unencoded_with_lineno(tokensource, outfile) 134 | return 135 | 136 | for ttype, value in tokensource: 137 | color = self.colorscheme.get(ttype) 138 | while color is None: 139 | ttype = ttype[:-1] 140 | color = self.colorscheme.get(ttype) 141 | if color: 142 | color = color[self.darkbg] 143 | spl = value.split('\n') 144 | for line in spl[:-1]: 145 | if line: 146 | outfile.write(ansiformat(color, line)) 147 | outfile.write('\n') 148 | if spl[-1]: 149 | outfile.write(ansiformat(color, spl[-1])) 150 | else: 151 | outfile.write(value) 152 | -------------------------------------------------------------------------------- /pygments/lexers/agile.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.lexers.agile 4 | ~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Just export lexer classes previously contained in this module. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | from pygments.lexers.lisp import SchemeLexer 13 | from pygments.lexers.jvm import IokeLexer, ClojureLexer 14 | from pygments.lexers.python import PythonLexer, PythonConsoleLexer, \ 15 | PythonTracebackLexer, Python3Lexer, Python3TracebackLexer, DgLexer 16 | from pygments.lexers.ruby import RubyLexer, RubyConsoleLexer, FancyLexer 17 | from pygments.lexers.perl import PerlLexer, Perl6Lexer 18 | from pygments.lexers.d import CrocLexer, MiniDLexer 19 | from pygments.lexers.iolang import IoLexer 20 | from pygments.lexers.tcl import TclLexer 21 | from pygments.lexers.factor import FactorLexer 22 | from pygments.lexers.scripting import LuaLexer, MoonScriptLexer 23 | 24 | __all__ = [] 25 | -------------------------------------------------------------------------------- /pygments/lexers/ambient.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.lexers.ambient 4 | ~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Lexers for AmbientTalk language. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | import re 13 | 14 | from pygments.lexer import RegexLexer, include, words 15 | from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ 16 | Number, Punctuation 17 | 18 | __all__ = ['AmbientTalkLexer'] 19 | 20 | 21 | class AmbientTalkLexer(RegexLexer): 22 | """ 23 | Lexer for `AmbientTalk `_ source code. 24 | 25 | .. versionadded:: 2.0 26 | """ 27 | name = 'AmbientTalk' 28 | filenames = ['*.at'] 29 | aliases = ['at', 'ambienttalk', 'ambienttalk/2'] 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+', Text), 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*', Punctuation), 74 | (r'[a-zA-Z_]\w*', Name.Variable), 75 | ], 76 | } 77 | -------------------------------------------------------------------------------- /pygments/lexers/apl.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.lexers.apl 4 | ~~~~~~~~~~~~~~~~~~~ 5 | 6 | Lexers for APL. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | from pygments.lexer import RegexLexer 13 | from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ 14 | Number, Punctuation 15 | 16 | __all__ = ['APLLexer'] 17 | 18 | 19 | class APLLexer(RegexLexer): 20 | """ 21 | A simple APL lexer. 22 | 23 | .. versionadded:: 2.0 24 | """ 25 | name = 'APL' 26 | aliases = ['apl'] 27 | filenames = ['*.apl'] 28 | 29 | tokens = { 30 | 'root': [ 31 | # Whitespace 32 | # ========== 33 | (r'\s+', Text), 34 | # 35 | # Comment 36 | # ======= 37 | # '⍝' is traditional; '#' is supported by GNU APL and NGN (but not Dyalog) 38 | (u'[⍝#].*$', Comment.Single), 39 | # 40 | # Strings 41 | # ======= 42 | (r'\'((\'\')|[^\'])*\'', String.Single), 43 | (r'"(("")|[^"])*"', String.Double), # supported by NGN APL 44 | # 45 | # Punctuation 46 | # =========== 47 | # This token type is used for diamond and parenthesis 48 | # but not for bracket and ; (see below) 49 | (u'[⋄◇()]', Punctuation), 50 | # 51 | # Array indexing 52 | # ============== 53 | # Since this token type is very important in APL, it is not included in 54 | # the punctuation token type but rather in the following one 55 | (r'[\[\];]', String.Regex), 56 | # 57 | # Distinguished names 58 | # =================== 59 | # following IBM APL2 standard 60 | (u'⎕[A-Za-zΔ∆⍙][A-Za-zΔ∆⍙_¯0-9]*', Name.Function), 61 | # 62 | # Labels 63 | # ====== 64 | # following IBM APL2 standard 65 | # (u'[A-Za-zΔ∆⍙][A-Za-zΔ∆⍙_¯0-9]*:', Name.Label), 66 | # 67 | # Variables 68 | # ========= 69 | # following IBM APL2 standard 70 | (u'[A-Za-zΔ∆⍙][A-Za-zΔ∆⍙_¯0-9]*', Name.Variable), 71 | # 72 | # Numbers 73 | # ======= 74 | (u'¯?(0[Xx][0-9A-Fa-f]+|[0-9]*\.?[0-9]+([Ee][+¯]?[0-9]+)?|¯|∞)' 75 | u'([Jj]¯?(0[Xx][0-9A-Fa-f]+|[0-9]*\.?[0-9]+([Ee][+¯]?[0-9]+)?|¯|∞))?', 76 | Number), 77 | # 78 | # Operators 79 | # ========== 80 | (u'[\.\\\/⌿⍀¨⍣⍨⍠⍤∘]', Name.Attribute), # closest token type 81 | (u'[+\-×÷⌈⌊∣|⍳?*⍟○!⌹<≤=>≥≠≡≢∊⍷∪∩~∨∧⍱⍲⍴,⍪⌽⊖⍉↑↓⊂⊃⌷⍋⍒⊤⊥⍕⍎⊣⊢⍁⍂≈⌸⍯↗]', 82 | Operator), 83 | # 84 | # Constant 85 | # ======== 86 | (u'⍬', Name.Constant), 87 | # 88 | # Quad symbol 89 | # =========== 90 | (u'[⎕⍞]', Name.Variable.Global), 91 | # 92 | # Arrows left/right 93 | # ================= 94 | (u'[←→]', Keyword.Declaration), 95 | # 96 | # D-Fn 97 | # ==== 98 | (u'[⍺⍵⍶⍹∇:]', Name.Builtin.Pseudo), 99 | (r'[{}]', Keyword.Type), 100 | ], 101 | } 102 | -------------------------------------------------------------------------------- /pygments/lexers/chapel.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.lexers.chapel 4 | ~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Lexer for the Chapel language. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | from pygments.lexer import RegexLexer, bygroups, words 13 | from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ 14 | Number, Punctuation 15 | 16 | __all__ = ['ChapelLexer'] 17 | 18 | 19 | class ChapelLexer(RegexLexer): 20 | """ 21 | For `Chapel `_ source. 22 | 23 | .. versionadded:: 2.0 24 | """ 25 | name = 'Chapel' 26 | filenames = ['*.chpl'] 27 | aliases = ['chapel', 'chpl'] 28 | # mimetypes = ['text/x-chapel'] 29 | 30 | tokens = { 31 | 'root': [ 32 | (r'\n', Text), 33 | (r'\s+', Text), 34 | (r'\\\n', Text), 35 | 36 | (r'//(.*?)\n', Comment.Single), 37 | (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline), 38 | 39 | (r'(config|const|in|inout|out|param|ref|type|var)\b', 40 | Keyword.Declaration), 41 | (r'(false|nil|true)\b', Keyword.Constant), 42 | (r'(bool|complex|imag|int|opaque|range|real|string|uint)\b', 43 | Keyword.Type), 44 | (words(( 45 | 'align', 'atomic', 'begin', 'break', 'by', 'cobegin', 'coforall', 46 | 'continue', 'delete', 'dmapped', 'do', 'domain', 'else', 'enum', 47 | 'export', 'extern', 'for', 'forall', 'if', 'index', 'inline', 48 | 'iter', 'label', 'lambda', 'let', 'local', 'new', 'noinit', 'on', 49 | 'otherwise', 'pragma', 'reduce', 'return', 'scan', 'select', 50 | 'serial', 'single', 'sparse', 'subdomain', 'sync', 'then', 'use', 51 | 'when', 'where', 'while', 'with', 'yield', 'zip'), suffix=r'\b'), 52 | Keyword), 53 | (r'(proc)((?:\s|\\\s)+)', bygroups(Keyword, Text), 'procname'), 54 | (r'(class|module|record|union)(\s+)', bygroups(Keyword, Text), 55 | 'classname'), 56 | 57 | # imaginary integers 58 | (r'\d+i', Number), 59 | (r'\d+\.\d*([Ee][-+]\d+)?i', Number), 60 | (r'\.\d+([Ee][-+]\d+)?i', Number), 61 | (r'\d+[Ee][-+]\d+i', Number), 62 | 63 | # reals cannot end with a period due to lexical ambiguity with 64 | # .. operator. See reference for rationale. 65 | (r'(\d*\.\d+)([eE][+-]?[0-9]+)?i?', Number.Float), 66 | (r'\d+[eE][+-]?[0-9]+i?', Number.Float), 67 | 68 | # integer literals 69 | # -- binary 70 | (r'0[bB][01]+', Number.Bin), 71 | # -- hex 72 | (r'0[xX][0-9a-fA-F]+', Number.Hex), 73 | # -- octal 74 | (r'0[oO][0-7]+', Number.Oct), 75 | # -- decimal 76 | (r'[0-9]+', Number.Integer), 77 | 78 | # strings 79 | (r'["\'](\\\\|\\"|[^"\'])*["\']', String), 80 | 81 | # tokens 82 | (r'(=|\+=|-=|\*=|/=|\*\*=|%=|&=|\|=|\^=|&&=|\|\|=|<<=|>>=|' 83 | r'<=>|<~>|\.\.|by|#|\.\.\.|' 84 | r'&&|\|\||!|&|\||\^|~|<<|>>|' 85 | r'==|!=|<=|>=|<|>|' 86 | r'[+\-*/%]|\*\*)', Operator), 87 | (r'[:;,.?()\[\]{}]', Punctuation), 88 | 89 | # identifiers 90 | (r'[a-zA-Z_][\w$]*', Name.Other), 91 | ], 92 | 'classname': [ 93 | (r'[a-zA-Z_][\w$]*', Name.Class, '#pop'), 94 | ], 95 | 'procname': [ 96 | (r'[a-zA-Z_][\w$]*', Name.Function, '#pop'), 97 | ], 98 | } 99 | -------------------------------------------------------------------------------- /pygments/lexers/compiled.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.lexers.compiled 4 | ~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Just export lexer classes previously contained in this module. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | from pygments.lexers.jvm import JavaLexer, ScalaLexer 13 | from pygments.lexers.c_cpp import CLexer, CppLexer 14 | from pygments.lexers.d import DLexer 15 | from pygments.lexers.objective import ObjectiveCLexer, \ 16 | ObjectiveCppLexer, LogosLexer 17 | from pygments.lexers.go import GoLexer 18 | from pygments.lexers.rust import RustLexer 19 | from pygments.lexers.c_like import ECLexer, ValaLexer, CudaLexer 20 | from pygments.lexers.pascal import DelphiLexer, Modula2Lexer, 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 | 33 | __all__ = [] 34 | -------------------------------------------------------------------------------- /pygments/lexers/console.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.lexers.console 4 | ~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Lexers for misc console output. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | from pygments.lexer import RegexLexer, include, bygroups 13 | from pygments.token import Generic, Comment, String, Text, Keyword, Name, \ 14 | Punctuation, Number 15 | 16 | __all__ = ['VCTreeStatusLexer', 'PyPyLogLexer'] 17 | 18 | 19 | class VCTreeStatusLexer(RegexLexer): 20 | """ 21 | For colorizing output of version control status commands, like "hg 22 | status" or "svn status". 23 | 24 | .. versionadded:: 2.0 25 | """ 26 | name = 'VCTreeStatus' 27 | aliases = ['vctreestatus'] 28 | filenames = [] 29 | mimetypes = [] 30 | 31 | tokens = { 32 | 'root': [ 33 | (r'^A \+ C\s+', Generic.Error), 34 | (r'^A\s+\+?\s+', String), 35 | (r'^M\s+', Generic.Inserted), 36 | (r'^C\s+', Generic.Error), 37 | (r'^D\s+', Generic.Deleted), 38 | (r'^[?!]\s+', Comment.Preproc), 39 | (r' >\s+.*\n', Comment.Preproc), 40 | (r'.*\n', Text) 41 | ] 42 | } 43 | 44 | 45 | class PyPyLogLexer(RegexLexer): 46 | """ 47 | Lexer for PyPy log files. 48 | 49 | .. versionadded:: 1.5 50 | """ 51 | name = "PyPy Log" 52 | aliases = ["pypylog", "pypy"] 53 | filenames = ["*.pypylog"] 54 | mimetypes = ['application/x-pypylog'] 55 | 56 | tokens = { 57 | "root": [ 58 | (r"\[\w+\] \{jit-log-.*?$", Keyword, "jit-log"), 59 | (r"\[\w+\] \{jit-backend-counts$", Keyword, "jit-backend-counts"), 60 | include("extra-stuff"), 61 | ], 62 | "jit-log": [ 63 | (r"\[\w+\] jit-log-.*?}$", Keyword, "#pop"), 64 | (r"^\+\d+: ", Comment), 65 | (r"--end of the loop--", Comment), 66 | (r"[ifp]\d+", Name), 67 | (r"ptr\d+", Name), 68 | (r"(\()(\w+(?:\.\w+)?)(\))", 69 | bygroups(Punctuation, Name.Builtin, Punctuation)), 70 | (r"[\[\]=,()]", Punctuation), 71 | (r"(\d+\.\d+|inf|-inf)", Number.Float), 72 | (r"-?\d+", Number.Integer), 73 | (r"'.*'", String), 74 | (r"(None|descr|ConstClass|ConstPtr|TargetToken)", Name), 75 | (r"<.*?>+", Name.Builtin), 76 | (r"(label|debug_merge_point|jump|finish)", Name.Class), 77 | (r"(int_add_ovf|int_add|int_sub_ovf|int_sub|int_mul_ovf|int_mul|" 78 | r"int_floordiv|int_mod|int_lshift|int_rshift|int_and|int_or|" 79 | r"int_xor|int_eq|int_ne|int_ge|int_gt|int_le|int_lt|int_is_zero|" 80 | r"int_is_true|" 81 | r"uint_floordiv|uint_ge|uint_lt|" 82 | r"float_add|float_sub|float_mul|float_truediv|float_neg|" 83 | r"float_eq|float_ne|float_ge|float_gt|float_le|float_lt|float_abs|" 84 | r"ptr_eq|ptr_ne|instance_ptr_eq|instance_ptr_ne|" 85 | r"cast_int_to_float|cast_float_to_int|" 86 | r"force_token|quasiimmut_field|same_as|virtual_ref_finish|" 87 | r"virtual_ref|mark_opaque_ptr|" 88 | r"call_may_force|call_assembler|call_loopinvariant|" 89 | r"call_release_gil|call_pure|call|" 90 | r"new_with_vtable|new_array|newstr|newunicode|new|" 91 | r"arraylen_gc|" 92 | r"getarrayitem_gc_pure|getarrayitem_gc|setarrayitem_gc|" 93 | r"getarrayitem_raw|setarrayitem_raw|getfield_gc_pure|" 94 | r"getfield_gc|getinteriorfield_gc|setinteriorfield_gc|" 95 | r"getfield_raw|setfield_gc|setfield_raw|" 96 | r"strgetitem|strsetitem|strlen|copystrcontent|" 97 | r"unicodegetitem|unicodesetitem|unicodelen|" 98 | r"guard_true|guard_false|guard_value|guard_isnull|" 99 | r"guard_nonnull_class|guard_nonnull|guard_class|guard_no_overflow|" 100 | r"guard_not_forced|guard_no_exception|guard_not_invalidated)", 101 | Name.Builtin), 102 | include("extra-stuff"), 103 | ], 104 | "jit-backend-counts": [ 105 | (r"\[\w+\] jit-backend-counts}$", Keyword, "#pop"), 106 | (r":", Punctuation), 107 | (r"\d+", Number), 108 | include("extra-stuff"), 109 | ], 110 | "extra-stuff": [ 111 | (r"\s+", Text), 112 | (r"#.*?$", Comment), 113 | ], 114 | } 115 | -------------------------------------------------------------------------------- /pygments/lexers/dalvik.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.lexers.dalvik 4 | ~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Pygments lexers for Dalvik VM-related languages. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | import re 13 | 14 | from pygments.lexer import RegexLexer, include, bygroups 15 | from pygments.token import Keyword, Text, Comment, Name, String, Number, \ 16 | Punctuation 17 | 18 | __all__ = ['SmaliLexer'] 19 | 20 | 21 | class SmaliLexer(RegexLexer): 22 | """ 23 | For `Smali `_ (Android/Dalvik) assembly 24 | code. 25 | 26 | .. versionadded:: 1.6 27 | """ 28 | name = 'Smali' 29 | aliases = ['smali'] 30 | filenames = ['*.smali'] 31 | mimetypes = ['text/smali'] 32 | 33 | tokens = { 34 | 'root': [ 35 | include('comment'), 36 | include('label'), 37 | include('field'), 38 | include('method'), 39 | include('class'), 40 | include('directive'), 41 | include('access-modifier'), 42 | include('instruction'), 43 | include('literal'), 44 | include('punctuation'), 45 | include('type'), 46 | include('whitespace') 47 | ], 48 | 'directive': [ 49 | (r'^[ \t]*\.(class|super|implements|field|subannotation|annotation|' 50 | r'enum|method|registers|locals|array-data|packed-switch|' 51 | r'sparse-switch|catchall|catch|line|parameter|local|prologue|' 52 | r'epilogue|source)', Keyword), 53 | (r'^[ \t]*\.end (field|subannotation|annotation|method|array-data|' 54 | 'packed-switch|sparse-switch|parameter|local)', Keyword), 55 | (r'^[ \t]*\.restart local', Keyword), 56 | ], 57 | 'access-modifier': [ 58 | (r'(public|private|protected|static|final|synchronized|bridge|' 59 | r'varargs|native|abstract|strictfp|synthetic|constructor|' 60 | r'declared-synchronized|interface|enum|annotation|volatile|' 61 | r'transient)', Keyword), 62 | ], 63 | 'whitespace': [ 64 | (r'\n', Text), 65 | (r'\s+', Text), 66 | ], 67 | 'instruction': [ 68 | (r'\b[vp]\d+\b', Name.Builtin), # registers 69 | (r'\b[a-z][A-Za-z0-9/-]+\s+', Text), # instructions 70 | ], 71 | 'literal': [ 72 | (r'".*"', String), 73 | (r'0x[0-9A-Fa-f]+t?', Number.Hex), 74 | (r'[0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), 75 | (r'[0-9]+L?', Number.Integer), 76 | ], 77 | 'field': [ 78 | (r'(\$?\b)([\w$]*)(:)', 79 | bygroups(Punctuation, Name.Variable, Punctuation)), 80 | ], 81 | 'method': [ 82 | (r'<(?:cl)?init>', Name.Function), # constructor 83 | (r'(\$?\b)([\w$]*)(\()', 84 | bygroups(Punctuation, Name.Function, Punctuation)), 85 | ], 86 | 'label': [ 87 | (r':\w+', Name.Label), 88 | ], 89 | 'class': [ 90 | # class names in the form Lcom/namespace/ClassName; 91 | # I only want to color the ClassName part, so the namespace part is 92 | # treated as 'Text' 93 | (r'(L)((?:[\w$]+/)*)([\w$]+)(;)', 94 | bygroups(Keyword.Type, Text, Name.Class, Text)), 95 | ], 96 | 'punctuation': [ 97 | (r'->', Punctuation), 98 | (r'[{},():=.-]', Punctuation), 99 | ], 100 | 'type': [ 101 | (r'[ZBSCIJFDV\[]+', Keyword.Type), 102 | ], 103 | 'comment': [ 104 | (r'#.*?\n', Comment), 105 | ], 106 | } 107 | 108 | def analyse_text(text): 109 | score = 0 110 | if re.search(r'^\s*\.class\s', text, re.MULTILINE): 111 | score += 0.5 112 | if re.search(r'\b((check-cast|instance-of|throw-verification-error' 113 | r')\b|(-to|add|[ais]get|[ais]put|and|cmpl|const|div|' 114 | r'if|invoke|move|mul|neg|not|or|rem|return|rsub|shl|' 115 | r'shr|sub|ushr)[-/])|{|}', text, re.MULTILINE): 116 | score += 0.3 117 | if re.search(r'(\.(catchall|epilogue|restart local|prologue)|' 118 | r'\b(array-data|class-change-error|declared-synchronized|' 119 | r'(field|inline|vtable)@0x[0-9a-fA-F]|generic-error|' 120 | r'illegal-class-access|illegal-field-access|' 121 | r'illegal-method-access|instantiation-error|no-error|' 122 | r'no-such-class|no-such-field|no-such-method|' 123 | r'packed-switch|sparse-switch))\b', text, re.MULTILINE): 124 | score += 0.6 125 | return score 126 | -------------------------------------------------------------------------------- /pygments/lexers/diff.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.lexers.diff 4 | ~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Lexers for diff/patch formats. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | from pygments.lexer import RegexLexer, include, bygroups 13 | from pygments.token import Text, Comment, Operator, Keyword, Name, Generic, \ 14 | Literal 15 | 16 | __all__ = ['DiffLexer', 'DarcsPatchLexer'] 17 | 18 | 19 | class DiffLexer(RegexLexer): 20 | """ 21 | Lexer for unified or context-style diffs or patches. 22 | """ 23 | 24 | name = 'Diff' 25 | aliases = ['diff', 'udiff'] 26 | filenames = ['*.diff', '*.patch'] 27 | mimetypes = ['text/x-diff', 'text/x-patch'] 28 | 29 | tokens = { 30 | 'root': [ 31 | (r' .*\n', Text), 32 | (r'\+.*\n', Generic.Inserted), 33 | (r'-.*\n', Generic.Deleted), 34 | (r'!.*\n', Generic.Strong), 35 | (r'@.*\n', Generic.Subheading), 36 | (r'([Ii]ndex|diff).*\n', Generic.Heading), 37 | (r'=.*\n', Generic.Heading), 38 | (r'.*\n', Text), 39 | ] 40 | } 41 | 42 | def analyse_text(text): 43 | if text[:7] == 'Index: ': 44 | return True 45 | if text[:5] == 'diff ': 46 | return True 47 | if text[:4] == '--- ': 48 | return 0.9 49 | 50 | 51 | class DarcsPatchLexer(RegexLexer): 52 | """ 53 | DarcsPatchLexer is a lexer for the various versions of the darcs patch 54 | format. Examples of this format are derived by commands such as 55 | ``darcs annotate --patch`` and ``darcs send``. 56 | 57 | .. versionadded:: 0.10 58 | """ 59 | 60 | name = 'Darcs Patch' 61 | aliases = ['dpatch'] 62 | filenames = ['*.dpatch', '*.darcspatch'] 63 | 64 | DPATCH_KEYWORDS = ('hunk', 'addfile', 'adddir', 'rmfile', 'rmdir', 'move', 65 | 'replace') 66 | 67 | tokens = { 68 | 'root': [ 69 | (r'<', Operator), 70 | (r'>', Operator), 71 | (r'\{', Operator), 72 | (r'\}', Operator), 73 | (r'(\[)((?:TAG )?)(.*)(\n)(.*)(\*\*)(\d+)(\s?)(\])', 74 | bygroups(Operator, Keyword, Name, Text, Name, Operator, 75 | Literal.Date, Text, Operator)), 76 | (r'(\[)((?:TAG )?)(.*)(\n)(.*)(\*\*)(\d+)(\s?)', 77 | bygroups(Operator, Keyword, Name, Text, Name, Operator, 78 | Literal.Date, Text), 'comment'), 79 | (r'New patches:', Generic.Heading), 80 | (r'Context:', Generic.Heading), 81 | (r'Patch bundle hash:', Generic.Heading), 82 | (r'(\s*)(%s)(.*\n)' % '|'.join(DPATCH_KEYWORDS), 83 | bygroups(Text, Keyword, Text)), 84 | (r'\+', Generic.Inserted, "insert"), 85 | (r'-', Generic.Deleted, "delete"), 86 | (r'.*\n', Text), 87 | ], 88 | 'comment': [ 89 | (r'[^\]].*\n', Comment), 90 | (r'\]', Operator, "#pop"), 91 | ], 92 | 'specialText': [ # darcs add [_CODE_] special operators for clarity 93 | (r'\n', Text, "#pop"), # line-based 94 | (r'\[_[^_]*_]', Operator), 95 | ], 96 | 'insert': [ 97 | include('specialText'), 98 | (r'\[', Generic.Inserted), 99 | (r'[^\n\[]+', Generic.Inserted), 100 | ], 101 | 'delete': [ 102 | include('specialText'), 103 | (r'\[', Generic.Deleted), 104 | (r'[^\n\[]+', Generic.Deleted), 105 | ], 106 | } 107 | -------------------------------------------------------------------------------- /pygments/lexers/eiffel.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.lexers.eiffel 4 | ~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Lexer for the Eiffel language. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | from pygments.lexer import RegexLexer, include, words 13 | from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ 14 | Number, Punctuation 15 | 16 | __all__ = ['EiffelLexer'] 17 | 18 | 19 | class EiffelLexer(RegexLexer): 20 | """ 21 | For `Eiffel `_ source code. 22 | 23 | .. versionadded:: 2.0 24 | """ 25 | name = 'Eiffel' 26 | aliases = ['eiffel'] 27 | filenames = ['*.e'] 28 | mimetypes = ['text/x-eiffel'] 29 | 30 | tokens = { 31 | 'root': [ 32 | (r'[^\S\n]+', Text), 33 | (r'--.*?\n', Comment.Single), 34 | (r'[^\S\n]+', Text), 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)(and(\s+then)?|not|xor|implies|or(\s+else)?)\b', Operator.Word), 38 | (words(( 39 | 'across', 'agent', 'alias', 'all', 'as', 'assign', 'attached', 40 | 'attribute', 'check', 'class', 'convert', 'create', 'debug', 41 | 'deferred', 'detachable', 'do', 'else', 'elseif', 'end', 'ensure', 42 | 'expanded', 'export', 'external', 'feature', 'from', 'frozen', 'if', 43 | 'inherit', 'inspect', 'invariant', 'like', 'local', 'loop', 'none', 44 | 'note', 'obsolete', 'old', 'once', 'only', 'redefine', 'rename', 45 | 'require', 'rescue', 'retry', 'select', 'separate', 'then', 46 | 'undefine', 'until', 'variant', 'when'), prefix=r'(?i)\b', suffix=r'\b'), 47 | Keyword.Reserved), 48 | (r'"\[(([^\]%]|\n)|%(.|\n)|\][^"])*?\]"', String), 49 | (r'"([^"%\n]|%.)*?"', String), 50 | include('numbers'), 51 | (r"'([^'%]|%'|%%)'", String.Char), 52 | (r"(//|\\\\|>=|<=|:=|/=|~|/~|[\\?!#%&@|+/\-=>*$<^\[\]])", Operator), 53 | (r"([{}():;,.])", Punctuation), 54 | (r'([a-z]\w*)|([A-Z][A-Z0-9_]*[a-z]\w*)', Name), 55 | (r'([A-Z][A-Z0-9_]*)', Name.Class), 56 | (r'\n+', Text), 57 | ], 58 | 'numbers': [ 59 | (r'0[xX][a-fA-F0-9]+', Number.Hex), 60 | (r'0[bB][01]+', Number.Bin), 61 | (r'0[cC][0-7]+', Number.Oct), 62 | (r'([0-9]+\.[0-9]*)|([0-9]*\.[0-9]+)', Number.Float), 63 | (r'[0-9]+', Number.Integer), 64 | ], 65 | } 66 | -------------------------------------------------------------------------------- /pygments/lexers/esoteric.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.lexers.esoteric 4 | ~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Lexers for esoteric languages. 7 | 8 | :copyright: Copyright 2006-2015 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 Text, Comment, Operator, Keyword, Name, String, \ 14 | Number, Punctuation, Error 15 | 16 | __all__ = ['BrainfuckLexer', 'BefungeLexer', 'RedcodeLexer'] 17 | 18 | 19 | class BrainfuckLexer(RegexLexer): 20 | """ 21 | Lexer for the esoteric `BrainFuck `_ 22 | language. 23 | """ 24 | 25 | name = 'Brainfuck' 26 | aliases = ['brainfuck', 'bf'] 27 | filenames = ['*.bf', '*.b'] 28 | mimetypes = ['application/x-brainfuck'] 29 | 30 | tokens = { 31 | 'common': [ 32 | # use different colors for different instruction types 33 | (r'[.,]+', Name.Tag), 34 | (r'[+-]+', Name.Builtin), 35 | (r'[<>]+', Name.Variable), 36 | (r'[^.,+\-<>\[\]]+', Comment), 37 | ], 38 | 'root': [ 39 | (r'\[', Keyword, 'loop'), 40 | (r'\]', Error), 41 | include('common'), 42 | ], 43 | 'loop': [ 44 | (r'\[', Keyword, '#push'), 45 | (r'\]', Keyword, '#pop'), 46 | include('common'), 47 | ] 48 | } 49 | 50 | 51 | class BefungeLexer(RegexLexer): 52 | """ 53 | Lexer for the esoteric `Befunge `_ 54 | language. 55 | 56 | .. versionadded:: 0.7 57 | """ 58 | name = 'Befunge' 59 | aliases = ['befunge'] 60 | filenames = ['*.befunge'] 61 | mimetypes = ['application/x-befunge'] 62 | 63 | tokens = { 64 | 'root': [ 65 | (r'[0-9a-f]', Number), 66 | (r'[+*/%!`-]', Operator), # Traditional math 67 | (r'[<>^v?\[\]rxjk]', Name.Variable), # Move, imperatives 68 | (r'[:\\$.,n]', Name.Builtin), # Stack ops, imperatives 69 | (r'[|_mw]', Keyword), 70 | (r'[{}]', Name.Tag), # Befunge-98 stack ops 71 | (r'".*?"', String.Double), # Strings don't appear to allow escapes 72 | (r'\'.', String.Single), # Single character 73 | (r'[#;]', Comment), # Trampoline... depends on direction hit 74 | (r'[pg&~=@iotsy]', Keyword), # Misc 75 | (r'[()A-Z]', Comment), # Fingerprints 76 | (r'\s+', Text), # Whitespace doesn't matter 77 | ], 78 | } 79 | 80 | 81 | class RedcodeLexer(RegexLexer): 82 | """ 83 | A simple Redcode lexer based on ICWS'94. 84 | Contributed by Adam Blinkinsop . 85 | 86 | .. versionadded:: 0.8 87 | """ 88 | name = 'Redcode' 89 | aliases = ['redcode'] 90 | filenames = ['*.cw'] 91 | 92 | opcodes = ('DAT', 'MOV', 'ADD', 'SUB', 'MUL', 'DIV', 'MOD', 93 | 'JMP', 'JMZ', 'JMN', 'DJN', 'CMP', 'SLT', 'SPL', 94 | 'ORG', 'EQU', 'END') 95 | modifiers = ('A', 'B', 'AB', 'BA', 'F', 'X', 'I') 96 | 97 | tokens = { 98 | 'root': [ 99 | # Whitespace: 100 | (r'\s+', Text), 101 | (r';.*$', Comment.Single), 102 | # Lexemes: 103 | # Identifiers 104 | (r'\b(%s)\b' % '|'.join(opcodes), Name.Function), 105 | (r'\b(%s)\b' % '|'.join(modifiers), Name.Decorator), 106 | (r'[A-Za-z_]\w+', Name), 107 | # Operators 108 | (r'[-+*/%]', Operator), 109 | (r'[#$@<>]', Operator), # mode 110 | (r'[.,]', Punctuation), # mode 111 | # Numbers 112 | (r'[-+]?\d+', Number.Integer), 113 | ], 114 | } 115 | -------------------------------------------------------------------------------- /pygments/lexers/functional.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.lexers.functional 4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Just export lexer classes previously contained in this module. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | from pygments.lexers.lisp import SchemeLexer, CommonLispLexer, RacketLexer, \ 13 | NewLispLexer 14 | from pygments.lexers.haskell import HaskellLexer, LiterateHaskellLexer, \ 15 | KokaLexer 16 | from pygments.lexers.theorem import CoqLexer 17 | from pygments.lexers.erlang import ErlangLexer, ErlangShellLexer, \ 18 | ElixirConsoleLexer, ElixirLexer 19 | from pygments.lexers.ml import SMLLexer, OcamlLexer, OpaLexer 20 | 21 | __all__ = [] 22 | -------------------------------------------------------------------------------- /pygments/lexers/go.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.lexers.go 4 | ~~~~~~~~~~~~~~~~~~ 5 | 6 | Lexers for the Google Go language. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | import re 13 | 14 | from pygments.lexer import RegexLexer, bygroups, words 15 | from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ 16 | Number, Punctuation 17 | 18 | __all__ = ['GoLexer'] 19 | 20 | 21 | class GoLexer(RegexLexer): 22 | """ 23 | For `Go `_ source. 24 | 25 | .. versionadded:: 1.2 26 | """ 27 | name = 'Go' 28 | filenames = ['*.go'] 29 | aliases = ['go'] 30 | mimetypes = ['text/x-gosrc'] 31 | 32 | flags = re.MULTILINE | re.UNICODE 33 | 34 | tokens = { 35 | 'root': [ 36 | (r'\n', Text), 37 | (r'\s+', Text), 38 | (r'\\\n', Text), # line continuations 39 | (r'//(.*?)\n', Comment.Single), 40 | (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline), 41 | (r'(import|package)\b', Keyword.Namespace), 42 | (r'(var|func|struct|map|chan|type|interface|const)\b', 43 | Keyword.Declaration), 44 | (words(( 45 | 'break', 'default', 'select', 'case', 'defer', 'go', 46 | 'else', 'goto', 'switch', 'fallthrough', 'if', 'range', 47 | 'continue', 'for', 'return'), suffix=r'\b'), 48 | Keyword), 49 | (r'(true|false|iota|nil)\b', Keyword.Constant), 50 | # It seems the builtin types aren't actually keywords, but 51 | # can be used as functions. So we need two declarations. 52 | (words(( 53 | 'uint', 'uint8', 'uint16', 'uint32', 'uint64', 54 | 'int', 'int8', 'int16', 'int32', 'int64', 55 | 'float', 'float32', 'float64', 56 | 'complex64', 'complex128', 'byte', 'rune', 57 | 'string', 'bool', 'error', 'uintptr', 58 | 'print', 'println', 'panic', 'recover', 'close', 'complex', 59 | 'real', 'imag', 'len', 'cap', 'append', 'copy', 'delete', 60 | 'new', 'make'), suffix=r'\b(\()'), 61 | bygroups(Name.Builtin, Punctuation)), 62 | (words(( 63 | 'uint', 'uint8', 'uint16', 'uint32', 'uint64', 64 | 'int', 'int8', 'int16', 'int32', 'int64', 65 | 'float', 'float32', 'float64', 66 | 'complex64', 'complex128', 'byte', 'rune', 67 | 'string', 'bool', 'error', 'uintptr'), suffix=r'\b'), 68 | Keyword.Type), 69 | # imaginary_lit 70 | (r'\d+i', Number), 71 | (r'\d+\.\d*([Ee][-+]\d+)?i', Number), 72 | (r'\.\d+([Ee][-+]\d+)?i', Number), 73 | (r'\d+[Ee][-+]\d+i', Number), 74 | # float_lit 75 | (r'\d+(\.\d+[eE][+\-]?\d+|' 76 | r'\.\d*|[eE][+\-]?\d+)', Number.Float), 77 | (r'\.\d+([eE][+\-]?\d+)?', Number.Float), 78 | # int_lit 79 | # -- octal_lit 80 | (r'0[0-7]+', Number.Oct), 81 | # -- hex_lit 82 | (r'0[xX][0-9a-fA-F]+', Number.Hex), 83 | # -- decimal_lit 84 | (r'(0|[1-9][0-9]*)', Number.Integer), 85 | # char_lit 86 | (r"""'(\\['"\\abfnrtv]|\\x[0-9a-fA-F]{2}|\\[0-7]{1,3}""" 87 | r"""|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|[^\\])'""", 88 | String.Char), 89 | # StringLiteral 90 | # -- raw_string_lit 91 | (r'`[^`]*`', String), 92 | # -- interpreted_string_lit 93 | (r'"(\\\\|\\"|[^"])*"', String), 94 | # Tokens 95 | (r'(<<=|>>=|<<|>>|<=|>=|&\^=|&\^|\+=|-=|\*=|/=|%=|&=|\|=|&&|\|\|' 96 | r'|<-|\+\+|--|==|!=|:=|\.\.\.|[+\-*/%&])', Operator), 97 | (r'[|^<>=!()\[\]{}.,;:]', Punctuation), 98 | # identifier 99 | (r'[^\W\d]\w*', Name.Other), 100 | ] 101 | } 102 | -------------------------------------------------------------------------------- /pygments/lexers/graph.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.lexers.graph 4 | ~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Lexers for graph query languages. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | import re 13 | 14 | from pygments.lexer import RegexLexer, include, bygroups, using, this 15 | from pygments.token import Keyword, Punctuation, Comment, Operator, Name,\ 16 | String, Number, Whitespace 17 | 18 | 19 | __all__ = ['CypherLexer'] 20 | 21 | 22 | class CypherLexer(RegexLexer): 23 | """ 24 | For `Cypher Query Language 25 | `_ 26 | 27 | For the Cypher version in Neo4J 2.0 28 | 29 | .. versionadded:: 2.0 30 | """ 31 | name = 'Cypher' 32 | aliases = ['cypher'] 33 | filenames = ['*.cyp', '*.cypher'] 34 | 35 | flags = re.MULTILINE | re.IGNORECASE 36 | 37 | tokens = { 38 | 'root': [ 39 | include('comment'), 40 | include('keywords'), 41 | include('clauses'), 42 | include('relations'), 43 | include('strings'), 44 | include('whitespace'), 45 | include('barewords'), 46 | ], 47 | 'comment': [ 48 | (r'^.*//.*\n', Comment.Single), 49 | ], 50 | 'keywords': [ 51 | (r'(create|order|match|limit|set|skip|start|return|with|where|' 52 | r'delete|foreach|not|by)\b', Keyword), 53 | ], 54 | 'clauses': [ 55 | # TODO: many missing ones, see http://docs.neo4j.org/refcard/2.0/ 56 | (r'(all|any|as|asc|create|create\s+unique|delete|' 57 | r'desc|distinct|foreach|in|is\s+null|limit|match|none|' 58 | r'order\s+by|return|set|skip|single|start|union|where|with)\b', 59 | Keyword), 60 | ], 61 | 'relations': [ 62 | (r'(-\[)(.*?)(\]->)', bygroups(Operator, using(this), Operator)), 63 | (r'(<-\[)(.*?)(\]-)', bygroups(Operator, using(this), Operator)), 64 | (r'-->|<--|\[|\]', Operator), 65 | (r'<|>|<>|=|<=|=>|\(|\)|\||:|,|;', Punctuation), 66 | (r'[.*{}]', Punctuation), 67 | ], 68 | 'strings': [ 69 | (r'"(?:\\[tbnrf\'"\\]|[^\\"])*"', String), 70 | (r'`(?:``|[^`])+`', Name.Variable), 71 | ], 72 | 'whitespace': [ 73 | (r'\s+', Whitespace), 74 | ], 75 | 'barewords': [ 76 | (r'[a-z]\w*', Name), 77 | (r'\d+', Number), 78 | ], 79 | } 80 | -------------------------------------------------------------------------------- /pygments/lexers/inferno.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.lexers.inferno 4 | ~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Lexers for Inferno os and all the related stuff. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | import re 13 | 14 | from pygments.lexer import RegexLexer, include, bygroups, default 15 | from pygments.token import Punctuation, Text, Comment, Operator, Keyword, \ 16 | Name, String, Number 17 | 18 | __all__ = ['LimboLexer'] 19 | 20 | 21 | class LimboLexer(RegexLexer): 22 | """ 23 | Lexer for `Limbo programming language `_ 24 | 25 | TODO: 26 | - maybe implement better var declaration highlighting 27 | - some simple syntax error highlighting 28 | 29 | .. versionadded:: 2.0 30 | """ 31 | name = 'Limbo' 32 | aliases = ['limbo'] 33 | filenames = ['*.b'] 34 | mimetypes = ['text/limbo'] 35 | 36 | tokens = { 37 | 'whitespace': [ 38 | (r'^(\s*)([a-zA-Z_]\w*:(\s*)\n)', 39 | bygroups(Text, Name.Label)), 40 | (r'\n', Text), 41 | (r'\s+', Text), 42 | (r'#(\n|(.|\n)*?[^\\]\n)', Comment.Single), 43 | ], 44 | 'string': [ 45 | (r'"', String, '#pop'), 46 | (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|' 47 | r'u[a-fA-F0-9]{4}|U[a-fA-F0-9]{8}|[0-7]{1,3})', String.Escape), 48 | (r'[^\\"\n]+', String), # all other characters 49 | (r'\\', String), # stray backslash 50 | ], 51 | 'statements': [ 52 | (r'"', String, 'string'), 53 | (r"'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", String.Char), 54 | (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+', Number.Float), 55 | (r'(\d+\.\d*|\.\d+|\d+[fF])', Number.Float), 56 | (r'16r[0-9a-fA-F]+', Number.Hex), 57 | (r'8r[0-7]+', Number.Oct), 58 | (r'((([1-3]\d)|([2-9]))r)?(\d+)', Number.Integer), 59 | (r'[()\[\],.]', Punctuation), 60 | (r'[~!%^&*+=|?:<>/-]|(->)|(<-)|(=>)|(::)', Operator), 61 | (r'(alt|break|case|continue|cyclic|do|else|exit' 62 | r'for|hd|if|implement|import|include|len|load|or' 63 | r'pick|return|spawn|tagof|tl|to|while)\b', Keyword), 64 | (r'(byte|int|big|real|string|array|chan|list|adt' 65 | r'|fn|ref|of|module|self|type)\b', Keyword.Type), 66 | (r'(con|iota|nil)\b', Keyword.Constant), 67 | ('[a-zA-Z_]\w*', Name), 68 | ], 69 | 'statement' : [ 70 | include('whitespace'), 71 | include('statements'), 72 | ('[{}]', Punctuation), 73 | (';', Punctuation, '#pop'), 74 | ], 75 | 'root': [ 76 | include('whitespace'), 77 | default('statement'), 78 | ], 79 | } 80 | 81 | def analyse_text(text): 82 | # Any limbo module implements something 83 | if re.search(r'^implement \w+;', text, re.MULTILINE): 84 | return 0.7 85 | 86 | # TODO: 87 | # - Make lexers for: 88 | # - asm sources 89 | # - man pages 90 | # - mkfiles 91 | # - module definitions 92 | # - namespace definitions 93 | # - shell scripts 94 | # - maybe keyfiles and fonts 95 | # they all seem to be quite similar to their equivalents 96 | # from unix world, so there should not be a lot of problems 97 | -------------------------------------------------------------------------------- /pygments/lexers/iolang.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.lexers.iolang 4 | ~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Lexers for the Io language. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | from pygments.lexer import RegexLexer 13 | from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ 14 | Number 15 | 16 | __all__ = ['IoLexer'] 17 | 18 | 19 | class IoLexer(RegexLexer): 20 | """ 21 | For `Io `_ (a small, prototype-based 22 | programming language) source. 23 | 24 | .. versionadded:: 0.10 25 | """ 26 | name = 'Io' 27 | filenames = ['*.io'] 28 | aliases = ['io'] 29 | mimetypes = ['text/x-iosrc'] 30 | tokens = { 31 | 'root': [ 32 | (r'\n', Text), 33 | (r'\s+', Text), 34 | # Comments 35 | (r'//(.*?)\n', Comment.Single), 36 | (r'#(.*?)\n', Comment.Single), 37 | (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline), 38 | (r'/\+', Comment.Multiline, 'nestedcomment'), 39 | # DoubleQuotedString 40 | (r'"(\\\\|\\"|[^"])*"', String), 41 | # Operators 42 | (r'::=|:=|=|\(|\)|;|,|\*|-|\+|>|<|@|!|/|\||\^|\.|%|&|\[|\]|\{|\}', 43 | Operator), 44 | # keywords 45 | (r'(clone|do|doFile|doString|method|for|if|else|elseif|then)\b', 46 | Keyword), 47 | # constants 48 | (r'(nil|false|true)\b', Name.Constant), 49 | # names 50 | (r'(Object|list|List|Map|args|Sequence|Coroutine|File)\b', 51 | Name.Builtin), 52 | ('[a-zA-Z_]\w*', Name), 53 | # numbers 54 | (r'(\d+\.?\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float), 55 | (r'\d+', Number.Integer) 56 | ], 57 | 'nestedcomment': [ 58 | (r'[^+/]+', Comment.Multiline), 59 | (r'/\+', Comment.Multiline, '#push'), 60 | (r'\+/', Comment.Multiline, '#pop'), 61 | (r'[+/]', Comment.Multiline), 62 | ] 63 | } 64 | -------------------------------------------------------------------------------- /pygments/lexers/math.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.lexers.math 4 | ~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Just export lexers that were contained in this module. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | from pygments.lexers.python import NumPyLexer 13 | from pygments.lexers.matlab import MatlabLexer, MatlabSessionLexer, \ 14 | OctaveLexer, ScilabLexer 15 | from pygments.lexers.julia import JuliaLexer, JuliaConsoleLexer 16 | from pygments.lexers.r import RConsoleLexer, SLexer, RdLexer 17 | from pygments.lexers.modeling import BugsLexer, JagsLexer, StanLexer 18 | from pygments.lexers.idl import IDLLexer 19 | from pygments.lexers.algebra import MuPADLexer 20 | 21 | __all__ = [] 22 | -------------------------------------------------------------------------------- /pygments/lexers/nimrod.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.lexers.nimrod 4 | ~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Lexer for the Nimrod language. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | import re 13 | 14 | from pygments.lexer import RegexLexer, include, default 15 | from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ 16 | Number, Punctuation, Error 17 | 18 | __all__ = ['NimrodLexer'] 19 | 20 | 21 | class NimrodLexer(RegexLexer): 22 | """ 23 | For `Nimrod `_ source code. 24 | 25 | .. versionadded:: 1.5 26 | """ 27 | 28 | name = 'Nimrod' 29 | aliases = ['nimrod', 'nim'] 30 | filenames = ['*.nim', '*.nimrod'] 31 | mimetypes = ['text/x-nimrod'] 32 | 33 | flags = re.MULTILINE | re.IGNORECASE | re.UNICODE 34 | 35 | def underscorize(words): 36 | newWords = [] 37 | new = "" 38 | for word in words: 39 | for ch in word: 40 | new += (ch + "_?") 41 | newWords.append(new) 42 | new = "" 43 | return "|".join(newWords) 44 | 45 | keywords = [ 46 | 'addr', 'and', 'as', 'asm', 'atomic', 'bind', 'block', 'break', 47 | 'case', 'cast', 'const', 'continue', 'converter', 'discard', 48 | 'distinct', 'div', 'elif', 'else', 'end', 'enum', 'except', 'finally', 49 | 'for', 'generic', 'if', 'implies', 'in', 'yield', 50 | 'is', 'isnot', 'iterator', 'lambda', 'let', 'macro', 'method', 51 | 'mod', 'not', 'notin', 'object', 'of', 'or', 'out', 'proc', 52 | 'ptr', 'raise', 'ref', 'return', 'shl', 'shr', 'template', 'try', 53 | 'tuple', 'type', 'when', 'while', 'with', 'without', 'xor' 54 | ] 55 | 56 | keywordsPseudo = [ 57 | 'nil', 'true', 'false' 58 | ] 59 | 60 | opWords = [ 61 | 'and', 'or', 'not', 'xor', 'shl', 'shr', 'div', 'mod', 'in', 62 | 'notin', 'is', 'isnot' 63 | ] 64 | 65 | types = [ 66 | 'int', 'int8', 'int16', 'int32', 'int64', 'float', 'float32', 'float64', 67 | 'bool', 'char', 'range', 'array', 'seq', 'set', 'string' 68 | ] 69 | 70 | tokens = { 71 | 'root': [ 72 | (r'##.*$', String.Doc), 73 | (r'#.*$', Comment), 74 | (r'[*=><+\-/@$~&%!?|\\\[\]]', Operator), 75 | (r'\.\.|\.|,|\[\.|\.\]|\{\.|\.\}|\(\.|\.\)|\{|\}|\(|\)|:|\^|`|;', 76 | Punctuation), 77 | 78 | # Strings 79 | (r'(?:[\w]+)"', String, 'rdqs'), 80 | (r'"""', String, 'tdqs'), 81 | ('"', String, 'dqs'), 82 | 83 | # Char 84 | ("'", String.Char, 'chars'), 85 | 86 | # Keywords 87 | (r'(%s)\b' % underscorize(opWords), Operator.Word), 88 | (r'(p_?r_?o_?c_?\s)(?![(\[\]])', Keyword, 'funcname'), 89 | (r'(%s)\b' % underscorize(keywords), Keyword), 90 | (r'(%s)\b' % underscorize(['from', 'import', 'include']), 91 | Keyword.Namespace), 92 | (r'(v_?a_?r)\b', Keyword.Declaration), 93 | (r'(%s)\b' % underscorize(types), Keyword.Type), 94 | (r'(%s)\b' % underscorize(keywordsPseudo), Keyword.Pseudo), 95 | # Identifiers 96 | (r'\b((?![_\d])\w)(((?!_)\w)|(_(?!_)\w))*', Name), 97 | # Numbers 98 | (r'[0-9][0-9_]*(?=([e.]|\'f(32|64)))', 99 | Number.Float, ('float-suffix', 'float-number')), 100 | (r'0x[a-f0-9][a-f0-9_]*', Number.Hex, 'int-suffix'), 101 | (r'0b[01][01_]*', Number.Bin, 'int-suffix'), 102 | (r'0o[0-7][0-7_]*', Number.Oct, 'int-suffix'), 103 | (r'[0-9][0-9_]*', Number.Integer, 'int-suffix'), 104 | # Whitespace 105 | (r'\s+', Text), 106 | (r'.+$', Error), 107 | ], 108 | 'chars': [ 109 | (r'\\([\\abcefnrtvl"\']|x[a-f0-9]{2}|[0-9]{1,3})', String.Escape), 110 | (r"'", String.Char, '#pop'), 111 | (r".", String.Char) 112 | ], 113 | 'strings': [ 114 | (r'(?`_ source. 22 | 23 | .. versionadded:: 2.0 24 | """ 25 | 26 | name = 'Nit' 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/nix.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.lexers.nix 4 | ~~~~~~~~~~~~~~~~~~~ 5 | 6 | Lexers for the NixOS Nix language. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | import re 13 | 14 | from pygments.lexer import RegexLexer, include 15 | from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ 16 | Number, Punctuation, Literal 17 | 18 | __all__ = ['NixLexer'] 19 | 20 | 21 | class NixLexer(RegexLexer): 22 | """ 23 | For the `Nix language `_. 24 | 25 | .. versionadded:: 2.0 26 | """ 27 | 28 | name = 'Nix' 29 | aliases = ['nixos', 'nix'] 30 | filenames = ['*.nix'] 31 | mimetypes = ['text/x-nix'] 32 | 33 | flags = re.MULTILINE | re.UNICODE 34 | 35 | keywords = ['rec', 'with', 'let', 'in', 'inherit', 'assert', 'if', 36 | 'else', 'then', '...'] 37 | builtins = ['import', 'abort', 'baseNameOf', 'dirOf', 'isNull', 'builtins', 38 | 'map', 'removeAttrs', 'throw', 'toString', 'derivation'] 39 | operators = ['++', '+', '?', '.', '!', '//', '==', 40 | '!=', '&&', '||', '->', '='] 41 | 42 | punctuations = ["(", ")", "[", "]", ";", "{", "}", ":", ",", "@"] 43 | 44 | tokens = { 45 | 'root': [ 46 | # comments starting with # 47 | (r'#.*$', Comment.Single), 48 | 49 | # multiline comments 50 | (r'/\*', Comment.Multiline, 'comment'), 51 | 52 | # whitespace 53 | (r'\s+', Text), 54 | 55 | # keywords 56 | ('(%s)' % '|'.join(re.escape(entry) + '\\b' for entry in keywords), Keyword), 57 | 58 | # highlight the builtins 59 | ('(%s)' % '|'.join(re.escape(entry) + '\\b' for entry in builtins), 60 | Name.Builtin), 61 | 62 | (r'\b(true|false|null)\b', Name.Constant), 63 | 64 | # operators 65 | ('(%s)' % '|'.join(re.escape(entry) for entry in operators), 66 | Operator), 67 | 68 | # word operators 69 | (r'\b(or|and)\b', Operator.Word), 70 | 71 | # punctuations 72 | ('(%s)' % '|'.join(re.escape(entry) for entry in punctuations), Punctuation), 73 | 74 | # integers 75 | (r'[0-9]+', Number.Integer), 76 | 77 | # strings 78 | (r'"', String.Double, 'doublequote'), 79 | (r"''", String.Single, 'singlequote'), 80 | 81 | # paths 82 | (r'[\w.+-]*(\/[\w.+-]+)+', Literal), 83 | (r'\<[\w.+-]+(\/[\w.+-]+)*\>', Literal), 84 | 85 | # urls 86 | (r'[a-zA-Z][a-zA-Z0-9\+\-\.]*\:[\w%/?:@&=+$,\\.!~*\'-]+', Literal), 87 | 88 | # names of variables 89 | (r'[\w-]+\s*=', String.Symbol), 90 | (r'[a-zA-Z_][\w\'-]*', Text), 91 | 92 | ], 93 | 'comment': [ 94 | (r'[^/*]+', Comment.Multiline), 95 | (r'/\*', Comment.Multiline, '#push'), 96 | (r'\*/', Comment.Multiline, '#pop'), 97 | (r'[*/]', Comment.Multiline), 98 | ], 99 | 'singlequote': [ 100 | (r"'''", String.Escape), 101 | (r"''\$\{", String.Escape), 102 | (r"''\n", String.Escape), 103 | (r"''\r", String.Escape), 104 | (r"''\t", String.Escape), 105 | (r"''", String.Single, '#pop'), 106 | (r'\$\{', String.Interpol, 'antiquote'), 107 | (r"[^']", String.Single), 108 | ], 109 | 'doublequote': [ 110 | (r'\\', String.Escape), 111 | (r'\\"', String.Escape), 112 | (r'\\$\{', String.Escape), 113 | (r'"', String.Double, '#pop'), 114 | (r'\$\{', String.Interpol, 'antiquote'), 115 | (r'[^"]', String.Double), 116 | ], 117 | 'antiquote': [ 118 | (r"\}", String.Interpol, '#pop'), 119 | # TODO: we should probably escape also here ''${ \${ 120 | (r"\$\{", String.Interpol, '#push'), 121 | include('root'), 122 | ], 123 | } 124 | 125 | def analyse_text(text): 126 | rv = 0.0 127 | # TODO: let/in 128 | if re.search(r'import.+?<[^>]+>', text): 129 | rv += 0.4 130 | if re.search(r'mkDerivation\s+(\(|\{|rec)', text): 131 | rv += 0.4 132 | if re.search(r'=\s+mkIf\s+', text): 133 | rv += 0.4 134 | if re.search(r'\{[a-zA-Z,\s]+\}:', text): 135 | rv += 0.1 136 | return rv 137 | -------------------------------------------------------------------------------- /pygments/lexers/ooc.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.lexers.ooc 4 | ~~~~~~~~~~~~~~~~~~~ 5 | 6 | Lexers for the Ooc language. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | from pygments.lexer import RegexLexer, bygroups, words 13 | from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ 14 | Number, Punctuation 15 | 16 | __all__ = ['OocLexer'] 17 | 18 | 19 | class OocLexer(RegexLexer): 20 | """ 21 | For `Ooc `_ source code 22 | 23 | .. versionadded:: 1.2 24 | """ 25 | name = 'Ooc' 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 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.lexers.other 4 | ~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Just export lexer classes previously contained in this module. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | from pygments.lexers.sql import SqlLexer, MySqlLexer, SqliteConsoleLexer 13 | from pygments.lexers.shell import BashLexer, BashSessionLexer, BatchLexer, \ 14 | TcshLexer 15 | from pygments.lexers.robotframework import RobotFrameworkLexer 16 | from pygments.lexers.testing import GherkinLexer 17 | from pygments.lexers.esoteric import BrainfuckLexer, BefungeLexer, RedcodeLexer 18 | from pygments.lexers.prolog import LogtalkLexer 19 | from pygments.lexers.snobol import SnobolLexer 20 | from pygments.lexers.rebol import RebolLexer 21 | from pygments.lexers.configs import KconfigLexer, Cfengine3Lexer 22 | from pygments.lexers.modeling import ModelicaLexer 23 | from pygments.lexers.scripting import AppleScriptLexer, MOOCodeLexer, \ 24 | HybrisLexer 25 | from pygments.lexers.graphics import PostScriptLexer, GnuplotLexer, \ 26 | AsymptoteLexer, PovrayLexer 27 | from pygments.lexers.business import ABAPLexer, OpenEdgeLexer, \ 28 | GoodDataCLLexer, MaqlLexer 29 | from pygments.lexers.automation import AutoItLexer, AutohotkeyLexer 30 | from pygments.lexers.dsls import ProtoBufLexer, BroLexer, PuppetLexer, \ 31 | MscgenLexer, VGLLexer 32 | from pygments.lexers.basic import CbmBasicV2Lexer 33 | from pygments.lexers.pawn import SourcePawnLexer, PawnLexer 34 | from pygments.lexers.ecl import ECLLexer 35 | from pygments.lexers.urbi import UrbiscriptLexer 36 | from pygments.lexers.smalltalk import SmalltalkLexer, NewspeakLexer 37 | from pygments.lexers.installers import NSISLexer, RPMSpecLexer 38 | from pygments.lexers.textedit import AwkLexer 39 | 40 | __all__ = [] 41 | -------------------------------------------------------------------------------- /pygments/lexers/rdf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.lexers.rdf 4 | ~~~~~~~~~~~~~~~~~~~ 5 | 6 | Lexers for semantic web and RDF query languages and markup. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | import re 13 | 14 | from pygments.lexer import RegexLexer, bygroups, default 15 | from pygments.token import Keyword, Punctuation, String, Number, Operator, \ 16 | Whitespace, Name, Literal, Comment, Text 17 | 18 | __all__ = ['SparqlLexer'] 19 | 20 | 21 | class SparqlLexer(RegexLexer): 22 | """ 23 | Lexer for `SPARQL `_ query language. 24 | 25 | .. versionadded:: 2.0 26 | """ 27 | name = 'SPARQL' 28 | aliases = ['sparql'] 29 | filenames = ['*.rq', '*.sparql'] 30 | mimetypes = ['application/sparql-query'] 31 | 32 | flags = re.IGNORECASE 33 | 34 | tokens = { 35 | 'root': [ 36 | (r'\s+', Whitespace), 37 | (r'(select|construct|describe|ask|where|filter|group\s+by|minus|' 38 | r'distinct|reduced|from named|from|order\s+by|limit|' 39 | r'offset|bindings|load|clear|drop|create|add|move|copy|' 40 | r'insert\s+data|delete\s+data|delete\s+where|delete|insert|' 41 | r'using named|using|graph|default|named|all|optional|service|' 42 | r'silent|bind|union|not in|in|as|a)', Keyword), 43 | (r'(prefix|base)(\s+)([a-z][\w-]*)(\s*)(\:)', 44 | bygroups(Keyword, Whitespace, Name.Namespace, Whitespace, 45 | Punctuation)), 46 | (r'\?[a-z_]\w*', Name.Variable), 47 | (r'<[^>]+>', Name.Label), 48 | (r'([a-z][\w-]*)(\:)([a-z][\w-]*)', 49 | bygroups(Name.Namespace, Punctuation, Name.Tag)), 50 | (r'(str|lang|langmatches|datatype|bound|iri|uri|bnode|rand|abs|' 51 | r'ceil|floor|round|concat|strlen|ucase|lcase|encode_for_uri|' 52 | r'contains|strstarts|strends|strbefore|strafter|year|month|day|' 53 | r'hours|minutes|seconds|timezone|tz|now|md5|sha1|sha256|sha384|' 54 | r'sha512|coalesce|if|strlang|strdt|sameterm|isiri|isuri|isblank|' 55 | r'isliteral|isnumeric|regex|substr|replace|exists|not exists|' 56 | r'count|sum|min|max|avg|sample|group_concat|separator)\b', 57 | Name.Function), 58 | (r'(true|false)', Literal), 59 | (r'[+\-]?\d*\.\d+', Number.Float), 60 | (r'[+\-]?\d*(:?\.\d+)?E[+\-]?\d+', Number.Float), 61 | (r'[+\-]?\d+', Number.Integer), 62 | (r'(\|\||&&|=|\*|\-|\+|/)', Operator), 63 | (r'[(){}.;,:^]', Punctuation), 64 | (r'#[^\n]+', Comment), 65 | (r'"""', String, 'triple-double-quoted-string'), 66 | (r'"', String, 'single-double-quoted-string'), 67 | (r"'''", String, 'triple-single-quoted-string'), 68 | (r"'", String, 'single-single-quoted-string'), 69 | ], 70 | 'triple-double-quoted-string': [ 71 | (r'"""', String, 'end-of-string'), 72 | (r'[^\\]+', String), 73 | (r'\\', String, 'string-escape'), 74 | ], 75 | 'single-double-quoted-string': [ 76 | (r'"', String, 'end-of-string'), 77 | (r'[^"\\\n]+', String), 78 | (r'\\', String, 'string-escape'), 79 | ], 80 | 'triple-single-quoted-string': [ 81 | (r"'''", String, 'end-of-string'), 82 | (r'[^\\]+', String), 83 | (r'\\', String, 'string-escape'), 84 | ], 85 | 'single-single-quoted-string': [ 86 | (r"'", String, 'end-of-string'), 87 | (r"[^'\\\n]+", String), 88 | (r'\\', String, 'string-escape'), 89 | ], 90 | 'string-escape': [ 91 | (r'.', String, '#pop'), 92 | ], 93 | 'end-of-string': [ 94 | (r'(@)([a-z]+(:?-[a-z0-9]+)*)', 95 | bygroups(Operator, Name.Function), '#pop:2'), 96 | (r'\^\^', Operator, '#pop:2'), 97 | default('#pop:2'), 98 | ], 99 | } 100 | -------------------------------------------------------------------------------- /pygments/lexers/resource.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.lexers.resource 4 | ~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Lexer for resource definition files. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | import re 13 | 14 | from pygments.lexer import RegexLexer, bygroups, words 15 | from pygments.token import Comment, String, Number, Operator, Text, \ 16 | Keyword, Name 17 | 18 | __all__ = ['ResourceLexer'] 19 | 20 | 21 | class ResourceLexer(RegexLexer): 22 | """Lexer for `ICU Resource bundles 23 | `_. 24 | 25 | .. versionadded:: 2.0 26 | """ 27 | name = 'ResourceBundle' 28 | aliases = ['resource', 'resourcebundle'] 29 | filenames = ['*.txt'] 30 | 31 | _types = (':table', ':array', ':string', ':bin', ':import', ':intvector', 32 | ':int', ':alias') 33 | 34 | flags = re.MULTILINE | re.IGNORECASE 35 | tokens = { 36 | 'root': [ 37 | (r'//.*?$', Comment), 38 | (r'"', String, 'string'), 39 | (r'-?\d+', Number.Integer), 40 | (r'[,{}]', Operator), 41 | (r'([^\s{:]+)(\s*)(%s?)' % '|'.join(_types), 42 | bygroups(Name, Text, Keyword)), 43 | (r'\s+', Text), 44 | (words(_types), Keyword), 45 | ], 46 | 'string': [ 47 | (r'(\\x[0-9a-f]{2}|\\u[0-9a-f]{4}|\\U00[0-9a-f]{6}|' 48 | r'\\[0-7]{1,3}|\\c.|\\[abtnvfre\'"?\\]|\\\{|[^"{\\])+', String), 49 | (r'\{', String.Escape, 'msgname'), 50 | (r'"', String, '#pop') 51 | ], 52 | 'msgname': [ 53 | (r'([^{},]+)(\s*)', bygroups(Name, String.Escape), ('#pop', 'message')) 54 | ], 55 | 'message': [ 56 | (r'\{', String.Escape, 'msgname'), 57 | (r'\}', String.Escape, '#pop'), 58 | (r'(,)(\s*)([a-z]+)(\s*\})', 59 | bygroups(Operator, String.Escape, Keyword, String.Escape), '#pop'), 60 | (r'(,)(\s*)([a-z]+)(\s*)(,)(\s*)(offset)(\s*)(:)(\s*)(-?\d+)(\s*)', 61 | bygroups(Operator, String.Escape, Keyword, String.Escape, Operator, 62 | String.Escape, Operator.Word, String.Escape, Operator, 63 | String.Escape, Number.Integer, String.Escape), 'choice'), 64 | (r'(,)(\s*)([a-z]+)(\s*)(,)(\s*)', 65 | bygroups(Operator, String.Escape, Keyword, String.Escape, Operator, 66 | String.Escape), 'choice'), 67 | (r'\s+', String.Escape) 68 | ], 69 | 'choice': [ 70 | (r'(=|<|>|<=|>=|!=)(-?\d+)(\s*\{)', 71 | bygroups(Operator, Number.Integer, String.Escape), 'message'), 72 | (r'([a-z]+)(\s*\{)', bygroups(Keyword.Type, String.Escape), 'str'), 73 | (r'\}', String.Escape, ('#pop', '#pop')), 74 | (r'\s+', String.Escape) 75 | ], 76 | 'str': [ 77 | (r'\}', String.Escape, '#pop'), 78 | (r'\{', String.Escape, 'msgname'), 79 | (r'[^{}]+', String) 80 | ] 81 | } 82 | 83 | def analyse_text(text): 84 | return text.startswith('root:table') 85 | -------------------------------------------------------------------------------- /pygments/lexers/snobol.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.lexers.snobol 4 | ~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Lexers for the SNOBOL language. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | from pygments.lexer import RegexLexer, bygroups 13 | from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ 14 | Number, Punctuation 15 | 16 | __all__ = ['SnobolLexer'] 17 | 18 | 19 | class SnobolLexer(RegexLexer): 20 | """ 21 | Lexer for the SNOBOL4 programming language. 22 | 23 | Recognizes the common ASCII equivalents of the original SNOBOL4 operators. 24 | Does not require spaces around binary operators. 25 | 26 | .. versionadded:: 1.5 27 | """ 28 | 29 | name = "Snobol" 30 | aliases = ["snobol"] 31 | filenames = ['*.snobol'] 32 | mimetypes = ['text/x-snobol'] 33 | 34 | tokens = { 35 | # root state, start of line 36 | # comments, continuation lines, and directives start in column 1 37 | # as do labels 38 | 'root': [ 39 | (r'\*.*\n', Comment), 40 | (r'[+.] ', Punctuation, 'statement'), 41 | (r'-.*\n', Comment), 42 | (r'END\s*\n', Name.Label, 'heredoc'), 43 | (r'[A-Za-z$][\w$]*', Name.Label, 'statement'), 44 | (r'\s+', Text, 'statement'), 45 | ], 46 | # statement state, line after continuation or label 47 | 'statement': [ 48 | (r'\s*\n', Text, '#pop'), 49 | (r'\s+', Text), 50 | (r'(?<=[^\w.])(LT|LE|EQ|NE|GE|GT|INTEGER|IDENT|DIFFER|LGT|SIZE|' 51 | r'REPLACE|TRIM|DUPL|REMDR|DATE|TIME|EVAL|APPLY|OPSYN|LOAD|UNLOAD|' 52 | r'LEN|SPAN|BREAK|ANY|NOTANY|TAB|RTAB|REM|POS|RPOS|FAIL|FENCE|' 53 | r'ABORT|ARB|ARBNO|BAL|SUCCEED|INPUT|OUTPUT|TERMINAL)(?=[^\w.])', 54 | Name.Builtin), 55 | (r'[A-Za-z][\w.]*', Name), 56 | # ASCII equivalents of original operators 57 | # | for the EBCDIC equivalent, ! likewise 58 | # \ for EBCDIC negation 59 | (r'\*\*|[?$.!%*/#+\-@|&\\=]', Operator), 60 | (r'"[^"]*"', String), 61 | (r"'[^']*'", String), 62 | # Accept SPITBOL syntax for real numbers 63 | # as well as Macro SNOBOL4 64 | (r'[0-9]+(?=[^.EeDd])', Number.Integer), 65 | (r'[0-9]+(\.[0-9]*)?([EDed][-+]?[0-9]+)?', Number.Float), 66 | # Goto 67 | (r':', Punctuation, 'goto'), 68 | (r'[()<>,;]', Punctuation), 69 | ], 70 | # Goto block 71 | 'goto': [ 72 | (r'\s*\n', Text, "#pop:2"), 73 | (r'\s+', Text), 74 | (r'F|S', Keyword), 75 | (r'(\()([A-Za-z][\w.]*)(\))', 76 | bygroups(Punctuation, Name.Label, Punctuation)) 77 | ], 78 | # everything after the END statement is basically one 79 | # big heredoc. 80 | 'heredoc': [ 81 | (r'.*\n', String.Heredoc) 82 | ] 83 | } 84 | -------------------------------------------------------------------------------- /pygments/lexers/special.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.lexers.special 4 | ~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Special lexers. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | import re 13 | 14 | from pygments.lexer import Lexer 15 | from pygments.token import Token, Error, Text 16 | from pygments.util import get_choice_opt, text_type, BytesIO 17 | 18 | 19 | __all__ = ['TextLexer', 'RawTokenLexer'] 20 | 21 | 22 | class TextLexer(Lexer): 23 | """ 24 | "Null" lexer, doesn't highlight anything. 25 | """ 26 | name = 'Text only' 27 | aliases = ['text'] 28 | filenames = ['*.txt'] 29 | mimetypes = ['text/plain'] 30 | 31 | def get_tokens_unprocessed(self, text): 32 | yield 0, Text, text 33 | 34 | 35 | _ttype_cache = {} 36 | 37 | line_re = re.compile(b'.*?\n') 38 | 39 | 40 | class RawTokenLexer(Lexer): 41 | """ 42 | Recreate a token stream formatted with the `RawTokenFormatter`. This 43 | lexer raises exceptions during parsing if the token stream in the 44 | file is malformed. 45 | 46 | Additional options accepted: 47 | 48 | `compress` 49 | If set to ``"gz"`` or ``"bz2"``, decompress the token stream with 50 | the given compression algorithm before lexing (default: ``""``). 51 | """ 52 | name = 'Raw token data' 53 | aliases = ['raw'] 54 | filenames = [] 55 | mimetypes = ['application/x-pygments-tokens'] 56 | 57 | def __init__(self, **options): 58 | self.compress = get_choice_opt(options, 'compress', 59 | ['', 'none', 'gz', 'bz2'], '') 60 | Lexer.__init__(self, **options) 61 | 62 | def get_tokens(self, text): 63 | if isinstance(text, text_type): 64 | # raw token stream never has any non-ASCII characters 65 | text = text.encode('ascii') 66 | if self.compress == 'gz': 67 | import gzip 68 | gzipfile = gzip.GzipFile('', 'rb', 9, BytesIO(text)) 69 | text = gzipfile.read() 70 | elif self.compress == 'bz2': 71 | import bz2 72 | text = bz2.decompress(text) 73 | 74 | # do not call Lexer.get_tokens() because we do not want Unicode 75 | # decoding to occur, and stripping is not optional. 76 | text = text.strip(b'\n') + b'\n' 77 | for i, t, v in self.get_tokens_unprocessed(text): 78 | yield t, v 79 | 80 | def get_tokens_unprocessed(self, text): 81 | length = 0 82 | for match in line_re.finditer(text): 83 | try: 84 | ttypestr, val = match.group().split(b'\t', 1) 85 | except ValueError: 86 | val = match.group().decode('ascii', 'replace') 87 | ttype = Error 88 | else: 89 | ttype = _ttype_cache.get(ttypestr) 90 | if not ttype: 91 | ttype = Token 92 | ttypes = ttypestr.split('.')[1:] 93 | for ttype_ in ttypes: 94 | if not ttype_ or not ttype_[0].isupper(): 95 | raise ValueError('malformed token name') 96 | ttype = getattr(ttype, ttype_) 97 | _ttype_cache[ttypestr] = ttype 98 | val = val[2:-2].decode('unicode-escape') 99 | yield length, ttype, val 100 | length += len(val) 101 | -------------------------------------------------------------------------------- /pygments/lexers/tcl.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.lexers.tcl 4 | ~~~~~~~~~~~~~~~~~~~ 5 | 6 | Lexers for Tcl and related languages. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | from pygments.lexer import RegexLexer, include, words 13 | from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ 14 | Number 15 | from pygments.util import shebang_matches 16 | 17 | __all__ = ['TclLexer'] 18 | 19 | 20 | class TclLexer(RegexLexer): 21 | """ 22 | For Tcl source code. 23 | 24 | .. versionadded:: 0.10 25 | """ 26 | 27 | keyword_cmds_re = words(( 28 | 'after', 'apply', 'array', 'break', 'catch', 'continue', 'elseif', 'else', 'error', 29 | 'eval', 'expr', 'for', 'foreach', 'global', 'if', 'namespace', 'proc', 'rename', 'return', 30 | 'set', 'switch', 'then', 'trace', 'unset', 'update', 'uplevel', 'upvar', 'variable', 31 | 'vwait', 'while'), prefix=r'\b', suffix=r'\b') 32 | 33 | builtin_cmds_re = words(( 34 | 'append', 'bgerror', 'binary', 'cd', 'chan', 'clock', 'close', 'concat', 'dde', 'dict', 35 | 'encoding', 'eof', 'exec', 'exit', 'fblocked', 'fconfigure', 'fcopy', 'file', 36 | 'fileevent', 'flush', 'format', 'gets', 'glob', 'history', 'http', 'incr', 'info', 'interp', 37 | 'join', 'lappend', 'lassign', 'lindex', 'linsert', 'list', 'llength', 'load', 'loadTk', 38 | 'lrange', 'lrepeat', 'lreplace', 'lreverse', 'lsearch', 'lset', 'lsort', 'mathfunc', 39 | 'mathop', 'memory', 'msgcat', 'open', 'package', 'pid', 'pkg::create', 'pkg_mkIndex', 40 | 'platform', 'platform::shell', 'puts', 'pwd', 're_syntax', 'read', 'refchan', 41 | 'regexp', 'registry', 'regsub', 'scan', 'seek', 'socket', 'source', 'split', 'string', 42 | 'subst', 'tell', 'time', 'tm', 'unknown', 'unload'), prefix=r'\b', suffix=r'\b') 43 | 44 | name = 'Tcl' 45 | aliases = ['tcl'] 46 | filenames = ['*.tcl', '*.rvt'] 47 | mimetypes = ['text/x-tcl', 'text/x-script.tcl', 'application/x-tcl'] 48 | 49 | def _gen_command_rules(keyword_cmds_re, builtin_cmds_re, context=""): 50 | return [ 51 | (keyword_cmds_re, Keyword, 'params' + context), 52 | (builtin_cmds_re, Name.Builtin, 'params' + context), 53 | (r'([\w.-]+)', Name.Variable, 'params' + context), 54 | (r'#', Comment, 'comment'), 55 | ] 56 | 57 | tokens = { 58 | 'root': [ 59 | include('command'), 60 | include('basic'), 61 | include('data'), 62 | (r'\}', Keyword), # HACK: somehow we miscounted our braces 63 | ], 64 | 'command': _gen_command_rules(keyword_cmds_re, builtin_cmds_re), 65 | 'command-in-brace': _gen_command_rules(keyword_cmds_re, 66 | builtin_cmds_re, 67 | "-in-brace"), 68 | 'command-in-bracket': _gen_command_rules(keyword_cmds_re, 69 | builtin_cmds_re, 70 | "-in-bracket"), 71 | 'command-in-paren': _gen_command_rules(keyword_cmds_re, 72 | builtin_cmds_re, 73 | "-in-paren"), 74 | 'basic': [ 75 | (r'\(', Keyword, 'paren'), 76 | (r'\[', Keyword, 'bracket'), 77 | (r'\{', Keyword, 'brace'), 78 | (r'"', String.Double, 'string'), 79 | (r'(eq|ne|in|ni)\b', Operator.Word), 80 | (r'!=|==|<<|>>|<=|>=|&&|\|\||\*\*|[-+~!*/%<>&^|?:]', Operator), 81 | ], 82 | 'data': [ 83 | (r'\s+', Text), 84 | (r'0x[a-fA-F0-9]+', Number.Hex), 85 | (r'0[0-7]+', Number.Oct), 86 | (r'\d+\.\d+', Number.Float), 87 | (r'\d+', Number.Integer), 88 | (r'\$([\w.:-]+)', Name.Variable), 89 | (r'([\w.:-]+)', Text), 90 | ], 91 | 'params': [ 92 | (r';', Keyword, '#pop'), 93 | (r'\n', Text, '#pop'), 94 | (r'(else|elseif|then)\b', Keyword), 95 | include('basic'), 96 | include('data'), 97 | ], 98 | 'params-in-brace': [ 99 | (r'\}', Keyword, ('#pop', '#pop')), 100 | include('params') 101 | ], 102 | 'params-in-paren': [ 103 | (r'\)', Keyword, ('#pop', '#pop')), 104 | include('params') 105 | ], 106 | 'params-in-bracket': [ 107 | (r'\]', Keyword, ('#pop', '#pop')), 108 | include('params') 109 | ], 110 | 'string': [ 111 | (r'\[', String.Double, 'string-square'), 112 | (r'(?s)(\\\\|\\[0-7]+|\\.|[^"\\])', String.Double), 113 | (r'"', String.Double, '#pop') 114 | ], 115 | 'string-square': [ 116 | (r'\[', String.Double, 'string-square'), 117 | (r'(?s)(\\\\|\\[0-7]+|\\.|\\\n|[^\]\\])', String.Double), 118 | (r'\]', String.Double, '#pop') 119 | ], 120 | 'brace': [ 121 | (r'\}', Keyword, '#pop'), 122 | include('command-in-brace'), 123 | include('basic'), 124 | include('data'), 125 | ], 126 | 'paren': [ 127 | (r'\)', Keyword, '#pop'), 128 | include('command-in-paren'), 129 | include('basic'), 130 | include('data'), 131 | ], 132 | 'bracket': [ 133 | (r'\]', Keyword, '#pop'), 134 | include('command-in-bracket'), 135 | include('basic'), 136 | include('data'), 137 | ], 138 | 'comment': [ 139 | (r'.*[^\\]\n', Comment, '#pop'), 140 | (r'.*\\\n', Comment), 141 | ], 142 | } 143 | 144 | def analyse_text(text): 145 | return shebang_matches(text, r'(tcl)') 146 | -------------------------------------------------------------------------------- /pygments/lexers/text.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.lexers.text 4 | ~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Lexers for non-source code file types. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | from pygments.lexers.configs import ApacheConfLexer, NginxConfLexer, \ 13 | SquidConfLexer, LighttpdConfLexer, IniLexer, RegeditLexer, PropertiesLexer 14 | from pygments.lexers.console import PyPyLogLexer 15 | from pygments.lexers.textedit import VimLexer 16 | from pygments.lexers.markup import BBCodeLexer, MoinWikiLexer, RstLexer, \ 17 | TexLexer, GroffLexer 18 | from pygments.lexers.installers import DebianControlLexer, SourcesListLexer 19 | from pygments.lexers.make import MakefileLexer, BaseMakefileLexer, CMakeLexer 20 | from pygments.lexers.haxe import HxmlLexer 21 | from pygments.lexers.diff import DiffLexer, DarcsPatchLexer 22 | from pygments.lexers.data import YamlLexer 23 | from pygments.lexers.textfmts import IrcLogsLexer, GettextLexer, HttpLexer 24 | 25 | __all__ = [] 26 | -------------------------------------------------------------------------------- /pygments/lexers/web.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.lexers.web 4 | ~~~~~~~~~~~~~~~~~~~ 5 | 6 | Just export previously exported lexers. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | from pygments.lexers.html import HtmlLexer, DtdLexer, XmlLexer, XsltLexer, \ 13 | HamlLexer, ScamlLexer, JadeLexer 14 | from pygments.lexers.css import CssLexer, SassLexer, ScssLexer 15 | from pygments.lexers.javascript import JavascriptLexer, LiveScriptLexer, \ 16 | DartLexer, TypeScriptLexer, LassoLexer, ObjectiveJLexer, CoffeeScriptLexer 17 | from pygments.lexers.actionscript import ActionScriptLexer, \ 18 | ActionScript3Lexer, MxmlLexer 19 | from pygments.lexers.php import PhpLexer 20 | from pygments.lexers.webmisc import DuelLexer, XQueryLexer, SlimLexer, QmlLexer 21 | from pygments.lexers.data import JsonLexer 22 | JSONLexer = JsonLexer # for backwards compatibility with Pygments 1.5 23 | 24 | __all__ = [] 25 | -------------------------------------------------------------------------------- /pygments/modeline.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.modeline 4 | ~~~~~~~~~~~~~~~~~ 5 | 6 | A simple modeline parser (based on pymodeline). 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | import re 13 | 14 | __all__ = ['get_filetype_from_buffer'] 15 | 16 | modeline_re = re.compile(r''' 17 | (?: vi | vim | ex ) (?: [<=>]? \d* )? : 18 | .* (?: ft | filetype | syn | syntax ) = ( [^:\s]+ ) 19 | ''', re.VERBOSE) 20 | 21 | def get_filetype_from_line(l): 22 | m = modeline_re.search(l) 23 | if m: 24 | return m.group(1) 25 | 26 | def get_filetype_from_buffer(buf, max_lines=5): 27 | """ 28 | Scan the buffer for modelines and return filetype if one is found. 29 | """ 30 | lines = buf.splitlines() 31 | for l in lines[-1:-max_lines-1:-1]: 32 | ret = get_filetype_from_line(l) 33 | if ret: 34 | return ret 35 | for l in lines[max_lines:0:-1]: 36 | ret = get_filetype_from_line(l) 37 | if ret: 38 | return ret 39 | 40 | return None 41 | -------------------------------------------------------------------------------- /pygments/plugin.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.plugin 4 | ~~~~~~~~~~~~~~~ 5 | 6 | Pygments setuptools plugin interface. The methods defined 7 | here also work if setuptools isn't installed but they just 8 | return nothing. 9 | 10 | lexer plugins:: 11 | 12 | [pygments.lexers] 13 | yourlexer = yourmodule:YourLexer 14 | 15 | formatter plugins:: 16 | 17 | [pygments.formatters] 18 | yourformatter = yourformatter:YourFormatter 19 | /.ext = yourformatter:YourFormatter 20 | 21 | As you can see, you can define extensions for the formatter 22 | with a leading slash. 23 | 24 | syntax plugins:: 25 | 26 | [pygments.styles] 27 | yourstyle = yourstyle:YourStyle 28 | 29 | filter plugin:: 30 | 31 | [pygments.filter] 32 | yourfilter = yourfilter:YourFilter 33 | 34 | 35 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 36 | :license: BSD, see LICENSE for details. 37 | """ 38 | try: 39 | import pkg_resources 40 | except ImportError: 41 | pkg_resources = None 42 | 43 | LEXER_ENTRY_POINT = 'pygments.lexers' 44 | FORMATTER_ENTRY_POINT = 'pygments.formatters' 45 | STYLE_ENTRY_POINT = 'pygments.styles' 46 | FILTER_ENTRY_POINT = 'pygments.filters' 47 | 48 | 49 | def find_plugin_lexers(): 50 | if pkg_resources is None: 51 | return 52 | for entrypoint in pkg_resources.iter_entry_points(LEXER_ENTRY_POINT): 53 | yield entrypoint.load() 54 | 55 | 56 | def find_plugin_formatters(): 57 | if pkg_resources is None: 58 | return 59 | for entrypoint in pkg_resources.iter_entry_points(FORMATTER_ENTRY_POINT): 60 | yield entrypoint.name, entrypoint.load() 61 | 62 | 63 | def find_plugin_styles(): 64 | if pkg_resources is None: 65 | return 66 | for entrypoint in pkg_resources.iter_entry_points(STYLE_ENTRY_POINT): 67 | yield entrypoint.name, entrypoint.load() 68 | 69 | 70 | def find_plugin_filters(): 71 | if pkg_resources is None: 72 | return 73 | for entrypoint in pkg_resources.iter_entry_points(FILTER_ENTRY_POINT): 74 | yield entrypoint.name, entrypoint.load() 75 | -------------------------------------------------------------------------------- /pygments/regexopt.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.regexopt 4 | ~~~~~~~~~~~~~~~~~ 5 | 6 | An algorithm that generates optimized regexes for matching long lists of 7 | literal strings. 8 | 9 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 10 | :license: BSD, see LICENSE for details. 11 | """ 12 | 13 | import re 14 | from re import escape 15 | from os.path import commonprefix 16 | from itertools import groupby 17 | from operator import itemgetter 18 | 19 | CS_ESCAPE = re.compile(r'[\^\\\-\]]') 20 | FIRST_ELEMENT = itemgetter(0) 21 | 22 | 23 | def make_charset(letters): 24 | return '[' + CS_ESCAPE.sub(lambda m: '\\' + m.group(), ''.join(letters)) + ']' 25 | 26 | 27 | def regex_opt_inner(strings, open_paren): 28 | """Return a regex that matches any string in the sorted list of strings.""" 29 | close_paren = open_paren and ')' or '' 30 | # print strings, repr(open_paren) 31 | if not strings: 32 | # print '-> nothing left' 33 | return '' 34 | first = strings[0] 35 | if len(strings) == 1: 36 | # print '-> only 1 string' 37 | return open_paren + escape(first) + close_paren 38 | if not first: 39 | # print '-> first string empty' 40 | return open_paren + regex_opt_inner(strings[1:], '(?:') \ 41 | + '?' + close_paren 42 | if len(first) == 1: 43 | # multiple one-char strings? make a charset 44 | oneletter = [] 45 | rest = [] 46 | for s in strings: 47 | if len(s) == 1: 48 | oneletter.append(s) 49 | else: 50 | rest.append(s) 51 | if len(oneletter) > 1: # do we have more than one oneletter string? 52 | if rest: 53 | # print '-> 1-character + rest' 54 | return open_paren + regex_opt_inner(rest, '') + '|' \ 55 | + make_charset(oneletter) + close_paren 56 | # print '-> only 1-character' 57 | return make_charset(oneletter) 58 | prefix = commonprefix(strings) 59 | if prefix: 60 | plen = len(prefix) 61 | # we have a prefix for all strings 62 | # print '-> prefix:', prefix 63 | return open_paren + escape(prefix) \ 64 | + regex_opt_inner([s[plen:] for s in strings], '(?:') \ 65 | + close_paren 66 | # is there a suffix? 67 | strings_rev = [s[::-1] for s in strings] 68 | suffix = commonprefix(strings_rev) 69 | if suffix: 70 | slen = len(suffix) 71 | # print '-> suffix:', suffix[::-1] 72 | return open_paren \ 73 | + regex_opt_inner(sorted(s[:-slen] for s in strings), '(?:') \ 74 | + escape(suffix[::-1]) + close_paren 75 | # recurse on common 1-string prefixes 76 | # print '-> last resort' 77 | return open_paren + \ 78 | '|'.join(regex_opt_inner(list(group[1]), '') 79 | for group in groupby(strings, lambda s: s[0] == first[0])) \ 80 | + close_paren 81 | 82 | 83 | def regex_opt(strings, prefix='', suffix=''): 84 | """Return a compiled regex that matches any string in the given list. 85 | 86 | The strings to match must be literal strings, not regexes. They will be 87 | regex-escaped. 88 | 89 | *prefix* and *suffix* are pre- and appended to the final regex. 90 | """ 91 | strings = sorted(strings) 92 | return prefix + regex_opt_inner(strings, '(') + suffix 93 | -------------------------------------------------------------------------------- /pygments/scanner.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.scanner 4 | ~~~~~~~~~~~~~~~~ 5 | 6 | This library implements a regex based scanner. Some languages 7 | like Pascal are easy to parse but have some keywords that 8 | depend on the context. Because of this it's impossible to lex 9 | that just by using a regular expression lexer like the 10 | `RegexLexer`. 11 | 12 | Have a look at the `DelphiLexer` to get an idea of how to use 13 | this scanner. 14 | 15 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 16 | :license: BSD, see LICENSE for details. 17 | """ 18 | import re 19 | 20 | 21 | class EndOfText(RuntimeError): 22 | """ 23 | Raise if end of text is reached and the user 24 | tried to call a match function. 25 | """ 26 | 27 | 28 | class Scanner(object): 29 | """ 30 | Simple scanner 31 | 32 | All method patterns are regular expression strings (not 33 | compiled expressions!) 34 | """ 35 | 36 | def __init__(self, text, flags=0): 37 | """ 38 | :param text: The text which should be scanned 39 | :param flags: default regular expression flags 40 | """ 41 | self.data = text 42 | self.data_length = len(text) 43 | self.start_pos = 0 44 | self.pos = 0 45 | self.flags = flags 46 | self.last = None 47 | self.match = None 48 | self._re_cache = {} 49 | 50 | def eos(self): 51 | """`True` if the scanner reached the end of text.""" 52 | return self.pos >= self.data_length 53 | eos = property(eos, eos.__doc__) 54 | 55 | def check(self, pattern): 56 | """ 57 | Apply `pattern` on the current position and return 58 | the match object. (Doesn't touch pos). Use this for 59 | lookahead. 60 | """ 61 | if self.eos: 62 | raise EndOfText() 63 | if pattern not in self._re_cache: 64 | self._re_cache[pattern] = re.compile(pattern, self.flags) 65 | return self._re_cache[pattern].match(self.data, self.pos) 66 | 67 | def test(self, pattern): 68 | """Apply a pattern on the current position and check 69 | if it patches. Doesn't touch pos.""" 70 | return self.check(pattern) is not None 71 | 72 | def scan(self, pattern): 73 | """ 74 | Scan the text for the given pattern and update pos/match 75 | and related fields. The return value is a boolen that 76 | indicates if the pattern matched. The matched value is 77 | stored on the instance as ``match``, the last value is 78 | stored as ``last``. ``start_pos`` is the position of the 79 | pointer before the pattern was matched, ``pos`` is the 80 | end position. 81 | """ 82 | if self.eos: 83 | raise EndOfText() 84 | if pattern not in self._re_cache: 85 | self._re_cache[pattern] = re.compile(pattern, self.flags) 86 | self.last = self.match 87 | m = self._re_cache[pattern].match(self.data, self.pos) 88 | if m is None: 89 | return False 90 | self.start_pos = m.start() 91 | self.pos = m.end() 92 | self.match = m.group() 93 | return True 94 | 95 | def get_char(self): 96 | """Scan exactly one char.""" 97 | self.scan('.') 98 | 99 | def __repr__(self): 100 | return '<%s %d/%d>' % ( 101 | self.__class__.__name__, 102 | self.pos, 103 | self.data_length 104 | ) 105 | -------------------------------------------------------------------------------- /pygments/sphinxext.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.sphinxext 4 | ~~~~~~~~~~~~~~~~~~ 5 | 6 | Sphinx extension to generate automatic documentation of lexers, 7 | formatters and filters. 8 | 9 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 10 | :license: BSD, see LICENSE for details. 11 | """ 12 | 13 | from __future__ import print_function 14 | 15 | import sys 16 | 17 | from docutils import nodes 18 | from docutils.statemachine import ViewList 19 | from sphinx.util.compat import Directive 20 | from sphinx.util.nodes import nested_parse_with_titles 21 | 22 | 23 | MODULEDOC = ''' 24 | .. module:: %s 25 | 26 | %s 27 | %s 28 | ''' 29 | 30 | LEXERDOC = ''' 31 | .. class:: %s 32 | 33 | :Short names: %s 34 | :Filenames: %s 35 | :MIME types: %s 36 | 37 | %s 38 | 39 | ''' 40 | 41 | FMTERDOC = ''' 42 | .. class:: %s 43 | 44 | :Short names: %s 45 | :Filenames: %s 46 | 47 | %s 48 | 49 | ''' 50 | 51 | FILTERDOC = ''' 52 | .. class:: %s 53 | 54 | :Name: %s 55 | 56 | %s 57 | 58 | ''' 59 | 60 | class PygmentsDoc(Directive): 61 | """ 62 | A directive to collect all lexers/formatters/filters and generate 63 | autoclass directives for them. 64 | """ 65 | has_content = False 66 | required_arguments = 1 67 | optional_arguments = 0 68 | final_argument_whitespace = False 69 | option_spec = {} 70 | 71 | def run(self): 72 | self.filenames = set() 73 | if self.arguments[0] == 'lexers': 74 | out = self.document_lexers() 75 | elif self.arguments[0] == 'formatters': 76 | out = self.document_formatters() 77 | elif self.arguments[0] == 'filters': 78 | out = self.document_filters() 79 | else: 80 | raise Exception('invalid argument for "pygmentsdoc" directive') 81 | node = nodes.compound() 82 | vl = ViewList(out.split('\n'), source='') 83 | nested_parse_with_titles(self.state, vl, node) 84 | for fn in self.filenames: 85 | self.state.document.settings.record_dependencies.add(fn) 86 | return node.children 87 | 88 | def document_lexers(self): 89 | from pygments.lexers._mapping import LEXERS 90 | out = [] 91 | modules = {} 92 | moduledocstrings = {} 93 | for classname, data in sorted(LEXERS.items(), key=lambda x: x[0]): 94 | module = data[0] 95 | mod = __import__(module, None, None, [classname]) 96 | self.filenames.add(mod.__file__) 97 | cls = getattr(mod, classname) 98 | if not cls.__doc__: 99 | print("Warning: %s does not have a docstring." % classname) 100 | docstring = cls.__doc__ 101 | if isinstance(docstring, bytes): 102 | docstring = docstring.decode('utf8') 103 | modules.setdefault(module, []).append(( 104 | classname, 105 | ', '.join(data[2]) or 'None', 106 | ', '.join(data[3]).replace('*', '\\*').replace('_', '\\') or 'None', 107 | ', '.join(data[4]) or 'None', 108 | docstring)) 109 | if module not in moduledocstrings: 110 | moddoc = mod.__doc__ 111 | if isinstance(moddoc, bytes): 112 | moddoc = moddoc.decode('utf8') 113 | moduledocstrings[module] = moddoc 114 | 115 | for module, lexers in sorted(modules.items(), key=lambda x: x[0]): 116 | heading = moduledocstrings[module].splitlines()[4].strip().rstrip('.') 117 | out.append(MODULEDOC % (module, heading, '-'*len(heading))) 118 | for data in lexers: 119 | out.append(LEXERDOC % data) 120 | 121 | return ''.join(out) 122 | 123 | def document_formatters(self): 124 | from pygments.formatters import FORMATTERS 125 | 126 | out = [] 127 | for classname, data in sorted(FORMATTERS.items(), key=lambda x: x[0]): 128 | module = data[0] 129 | mod = __import__(module, None, None, [classname]) 130 | self.filenames.add(mod.__file__) 131 | cls = getattr(mod, classname) 132 | docstring = cls.__doc__ 133 | if isinstance(docstring, bytes): 134 | docstring = docstring.decode('utf8') 135 | heading = cls.__name__ 136 | out.append(FMTERDOC % (heading, ', '.join(data[2]) or 'None', 137 | ', '.join(data[3]).replace('*', '\\*') or 'None', 138 | docstring)) 139 | return ''.join(out) 140 | 141 | def document_filters(self): 142 | from pygments.filters import FILTERS 143 | 144 | out = [] 145 | for name, cls in FILTERS.items(): 146 | self.filenames.add(sys.modules[cls.__module__].__file__) 147 | docstring = cls.__doc__ 148 | if isinstance(docstring, bytes): 149 | docstring = docstring.decode('utf8') 150 | out.append(FILTERDOC % (cls.__name__, name, docstring)) 151 | return ''.join(out) 152 | 153 | 154 | def setup(app): 155 | app.add_directive('pygmentsdoc', PygmentsDoc) 156 | -------------------------------------------------------------------------------- /pygments/style.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.style 4 | ~~~~~~~~~~~~~~ 5 | 6 | Basic style object. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | from pygments.token import Token, STANDARD_TYPES 13 | from pygments.util import add_metaclass 14 | 15 | 16 | class StyleMeta(type): 17 | 18 | def __new__(mcs, name, bases, dct): 19 | obj = type.__new__(mcs, name, bases, dct) 20 | for token in STANDARD_TYPES: 21 | if token not in obj.styles: 22 | obj.styles[token] = '' 23 | 24 | def colorformat(text): 25 | if text[0:1] == '#': 26 | col = text[1:] 27 | if len(col) == 6: 28 | return col 29 | elif len(col) == 3: 30 | return col[0]*2 + col[1]*2 + col[2]*2 31 | elif text == '': 32 | return '' 33 | assert False, "wrong color format %r" % text 34 | 35 | _styles = obj._styles = {} 36 | 37 | for ttype in obj.styles: 38 | for token in ttype.split(): 39 | if token in _styles: 40 | continue 41 | ndef = _styles.get(token.parent, None) 42 | styledefs = obj.styles.get(token, '').split() 43 | if not ndef or token is None: 44 | ndef = ['', 0, 0, 0, '', '', 0, 0, 0] 45 | elif 'noinherit' in styledefs and token is not Token: 46 | ndef = _styles[Token][:] 47 | else: 48 | ndef = ndef[:] 49 | _styles[token] = ndef 50 | for styledef in obj.styles.get(token, '').split(): 51 | if styledef == 'noinherit': 52 | pass 53 | elif styledef == 'bold': 54 | ndef[1] = 1 55 | elif styledef == 'nobold': 56 | ndef[1] = 0 57 | elif styledef == 'italic': 58 | ndef[2] = 1 59 | elif styledef == 'noitalic': 60 | ndef[2] = 0 61 | elif styledef == 'underline': 62 | ndef[3] = 1 63 | elif styledef == 'nounderline': 64 | ndef[3] = 0 65 | elif styledef[:3] == 'bg:': 66 | ndef[4] = colorformat(styledef[3:]) 67 | elif styledef[:7] == 'border:': 68 | ndef[5] = colorformat(styledef[7:]) 69 | elif styledef == 'roman': 70 | ndef[6] = 1 71 | elif styledef == 'sans': 72 | ndef[7] = 1 73 | elif styledef == 'mono': 74 | ndef[8] = 1 75 | else: 76 | ndef[0] = colorformat(styledef) 77 | 78 | return obj 79 | 80 | def style_for_token(cls, token): 81 | t = cls._styles[token] 82 | return { 83 | 'color': t[0] or None, 84 | 'bold': bool(t[1]), 85 | 'italic': bool(t[2]), 86 | 'underline': bool(t[3]), 87 | 'bgcolor': t[4] or None, 88 | 'border': t[5] or None, 89 | 'roman': bool(t[6]) or None, 90 | 'sans': bool(t[7]) or None, 91 | 'mono': bool(t[8]) or None, 92 | } 93 | 94 | def list_styles(cls): 95 | return list(cls) 96 | 97 | def styles_token(cls, ttype): 98 | return ttype in cls._styles 99 | 100 | def __iter__(cls): 101 | for token in cls._styles: 102 | yield token, cls.style_for_token(token) 103 | 104 | def __len__(cls): 105 | return len(cls._styles) 106 | 107 | 108 | @add_metaclass(StyleMeta) 109 | class Style(object): 110 | 111 | #: overall background color (``None`` means transparent) 112 | background_color = '#ffffff' 113 | 114 | #: highlight background color 115 | highlight_color = '#ffffcc' 116 | 117 | #: Style definitions for individual token types. 118 | styles = {} 119 | -------------------------------------------------------------------------------- /pygments/styles/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.styles 4 | ~~~~~~~~~~~~~~~ 5 | 6 | Contains built-in styles. 7 | 8 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | from pygments.plugin import find_plugin_styles 13 | from pygments.util import ClassNotFound 14 | 15 | 16 | #: Maps style names to 'submodule::classname'. 17 | STYLE_MAP = { 18 | 'default': 'default::DefaultStyle', 19 | 'emacs': 'emacs::EmacsStyle', 20 | 'friendly': 'friendly::FriendlyStyle', 21 | 'colorful': 'colorful::ColorfulStyle', 22 | 'autumn': 'autumn::AutumnStyle', 23 | 'murphy': 'murphy::MurphyStyle', 24 | 'manni': 'manni::ManniStyle', 25 | 'monokai': 'monokai::MonokaiStyle', 26 | 'perldoc': 'perldoc::PerldocStyle', 27 | 'pastie': 'pastie::PastieStyle', 28 | 'borland': 'borland::BorlandStyle', 29 | 'trac': 'trac::TracStyle', 30 | 'native': 'native::NativeStyle', 31 | 'fruity': 'fruity::FruityStyle', 32 | 'bw': 'bw::BlackWhiteStyle', 33 | 'vim': 'vim::VimStyle', 34 | 'vs': 'vs::VisualStudioStyle', 35 | 'tango': 'tango::TangoStyle', 36 | 'rrt': 'rrt::RrtStyle', 37 | 'xcode': 'xcode::XcodeStyle', 38 | 'igor': 'igor::IgorStyle', 39 | 'paraiso-light': 'paraiso_light::ParaisoLightStyle', 40 | 'paraiso-dark': 'paraiso_dark::ParaisoDarkStyle', 41 | } 42 | 43 | 44 | def get_style_by_name(name): 45 | if name in STYLE_MAP: 46 | mod, cls = STYLE_MAP[name].split('::') 47 | builtin = "yes" 48 | else: 49 | for found_name, style in find_plugin_styles(): 50 | if name == found_name: 51 | return style 52 | # perhaps it got dropped into our styles package 53 | builtin = "" 54 | mod = name 55 | cls = name.title() + "Style" 56 | 57 | try: 58 | mod = __import__('pygments.styles.' + mod, None, None, [cls]) 59 | except ImportError: 60 | raise ClassNotFound("Could not find style module %r" % mod + 61 | (builtin and ", though it should be builtin") + ".") 62 | try: 63 | return getattr(mod, cls) 64 | except AttributeError: 65 | raise ClassNotFound("Could not find style class %r in style module." % cls) 66 | 67 | 68 | def get_all_styles(): 69 | """Return an generator for all styles by name, 70 | both builtin and plugin.""" 71 | for name in STYLE_MAP: 72 | yield name 73 | for name, _ in find_plugin_styles(): 74 | yield name 75 | -------------------------------------------------------------------------------- /pygments/styles/arduino.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.styles.arduino 4 | ~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Arduino® Syntax highlighting style. 7 | 8 | :copyright: Copyright 2006-2015 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, Generic, Whitespace 15 | 16 | 17 | class ArduinoStyle(Style): 18 | """ 19 | The Arduino® language style. This style is designed to highlight the Arduino source code, so exepect the best results with it. 20 | """ 21 | 22 | background_color = "#ffffff" 23 | default_style = "" 24 | 25 | styles = { 26 | Whitespace: "", # class: 'w' 27 | Error: "#a61717", # class: 'err' 28 | 29 | Comment: "#95a5a6", # class: 'c' 30 | Comment.Multiline: "", # class: 'cm' 31 | Comment.Preproc: "#434f54", # class: 'cp' 32 | Comment.Single: "", # class: 'c1' 33 | Comment.Special: "", # class: 'cs' 34 | 35 | Keyword: "#728E00", # class: 'k' 36 | Keyword.Constant: "#00979D", # class: 'kc' 37 | Keyword.Declaration: "", # class: 'kd' 38 | Keyword.Namespace: "", # class: 'kn' 39 | Keyword.Pseudo: "#00979D", # class: 'kp' 40 | Keyword.Reserved: "", # class: 'kr' 41 | Keyword.Type: "#00979D", # class: 'kt' 42 | 43 | Operator: "#434f54", # class: 'o' 44 | Operator.Word: "", # class: 'ow' 45 | 46 | Name: "#434f54", # class: 'n' 47 | Name.Attribute: "", # class: 'na' 48 | Name.Builtin: "", # class: 'nb' 49 | Name.Builtin.Pseudo: "", # class: 'bp' 50 | Name.Class: "", # class: 'nc' 51 | Name.Constant: "", # class: 'no' 52 | Name.Decorator: "", # class: 'nd' 53 | Name.Entity: "", # class: 'ni' 54 | Name.Exception: "", # class: 'ne' 55 | Name.Function: "#D35400", # class: 'nf' 56 | Name.Property: "", # class: 'py' 57 | Name.Label: "", # class: 'nl' 58 | Name.Namespace: "", # class: 'nn' 59 | Name.Other: "#728E00", # class: 'nx' 60 | Name.Tag: "", # class: 'nt' 61 | Name.Variable: "", # class: 'nv' 62 | Name.Variable.Class: "", # class: 'vc' 63 | Name.Variable.Global: "", # class: 'vg' 64 | Name.Variable.Instance: "", # class: 'vi' 65 | 66 | Number: "#434f54", # class: 'm' 67 | Number.Float: "", # class: 'mf' 68 | Number.Hex: "", # class: 'mh' 69 | Number.Integer: "", # class: 'mi' 70 | Number.Integer.Long: "", # class: 'il' 71 | Number.Oct: "", # class: 'mo' 72 | 73 | String: "#7F8C8D", # class: 's' 74 | String.Backtick: "", # class: 'sb' 75 | String.Char: "", # class: 'sc' 76 | String.Doc: "", # class: 'sd' 77 | String.Double: "", # class: 's2' 78 | String.Escape: "", # class: 'se' 79 | String.Heredoc: "", # class: 'sh' 80 | String.Interpol: "", # class: 'si' 81 | String.Other: "", # class: 'sx' 82 | String.Regex: "", # class: 'sr' 83 | String.Single: "", # class: 's1' 84 | String.Symbol: "", # class: 'ss' 85 | 86 | Generic: "", # class: 'g' 87 | Generic.Deleted: "", # class: 'gd', 88 | Generic.Emph: "", # class: 'ge' 89 | Generic.Error: "", # class: 'gr' 90 | Generic.Heading: "", # class: 'gh' 91 | Generic.Inserted: "", # class: 'gi' 92 | Generic.Output: "", # class: 'go' 93 | Generic.Prompt: "", # class: 'gp' 94 | Generic.Strong: "", # class: 'gs' 95 | Generic.Subheading: "", # class: 'gu' 96 | Generic.Traceback: "", # class: 'gt' 97 | } 98 | -------------------------------------------------------------------------------- /pygments/styles/autumn.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.styles.autumn 4 | ~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | A colorful style, inspired by the terminal highlighting style. 7 | 8 | :copyright: Copyright 2006-2015 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, Generic, Whitespace 15 | 16 | 17 | class AutumnStyle(Style): 18 | """ 19 | A colorful style, inspired by the terminal highlighting style. 20 | """ 21 | 22 | default_style = "" 23 | 24 | styles = { 25 | Whitespace: '#bbbbbb', 26 | 27 | Comment: 'italic #aaaaaa', 28 | Comment.Preproc: 'noitalic #4c8317', 29 | Comment.Special: 'italic #0000aa', 30 | 31 | Keyword: '#0000aa', 32 | Keyword.Type: '#00aaaa', 33 | 34 | Operator.Word: '#0000aa', 35 | 36 | Name.Builtin: '#00aaaa', 37 | Name.Function: '#00aa00', 38 | Name.Class: 'underline #00aa00', 39 | Name.Namespace: 'underline #00aaaa', 40 | Name.Variable: '#aa0000', 41 | Name.Constant: '#aa0000', 42 | Name.Entity: 'bold #800', 43 | Name.Attribute: '#1e90ff', 44 | Name.Tag: 'bold #1e90ff', 45 | Name.Decorator: '#888888', 46 | 47 | String: '#aa5500', 48 | String.Symbol: '#0000aa', 49 | String.Regex: '#009999', 50 | 51 | Number: '#009999', 52 | 53 | Generic.Heading: 'bold #000080', 54 | Generic.Subheading: 'bold #800080', 55 | Generic.Deleted: '#aa0000', 56 | Generic.Inserted: '#00aa00', 57 | Generic.Error: '#aa0000', 58 | Generic.Emph: 'italic', 59 | Generic.Strong: 'bold', 60 | Generic.Prompt: '#555555', 61 | Generic.Output: '#888888', 62 | Generic.Traceback: '#aa0000', 63 | 64 | Error: '#F00 bg:#FAA' 65 | } 66 | -------------------------------------------------------------------------------- /pygments/styles/borland.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.styles.borland 4 | ~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Style similar to the style used in the Borland IDEs. 7 | 8 | :copyright: Copyright 2006-2015 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, Generic, Whitespace 15 | 16 | 17 | class BorlandStyle(Style): 18 | """ 19 | Style similar to the style used in the borland IDEs. 20 | """ 21 | 22 | default_style = '' 23 | 24 | styles = { 25 | Whitespace: '#bbbbbb', 26 | 27 | Comment: 'italic #008800', 28 | Comment.Preproc: 'noitalic #008080', 29 | Comment.Special: 'noitalic bold', 30 | 31 | String: '#0000FF', 32 | String.Char: '#800080', 33 | Number: '#0000FF', 34 | Keyword: 'bold #000080', 35 | Operator.Word: 'bold', 36 | Name.Tag: 'bold #000080', 37 | Name.Attribute: '#FF0000', 38 | 39 | Generic.Heading: '#999999', 40 | Generic.Subheading: '#aaaaaa', 41 | Generic.Deleted: 'bg:#ffdddd #000000', 42 | Generic.Inserted: 'bg:#ddffdd #000000', 43 | Generic.Error: '#aa0000', 44 | Generic.Emph: 'italic', 45 | Generic.Strong: 'bold', 46 | Generic.Prompt: '#555555', 47 | Generic.Output: '#888888', 48 | Generic.Traceback: '#aa0000', 49 | 50 | Error: 'bg:#e3d2d2 #a61717' 51 | } 52 | -------------------------------------------------------------------------------- /pygments/styles/bw.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.styles.bw 4 | ~~~~~~~~~~~~~~~~~~ 5 | 6 | Simple black/white only style. 7 | 8 | :copyright: Copyright 2006-2015 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 | Operator, Generic 15 | 16 | 17 | class BlackWhiteStyle(Style): 18 | 19 | background_color = "#ffffff" 20 | default_style = "" 21 | 22 | styles = { 23 | Comment: "italic", 24 | Comment.Preproc: "noitalic", 25 | 26 | Keyword: "bold", 27 | Keyword.Pseudo: "nobold", 28 | Keyword.Type: "nobold", 29 | 30 | Operator.Word: "bold", 31 | 32 | Name.Class: "bold", 33 | Name.Namespace: "bold", 34 | Name.Exception: "bold", 35 | Name.Entity: "bold", 36 | Name.Tag: "bold", 37 | 38 | String: "italic", 39 | String.Interpol: "bold", 40 | String.Escape: "bold", 41 | 42 | Generic.Heading: "bold", 43 | Generic.Subheading: "bold", 44 | Generic.Emph: "italic", 45 | Generic.Strong: "bold", 46 | Generic.Prompt: "bold", 47 | 48 | Error: "border:#FF0000" 49 | } 50 | -------------------------------------------------------------------------------- /pygments/styles/colorful.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.styles.colorful 4 | ~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | A colorful style, inspired by CodeRay. 7 | 8 | :copyright: Copyright 2006-2015 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, Generic, Whitespace 15 | 16 | 17 | class ColorfulStyle(Style): 18 | """ 19 | A colorful style, inspired by CodeRay. 20 | """ 21 | 22 | default_style = "" 23 | 24 | styles = { 25 | Whitespace: "#bbbbbb", 26 | 27 | Comment: "#888", 28 | Comment.Preproc: "#579", 29 | Comment.Special: "bold #cc0000", 30 | 31 | Keyword: "bold #080", 32 | Keyword.Pseudo: "#038", 33 | Keyword.Type: "#339", 34 | 35 | Operator: "#333", 36 | Operator.Word: "bold #000", 37 | 38 | Name.Builtin: "#007020", 39 | Name.Function: "bold #06B", 40 | Name.Class: "bold #B06", 41 | Name.Namespace: "bold #0e84b5", 42 | Name.Exception: "bold #F00", 43 | Name.Variable: "#963", 44 | Name.Variable.Instance: "#33B", 45 | Name.Variable.Class: "#369", 46 | Name.Variable.Global: "bold #d70", 47 | Name.Constant: "bold #036", 48 | Name.Label: "bold #970", 49 | Name.Entity: "bold #800", 50 | Name.Attribute: "#00C", 51 | Name.Tag: "#070", 52 | Name.Decorator: "bold #555", 53 | 54 | String: "bg:#fff0f0", 55 | String.Char: "#04D bg:", 56 | String.Doc: "#D42 bg:", 57 | String.Interpol: "bg:#eee", 58 | String.Escape: "bold #666", 59 | String.Regex: "bg:#fff0ff #000", 60 | String.Symbol: "#A60 bg:", 61 | String.Other: "#D20", 62 | 63 | Number: "bold #60E", 64 | Number.Integer: "bold #00D", 65 | Number.Float: "bold #60E", 66 | Number.Hex: "bold #058", 67 | Number.Oct: "bold #40E", 68 | 69 | Generic.Heading: "bold #000080", 70 | Generic.Subheading: "bold #800080", 71 | Generic.Deleted: "#A00000", 72 | Generic.Inserted: "#00A000", 73 | Generic.Error: "#FF0000", 74 | Generic.Emph: "italic", 75 | Generic.Strong: "bold", 76 | Generic.Prompt: "bold #c65d09", 77 | Generic.Output: "#888", 78 | Generic.Traceback: "#04D", 79 | 80 | Error: "#F00 bg:#FAA" 81 | } 82 | -------------------------------------------------------------------------------- /pygments/styles/default.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.styles.default 4 | ~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | The default highlighting style. 7 | 8 | :copyright: Copyright 2006-2015 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, Generic, Whitespace 15 | 16 | 17 | class DefaultStyle(Style): 18 | """ 19 | The default style (inspired by Emacs 22). 20 | """ 21 | 22 | background_color = "#f8f8f8" 23 | default_style = "" 24 | 25 | styles = { 26 | Whitespace: "#bbbbbb", 27 | Comment: "italic #408080", 28 | Comment.Preproc: "noitalic #BC7A00", 29 | 30 | #Keyword: "bold #AA22FF", 31 | Keyword: "bold #008000", 32 | Keyword.Pseudo: "nobold", 33 | Keyword.Type: "nobold #B00040", 34 | 35 | Operator: "#666666", 36 | Operator.Word: "bold #AA22FF", 37 | 38 | Name.Builtin: "#008000", 39 | Name.Function: "#0000FF", 40 | Name.Class: "bold #0000FF", 41 | Name.Namespace: "bold #0000FF", 42 | Name.Exception: "bold #D2413A", 43 | Name.Variable: "#19177C", 44 | Name.Constant: "#880000", 45 | Name.Label: "#A0A000", 46 | Name.Entity: "bold #999999", 47 | Name.Attribute: "#7D9029", 48 | Name.Tag: "bold #008000", 49 | Name.Decorator: "#AA22FF", 50 | 51 | String: "#BA2121", 52 | String.Doc: "italic", 53 | String.Interpol: "bold #BB6688", 54 | String.Escape: "bold #BB6622", 55 | String.Regex: "#BB6688", 56 | #String.Symbol: "#B8860B", 57 | String.Symbol: "#19177C", 58 | String.Other: "#008000", 59 | Number: "#666666", 60 | 61 | Generic.Heading: "bold #000080", 62 | Generic.Subheading: "bold #800080", 63 | Generic.Deleted: "#A00000", 64 | Generic.Inserted: "#00A000", 65 | Generic.Error: "#FF0000", 66 | Generic.Emph: "italic", 67 | Generic.Strong: "bold", 68 | Generic.Prompt: "bold #000080", 69 | Generic.Output: "#888", 70 | Generic.Traceback: "#04D", 71 | 72 | Error: "border:#FF0000" 73 | } 74 | -------------------------------------------------------------------------------- /pygments/styles/emacs.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.styles.emacs 4 | ~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | A highlighting style for Pygments, inspired by Emacs. 7 | 8 | :copyright: Copyright 2006-2015 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, Generic, Whitespace 15 | 16 | 17 | class EmacsStyle(Style): 18 | """ 19 | The default style (inspired by Emacs 22). 20 | """ 21 | 22 | background_color = "#f8f8f8" 23 | default_style = "" 24 | 25 | styles = { 26 | Whitespace: "#bbbbbb", 27 | Comment: "italic #008800", 28 | Comment.Preproc: "noitalic", 29 | Comment.Special: "noitalic bold", 30 | 31 | Keyword: "bold #AA22FF", 32 | Keyword.Pseudo: "nobold", 33 | Keyword.Type: "bold #00BB00", 34 | 35 | Operator: "#666666", 36 | Operator.Word: "bold #AA22FF", 37 | 38 | Name.Builtin: "#AA22FF", 39 | Name.Function: "#00A000", 40 | Name.Class: "#0000FF", 41 | Name.Namespace: "bold #0000FF", 42 | Name.Exception: "bold #D2413A", 43 | Name.Variable: "#B8860B", 44 | Name.Constant: "#880000", 45 | Name.Label: "#A0A000", 46 | Name.Entity: "bold #999999", 47 | Name.Attribute: "#BB4444", 48 | Name.Tag: "bold #008000", 49 | Name.Decorator: "#AA22FF", 50 | 51 | String: "#BB4444", 52 | String.Doc: "italic", 53 | String.Interpol: "bold #BB6688", 54 | String.Escape: "bold #BB6622", 55 | String.Regex: "#BB6688", 56 | String.Symbol: "#B8860B", 57 | String.Other: "#008000", 58 | Number: "#666666", 59 | 60 | Generic.Heading: "bold #000080", 61 | Generic.Subheading: "bold #800080", 62 | Generic.Deleted: "#A00000", 63 | Generic.Inserted: "#00A000", 64 | Generic.Error: "#FF0000", 65 | Generic.Emph: "italic", 66 | Generic.Strong: "bold", 67 | Generic.Prompt: "bold #000080", 68 | Generic.Output: "#888", 69 | Generic.Traceback: "#04D", 70 | 71 | Error: "border:#FF0000" 72 | } 73 | -------------------------------------------------------------------------------- /pygments/styles/friendly.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.styles.friendly 4 | ~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | A modern style based on the VIM pyte theme. 7 | 8 | :copyright: Copyright 2006-2015 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, Generic, Whitespace 15 | 16 | 17 | class FriendlyStyle(Style): 18 | """ 19 | A modern style based on the VIM pyte theme. 20 | """ 21 | 22 | background_color = "#f0f0f0" 23 | default_style = "" 24 | 25 | styles = { 26 | Whitespace: "#bbbbbb", 27 | Comment: "italic #60a0b0", 28 | Comment.Preproc: "noitalic #007020", 29 | Comment.Special: "noitalic bg:#fff0f0", 30 | 31 | Keyword: "bold #007020", 32 | Keyword.Pseudo: "nobold", 33 | Keyword.Type: "nobold #902000", 34 | 35 | Operator: "#666666", 36 | Operator.Word: "bold #007020", 37 | 38 | Name.Builtin: "#007020", 39 | Name.Function: "#06287e", 40 | Name.Class: "bold #0e84b5", 41 | Name.Namespace: "bold #0e84b5", 42 | Name.Exception: "#007020", 43 | Name.Variable: "#bb60d5", 44 | Name.Constant: "#60add5", 45 | Name.Label: "bold #002070", 46 | Name.Entity: "bold #d55537", 47 | Name.Attribute: "#4070a0", 48 | Name.Tag: "bold #062873", 49 | Name.Decorator: "bold #555555", 50 | 51 | String: "#4070a0", 52 | String.Doc: "italic", 53 | String.Interpol: "italic #70a0d0", 54 | String.Escape: "bold #4070a0", 55 | String.Regex: "#235388", 56 | String.Symbol: "#517918", 57 | String.Other: "#c65d09", 58 | Number: "#40a070", 59 | 60 | Generic.Heading: "bold #000080", 61 | Generic.Subheading: "bold #800080", 62 | Generic.Deleted: "#A00000", 63 | Generic.Inserted: "#00A000", 64 | Generic.Error: "#FF0000", 65 | Generic.Emph: "italic", 66 | Generic.Strong: "bold", 67 | Generic.Prompt: "bold #c65d09", 68 | Generic.Output: "#888", 69 | Generic.Traceback: "#04D", 70 | 71 | Error: "border:#FF0000" 72 | } 73 | -------------------------------------------------------------------------------- /pygments/styles/fruity.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.styles.fruity 4 | ~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | pygments version of my "fruity" vim theme. 7 | 8 | :copyright: Copyright 2006-2015 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 Token, Comment, Name, Keyword, \ 14 | Generic, Number, String, Whitespace 15 | 16 | class FruityStyle(Style): 17 | """ 18 | Pygments version of the "native" vim theme. 19 | """ 20 | 21 | background_color = '#111111' 22 | highlight_color = '#333333' 23 | 24 | styles = { 25 | Whitespace: '#888888', 26 | Token: '#ffffff', 27 | Generic.Output: '#444444 bg:#222222', 28 | Keyword: '#fb660a bold', 29 | Keyword.Pseudo: 'nobold', 30 | Number: '#0086f7 bold', 31 | Name.Tag: '#fb660a bold', 32 | Name.Variable: '#fb660a', 33 | Comment: '#008800 bg:#0f140f italic', 34 | Name.Attribute: '#ff0086 bold', 35 | String: '#0086d2', 36 | Name.Function: '#ff0086 bold', 37 | Generic.Heading: '#ffffff bold', 38 | Keyword.Type: '#cdcaa9 bold', 39 | Generic.Subheading: '#ffffff bold', 40 | Name.Constant: '#0086d2', 41 | Comment.Preproc: '#ff0007 bold' 42 | } 43 | -------------------------------------------------------------------------------- /pygments/styles/igor.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.styles.igor 4 | ~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Igor Pro default style. 7 | 8 | :copyright: Copyright 2006-2015 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 14 | 15 | 16 | class IgorStyle(Style): 17 | """ 18 | Pygments version of the official colors for Igor Pro procedures. 19 | """ 20 | default_style = "" 21 | 22 | styles = { 23 | Comment: 'italic #FF0000', 24 | Keyword: '#0000FF', 25 | Name.Function: '#C34E00', 26 | Name.Decorator: '#CC00A3', 27 | Name.Class: '#007575', 28 | String: '#009C00' 29 | } 30 | -------------------------------------------------------------------------------- /pygments/styles/manni.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.styles.manni 4 | ~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | A colorful style, inspired by the terminal highlighting style. 7 | 8 | This is a port of the style used in the `php port`_ of pygments 9 | by Manni. The style is called 'default' there. 10 | 11 | :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 12 | :license: BSD, see LICENSE for details. 13 | """ 14 | 15 | from pygments.style import Style 16 | from pygments.token import Keyword, Name, Comment, String, Error, \ 17 | Number, Operator, Generic, Whitespace 18 | 19 | 20 | class ManniStyle(Style): 21 | """ 22 | A colorful style, inspired by the terminal highlighting style. 23 | """ 24 | 25 | background_color = '#f0f3f3' 26 | 27 | styles = { 28 | Whitespace: '#bbbbbb', 29 | Comment: 'italic #0099FF', 30 | Comment.Preproc: 'noitalic #009999', 31 | Comment.Special: 'bold', 32 | 33 | Keyword: 'bold #006699', 34 | Keyword.Pseudo: 'nobold', 35 | Keyword.Type: '#007788', 36 | 37 | Operator: '#555555', 38 | Operator.Word: 'bold #000000', 39 | 40 | Name.Builtin: '#336666', 41 | Name.Function: '#CC00FF', 42 | Name.Class: 'bold #00AA88', 43 | Name.Namespace: 'bold #00CCFF', 44 | Name.Exception: 'bold #CC0000', 45 | Name.Variable: '#003333', 46 | Name.Constant: '#336600', 47 | Name.Label: '#9999FF', 48 | Name.Entity: 'bold #999999', 49 | Name.Attribute: '#330099', 50 | Name.Tag: 'bold #330099', 51 | Name.Decorator: '#9999FF', 52 | 53 | String: '#CC3300', 54 | String.Doc: 'italic', 55 | String.Interpol: '#AA0000', 56 | String.Escape: 'bold #CC3300', 57 | String.Regex: '#33AAAA', 58 | String.Symbol: '#FFCC33', 59 | String.Other: '#CC3300', 60 | 61 | Number: '#FF6600', 62 | 63 | Generic.Heading: 'bold #003300', 64 | Generic.Subheading: 'bold #003300', 65 | Generic.Deleted: 'border:#CC0000 bg:#FFCCCC', 66 | Generic.Inserted: 'border:#00CC00 bg:#CCFFCC', 67 | Generic.Error: '#FF0000', 68 | Generic.Emph: 'italic', 69 | Generic.Strong: 'bold', 70 | Generic.Prompt: 'bold #000099', 71 | Generic.Output: '#AAAAAA', 72 | Generic.Traceback: '#99CC66', 73 | 74 | Error: 'bg:#FFAAAA #AA0000' 75 | } 76 | -------------------------------------------------------------------------------- /pygments/styles/monokai.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.styles.monokai 4 | ~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Mimic the Monokai color scheme. Based on tango.py. 7 | 8 | http://www.monokai.nl/blog/2006/07/15/textmate-color-theme/ 9 | 10 | :copyright: Copyright 2006-2015 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, Text, \ 16 | Number, Operator, Generic, Whitespace, Punctuation, Other, Literal 17 | 18 | class MonokaiStyle(Style): 19 | """ 20 | This style mimics the Monokai color scheme. 21 | """ 22 | 23 | background_color = "#272822" 24 | highlight_color = "#49483e" 25 | 26 | styles = { 27 | # No corresponding class for the following: 28 | Text: "#f8f8f2", # class: '' 29 | Whitespace: "", # class: 'w' 30 | Error: "#960050 bg:#1e0010", # class: 'err' 31 | Other: "", # class 'x' 32 | 33 | Comment: "#75715e", # class: 'c' 34 | Comment.Multiline: "", # class: 'cm' 35 | Comment.Preproc: "", # class: 'cp' 36 | Comment.Single: "", # class: 'c1' 37 | Comment.Special: "", # class: 'cs' 38 | 39 | Keyword: "#66d9ef", # class: 'k' 40 | Keyword.Constant: "", # class: 'kc' 41 | Keyword.Declaration: "", # class: 'kd' 42 | Keyword.Namespace: "#f92672", # class: 'kn' 43 | Keyword.Pseudo: "", # class: 'kp' 44 | Keyword.Reserved: "", # class: 'kr' 45 | Keyword.Type: "", # class: 'kt' 46 | 47 | Operator: "#f92672", # class: 'o' 48 | Operator.Word: "", # class: 'ow' - like keywords 49 | 50 | Punctuation: "#f8f8f2", # class: 'p' 51 | 52 | Name: "#f8f8f2", # class: 'n' 53 | Name.Attribute: "#a6e22e", # class: 'na' - to be revised 54 | Name.Builtin: "", # class: 'nb' 55 | Name.Builtin.Pseudo: "", # class: 'bp' 56 | Name.Class: "#a6e22e", # class: 'nc' - to be revised 57 | Name.Constant: "#66d9ef", # class: 'no' - to be revised 58 | Name.Decorator: "#a6e22e", # class: 'nd' - to be revised 59 | Name.Entity: "", # class: 'ni' 60 | Name.Exception: "#a6e22e", # class: 'ne' 61 | Name.Function: "#a6e22e", # class: 'nf' 62 | Name.Property: "", # class: 'py' 63 | Name.Label: "", # class: 'nl' 64 | Name.Namespace: "", # class: 'nn' - to be revised 65 | Name.Other: "#a6e22e", # class: 'nx' 66 | Name.Tag: "#f92672", # class: 'nt' - like a keyword 67 | Name.Variable: "", # class: 'nv' - to be revised 68 | Name.Variable.Class: "", # class: 'vc' - to be revised 69 | Name.Variable.Global: "", # class: 'vg' - to be revised 70 | Name.Variable.Instance: "", # class: 'vi' - to be revised 71 | 72 | Number: "#ae81ff", # class: 'm' 73 | Number.Float: "", # class: 'mf' 74 | Number.Hex: "", # class: 'mh' 75 | Number.Integer: "", # class: 'mi' 76 | Number.Integer.Long: "", # class: 'il' 77 | Number.Oct: "", # class: 'mo' 78 | 79 | Literal: "#ae81ff", # class: 'l' 80 | Literal.Date: "#e6db74", # class: 'ld' 81 | 82 | String: "#e6db74", # class: 's' 83 | String.Backtick: "", # class: 'sb' 84 | String.Char: "", # class: 'sc' 85 | String.Doc: "", # class: 'sd' - like a comment 86 | String.Double: "", # class: 's2' 87 | String.Escape: "#ae81ff", # class: 'se' 88 | String.Heredoc: "", # class: 'sh' 89 | String.Interpol: "", # class: 'si' 90 | String.Other: "", # class: 'sx' 91 | String.Regex: "", # class: 'sr' 92 | String.Single: "", # class: 's1' 93 | String.Symbol: "", # class: 'ss' 94 | 95 | Generic: "", # class: 'g' 96 | Generic.Deleted: "#f92672", # class: 'gd', 97 | Generic.Emph: "italic", # class: 'ge' 98 | Generic.Error: "", # class: 'gr' 99 | Generic.Heading: "", # class: 'gh' 100 | Generic.Inserted: "#a6e22e", # class: 'gi' 101 | Generic.Output: "", # class: 'go' 102 | Generic.Prompt: "", # class: 'gp' 103 | Generic.Strong: "bold", # class: 'gs' 104 | Generic.Subheading: "#75715e", # class: 'gu' 105 | Generic.Traceback: "", # class: 'gt' 106 | } 107 | -------------------------------------------------------------------------------- /pygments/styles/murphy.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.styles.murphy 4 | ~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Murphy's style from CodeRay. 7 | 8 | :copyright: Copyright 2006-2015 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, Generic, Whitespace 15 | 16 | 17 | class MurphyStyle(Style): 18 | """ 19 | Murphy's style from CodeRay. 20 | """ 21 | 22 | default_style = "" 23 | 24 | styles = { 25 | Whitespace: "#bbbbbb", 26 | Comment: "#666 italic", 27 | Comment.Preproc: "#579 noitalic", 28 | Comment.Special: "#c00 bold", 29 | 30 | Keyword: "bold #289", 31 | Keyword.Pseudo: "#08f", 32 | Keyword.Type: "#66f", 33 | 34 | Operator: "#333", 35 | Operator.Word: "bold #000", 36 | 37 | Name.Builtin: "#072", 38 | Name.Function: "bold #5ed", 39 | Name.Class: "bold #e9e", 40 | Name.Namespace: "bold #0e84b5", 41 | Name.Exception: "bold #F00", 42 | Name.Variable: "#036", 43 | Name.Variable.Instance: "#aaf", 44 | Name.Variable.Class: "#ccf", 45 | Name.Variable.Global: "#f84", 46 | Name.Constant: "bold #5ed", 47 | Name.Label: "bold #970", 48 | Name.Entity: "#800", 49 | Name.Attribute: "#007", 50 | Name.Tag: "#070", 51 | Name.Decorator: "bold #555", 52 | 53 | String: "bg:#e0e0ff", 54 | String.Char: "#88F bg:", 55 | String.Doc: "#D42 bg:", 56 | String.Interpol: "bg:#eee", 57 | String.Escape: "bold #666", 58 | String.Regex: "bg:#e0e0ff #000", 59 | String.Symbol: "#fc8 bg:", 60 | String.Other: "#f88", 61 | 62 | Number: "bold #60E", 63 | Number.Integer: "bold #66f", 64 | Number.Float: "bold #60E", 65 | Number.Hex: "bold #058", 66 | Number.Oct: "bold #40E", 67 | 68 | Generic.Heading: "bold #000080", 69 | Generic.Subheading: "bold #800080", 70 | Generic.Deleted: "#A00000", 71 | Generic.Inserted: "#00A000", 72 | Generic.Error: "#FF0000", 73 | Generic.Emph: "italic", 74 | Generic.Strong: "bold", 75 | Generic.Prompt: "bold #c65d09", 76 | Generic.Output: "#888", 77 | Generic.Traceback: "#04D", 78 | 79 | Error: "#F00 bg:#FAA" 80 | } 81 | -------------------------------------------------------------------------------- /pygments/styles/native.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.styles.native 4 | ~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | pygments version of my "native" vim theme. 7 | 8 | :copyright: Copyright 2006-2015 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, Generic, Token, Whitespace 15 | 16 | 17 | class NativeStyle(Style): 18 | """ 19 | Pygments version of the "native" vim theme. 20 | """ 21 | 22 | background_color = '#202020' 23 | highlight_color = '#404040' 24 | 25 | styles = { 26 | Token: '#d0d0d0', 27 | Whitespace: '#666666', 28 | 29 | Comment: 'italic #999999', 30 | Comment.Preproc: 'noitalic bold #cd2828', 31 | Comment.Special: 'noitalic bold #e50808 bg:#520000', 32 | 33 | Keyword: 'bold #6ab825', 34 | Keyword.Pseudo: 'nobold', 35 | Operator.Word: 'bold #6ab825', 36 | 37 | String: '#ed9d13', 38 | String.Other: '#ffa500', 39 | 40 | Number: '#3677a9', 41 | 42 | Name.Builtin: '#24909d', 43 | Name.Variable: '#40ffff', 44 | Name.Constant: '#40ffff', 45 | Name.Class: 'underline #447fcf', 46 | Name.Function: '#447fcf', 47 | Name.Namespace: 'underline #447fcf', 48 | Name.Exception: '#bbbbbb', 49 | Name.Tag: 'bold #6ab825', 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/pastie.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.styles.pastie 4 | ~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Style similar to the `pastie`_ default style. 7 | 8 | .. _pastie: http://pastie.caboo.se/ 9 | 10 | :copyright: Copyright 2006-2015 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 PastieStyle(Style): 20 | """ 21 | Style similar to the pastie default style. 22 | """ 23 | 24 | default_style = '' 25 | 26 | styles = { 27 | Whitespace: '#bbbbbb', 28 | Comment: '#888888', 29 | Comment.Preproc: 'bold #cc0000', 30 | Comment.Special: 'bg:#fff0f0 bold #cc0000', 31 | 32 | String: 'bg:#fff0f0 #dd2200', 33 | String.Regex: 'bg:#fff0ff #008800', 34 | String.Other: 'bg:#f0fff0 #22bb22', 35 | String.Symbol: '#aa6600', 36 | String.Interpol: '#3333bb', 37 | String.Escape: '#0044dd', 38 | 39 | Operator.Word: '#008800', 40 | 41 | Keyword: 'bold #008800', 42 | Keyword.Pseudo: 'nobold', 43 | Keyword.Type: '#888888', 44 | 45 | Name.Class: 'bold #bb0066', 46 | Name.Exception: 'bold #bb0066', 47 | Name.Function: 'bold #0066bb', 48 | Name.Property: 'bold #336699', 49 | Name.Namespace: 'bold #bb0066', 50 | Name.Builtin: '#003388', 51 | Name.Variable: '#336699', 52 | Name.Variable.Class: '#336699', 53 | Name.Variable.Instance: '#3333bb', 54 | Name.Variable.Global: '#dd7700', 55 | Name.Constant: 'bold #003366', 56 | Name.Tag: 'bold #bb0066', 57 | Name.Attribute: '#336699', 58 | Name.Decorator: '#555555', 59 | Name.Label: 'italic #336699', 60 | 61 | Number: 'bold #0000DD', 62 | 63 | Generic.Heading: '#333', 64 | Generic.Subheading: '#666', 65 | Generic.Deleted: 'bg:#ffdddd #000000', 66 | Generic.Inserted: 'bg:#ddffdd #000000', 67 | Generic.Error: '#aa0000', 68 | Generic.Emph: 'italic', 69 | Generic.Strong: 'bold', 70 | Generic.Prompt: '#555555', 71 | Generic.Output: '#888888', 72 | Generic.Traceback: '#aa0000', 73 | 74 | Error: 'bg:#e3d2d2 #a61717' 75 | } 76 | -------------------------------------------------------------------------------- /pygments/styles/perldoc.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.styles.perldoc 4 | ~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Style similar to the style used in the `perldoc`_ code blocks. 7 | 8 | .. _perldoc: http://perldoc.perl.org/ 9 | 10 | :copyright: Copyright 2006-2015 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 PerldocStyle(Style): 20 | """ 21 | Style similar to the style used in the perldoc code blocks. 22 | """ 23 | 24 | background_color = '#eeeedd' 25 | default_style = '' 26 | 27 | styles = { 28 | Whitespace: '#bbbbbb', 29 | Comment: '#228B22', 30 | Comment.Preproc: '#1e889b', 31 | Comment.Special: '#8B008B bold', 32 | 33 | String: '#CD5555', 34 | String.Heredoc: '#1c7e71 italic', 35 | String.Regex: '#B452CD', 36 | String.Other: '#cb6c20', 37 | String.Regex: '#1c7e71', 38 | 39 | Number: '#B452CD', 40 | 41 | Operator.Word: '#8B008B', 42 | 43 | Keyword: '#8B008B bold', 44 | Keyword.Type: '#a7a7a7', 45 | 46 | Name.Class: '#008b45 bold', 47 | Name.Exception: '#008b45 bold', 48 | Name.Function: '#008b45', 49 | Name.Namespace: '#008b45 underline', 50 | Name.Variable: '#00688B', 51 | Name.Constant: '#00688B', 52 | Name.Decorator: '#707a7c', 53 | Name.Tag: '#8B008B bold', 54 | Name.Attribute: '#658b00', 55 | Name.Builtin: '#658b00', 56 | 57 | Generic.Heading: 'bold #000080', 58 | Generic.Subheading: 'bold #800080', 59 | Generic.Deleted: '#aa0000', 60 | Generic.Inserted: '#00aa00', 61 | Generic.Error: '#aa0000', 62 | Generic.Emph: 'italic', 63 | Generic.Strong: 'bold', 64 | Generic.Prompt: '#555555', 65 | Generic.Output: '#888888', 66 | Generic.Traceback: '#aa0000', 67 | 68 | Error: 'bg:#e3d2d2 #a61717' 69 | } 70 | -------------------------------------------------------------------------------- /pygments/styles/rrt.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.styles.rrt 4 | ~~~~~~~~~~~~~~~~~~~ 5 | 6 | pygments "rrt" theme, based on Zap and Emacs defaults. 7 | 8 | :copyright: Copyright 2006-2015 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 Comment, Name, Keyword, String 14 | 15 | 16 | class RrtStyle(Style): 17 | """ 18 | Minimalistic "rrt" theme, based on Zap and Emacs defaults. 19 | """ 20 | 21 | background_color = '#000000' 22 | highlight_color = '#0000ff' 23 | 24 | styles = { 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/trac.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.styles.trac 4 | ~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Port of the default trac highlighter design. 7 | 8 | :copyright: Copyright 2006-2015 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, Generic, Whitespace 15 | 16 | 17 | class TracStyle(Style): 18 | """ 19 | Port of the default trac highlighter design. 20 | """ 21 | 22 | default_style = '' 23 | 24 | styles = { 25 | Whitespace: '#bbbbbb', 26 | Comment: 'italic #999988', 27 | Comment.Preproc: 'bold noitalic #999999', 28 | Comment.Special: 'bold #999999', 29 | 30 | Operator: 'bold', 31 | 32 | String: '#bb8844', 33 | String.Regex: '#808000', 34 | 35 | Number: '#009999', 36 | 37 | Keyword: 'bold', 38 | Keyword.Type: '#445588', 39 | 40 | Name.Builtin: '#999999', 41 | Name.Function: 'bold #990000', 42 | Name.Class: 'bold #445588', 43 | Name.Exception: 'bold #990000', 44 | Name.Namespace: '#555555', 45 | Name.Variable: '#008080', 46 | Name.Constant: '#008080', 47 | Name.Tag: '#000080', 48 | Name.Attribute: '#008080', 49 | Name.Entity: '#800080', 50 | 51 | Generic.Heading: '#999999', 52 | Generic.Subheading: '#aaaaaa', 53 | Generic.Deleted: 'bg:#ffdddd #000000', 54 | Generic.Inserted: 'bg:#ddffdd #000000', 55 | Generic.Error: '#aa0000', 56 | Generic.Emph: 'italic', 57 | Generic.Strong: 'bold', 58 | Generic.Prompt: '#555555', 59 | Generic.Output: '#888888', 60 | Generic.Traceback: '#aa0000', 61 | 62 | Error: 'bg:#e3d2d2 #a61717' 63 | } 64 | -------------------------------------------------------------------------------- /pygments/styles/vim.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.styles.vim 4 | ~~~~~~~~~~~~~~~~~~~ 5 | 6 | A highlighting style for Pygments, inspired by vim. 7 | 8 | :copyright: Copyright 2006-2015 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, Generic, Whitespace, Token 15 | 16 | 17 | class VimStyle(Style): 18 | """ 19 | Styles somewhat like vim 7.0 20 | """ 21 | 22 | background_color = "#000000" 23 | highlight_color = "#222222" 24 | default_style = "#cccccc" 25 | 26 | styles = { 27 | Token: "#cccccc", 28 | Whitespace: "", 29 | Comment: "#000080", 30 | Comment.Preproc: "", 31 | Comment.Special: "bold #cd0000", 32 | 33 | Keyword: "#cdcd00", 34 | Keyword.Declaration: "#00cd00", 35 | Keyword.Namespace: "#cd00cd", 36 | Keyword.Pseudo: "", 37 | Keyword.Type: "#00cd00", 38 | 39 | Operator: "#3399cc", 40 | Operator.Word: "#cdcd00", 41 | 42 | Name: "", 43 | Name.Class: "#00cdcd", 44 | Name.Builtin: "#cd00cd", 45 | Name.Exception: "bold #666699", 46 | Name.Variable: "#00cdcd", 47 | 48 | String: "#cd0000", 49 | Number: "#cd00cd", 50 | 51 | Generic.Heading: "bold #000080", 52 | Generic.Subheading: "bold #800080", 53 | Generic.Deleted: "#cd0000", 54 | Generic.Inserted: "#00cd00", 55 | Generic.Error: "#FF0000", 56 | Generic.Emph: "italic", 57 | Generic.Strong: "bold", 58 | Generic.Prompt: "bold #000080", 59 | Generic.Output: "#888", 60 | Generic.Traceback: "#04D", 61 | 62 | Error: "border:#FF0000" 63 | } 64 | -------------------------------------------------------------------------------- /pygments/styles/vs.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.styles.vs 4 | ~~~~~~~~~~~~~~~~~~ 5 | 6 | Simple style with MS Visual Studio colors. 7 | 8 | :copyright: Copyright 2006-2015 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 | Operator, Generic 15 | 16 | 17 | class VisualStudioStyle(Style): 18 | 19 | background_color = "#ffffff" 20 | default_style = "" 21 | 22 | styles = { 23 | Comment: "#008000", 24 | Comment.Preproc: "#0000ff", 25 | Keyword: "#0000ff", 26 | Operator.Word: "#0000ff", 27 | Keyword.Type: "#2b91af", 28 | Name.Class: "#2b91af", 29 | String: "#a31515", 30 | 31 | Generic.Heading: "bold", 32 | Generic.Subheading: "bold", 33 | Generic.Emph: "italic", 34 | Generic.Strong: "bold", 35 | Generic.Prompt: "bold", 36 | 37 | Error: "border:#FF0000" 38 | } 39 | -------------------------------------------------------------------------------- /pygments/styles/xcode.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | pygments.styles.xcode 4 | ~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Style similar to the `Xcode` default theme. 7 | 8 | :copyright: Copyright 2006-2015 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, Literal 15 | 16 | 17 | class XcodeStyle(Style): 18 | """ 19 | Style similar to the Xcode default colouring theme. 20 | """ 21 | 22 | default_style = '' 23 | 24 | styles = { 25 | Comment: '#177500', 26 | Comment.Preproc: '#633820', 27 | 28 | String: '#C41A16', 29 | String.Char: '#2300CE', 30 | 31 | Operator: '#000000', 32 | 33 | Keyword: '#A90D91', 34 | 35 | Name: '#000000', 36 | Name.Attribute: '#836C28', 37 | Name.Class: '#3F6E75', 38 | Name.Function: '#000000', 39 | Name.Builtin: '#A90D91', 40 | # In Obj-C code this token is used to colour Cocoa types 41 | Name.Builtin.Pseudo: '#5B269A', 42 | Name.Variable: '#000000', 43 | Name.Tag: '#000000', 44 | Name.Decorator: '#000000', 45 | # Workaround for a BUG here: lexer treats multiline method signatres as labels 46 | Name.Label: '#000000', 47 | 48 | Literal: '#1C01CE', 49 | Number: '#1C01CE', 50 | Error: '#000000', 51 | } 52 | --------------------------------------------------------------------------------