{ "name": "MagicPython", "scopeName": "source.python", "fileTypes": [ "py", "py3", "rpy", "pyw", "cpy", "SConstruct", "Sconstruct", "sconstruct", "SConscript" ], "first_line_match": "^#!/.*\\bpython[\\d\\.]*\\b", "firstLineMatch": "^#!/.*\\bpython[\\d\\.]*\\b", "uuid": "742deb57-6e38-4192-bed6-410746efd85d", "patterns": [ { "include": "#statement" }, { "include": "#expression" } ], "repository": { "statement": { "patterns": [ { "include": "#import" }, { "include": "#class-declaration" }, { "include": "#function-declaration" }, { "include": "#statement-keyword" }, { "include": "#assignment-operator" }, { "include": "#decorator" }, { "include": "#docstring-statement" }, { "include": "#semicolon" } ] }, "semicolon": { "patterns": [ { "name": "invalid.deprecated.semicolon.python", "match": "\\;$" } ] }, "comments": { "patterns": [ { "name": "comment.line.number-sign.python", "contentName": "meta.typehint.comment.python", "begin": "(?x)\n (?:\n \\# \\s* (type:)\n \\s*+ (?# we want `\\s*+` which is possessive quantifier since\n we do not actually want to backtrack when matching\n whitespace here)\n (?! $ | \\#)\n )\n", "end": "(?:$|(?=\\#))", "beginCaptures": { "0": { "name": "meta.typehint.comment.python" }, "1": { "name": "comment.typehint.directive.notation.python" } }, "patterns": [ { "name": "comment.typehint.ignore.notation.python", "match": "(?x)\n \\G ignore\n (?= \\s* (?: $ | \\#))\n" }, { "name": "comment.typehint.type.notation.python", "match": "(?x)\n (?))" }, { "name": "comment.typehint.variable.notation.python", "match": "([[:alpha:]_]\\w*)" } ] }, { "include": "#comments-base" } ] }, "docstring-statement": { "begin": "^(?=\\s*[rR]?(\\'\\'\\'|\\\"\\\"\\\"|\\'|\\\"))", "end": "(?<=\\'\\'\\'|\\\"\\\"\\\"|\\'|\\\")", "patterns": [ { "include": "#docstring" } ] }, "docstring": { "patterns": [ { "name": "string.quoted.docstring.multi.python", "begin": "(\\'\\'\\'|\\\"\\\"\\\")", "end": "(\\1)", "beginCaptures": { "1": { "name": "punctuation.definition.string.begin.python" } }, "endCaptures": { "1": { "name": "punctuation.definition.string.end.python" } }, "patterns": [ { "include": "#docstring-prompt" }, { "include": "#codetags" }, { "include": "#docstring-guts-unicode" } ] }, { "name": "string.quoted.docstring.raw.multi.python", "begin": "([rR])(\\'\\'\\'|\\\"\\\"\\\")", "end": "(\\2)", "beginCaptures": { "1": { "name": "storage.type.string.python" }, "2": { "name": "punctuation.definition.string.begin.python" } }, "endCaptures": { "1": { "name": "punctuation.definition.string.end.python" } }, "patterns": [ { "include": "#string-consume-escape" }, { "include": "#docstring-prompt" }, { "include": "#codetags" } ] }, { "name": "string.quoted.docstring.single.python", "begin": "(\\'|\\\")", "end": "(\\1)|((?>>|\\.\\.\\.) \\s) (?=\\s*\\S)\n )\n", "captures": { "1": { "name": "keyword.control.flow.python" } } }, "codetags": { "match": "(?:\\b(NOTE|XXX|HACK|FIXME|BUG|TODO)\\b)", "captures": { "1": { "name": "keyword.codetag.notation.python" } } }, "statement-keyword": { "patterns": [ { "name": "storage.type.function.python", "match": "\\b((async\\s+)?\\s*def)\\b" }, { "name": "keyword.control.flow.python", "match": "(?x)\n \\b(?>= | //= | \\*\\*=\n | \\+= | -= | /= | @=\n | \\*= | %= | ~= | \\^= | &= | \\|=\n | =\n" }, "operator": { "match": "(?x)\n \\b(?> | & | \\| | \\^ | ~) (?# 3)\n\n | (\\*\\* | \\* | \\+ | - | % | // | / | @) (?# 4)\n\n | (!= | == | >= | <= | < | >) (?# 5)\n", "captures": { "1": { "name": "keyword.operator.logical.python" }, "2": { "name": "keyword.control.flow.python" }, "3": { "name": "keyword.operator.bitwise.python" }, "4": { "name": "keyword.operator.arithmetic.python" }, "5": { "name": "keyword.operator.comparison.python" } } }, "literal": { "patterns": [ { "name": "constant.language.python", "match": "\\b(True|False|None|NotImplemented|Ellipsis)\\b" }, { "include": "#number" } ] }, "number": { "name": "constant.numeric.python", "patterns": [ { "include": "#number-float" }, { "include": "#number-dec" }, { "include": "#number-hex" }, { "include": "#number-oct" }, { "include": "#number-bin" }, { "include": "#number-long" }, { "name": "invalid.illegal.name.python", "match": "\\b[0-9]+\\w+" } ] }, "number-float": { "name": "constant.numeric.float.python", "match": "(?x)\n (?=^]? [-+ ]? \\#?\n \\d* ,? (\\.\\d+)? [bcdeEfFgGnosxX%]? )?\n })\n )\n", "captures": { "2": { "name": "storage.type.format.python" }, "3": { "name": "support.other.format.python" } } }, { "name": "constant.character.format.placeholder.other.python", "begin": "(?x)\n \\{\n \\w*? (\\.[[:alpha:]_]\\w*? | \\[[^\\]'\"]+\\])*?\n (![rsa])?\n (:)\n (?=[^'\"}\\n]*\\})\n", "end": "\\}", "beginCaptures": { "2": { "name": "storage.type.format.python" }, "3": { "name": "support.other.format.python" } }, "patterns": [ { "match": "(?x) \\{ [^'\"}\\n]*? \\} (?=.*?\\})\n" } ] } ] }, "import": { "comment": "Import statements\n", "patterns": [ { "match": "(?x)\n \\s* \\b(from)\\b (\\s*\\.+\\s*) (import)?\n", "captures": { "1": { "name": "keyword.control.import.python" }, "3": { "name": "keyword.control.import.python" } } }, { "name": "keyword.control.import.python", "match": "\\b(?)", "end": "(?=:)", "beginCaptures": { "1": { "name": "punctuation.separator.annotation.result.python" } }, "patterns": [ { "include": "#expression" } ] }, "item-access": { "patterns": [ { "name": "meta.item-access.python", "begin": "(?x)\n \\b(?=\n [[:alpha:]_]\\w* \\s* \\[\n )\n", "end": "(\\])", "endCaptures": { "1": { "name": "punctuation.definition.arguments.end.python" } }, "patterns": [ { "include": "#item-name" }, { "include": "#item-index" }, { "include": "#expression" } ] } ] }, "item-name": { "patterns": [ { "include": "#special-variables" }, { "include": "#builtin-functions" }, { "include": "#special-names" }, { "match": "(?x)\n \\b ([[:alpha:]_]\\w*) \\b\n" } ] }, "item-index": { "begin": "(\\[)", "end": "(?=\\])", "beginCaptures": { "1": { "name": "punctuation.definition.arguments.begin.python" } }, "contentName": "meta.item-access.arguments.python", "patterns": [ { "include": "#expression" } ] }, "decorator": { "name": "meta.function.decorator.python", "begin": "(?x)\n ^\\s*\n (@) \\s* (?=[[:alpha:]_]\\w*)\n", "end": "(?x)\n ( \\) ) (?: (?=\\s*\\#|$) | (.*$) )\n | (?=\\n|\\#)\n", "beginCaptures": { "1": { "name": "entity.name.function.decorator.python" } }, "endCaptures": { "1": { "name": "punctuation.definition.arguments.end.python" }, "2": { "name": "invalid.illegal.decorator.python" } }, "patterns": [ { "include": "#decorator-name" }, { "include": "#function-arguments" } ] }, "decorator-name": { "patterns": [ { "include": "#builtin-callables" }, { "include": "#illegal-object-name" }, { "name": "entity.name.function.decorator.python", "match": "(?x)\n ([[:alpha:]_]\\w*) | \\.\n" }, { "include": "#line-continuation" }, { "name": "invalid.illegal.decorator.python", "match": "(?x)\n \\s* ([^([:alpha:]\\s_\\.#\\\\] .*?) (?=\\#|$)\n", "captures": { "1": { "name": "invalid.illegal.decorator.python" } } } ] }, "call-wrapper-inheritance": { "comment": "same as a funciton call, but in inheritance context", "name": "meta.function-call.python", "begin": "(?x)\n \\b(?=\n ([[:alpha:]_]\\w*) \\s* (\\()\n )\n", "end": "(\\))", "endCaptures": { "1": { "name": "punctuation.definition.arguments.end.python" } }, "patterns": [ { "include": "#inheritance-name" }, { "include": "#function-arguments" } ] }, "inheritance-name": { "patterns": [ { "include": "#lambda-incomplete" }, { "include": "#builtin-possible-callables" }, { "include": "#inheritance-identifier" } ] }, "function-call": { "name": "meta.function-call.python", "begin": "(?x)\n \\b(?=\n ([[:alpha:]_]\\w*) \\s* (\\()\n )\n", "end": "(\\))", "endCaptures": { "1": { "name": "punctuation.definition.arguments.end.python" } }, "patterns": [ { "include": "#special-variables" }, { "include": "#function-name" }, { "include": "#function-arguments" } ] }, "function-name": { "patterns": [ { "include": "#builtin-possible-callables" }, { "comment": "Some color schemas support meta.function-call.generic scope", "name": "meta.function-call.generic.python", "match": "(?x)\n \\b ([[:alpha:]_]\\w*) \\b\n" } ] }, "function-arguments": { "begin": "(?x)\n (?:\n (\\()\n (?:\\s*(\\*\\*|\\*))?\n )\n", "end": "(?=\\))(?!\\)\\s*\\()", "beginCaptures": { "1": { "name": "punctuation.definition.arguments.begin.python" }, "2": { "name": "keyword.operator.unpacking.arguments.python" } }, "contentName": "meta.function-call.arguments.python", "patterns": [ { "match": "(?x)\n (?:\n (,)\n (?:\\s*(\\*\\*|\\*))?\n )\n", "captures": { "1": { "name": "punctuation.separator.arguments.python" }, "2": { "name": "keyword.operator.unpacking.arguments.python" } } }, { "include": "#lambda-incomplete" }, { "include": "#illegal-names" }, { "match": "\\b([[:alpha:]_]\\w*)\\s*(=)(?!=)", "captures": { "1": { "name": "variable.parameter.function-call.python" }, "2": { "name": "keyword.operator.assignment.python" } } }, { "name": "keyword.operator.assignment.python", "match": "\\=" }, { "include": "#expression" }, { "match": "\\s*(\\))\\s*(\\()", "captures": { "1": { "name": "punctuation.definition.arguments.end.python" }, "2": { "name": "punctuation.definition.arguments.begin.python" } } } ] }, "builtin-callables": { "patterns": [ { "include": "#illegal-names" }, { "include": "#illegal-object-name" }, { "include": "#builtin-exceptions" }, { "include": "#builtin-functions" }, { "include": "#builtin-types" } ] }, "builtin-possible-callables": { "patterns": [ { "include": "#builtin-callables" }, { "include": "#magic-names" } ] }, "builtin-exceptions": { "name": "support.type.exception.python", "match": "(?x) (?" }, "regexp-base-expression": { "patterns": [ { "name": "support.other.match.any.regexp", "match": "\\." }, { "name": "support.other.match.begin.regexp", "match": "\\^" }, { "name": "support.other.match.end.regexp", "match": "\\$" }, { "name": "keyword.operator.quantifier.regexp", "match": "[+*?]\\??" }, { "name": "keyword.operator.disjunction.regexp", "match": "\\|" }, { "name": "keyword.operator.quantifier.regexp", "match": "(?x)\n \\{(\n \\d+ | \\d+,(\\d+)? | ,\\d+\n )\\}\n" }, { "include": "#regexp-escape-sequence" } ] }, "regexp-backreference-number": { "name": "meta.backreference.regexp", "match": "(\\\\[1-9]\\d?)", "captures": { "1": { "name": "entity.name.tag.backreference.regexp" } } }, "regexp-backreference": { "name": "meta.backreference.named.regexp", "match": "(?x)\n (\\() (\\?P= \\w+(?:\\s+[[:alnum:]]+)?) (\\))\n", "captures": { "1": { "name": "punctuation.parenthesis.backreference.named.begin.regexp support.other.parenthesis.regexp" }, "2": { "name": "entity.name.tag.named.backreference.regexp" }, "3": { "name": "punctuation.parenthesis.backreference.named.end.regexp support.other.parenthesis.regexp" } } }, "regexp-flags": { "name": "storage.modifier.flag.regexp", "match": "\\(\\?[aiLmsux]+\\)" }, "regexp-escape-special": { "name": "support.other.escape.special.regexp", "match": "\\\\([AbBdDsSwWZ])" }, "regexp-escape-character": { "name": "constant.character.escape.regexp", "match": "(?x)\n \\\\ (\n x[0-9A-Fa-f]{2}\n | 0[0-7]{1,2}\n | [0-7]{3}\n )\n" }, "regexp-escape-unicode": { "name": "constant.character.unicode.regexp", "match": "(?x)\n \\\\ (\n u[0-9A-Fa-f]{4}\n | U[0-9A-Fa-f]{8}\n )\n" }, "regexp-escape-catchall": { "name": "constant.character.escape.regexp", "match": "\\\\(.|\\n)" }, "regexp-escape-sequence": { "patterns": [ { "include": "#regexp-escape-special" }, { "include": "#regexp-escape-character" }, { "include": "#regexp-escape-unicode" }, { "include": "#regexp-backreference-number" }, { "include": "#regexp-escape-catchall" } ] }, "regexp-charecter-set-escapes": { "patterns": [ { "name": "constant.character.escape.regexp", "match": "\\\\[abfnrtv\\\\]" }, { "include": "#regexp-escape-special" }, { "name": "constant.character.escape.regexp", "match": "\\\\([0-7]{1,3})" }, { "include": "#regexp-escape-character" }, { "include": "#regexp-escape-unicode" }, { "include": "#regexp-escape-catchall" } ] }, "comments-base": { "name": "comment.line.number-sign.python", "begin": "(\\#)", "beginCaptures": { "1": { "name": "punctuation.definition.comment.python" } }, "end": "($)", "patterns": [ { "include": "#codetags" } ] }, "comments-string-single-three": { "name": "comment.line.number-sign.python", "begin": "(\\#)", "beginCaptures": { "1": { "name": "punctuation.definition.comment.python" } }, "end": "($|(?='''))", "patterns": [ { "include": "#codetags" } ] }, "comments-string-double-three": { "name": "comment.line.number-sign.python", "begin": "(\\#)", "beginCaptures": { "1": { "name": "punctuation.definition.comment.python" } }, "end": "($|(?=\"\"\"))", "patterns": [ { "include": "#codetags" } ] }, "single-one-regexp-expression": { "patterns": [ { "include": "#regexp-base-expression" }, { "include": "#single-one-regexp-character-set" }, { "include": "#single-one-regexp-comments" }, { "include": "#regexp-flags" }, { "include": "#single-one-regexp-named-group" }, { "include": "#regexp-backreference" }, { "include": "#single-one-regexp-lookahead" }, { "include": "#single-one-regexp-lookahead-negative" }, { "include": "#single-one-regexp-lookbehind" }, { "include": "#single-one-regexp-lookbehind-negative" }, { "include": "#single-one-regexp-conditional" }, { "include": "#single-one-regexp-parentheses-non-capturing" }, { "include": "#single-one-regexp-parentheses" } ] }, "single-one-regexp-character-set": { "patterns": [ { "match": "(?x)\n \\[ \\^? \\] (?! .*?\\])\n" }, { "name": "meta.character.set.regexp", "begin": "(\\[)(\\^)?(\\])?", "end": "(\\]|(?=\\'))|((?=(?)\n", "end": "(\\)|(?=\\'))|((?=(?)\n", "end": "(\\)|(?=\\'\\'\\'))", "beginCaptures": { "1": { "name": "punctuation.parenthesis.named.begin.regexp support.other.parenthesis.regexp" }, "2": { "name": "entity.name.tag.named.group.regexp" } }, "endCaptures": { "1": { "name": "punctuation.parenthesis.named.end.regexp support.other.parenthesis.regexp" }, "2": { "name": "invalid.illegal.newline.python" } }, "patterns": [ { "include": "#single-three-regexp-expression" }, { "include": "#comments-string-single-three" } ] }, "single-three-regexp-comments": { "name": "comment.regexp", "begin": "\\(\\?#", "end": "(\\)|(?=\\'\\'\\'))", "beginCaptures": { "0": { "name": "punctuation.comment.begin.regexp" } }, "endCaptures": { "1": { "name": "punctuation.comment.end.regexp" }, "2": { "name": "invalid.illegal.newline.python" } }, "patterns": [ { "include": "#codetags" } ] }, "single-three-regexp-lookahead": { "begin": "(\\()\\?=", "end": "(\\)|(?=\\'\\'\\'))", "beginCaptures": { "0": { "name": "keyword.operator.lookahead.regexp" }, "1": { "name": "punctuation.parenthesis.lookahead.begin.regexp" } }, "endCaptures": { "1": { "name": "punctuation.parenthesis.lookahead.end.regexp keyword.operator.lookahead.regexp" }, "2": { "name": "invalid.illegal.newline.python" } }, "patterns": [ { "include": "#single-three-regexp-expression" }, { "include": "#comments-string-single-three" } ] }, "single-three-regexp-lookahead-negative": { "begin": "(\\()\\?!", "end": "(\\)|(?=\\'\\'\\'))", "beginCaptures": { "0": { "name": "keyword.operator.lookahead.negative.regexp" }, "1": { "name": "punctuation.parenthesis.lookahead.begin.regexp" } }, "endCaptures": { "1": { "name": "punctuation.parenthesis.lookahead.end.regexp keyword.operator.lookahead.negative.regexp" }, "2": { "name": "invalid.illegal.newline.python" } }, "patterns": [ { "include": "#single-three-regexp-expression" }, { "include": "#comments-string-single-three" } ] }, "single-three-regexp-lookbehind": { "begin": "(\\()\\?<=", "end": "(\\)|(?=\\'\\'\\'))", "beginCaptures": { "0": { "name": "keyword.operator.lookbehind.regexp" }, "1": { "name": "punctuation.parenthesis.lookbehind.begin.regexp" } }, "endCaptures": { "1": { "name": "punctuation.parenthesis.lookbehind.end.regexp keyword.operator.lookbehind.regexp" }, "2": { "name": "invalid.illegal.newline.python" } }, "patterns": [ { "include": "#single-three-regexp-expression" }, { "include": "#comments-string-single-three" } ] }, "single-three-regexp-lookbehind-negative": { "begin": "(\\()\\?)\n", "end": "(\\)|(?=\"))|((?=(?)\n", "end": "(\\)|(?=\"\"\"))", "beginCaptures": { "1": { "name": "punctuation.parenthesis.named.begin.regexp support.other.parenthesis.regexp" }, "2": { "name": "entity.name.tag.named.group.regexp" } }, "endCaptures": { "1": { "name": "punctuation.parenthesis.named.end.regexp support.other.parenthesis.regexp" }, "2": { "name": "invalid.illegal.newline.python" } }, "patterns": [ { "include": "#double-three-regexp-expression" }, { "include": "#comments-string-double-three" } ] }, "double-three-regexp-comments": { "name": "comment.regexp", "begin": "\\(\\?#", "end": "(\\)|(?=\"\"\"))", "beginCaptures": { "0": { "name": "punctuation.comment.begin.regexp" } }, "endCaptures": { "1": { "name": "punctuation.comment.end.regexp" }, "2": { "name": "invalid.illegal.newline.python" } }, "patterns": [ { "include": "#codetags" } ] }, "double-three-regexp-lookahead": { "begin": "(\\()\\?=", "end": "(\\)|(?=\"\"\"))", "beginCaptures": { "0": { "name": "keyword.operator.lookahead.regexp" }, "1": { "name": "punctuation.parenthesis.lookahead.begin.regexp" } }, "endCaptures": { "1": { "name": "punctuation.parenthesis.lookahead.end.regexp keyword.operator.lookahead.regexp" }, "2": { "name": "invalid.illegal.newline.python" } }, "patterns": [ { "include": "#double-three-regexp-expression" }, { "include": "#comments-string-double-three" } ] }, "double-three-regexp-lookahead-negative": { "begin": "(\\()\\?!", "end": "(\\)|(?=\"\"\"))", "beginCaptures": { "0": { "name": "keyword.operator.lookahead.negative.regexp" }, "1": { "name": "punctuation.parenthesis.lookahead.begin.regexp" } }, "endCaptures": { "1": { "name": "punctuation.parenthesis.lookahead.end.regexp keyword.operator.lookahead.negative.regexp" }, "2": { "name": "invalid.illegal.newline.python" } }, "patterns": [ { "include": "#double-three-regexp-expression" }, { "include": "#comments-string-double-three" } ] }, "double-three-regexp-lookbehind": { "begin": "(\\()\\?<=", "end": "(\\)|(?=\"\"\"))", "beginCaptures": { "0": { "name": "keyword.operator.lookbehind.regexp" }, "1": { "name": "punctuation.parenthesis.lookbehind.begin.regexp" } }, "endCaptures": { "1": { "name": "punctuation.parenthesis.lookbehind.end.regexp keyword.operator.lookbehind.regexp" }, "2": { "name": "invalid.illegal.newline.python" } }, "patterns": [ { "include": "#double-three-regexp-expression" }, { "include": "#comments-string-double-three" } ] }, "double-three-regexp-lookbehind-negative": { "begin": "(\\()\\?