Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve python highlighting #3103

Merged
merged 6 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ indent = { tab-width = 4, unit = " " }

[[grammar]]
name = "python"
source = { git = "https://github.com/tree-sitter/tree-sitter-python", rev = "d6210ceab11e8d812d4ab59c07c81458ec6e5184" }
source = { git = "https://github.com/tree-sitter/tree-sitter-python", rev = "de221eccf9a221f5b85474a553474a69b4b5784d" }

[[language]]
name = "nickel"
Expand Down
83 changes: 60 additions & 23 deletions runtime/queries/python/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
(dotted_name
(identifier)* @namespace)

; Builtin functions

((call
Expand All @@ -8,6 +11,11 @@

; Function calls

[
"def"
"lambda"
] @keyword.function

(call
function: (attribute attribute: (identifier) @constructor)
(#match? @constructor "^[A-Z]"))
Expand Down Expand Up @@ -49,6 +57,13 @@
(parameters (typed_default_parameter name: (identifier) @variable.parameter))
(keyword_argument name: (identifier) @variable.parameter)

(parameters
(list_splat_pattern ; *args
(identifier) @variable.parameter))
(parameters
(dictionary_splat_pattern ; **kwargs
(identifier) @variable.parameter))

; Types

((identifier) @type.builtin
Expand Down Expand Up @@ -81,22 +96,23 @@
(identifier) @variable

; Literals

(none) @constant.builtin
[
(none)
(true)
(false)
] @constant.builtin
] @constant.builtin.boolean

(integer) @constant.numeric.integer
(float) @constant.numeric.float
(comment) @comment
(string) @string
(escape_sequence) @constant.character.escape

["," "." ":" ";" (ellipsis)] @punctuation.delimiter
(interpolation
"{" @punctuation.special
kirawi marked this conversation as resolved.
Show resolved Hide resolved
"}" @punctuation.special) @embedded
"(" ")" "[" "]" "{" "}"] @punctuation.bracket

[
"-"
Expand Down Expand Up @@ -135,24 +151,39 @@
"as"
"assert"
"await"
"break"
"continue"
"from"
"pass"

"with"
] @keyword.control

[
"if"
"elif"
"else"
"except"
"finally"
] @keyword.control.conditional

[
"while"
"for"
"from"
"if"
"import"
"pass"
"raise"
"break"
"continue"
] @keyword.control.repeat

[
"return"
"try"
"while"
"with"
"yield"
] @keyword.control
] @keyword.control.return
(yield "from" @keyword.control.return)

[
"raise"
"try"
"except"
"finally"
] @keyword.control.except
(raise_statement "from" @keyword.control.except)
"import" @keyword.control.import

(for_statement "in" @keyword.control)
(for_in_clause "in" @keyword.control)
Expand All @@ -161,16 +192,22 @@
"and"
"async"
"class"
"def"
"del"
"exec"
"global"
"in"
"is"
"lambda"
"nonlocal"
"not"
"or"
"print"
] @keyword
[
"and"
"or"
"in"
"not"
"del"
"is"
] @keyword.operator

((identifier) @type.builtin
(#match? @type.builtin
"^(BaseException|Exception|ArithmeticError|BufferError|LookupError|AssertionError|AttributeError|EOFError|FloatingPointError|GeneratorExit|ImportError|ModuleNotFoundError|IndexError|KeyError|KeyboardInterrupt|MemoryError|NameError|NotImplementedError|OSError|OverflowError|RecursionError|ReferenceError|RuntimeError|StopIteration|StopAsyncIteration|SyntaxError|IndentationError|TabError|SystemError|SystemExit|TypeError|UnboundLocalError|UnicodeError|UnicodeEncodeError|UnicodeDecodeError|UnicodeTranslateError|ValueError|ZeroDivisionError|EnvironmentError|IOError|WindowsError|BlockingIOError|ChildProcessError|ConnectionError|BrokenPipeError|ConnectionAbortedError|ConnectionRefusedError|ConnectionResetError|FileExistsError|FileNotFoundError|InterruptedError|IsADirectoryError|NotADirectoryError|PermissionError|ProcessLookupError|TimeoutError|Warning|UserWarning|DeprecationWarning|PendingDeprecationWarning|SyntaxWarning|RuntimeWarning|FutureWarning|ImportWarning|UnicodeWarning|BytesWarning|ResourceWarning)$"))

(ERROR) @error