Files
oak-gpui/crates/languages/src/python/highlights.scm
T
Nigel JoseandJoseph T Lyons ba59e66314 Improve Python syntax highlighting (#12868)
Release Notes:

- Improve syntax highlighting in Python #12578 

Before:
<img width="1181" alt="Screenshot 2024-06-08 at 01 44 54"
src="https://github.com/zed-industries/zed/assets/87859239/0b8ab26b-149b-477e-af08-8cd9f2b1c117">

After:

<img width="1184" alt="Screenshot 2024-06-10 at 01 02 35"
src="https://github.com/zed-industries/zed/assets/87859239/a319a5ea-54b7-4681-951d-130ea26aa390">

---------

Co-authored-by: Joseph T Lyons <JosephTLyons@gmail.com>
2024-06-18 12:21:18 -04:00

172 lines
2.5 KiB
Scheme

(parameter (identifier) @variable)
(attribute attribute: (identifier) @property)
(type (identifier) @type)
; Module imports
(import_statement
(dotted_name (identifier) @type))
(import_statement
(aliased_import
name: (dotted_name (identifier) @type)
alias: (identifier) @type))
(import_from_statement
(dotted_name (identifier) @type))
(import_from_statement
(aliased_import
name: (dotted_name (identifier) @type)
alias: (identifier) @type))
; Function calls
(decorator) @function
(call
function: (attribute attribute: (identifier) @function.method))
(call
function: (identifier) @function)
; Function definitions
(function_definition
name: (identifier) @function)
; Identifier naming conventions
((identifier) @type
(#match? @type "^[A-Z]"))
((identifier) @constant
(#match? @constant "^_*[A-Z][A-Z\\d_]*$"))
; 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)
] @constant.builtin
[
(integer)
(float)
] @number
; Self references
[
(parameters (identifier) @variable.special)
(attribute (identifier) @variable.special)
(#match? @variable.special "^self$")
]
(comment) @comment
(string) @string
(escape_sequence) @escape
[
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket
(interpolation
"{" @punctuation.special
"}" @punctuation.special) @embedded
; Docstrings.
(function_definition
"async"?
"def"
name: (_)
(parameters)?
body: (block (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