[d24f17c] | 1 | 'use strict'
|
---|
| 2 |
|
---|
| 3 | module.exports = python
|
---|
| 4 | python.displayName = 'python'
|
---|
| 5 | python.aliases = ['py']
|
---|
| 6 | function python(Prism) {
|
---|
| 7 | Prism.languages.python = {
|
---|
| 8 | comment: {
|
---|
| 9 | pattern: /(^|[^\\])#.*/,
|
---|
| 10 | lookbehind: true,
|
---|
| 11 | greedy: true
|
---|
| 12 | },
|
---|
| 13 | 'string-interpolation': {
|
---|
| 14 | pattern:
|
---|
| 15 | /(?:f|fr|rf)(?:("""|''')[\s\S]*?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2)/i,
|
---|
| 16 | greedy: true,
|
---|
| 17 | inside: {
|
---|
| 18 | interpolation: {
|
---|
| 19 | // "{" <expression> <optional "!s", "!r", or "!a"> <optional ":" format specifier> "}"
|
---|
| 20 | pattern:
|
---|
| 21 | /((?:^|[^{])(?:\{\{)*)\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}])+\})+\})+\}/,
|
---|
| 22 | lookbehind: true,
|
---|
| 23 | inside: {
|
---|
| 24 | 'format-spec': {
|
---|
| 25 | pattern: /(:)[^:(){}]+(?=\}$)/,
|
---|
| 26 | lookbehind: true
|
---|
| 27 | },
|
---|
| 28 | 'conversion-option': {
|
---|
| 29 | pattern: //,
|
---|
| 30 | alias: 'punctuation'
|
---|
| 31 | },
|
---|
| 32 | rest: null
|
---|
| 33 | }
|
---|
| 34 | },
|
---|
| 35 | string: /[\s\S]+/
|
---|
| 36 | }
|
---|
| 37 | },
|
---|
| 38 | 'triple-quoted-string': {
|
---|
| 39 | pattern: /(?:[rub]|br|rb)?("""|''')[\s\S]*?\1/i,
|
---|
| 40 | greedy: true,
|
---|
| 41 | alias: 'string'
|
---|
| 42 | },
|
---|
| 43 | string: {
|
---|
| 44 | pattern: /(?:[rub]|br|rb)?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/i,
|
---|
| 45 | greedy: true
|
---|
| 46 | },
|
---|
| 47 | function: {
|
---|
| 48 | pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g,
|
---|
| 49 | lookbehind: true
|
---|
| 50 | },
|
---|
| 51 | 'class-name': {
|
---|
| 52 | pattern: /(\bclass\s+)\w+/i,
|
---|
| 53 | lookbehind: true
|
---|
| 54 | },
|
---|
| 55 | decorator: {
|
---|
| 56 | pattern: /(^[\t ]*)@\w+(?:\.\w+)*/m,
|
---|
| 57 | lookbehind: true,
|
---|
| 58 | alias: ['annotation', 'punctuation'],
|
---|
| 59 | inside: {
|
---|
| 60 | punctuation: /\./
|
---|
| 61 | }
|
---|
| 62 | },
|
---|
| 63 | keyword:
|
---|
| 64 | /\b(?:_(?=\s*:)|and|as|assert|async|await|break|case|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|match|nonlocal|not|or|pass|print|raise|return|try|while|with|yield)\b/,
|
---|
| 65 | builtin:
|
---|
| 66 | /\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/,
|
---|
| 67 | boolean: /\b(?:False|None|True)\b/,
|
---|
| 68 | number:
|
---|
| 69 | /\b0(?:b(?:_?[01])+|o(?:_?[0-7])+|x(?:_?[a-f0-9])+)\b|(?:\b\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\B\.\d+(?:_\d+)*)(?:e[+-]?\d+(?:_\d+)*)?j?(?!\w)/i,
|
---|
| 70 | operator: /[-+%=]=?|!=|:=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,
|
---|
| 71 | punctuation: /[{}[\];(),.:]/
|
---|
| 72 | }
|
---|
| 73 | Prism.languages.python['string-interpolation'].inside[
|
---|
| 74 | 'interpolation'
|
---|
| 75 | ].inside.rest = Prism.languages.python
|
---|
| 76 | Prism.languages.py = Prism.languages.python
|
---|
| 77 | }
|
---|