# AUTOGENERATED FROM grammars/src/MagicPython.syntax.yaml
name: "MagicPython"
scopeName: "source.python"
fileTypes: [
"py"
"py3"
"rpy"
"pyw"
"cpy"
"pyi"
"SConstruct"
"Sconstruct"
"sconstruct"
"SConscript"
"gyp"
"gypi"
"wsgi"
"kv"
"Snakefile"
"smk"
"tac"
]
firstLineMatch: "^#![ \\t]*/.*\\bpython[\\d\\.]*\\b"
uuid: "742deb57-6e38-4192-bed6-410746efd85d"
patterns: [
{
include: "#statement"
}
{
include: "#expression"
}
]
repository:
impossible:
comment: "This is a special rule that should be used where no match is desired. It is not a good idea to match something like '1{0}' because in some cases that can result in infinite loops in token generation. So the rule instead matches and impossible expression to allow a match to fail and move to the next token."
match: "$.^"
statement:
patterns: [
{
include: "#import"
}
{
include: "#class-declaration"
}
{
include: "#function-declaration"
}
{
include: "#generator"
}
{
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)
(?:
\\# \\s* (type:)
\\s*+ (?# we want `\\s*+` which is possessive quantifier since
we do not actually want to backtrack when matching
whitespace here)
(?! $ | \\#)
)
'''
end: "(?:$|(?=\\#))"
beginCaptures:
"0":
name: "meta.typehint.comment.python"
"1":
name: "comment.typehint.directive.notation.python"
patterns: [
{
name: "comment.typehint.ignore.notation.python"
match: '''
(?x)
\\G ignore
(?= \\s* (?: $ | \\#))
'''
}
{
name: "comment.typehint.type.notation.python"
match: '''
(?x)
(?))"
}
{
name: "comment.typehint.variable.notation.python"
match: "([[:alpha:]_]\\w*)"
}
]
}
{
include: "#comments-base"
}
]
"docstring-statement":
begin: "^(?=\\s*[rR]?(\\'\\'\\'|\\\"\\\"\\\"|\\'|\\\"))"
comment: "the string either terminates correctly or by the beginning of a new line (this is for single line docstrings that aren't terminated) AND it's not followed by another docstring"
end: "((?<=\\1)|^)(?!\\s*[rR]?(\\'\\'\\'|\\\"\\\"\\\"|\\'|\\\"))"
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)|(\\n)"
beginCaptures:
"1":
name: "punctuation.definition.string.begin.python"
endCaptures:
"1":
name: "punctuation.definition.string.end.python"
"2":
name: "invalid.illegal.newline.python"
patterns: [
{
include: "#codetags"
}
{
include: "#docstring-guts-unicode"
}
]
}
{
name: "string.quoted.docstring.raw.single.python"
begin: "([rR])(\\'|\\\")"
end: "(\\2)|(\\n)"
beginCaptures:
"1":
name: "storage.type.string.python"
"2":
name: "punctuation.definition.string.begin.python"
endCaptures:
"1":
name: "punctuation.definition.string.end.python"
"2":
name: "invalid.illegal.newline.python"
patterns: [
{
include: "#string-consume-escape"
}
{
include: "#codetags"
}
]
}
]
"docstring-guts-unicode":
patterns: [
{
include: "#escape-sequence-unicode"
}
{
include: "#escape-sequence"
}
{
include: "#string-line-continuation"
}
]
"docstring-prompt":
match: '''
(?x)
(?:
(?:^|\\G) \\s* (?# '\\G' is necessary for ST)
((?:>>>|\\.\\.\\.) \\s) (?=\\s*\\S)
)
'''
captures:
"1":
name: "keyword.control.flow.python"
"statement-keyword":
patterns: [
{
name: "storage.type.function.python"
match: "\\b((async\\s+)?\\s*def)\\b"
}
{
name: "keyword.control.flow.python"
comment: '''
if `as` is eventually followed by `:` or line continuation
it's probably control flow like:
with foo as bar, \\
Foo as Bar:
try:
do_stuff()
except Exception as e:
pass
'''
match: "\\b(?>= | //= | \\*\\*=
| \\+= | -= | /= | @=
| \\*= | %= | ~= | \\^= | &= | \\|=
| =(?!=)
'''
operator:
match: '''
(?x)
\\b(?> | & | \\| | \\^ | ~) (?# 3)
| (\\*\\* | \\* | \\+ | - | % | // | / | @) (?# 4)
| (!= | == | >= | <= | < | >) (?# 5)
| (:=) (?# 6)
'''
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"
"6":
name: "keyword.operator.assignment.python"
punctuation:
patterns: [
{
name: "punctuation.separator.colon.python"
match: ":"
}
{
name: "punctuation.separator.element.python"
match: ","
}
]
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)
(?=^]? [-+ ]? \\#?
\\d* ,? (\\.\\d+)? [bcdeEfFgGnosxX%]? )?
})
)
'''
captures:
"1":
name: "constant.character.format.placeholder.other.python"
"3":
name: "storage.type.format.python"
"4":
name: "storage.type.format.python"
}
{
name: "meta.format.brace.python"
match: '''
(?x)
(
{
\\w* (\\.[[:alpha:]_]\\w* | \\[[^\\]'"]+\\])*
(![rsa])?
(:)
[^'"{}\\n]* (?:
\\{ [^'"}\\n]*? \\} [^'"{}\\n]*
)*
}
)
'''
captures:
"1":
name: "constant.character.format.placeholder.other.python"
"3":
name: "storage.type.format.python"
"4":
name: "storage.type.format.python"
}
]
"fstring-formatting":
patterns: [
{
include: "#fstring-formatting-braces"
}
{
include: "#fstring-formatting-singe-brace"
}
]
"fstring-formatting-singe-brace":
name: "invalid.illegal.brace.python"
match: "(}(?!}))"
import:
comment: '''
Import statements used to correctly mark `from`, `import`, and `as`
'''
patterns: [
{
begin: "\\b(?)"
end: "(?=:)"
beginCaptures:
"1":
name: "punctuation.separator.annotation.result.python"
patterns: [
{
include: "#expression"
}
]
"item-access":
patterns: [
{
name: "meta.item-access.python"
begin: '''
(?x)
\\b(?=
[[:alpha:]_]\\w* \\s* \\[
)
'''
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"
}
{
name: "meta.indexed-name.python"
match: '''
(?x)
\\b ([[:alpha:]_]\\w*) \\b
'''
}
]
"item-index":
begin: "(\\[)"
end: "(?=\\])"
beginCaptures:
"1":
name: "punctuation.definition.arguments.begin.python"
contentName: "meta.item-access.arguments.python"
patterns: [
{
name: "punctuation.separator.slice.python"
match: ":"
}
{
include: "#expression"
}
]
decorator:
name: "meta.function.decorator.python"
begin: '''
(?x)
^\\s*
((@)) \\s* (?=[[:alpha:]_]\\w*)
'''
end: '''
(?x)
( \\) )
# trailing whitespace and comments are legal
(?: (.*?) (?=\\s*(?:\\#|$)) )
| (?=\\n|\\#)
'''
beginCaptures:
"1":
name: "entity.name.function.decorator.python"
"2":
name: "punctuation.definition.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)
([[:alpha:]_]\\w*) | (\\.)
'''
captures:
"2":
name: "punctuation.separator.period.python"
}
{
include: "#line-continuation"
}
{
name: "invalid.illegal.decorator.python"
match: '''
(?x)
\\s* ([^([:alpha:]\\s_\\.#\\\\] .*?) (?=\\#|$)
'''
captures:
"1":
name: "invalid.illegal.decorator.python"
}
]
"call-wrapper-inheritance":
comment: "same as a function call, but in inheritance context"
name: "meta.function-call.python"
begin: '''
(?x)
\\b(?=
([[:alpha:]_]\\w*) \\s* (\\()
)
'''
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"
comment: "Regular function call of the type \"name(args)\""
begin: '''
(?x)
\\b(?=
([[:alpha:]_]\\w*) \\s* (\\()
)
'''
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)
\\b ([[:alpha:]_]\\w*) \\b
'''
}
]
"function-arguments":
begin: "(\\()"
end: "(?=\\))(?!\\)\\s*\\()"
beginCaptures:
"1":
name: "punctuation.definition.arguments.begin.python"
contentName: "meta.function-call.arguments.python"
patterns: [
{
name: "punctuation.separator.arguments.python"
match: "(,)"
}
{
match: '''
(?x)
(?:(?<=[,(])|^) \\s* (\\*{1,2})
'''
captures:
"1":
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: [
{
include: "#regexp-quantifier"
}
{
include: "#regexp-base-common"
}
]
"fregexp-base-expression":
patterns: [
{
include: "#fregexp-quantifier"
}
{
include: "#fstring-formatting-braces"
}
{
match: "\\{.*?\\}"
}
{
include: "#regexp-base-common"
}
]
"fstring-formatting-braces":
patterns: [
{
comment: "empty braces are illegal"
match: "({)(\\s*?)(})"
captures:
"1":
name: "constant.character.format.placeholder.other.python"
"2":
name: "invalid.illegal.brace.python"
"3":
name: "constant.character.format.placeholder.other.python"
}
{
name: "constant.character.escape.python"
match: "({{|}})"
}
]
"regexp-base-common":
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: "\\|"
}
{
include: "#regexp-escape-sequence"
}
]
"regexp-quantifier":
name: "keyword.operator.quantifier.regexp"
match: '''
(?x)
\\{(
\\d+ | \\d+,(\\d+)? | ,\\d+
)\\}
'''
"fregexp-quantifier":
name: "keyword.operator.quantifier.regexp"
match: '''
(?x)
\\{\\{(
\\d+ | \\d+,(\\d+)? | ,\\d+
)\\}\\}
'''
"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)
(\\() (\\?P= \\w+(?:\\s+[[:alnum:]]+)?) (\\))
'''
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)
\\\\ (
x[0-9A-Fa-f]{2}
| 0[0-7]{1,2}
| [0-7]{3}
)
'''
"regexp-escape-unicode":
name: "constant.character.unicode.regexp"
match: '''
(?x)
\\\\ (
u[0-9A-Fa-f]{4}
| U[0-9A-Fa-f]{8}
)
'''
"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"
}
]
codetags:
match: "(?:\\b(NOTE|XXX|HACK|FIXME|BUG|TODO)\\b)"
captures:
"1":
name: "keyword.codetag.notation.python"
"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)
\\[ \\^? \\] (?! .*?\\])
'''
}
{
name: "meta.character.set.regexp"
begin: "(\\[)(\\^)?(\\])?"
end: "(\\]|(?=\\'))|((?=(?)
'''
end: "(\\)|(?=\\'))|((?=(?)
'''
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: "(\\()\\?)
'''
end: "(\\)|(?=\"))|((?=(?)
'''
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: "(\\()\\?=^]? [-+ ]? \\#?
\\d* ,? (\\.\\d+)? [bcdeEfFgGnosxX%]? )(?=})
'''
captures:
"1":
name: "storage.type.format.python"
"2":
name: "storage.type.format.python"
}
{
include: "#fstring-terminator-single-tail"
}
]
"fstring-terminator-single-tail":
begin: "((?:=?)(?:![rsa])?)(:)(?=.*?{)"
end: "(?=})|(?=\\n)"
beginCaptures:
"1":
name: "storage.type.format.python"
"2":
name: "storage.type.format.python"
patterns: [
{
include: "#fstring-illegal-single-brace"
}
{
include: "#fstring-single-brace"
}
{
name: "storage.type.format.python"
match: "([bcdeEfFgGnosxX%])(?=})"
}
{
name: "storage.type.format.python"
match: "(\\.\\d+)"
}
{
name: "storage.type.format.python"
match: "(,)"
}
{
name: "storage.type.format.python"
match: "(\\d+)"
}
{
name: "storage.type.format.python"
match: "(\\#)"
}
{
name: "storage.type.format.python"
match: "([-+ ])"
}
{
name: "storage.type.format.python"
match: "([<>=^])"
}
{
name: "storage.type.format.python"
match: "(\\w)"
}
]
"fstring-fnorm-quoted-multi-line":
name: "meta.fstring.python"
begin: "(\\b[fF])([bBuU])?('''|\"\"\")"
end: "(\\3)"
beginCaptures:
"1":
name: "storage.type.string.python string.quoted.multi.python string.interpolated.python"
"2":
name: "invalid.illegal.prefix.python"
"3":
name: "string.quoted.multi.python string.interpolated.python punctuation.definition.string.begin.python"
endCaptures:
"1":
name: "string.quoted.multi.python string.interpolated.python punctuation.definition.string.end.python"
"2":
name: "invalid.illegal.newline.python"
patterns: [
{
include: "#fstring-guts"
}
{
include: "#fstring-illegal-multi-brace"
}
{
include: "#fstring-multi-brace"
}
{
include: "#fstring-multi-core"
}
]
"fstring-normf-quoted-multi-line":
name: "meta.fstring.python"
begin: "(\\b[bBuU])([fF])('''|\"\"\")"
end: "(\\3)"
beginCaptures:
"1":
name: "invalid.illegal.prefix.python"
"2":
name: "storage.type.string.python string.quoted.multi.python string.interpolated.python"
"3":
name: "string.quoted.multi.python punctuation.definition.string.begin.python"
endCaptures:
"1":
name: "string.quoted.multi.python string.interpolated.python punctuation.definition.string.end.python"
"2":
name: "invalid.illegal.newline.python"
patterns: [
{
include: "#fstring-guts"
}
{
include: "#fstring-illegal-multi-brace"
}
{
include: "#fstring-multi-brace"
}
{
include: "#fstring-multi-core"
}
]
"fstring-raw-quoted-multi-line":
name: "meta.fstring.python"
begin: "(\\b(?:[rR][fF]|[fF][rR]))('''|\"\"\")"
end: "(\\2)"
beginCaptures:
"1":
name: "storage.type.string.python string.quoted.raw.multi.python string.interpolated.python"
"2":
name: "string.quoted.raw.multi.python punctuation.definition.string.begin.python"
endCaptures:
"1":
name: "string.quoted.raw.multi.python string.interpolated.python punctuation.definition.string.end.python"
"2":
name: "invalid.illegal.newline.python"
patterns: [
{
include: "#fstring-raw-guts"
}
{
include: "#fstring-illegal-multi-brace"
}
{
include: "#fstring-multi-brace"
}
{
include: "#fstring-raw-multi-core"
}
]
"fstring-multi-core":
name: "string.quoted.multi.python string.interpolated.python"
match: '''
(?x)
(.+?)
(
(?# .* and .*? in multi-line match need special handling of
newlines otherwise SublimeText and Atom will match slightly
differently.
The guard for newlines has to be separate from the
lookahead because of special $ matching rule.)
($\\n?)
|
(?=[\\\\\\}\\{]|\'''|""")
)
(?# due to how multiline regexps are matched we need a special case
for matching a newline character)
| \\n
'''
"fstring-raw-multi-core":
name: "string.quoted.raw.multi.python string.interpolated.python"
match: '''
(?x)
(.+?)
(
(?# .* and .*? in multi-line match need special handling of
newlines otherwise SublimeText and Atom will match slightly
differently.
The guard for newlines has to be separate from the
lookahead because of special $ matching rule.)
($\\n?)
|
(?=[\\\\\\}\\{]|\'''|""")
)
(?# due to how multiline regexps are matched we need a special case
for matching a newline character)
| \\n
'''
"fstring-multi-brace":
comment: "value interpolation using { ... }"
begin: "(\\{)"
end: '''
(?x)
(\\})
'''
beginCaptures:
"1":
name: "constant.character.format.placeholder.other.python"
endCaptures:
"1":
name: "constant.character.format.placeholder.other.python"
patterns: [
{
include: "#fstring-terminator-multi"
}
{
include: "#f-expression"
}
]
"fstring-terminator-multi":
patterns: [
{
name: "storage.type.format.python"
match: "(=(![rsa])?)(?=})"
}
{
name: "storage.type.format.python"
match: "(=?![rsa])(?=})"
}
{
match: '''
(?x)
( (?: =?) (?: ![rsa])? )
( : \\w? [<>=^]? [-+ ]? \\#?
\\d* ,? (\\.\\d+)? [bcdeEfFgGnosxX%]? )(?=})
'''
captures:
"1":
name: "storage.type.format.python"
"2":
name: "storage.type.format.python"
}
{
include: "#fstring-terminator-multi-tail"
}
]
"fstring-terminator-multi-tail":
begin: "((?:=?)(?:![rsa])?)(:)(?=.*?{)"
end: "(?=})"
beginCaptures:
"1":
name: "storage.type.format.python"
"2":
name: "storage.type.format.python"
patterns: [
{
include: "#fstring-illegal-multi-brace"
}
{
include: "#fstring-multi-brace"
}
{
name: "storage.type.format.python"
match: "([bcdeEfFgGnosxX%])(?=})"
}
{
name: "storage.type.format.python"
match: "(\\.\\d+)"
}
{
name: "storage.type.format.python"
match: "(,)"
}
{
name: "storage.type.format.python"
match: "(\\d+)"
}
{
name: "storage.type.format.python"
match: "(\\#)"
}
{
name: "storage.type.format.python"
match: "([-+ ])"
}
{
name: "storage.type.format.python"
match: "([<>=^])"
}
{
name: "storage.type.format.python"
match: "(\\w)"
}
]