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 ; Misc keywords
(variable_declaration
.
(scope) @keyword)
[ [
(single_var_declaration) "my" "our" "local"
(scalar_variable) "next" "last" "redo"
(array_variable) "goto"
(hash_variable) "package"
(hash_variable) ; "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 ] @variable
; Special builtin variables
[ [
(package_name) (special_scalar_variable)
(special_scalar_variable) (special_array_variable)
(special_array_variable) (special_hash_variable)
(special_hash_variable) (special_literal)
(special_literal)
(super)
] @constant
(
[
(package_name)
(super) (super)
] ] @variable.builtin
.
("::" @operator)
)
(comments) @comment
(pod_statement) @comment
; Integer numbers
[ [
(use_no_statement) (integer)
(use_no_feature_statement) (hexadecimal)
(use_no_if_statement) ] @number
(use_no_version)
(use_constant_statement) ; Float numbers
(use_parent_statement) [
] @include (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 (use_constant_statement
constant: (identifier) @constant) constant: (identifier) @constant)
[
"require"
] @include
(method_invocation
.
(identifier) @variable)
(method_invocation
(arrow_operator)
.
(identifier) @function)
(method_invocation
function_name: (identifier) @function)
(named_block_statement (named_block_statement
function_name: (identifier) @function) function_name: (identifier) @function)
(call_expression
function_name: (identifier) @function)
(function_definition (function_definition
name: (identifier) @function) name: (identifier) @function)
[ [
(function) (function)
(map) (map)
@ -72,14 +111,6 @@
(bless) (bless)
] @function ] @function
[
"return"
"sub"
"package"
"BEGIN"
"END"
] @keyword.function
[ [
"(" "("
")" ")"
@ -92,7 +123,7 @@
[ [
"=~" "=~"
"or" "!~"
"=" "="
"==" "=="
"+" "+"
@ -119,10 +150,6 @@
(type_glob (type_glob
(identifier) @variable) (identifier) @variable)
(
(scalar_variable)
.
("->" @operator))
[ [
(word_list_qw) (word_list_qw)
@ -150,25 +177,6 @@
(ellipsis_statement) (ellipsis_statement)
] @punctuation.delimiter ] @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_attribute) @field
(function_signature) @type (function_signature) @type