[PEP484](https://peps.python.org/pep-0484/) defines "Forward references" for undefined types. This PR treats such annotations as types rather than strings. Release Notes: - Added Python syntax highlighting for forward references.
208 lines
3.4 KiB
Scheme
208 lines
3.4 KiB
Scheme
(attribute attribute: (identifier) @property)
|
|
(type (identifier) @type)
|
|
(generic_type (identifier) @type)
|
|
|
|
; Type alias
|
|
(type_alias_statement "type" @keyword)
|
|
|
|
; Identifier naming conventions
|
|
|
|
((identifier) @type.class
|
|
(#match? @type.class "^[A-Z]"))
|
|
|
|
((identifier) @constant
|
|
(#match? @constant "^_*[A-Z][A-Z\\d_]*$"))
|
|
|
|
; TypeVar with constraints in type parameters
|
|
(type
|
|
(tuple (identifier) @type)
|
|
)
|
|
|
|
; Forward references
|
|
(type
|
|
(string) @type
|
|
)
|
|
|
|
|
|
; Function calls
|
|
|
|
(decorator
|
|
"@" @punctuation.special
|
|
(identifier) @function.decorator)
|
|
|
|
(call
|
|
function: (attribute attribute: (identifier) @function.method.call))
|
|
(call
|
|
function: (identifier) @function.call)
|
|
|
|
; Function and class definitions
|
|
|
|
(function_definition
|
|
name: (identifier) @function.definition)
|
|
|
|
; Class definitions and calling: needs to come after the regex matching above
|
|
|
|
(class_definition
|
|
name: (identifier) @type.class.definition)
|
|
|
|
(call
|
|
function: (identifier) @type.class.call
|
|
(#match? @type.class.call "^[A-Z][A-Z0-9_]*[a-z]"))
|
|
|
|
; Builtin functions
|
|
|
|
((call
|
|
function: (identifier) @function.builtin)
|
|
(#match?
|
|
@function.builtin
|
|
"^(abs|all|any|ascii|bin|bool|breakpoint|bytearray|bytes|callable|chr|classmethod|compile|complex|delattr|dict|dir|divmod|enumerate|eval|exec|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|isinstance|issubclass|iter|len|list|locals|map|max|memoryview|min|next|object|oct|open|ord|pow|print|property|range|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|vars|zip|__import__)$"))
|
|
|
|
; Literals
|
|
|
|
[
|
|
(none)
|
|
(true)
|
|
(false)
|
|
(ellipsis)
|
|
] @constant.builtin
|
|
|
|
[
|
|
(integer)
|
|
(float)
|
|
] @number
|
|
|
|
; Self references
|
|
|
|
[
|
|
(parameters (identifier) @variable.special)
|
|
(attribute (identifier) @variable.special)
|
|
(#match? @variable.special "^self|cls$")
|
|
]
|
|
|
|
(comment) @comment
|
|
(string) @string
|
|
(escape_sequence) @string.escape
|
|
|
|
[
|
|
"("
|
|
")"
|
|
"["
|
|
"]"
|
|
"{"
|
|
"}"
|
|
] @punctuation.bracket
|
|
|
|
(interpolation
|
|
"{" @punctuation.special
|
|
"}" @punctuation.special) @embedded
|
|
|
|
; Docstrings.
|
|
(function_definition
|
|
"async"?
|
|
"def"
|
|
name: (_)
|
|
(parameters)?
|
|
body: (block . (expression_statement (string) @string.doc)))
|
|
|
|
(class_definition
|
|
body: (block
|
|
. (comment) @comment*
|
|
. (expression_statement (string) @string.doc)))
|
|
|
|
(module
|
|
. (comment) @comment*
|
|
. (expression_statement (string) @string.doc))
|
|
|
|
(module
|
|
(expression_statement (assignment))
|
|
. (expression_statement (string) @string.doc))
|
|
|
|
(class_definition
|
|
body: (block
|
|
(expression_statement (assignment))
|
|
. (expression_statement (string) @string.doc)))
|
|
|
|
(class_definition
|
|
body: (block
|
|
(function_definition
|
|
name: (identifier) @function.method.constructor
|
|
(#eq? @function.method.constructor "__init__")
|
|
body: (block
|
|
(expression_statement (assignment))
|
|
. (expression_statement (string) @string.doc)))))
|
|
|
|
|
|
[
|
|
"-"
|
|
"-="
|
|
"!="
|
|
"*"
|
|
"**"
|
|
"**="
|
|
"*="
|
|
"/"
|
|
"//"
|
|
"//="
|
|
"/="
|
|
"&"
|
|
"%"
|
|
"%="
|
|
"^"
|
|
"+"
|
|
"->"
|
|
"+="
|
|
"<"
|
|
"<<"
|
|
"<="
|
|
"<>"
|
|
"="
|
|
":="
|
|
"=="
|
|
">"
|
|
">="
|
|
">>"
|
|
"|"
|
|
"~"
|
|
"and"
|
|
"in"
|
|
"is"
|
|
"not"
|
|
"or"
|
|
"is not"
|
|
"not in"
|
|
] @operator
|
|
|
|
[
|
|
"as"
|
|
"assert"
|
|
"async"
|
|
"await"
|
|
"break"
|
|
"class"
|
|
"continue"
|
|
"def"
|
|
"del"
|
|
"elif"
|
|
"else"
|
|
"except"
|
|
"exec"
|
|
"finally"
|
|
"for"
|
|
"from"
|
|
"global"
|
|
"if"
|
|
"import"
|
|
"lambda"
|
|
"nonlocal"
|
|
"pass"
|
|
"print"
|
|
"raise"
|
|
"return"
|
|
"try"
|
|
"while"
|
|
"with"
|
|
"yield"
|
|
"match"
|
|
"case"
|
|
] @keyword
|