From bb3f8f40b1443fb40665263e1b5b0658bc24be03 Mon Sep 17 00:00:00 2001 From: Veesh Goldman Date: Tue, 17 Oct 2023 19:32:09 +0000 Subject: feat(perl)!: switch to tree-sitter-perl org's parser --- lockfile.json | 2 +- lua/nvim-treesitter/parsers.lua | 7 +- queries/perl/folds.scm | 30 +++-- queries/perl/highlights.scm | 254 ++++++++++++++++------------------------ queries/perl/injections.scm | 14 ++- 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) + "}" @punct