Expand Up
@@ -39,6 +39,9 @@ repository:
{
include: "#import"
}
{
include: "#type-declaration"
}
{
include: "#class-declaration"
}
Expand Down
Expand Up
@@ -1099,6 +1102,45 @@ repository:
]
}
]
"type-declaration":
name: "meta.type.python"
begin: '''
(?x)
\\s*(type)\\s+
(?=
[[:alpha:]_][[:word:]]* \\s* [=\\[]
)
'''
end: "((?=[=]))"
beginCaptures:
"1":
name: "storage.type.type.python"
patterns: [
{
include: "#type-name"
}
{
include: "#type-parameters"
}
]
"type-name":
patterns: [
{
include: "#illegal-object-name"
}
{
include: "#builtin-possible-callables"
}
{
name: "entity.name.type.type.python"
match: '''
(?x)
\\b ([[:alpha:]_]\\w*) \\b
'''
}
]
"class-declaration":
patterns: [
{
Expand All
@@ -1107,7 +1149,7 @@ repository:
(?x)
\\s*(class)\\s+
(?=
[[:alpha:]_]\\w* \\s* (:|\\()
[[:alpha:]_]\\w* \\s* (:|[\\[(])
)
'''
Expand All
@@ -1125,6 +1167,9 @@ repository:
{
include: "#class-inheritance"
}
{
include: "#type-parameters"
}
]
}
]
Expand Down
Expand Up
@@ -1355,7 +1400,7 @@ repository:
\\s*
(?:\\b(async) \\s+)? \\b(def)\\s+
(?=
[[:alpha:]_][[:word:]]* \\s* \\(
[[:alpha:]_][[:word:]]* \\s* [(\\[]
)
'''
Expand All
@@ -1372,6 +1417,9 @@ repository:
{
include: "#function-def-name"
}
{
include: "#type-parameters"
}
{
include: "#parameters"
}
Expand Down
Expand Up
@@ -1399,6 +1447,67 @@ repository:
'''
}
]
"type-parameters":
name: "meta.function.parameters.type.python"
begin: "(\\[)"
end: "(\\])"
beginCaptures:
"1":
name: "punctuation.definition.parameters.begin.python"
endCaptures:
"1":
name: "punctuation.definition.parameters.end.python"
patterns: [
{
name: "keyword.operator.unpacking.parameter.python"
match: "(\\*\\*|\\*)"
}
{
include: "#lambda-incomplete"
}
{
include: "#illegal-names"
}
{
include: "#illegal-object-name"
}
{
match: '''
(?x)
([[:alpha:]_]\\w*)
\\s* (?: (,) | (?=[\\]#\\n=]))
'''
captures:
"1":
name: "variable.parameter.function.language.python"
"2":
name: "punctuation.separator.parameters.python"
}
{
include: "#comments"
}
{
include: "#type-loose-default"
}
{
include: "#type-annotated-parameter"
}
]
"type-loose-default":
begin: "(=)"
end: "(,)|(?=\\])"
beginCaptures:
"1":
name: "keyword.operator.python"
endCaptures:
"1":
name: "punctuation.separator.parameters.python"
patterns: [
{
include: "#expression"
}
]
parameters:
name: "meta.function.parameters.python"
begin: "(\\()"
Expand Down
Expand Up
@@ -1482,6 +1591,31 @@ repository:
include: "#expression"
}
]
"type-annotated-parameter":
begin: '''
(?x)
\\b
([[:alpha:]_]\\w*) \\s* (:)
'''
end: "(,)|(?=\\])"
beginCaptures:
"1":
name: "variable.parameter.function.language.python"
"2":
name: "punctuation.separator.annotation.python"
endCaptures:
"1":
name: "punctuation.separator.parameters.python"
patterns: [
{
include: "#expression"
}
{
name: "keyword.operator.assignment.python"
match: "=(?!=)"
}
]
"annotated-parameter":
begin: '''
(?x)
Expand Down