aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVeesh Goldman <rabbiveesh@gmail.com>2023-10-17 19:32:09 +0000
committerAmaan Qureshi <amaanq12@gmail.com>2023-10-21 14:41:22 -0400
commitbb3f8f40b1443fb40665263e1b5b0658bc24be03 (patch)
tree60e33e92e8e79977260f8ef9a3a167cf4642e3b2
parentfeat(pod): add tree-sitter-perl org's POD parser (diff)
downloadnvim-treesitter-bb3f8f40b1443fb40665263e1b5b0658bc24be03.tar
nvim-treesitter-bb3f8f40b1443fb40665263e1b5b0658bc24be03.tar.gz
nvim-treesitter-bb3f8f40b1443fb40665263e1b5b0658bc24be03.tar.bz2
nvim-treesitter-bb3f8f40b1443fb40665263e1b5b0658bc24be03.tar.lz
nvim-treesitter-bb3f8f40b1443fb40665263e1b5b0658bc24be03.tar.xz
nvim-treesitter-bb3f8f40b1443fb40665263e1b5b0658bc24be03.tar.zst
nvim-treesitter-bb3f8f40b1443fb40665263e1b5b0658bc24be03.zip
feat(perl)!: switch to tree-sitter-perl org's parser
-rw-r--r--lockfile.json2
-rw-r--r--lua/nvim-treesitter/parsers.lua7
-rw-r--r--queries/perl/folds.scm30
-rw-r--r--queries/perl/highlights.scm254
-rw-r--r--queries/perl/injections.scm14
5 files changed, 138 insertions, 169 deletions
diff --git a/lockfile.json b/lockfile.json
index 0d3748886..e2706fc6b 100644
--- a/lockfile.json
+++ b/lockfile.json
@@ -414,7 +414,7 @@
"revision": "e01767921df18142055d97407595329d7629e643"
},
"perl": {
- "revision": "79e88f64681660f3961939bf764d8f3b4bbb0d27"
+ "revision": "99bbcb0faddfc79db3fd2996cb56689a4685e78c"
},
"php": {
"revision": "0e02e7fab7913a0e77343edb347c8f17cac1f0ba"
diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua
index 8d12a69aa..526a34cd7 100644
--- a/lua/nvim-treesitter/parsers.lua
+++ b/lua/nvim-treesitter/parsers.lua
@@ -1240,10 +1240,11 @@ list.pem = {
list.perl = {
install_info = {
- url = "https://github.com/ganezdragon/tree-sitter-perl",
- files = { "src/parser.c", "src/scanner.cc" },
+ url = "https://github.com/tree-sitter-perl/tree-sitter-perl",
+ files = { "src/parser.c", "src/scanner.c" },
+ branch = "release",
},
- maintainers = { "@lcrownover" },
+ maintainers = { "@RabbiVeesh", "@LeoNerd" },
}
list.php = {
diff --git a/queries/perl/folds.scm b/queries/perl/folds.scm
index 7be36e5e0..df23f6317 100644
--- a/queries/perl/folds.scm
+++ b/queries/perl/folds.scm
@@ -1,11 +1,19 @@
-[
- (function_definition)
- (if_statement)
- (unless_statement)
- (while_statement)
- (until_statement)
- (for_statement_1)
- (for_statement_2)
- (standalone_block)
- (pod_statement)
-] @fold
+(comment)+ @fold
+(pod) @fold
+
+; fold the block-typed package statements only
+(package_statement (block)) @fold
+
+[(subroutine_declaration_statement)
+ (conditional_statement)
+ (loop_statement)
+ (for_statement)
+ (cstyle_for_statement)
+ (block_statement)
+ (phaser_statement)] @fold
+
+(anonymous_subroutine_expression) @fold
+
+; perhaps folks want to fold these too?
+[(anonymous_array_expression)
+ (anonymous_hash_expression)] @fold
diff --git a/queries/perl/highlights.scm b/queries/perl/highlights.scm
index c7403b6e7..82d181183 100644
--- a/queries/perl/highlights.scm
+++ b/queries/perl/highlights.scm
@@ -1,198 +1,146 @@
-; Misc keywords
-[
- "my" "our" "local"
- "next" "last" "redo"
- "goto"
- "package"
-; "do"
-; "eval"
-] @keyword
+((source_file . (comment) @preproc)
+ (#lua-match? @preproc "^#!/"))
-; Keywords for including
[ "use" "no" "require" ] @include
-; Keywords that mark conditional statements
[ "if" "elsif" "unless" "else" ] @conditional
-(ternary_expression
- ["?" ":"] @conditional.ternary)
-; Keywords that mark repeating loops
+(conditional_expression [ "?" ":" ] @conditional.ternary)
+
[ "while" "until" "for" "foreach" ] @repeat
-; Keyword for return expressions
-[ "return" ] @keyword.return
+"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
+"sub" @keyword.function
-; Keywords to define a function
-[ "sub" ] @keyword.function
+[ "map" "grep" ] @function.builtin
-; Keywords that are regular infix operators
-[
- "and" "or" "not" "xor"
- "eq" "ne" "lt" "le" "ge" "gt" "cmp"
-] @keyword.operator
+"package" @include
-; Variables
[
- (scalar_variable)
- (array_variable)
- (hash_variable)
-] @variable
+ "do"
+ "my" "our" "local"
+ "last" "next" "redo" "goto"
+ "undef"
+] @keyword
+
+(_ operator: _ @operator)
+"\\" @operator
+
+(yadayada) @exception
+
+(phaser_statement phase: _ @keyword.phaser)
-; Special builtin variables
[
- (special_scalar_variable)
- (special_array_variable)
- (special_hash_variable)
- (special_literal)
- (super)
-] @variable.builtin
+ "or" "and"
+ "eq" "ne" "cmp" "lt" "le" "ge" "gt"
+ "isa"
+] @keyword.operator
-((scalar_variable) @variable.builtin
- (#eq? @variable.builtin "$#ARGV"))
+(eof_marker) @preproc
+(data_section) @comment
+
+(pod) @text
-; Integer numbers
[
- (integer)
- (hexadecimal)
+ (number)
+ (version)
] @number
-; Float numbers
[
- (floating_point)
- (scientific_notation)
-] @float
-
-; version sortof counts as a kind of multipart integer
-(version) @constant
+ (string_literal)
+ (interpolated_string_literal)
+ (quoted_word_list)
+ (command_string)
+ (heredoc_content)
+ (replacement)
+ (transliteration_content)
+] @string
-; Package names are types
-(package_name) @type
+[
+ (heredoc_token)
+ (command_heredoc_token)
+ (heredoc_end)
+] @label
-; 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
+[(escape_sequence) (escaped_delimiter)] @string.escape
-; Comments are comments
-(comments) @comment @spell
+(_ modifiers: _ @character.special)
+[
+ (quoted_regexp)
+ (match_regexp)
+ (regexp_content)
+] @string.regex
-((source_file . (comments) @preproc)
- (#lua-match? @preproc "^#!/"))
+(autoquoted_bareword _?) @string.special
-; POD should be handled specially with its own embedded subtype but for now
-; we'll just have to do this.
-(pod_statement) @text
+(use_statement (package) @type)
+(package_statement (package) @type)
+(require_expression (bareword) @type)
-(method_invocation
- function_name: (identifier) @method.call)
-(call_expression
- function_name: (identifier) @function.call)
+(subroutine_declaration_statement name: (bareword) @function)
+(attribute_name) @attribute
+(attribute_value) @string
-; Built-in functions
-((call_expression
- function_name: (identifier) @function.builtin)
- (#any-of? @function.builtin
- "print" "printf" "sprintf" "say"
- "push" "pop" "shift" "unshift" "splice"
- "exists" "delete" "keys" "values"
- "each"))
+(label) @label
-[
- (map)
- (grep)
- (bless)
-] @function.builtin
+(statement_label label: _ @label)
-;; ----------
+(relational_expression operator: "isa" right: (bareword) @type)
-(use_constant_statement
- constant: (identifier) @constant)
+(function_call_expression (function) @function.call)
+(method_call_expression (method) @method.call)
+(method_call_expression invocant: (bareword) @type)
-(named_block_statement
- function_name: (identifier) @function)
+(func0op_call_expression function: _ @function.builtin)
+(func1op_call_expression function: _ @function.builtin)
-(function_definition
- name: (identifier) @function)
+([(function)(expression_statement (bareword))] @function.builtin
+ (#set! "priority" 101)
+ (#lua-match? @function.builtin
+ "^(accept|atan2|bind|binmode|bless|crypt|chmod|chown|connect|die|dbmopen|exec|fcntl|flock|getpriority|getprotobynumber|gethostbyaddr|getnetbyaddr|getservbyname|getservbyport|getsockopt|glob|index|ioctl|join|kill|link|listen|mkdir|msgctl|msgget|msgrcv|msgsend|opendir|print|printf|push|pack|pipe|return|rename|rindex|read|recv|reverse|say|select|seek|semctl|semget|semop|send|setpgrp|setpriority|seekdir|setsockopt|shmctl|shmread|shmwrite|shutdown|socket|socketpair|split|sprintf|splice|substr|system|symlink|syscall|sysopen|sysseek|sysread|syswrite|tie|truncate|unlink|unpack|utime|unshift|vec|warn|waitpid|formline|open|sort)$"
+))
(function) @function
-[
- "(" ")"
- "[" "]"
- "{" "}"
- (standard_input_to_variable)
-] @punctuation.bracket
-
-[ "`" "\"" ] @punctuation.special
-
-[
- "=~"
- "!~"
- "="
- "=="
- "+"
- "-"
- "."
- "//"
- "||"
- "&&"
- "<<"
- (arrow_operator)
- (hash_arrow_operator)
- (array_dereference)
- (hash_dereference)
- (to_reference)
- (type_glob)
- (hash_access_variable)
-] @operator
+(ERROR) @error
-[
- (regex_option)
- (regex_option_for_substitution)
- (regex_option_for_transliteration)
-] @parameter
+(_
+ "{" @punctuation.special
+ (varname)
+ "}" @punctuation.special)
-(type_glob
- (identifier) @variable)
+(varname
+ (block
+ "{" @punctuation.special
+ "}" @punctuation.special))
-[
- (word_list_qw)
- (command_qx_quoted)
- (string_single_quoted)
- (string_double_quoted)
- (string_qq_quoted)
- (bareword)
- (transliteration_tr_or_y)
-] @string
-[
- (heredoc_start_identifier)
- (heredoc_end_identifier)
-] @label
+(
+ [(varname) (filehandle)] @variable.builtin
+ (#lua-match? @variable.builtin "^((ENV|ARGV|INC|ARGVOUT|SIG|STDIN|STDOUT|STDERR)|[_ab]|\\W|\\d+|\\^.*)$")
+)
-(heredoc_body_statement) @text.literal
+(scalar) @variable.scalar
+(scalar_deref_expression [ "$" "*"] @variable.scalar)
+[(array) (arraylen)] @variable.array
+(array_deref_expression [ "@" "*"] @variable.array)
+(hash) @variable.hash
+(hash_deref_expression [ "%" "*"] @variable.hash)
-[
- (pattern_matcher)
- (regex_pattern_qr)
- (patter_matcher_m)
- (substitution_pattern_s)
-] @string.regex
+(array_element_expression array:(_) @variable.array)
+(slice_expression array:(_) @variable.array)
+(keyval_expression array:(_) @variable.array)
-(escape_sequence) @string.escape
+(hash_element_expression hash:(_) @variable.hash)
+(slice_expression hash:(_) @variable.hash)
+(keyval_expression hash:(_) @variable.hash)
-[
- ","
- (semi_colon)
- (start_delimiter)
- (end_delimiter)
- (ellipsis_statement)
-] @punctuation.delimiter
+(comment) @comment
-(function_attribute) @field
+([ "=>" "," ";" "->" ] @punctuation.delimiter)
-(function_signature) @type
+(
+ [ "[" "]" "{" "}" "(" ")" ] @punctuation.bracket
+ ; priority hack so nvim + ts-cli behave the same
+ (#set! "priority" 90))
diff --git a/queries/perl/injections.scm b/queries/perl/injections.scm
index cab5f53d5..ba5e45f45 100644
--- a/queries/perl/injections.scm
+++ b/queries/perl/injections.scm
@@ -1,2 +1,14 @@
-((comments) @injection.content
+; an injections.scm file for nvim-treesitter
+((comment) @injection.content
(#set! injection.language "comment"))
+
+((pod) @injection.content
+ (#set! injection.language "pod"))
+
+((substitution_regexp
+ (replacement) @injection.content
+ (substitution_regexp_modifiers) @_modifiers)
+ ; match if there's a single `e` in the modifiers list
+ (#lua-match? @_modifiers "e")
+ (#not-lua-match? @_modifiers "e.*e")
+ (#set! injection.language "perl"))