CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/assets/rainbow/python.js
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
/**
7
* Python patterns
8
*
9
* @author Craig Campbell
10
* @version 1.0.6
11
*/
12
Rainbow.extend('python', [
13
/**
14
* don't highlight self as a keyword
15
*/
16
{
17
'name': 'variable.self',
18
'pattern': /self/g
19
},
20
{
21
'name': 'constant.language',
22
'pattern': /None|True|False/g
23
},
24
{
25
'name': 'support.object',
26
'pattern': /object/g
27
},
28
29
/**
30
* built in python functions
31
*
32
* this entire list is 580 bytes minified / 379 bytes gzipped
33
*
34
* @see http://docs.python.org/library/functions.html
35
*
36
* @todo strip some out or consolidate the regexes with matching patterns?
37
*/
38
{
39
'name': 'support.function.python',
40
'pattern': /\b(bs|divmod|input|open|staticmethod|all|enumerate|int|ord|str|any|eval|isinstance|pow|sum|basestring|execfile|issubclass|print|super|bin|file|iter|property|tuple|bool|filter|len|range|type|bytearray|float|list|raw_input|unichr|callable|format|locals|reduce|unicode|chr|frozenset|long|reload|vars|classmethod|getattr|map|repr|xrange|cmp|globals|max|reversed|zip|compile|hasattr|memoryview|round|__import__|complex|hash|min|set|apply|delattr|help|next|setattr|buffer|dict|hex|object|slice|coerce|dir|id|oct|sorted|intern)(?=\()/g
41
},
42
{
43
'matches': {
44
1: 'keyword'
45
},
46
'pattern': /\b(pass|lambda|with|is|not|in|from|elif)(?=\(|\b)/g
47
},
48
{
49
'matches': {
50
1: 'storage.class',
51
2: 'entity.name.class',
52
3: 'entity.other.inherited-class'
53
},
54
'pattern': /(class)\s+(\w+)\((\w+?)\)/g
55
},
56
{
57
'matches': {
58
1: 'storage.function',
59
2: 'support.magic'
60
},
61
'pattern': /(def)\s+(__\w+)(?=\()/g
62
},
63
{
64
'name': 'support.magic',
65
'pattern': /__(name)__/g
66
},
67
{
68
'matches': {
69
1: 'keyword.control',
70
2: 'support.exception.type'
71
},
72
'pattern': /(except) (\w+):/g
73
},
74
{
75
'matches': {
76
1: 'storage.function',
77
2: 'entity.name.function'
78
},
79
'pattern': /(def)\s+(\w+)(?=\()/g
80
},
81
{
82
'name': 'entity.name.function.decorator',
83
'pattern': /@(\w+)/g
84
},
85
{
86
'name': 'comment.docstring',
87
'pattern': /('{3}|"{3})[\s\S]*?\1/gm
88
}
89
]);
90
91