1 | Prism.languages.python = {
|
2 | 'comment': {
|
3 | pattern: /(^|[^\\])#.*/,
|
4 | lookbehind: true
|
5 | },
|
6 | 'string-interpolation': {
|
7 | pattern: /(?:f|rf|fr)(?:("""|''')[\s\S]*?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2)/i,
|
8 | greedy: true,
|
9 | inside: {
|
10 | 'interpolation': {
|
11 |
|
12 | pattern: /((?:^|[^{])(?:{{)*){(?!{)(?:[^{}]|{(?!{)(?:[^{}]|{(?!{)(?:[^{}])+})+})+}/,
|
13 | lookbehind: true,
|
14 | inside: {
|
15 | 'format-spec': {
|
16 | pattern: /(:)[^:(){}]+(?=}$)/,
|
17 | lookbehind: true
|
18 | },
|
19 | 'conversion-option': {
|
20 | pattern: /![sra](?=[:}]$)/,
|
21 | alias: 'punctuation'
|
22 | },
|
23 | rest: null
|
24 | }
|
25 | },
|
26 | 'string': /[\s\S]+/
|
27 | }
|
28 | },
|
29 | 'triple-quoted-string': {
|
30 | pattern: /(?:[rub]|rb|br)?("""|''')[\s\S]*?\1/i,
|
31 | greedy: true,
|
32 | alias: 'string'
|
33 | },
|
34 | 'string': {
|
35 | pattern: /(?:[rub]|rb|br)?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/i,
|
36 | greedy: true
|
37 | },
|
38 | 'function': {
|
39 | pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g,
|
40 | lookbehind: true
|
41 | },
|
42 | 'class-name': {
|
43 | pattern: /(\bclass\s+)\w+/i,
|
44 | lookbehind: true
|
45 | },
|
46 | 'decorator': {
|
47 | pattern: /(^\s*)@\w+(?:\.\w+)*/im,
|
48 | lookbehind: true,
|
49 | alias: ['annotation', 'punctuation'],
|
50 | inside: {
|
51 | 'punctuation': /\./
|
52 | }
|
53 | },
|
54 | 'keyword': /\b(?:and|as|assert|async|await|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|nonlocal|not|or|pass|print|raise|return|try|while|with|yield)\b/,
|
55 | 'builtin': /\b(?:__import__|abs|all|any|apply|ascii|basestring|bin|bool|buffer|bytearray|bytes|callable|chr|classmethod|cmp|coerce|compile|complex|delattr|dict|dir|divmod|enumerate|eval|execfile|file|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|intern|isinstance|issubclass|iter|len|list|locals|long|map|max|memoryview|min|next|object|oct|open|ord|pow|property|range|raw_input|reduce|reload|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|unichr|unicode|vars|xrange|zip)\b/,
|
56 | 'boolean': /\b(?:True|False|None)\b/,
|
57 | 'number': /(?:\b(?=\d)|\B(?=\.))(?:0[bo])?(?:(?:\d|0x[\da-f])[\da-f]*\.?\d*|\.\d+)(?:e[+-]?\d+)?j?\b/i,
|
58 | 'operator': /[-+%=]=?|!=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,
|
59 | 'punctuation': /[{}[\];(),.:]/
|
60 | };
|
61 |
|
62 | Prism.languages.python['string-interpolation'].inside['interpolation'].inside.rest = Prism.languages.python;
|
63 |
|
64 | Prism.languages.py = Prism.languages.python;
|