Add many perl keywords; highlight on those in preference to structural elements

This commit is contained in:
Paul "LeoNerd" Evans 2022-02-21 15:30:35 +00:00 committed by Stephan Seitz
parent c0d28a9535
commit 09ea6ccd1d

View file

@ -1,70 +1,109 @@
; Variables
(variable_declaration
.
(scope) @keyword)
; Misc keywords
[
(single_var_declaration)
(scalar_variable)
(array_variable)
(hash_variable)
(hash_variable)
"my" "our" "local"
"next" "last" "redo"
"goto"
"package"
; "do"
; "eval"
] @keyword
; Keywords for including
[ "use" "no" "require" ] @include
; Keywords that mark conditional statements
[ "if" "elsif" "unless" "else" ] @conditional
; Keywords that mark repeating loops
[ "while" "until" "for" "foreach" ] @repeat
; Keyword for return expressions
[ "return" ] @keyword.return
; Keywords for phaser blocks
; TODO: Ideally these would be @keyword.phaser but vim-treesitter doesn't
; have such a thing yet
[ "BEGIN" "CHECK" "UNITCHECK" "INIT" "END" ] @keyword.function
; Keywords to define a function
[ "sub" ] @keyword.function
; Lots of builtin functions, except tree-sitter-perl doesn't emit most of
; these yet
;[
; "print" "printf" "sprintf" "say"
; "push" "pop" "shift" "unshift" "splice"
; "exists" "delete" "keys" "values"
; "each"
;] @function.builtin
; Keywords that are regular infix operators
[
"and" "or" "not" "xor"
"eq" "ne" "lt" "le" "ge" "gt" "cmp"
] @keyword.operator
; Variables
[
(scalar_variable)
(array_variable)
(hash_variable)
] @variable
; Special builtin variables
[
(package_name)
(special_scalar_variable)
(special_array_variable)
(special_hash_variable)
(special_literal)
(super)
] @constant
(
[
(package_name)
(special_scalar_variable)
(special_array_variable)
(special_hash_variable)
(special_literal)
(super)
]
.
("::" @operator)
)
(comments) @comment
(pod_statement) @comment
] @variable.builtin
; Integer numbers
[
(use_no_statement)
(use_no_feature_statement)
(use_no_if_statement)
(use_no_version)
(use_constant_statement)
(use_parent_statement)
] @include
(integer)
(hexadecimal)
] @number
; Float numbers
[
(floating_point)
(scientific_notation)
] @float
; version sortof counts as a kind of multipart integer
(version) @constant
; Package names are types
(package_name) @type
; The special SUPER:: could be called a namespace. It isn't really but it
; should highlight differently and we might as well do it this way
(super) @namespace
; Comments are comments
(comments) @comment
; POD should be handled specially with its own embedded subtype but for now
; we'll just have to do this.
(pod_statement) @text
(method_invocation
function_name: (identifier) @method)
(call_expression
function_name: (identifier) @function)
;; ----------
(use_constant_statement
constant: (identifier) @constant)
[
"require"
] @include
(method_invocation
.
(identifier) @variable)
(method_invocation
(arrow_operator)
.
(identifier) @function)
(method_invocation
function_name: (identifier) @function)
(named_block_statement
function_name: (identifier) @function)
(call_expression
function_name: (identifier) @function)
(function_definition
name: (identifier) @function)
[
(function)
(map)
@ -72,14 +111,6 @@
(bless)
] @function
[
"return"
"sub"
"package"
"BEGIN"
"END"
] @keyword.function
[
"("
")"
@ -92,7 +123,7 @@
[
"=~"
"or"
"!~"
"="
"=="
"+"
@ -119,10 +150,6 @@
(type_glob
(identifier) @variable)
(
(scalar_variable)
.
("->" @operator))
[
(word_list_qw)
@ -150,25 +177,6 @@
(ellipsis_statement)
] @punctuation.delimiter
[
(integer)
(floating_point)
(scientific_notation)
(hexadecimal)
] @number
[
(if_statement)
(unless_statement)
(if_simple_statement)
(unless_simple_statement)
] @conditional
(foreach_statement) @repeat
(foreach_statement
.
(scope) @keyword)
(function_attribute) @field
(function_signature) @type