From 461d841771c7a576e5fd33d1320934a4a0f1dbc9 Mon Sep 17 00:00:00 2001 From: OK Ryoko <59705845+ok-ryoko@users.noreply.github.com> Date: Tue, 18 Jul 2023 19:55:06 +0000 Subject: [PATCH] feat: add SystemTap (#5097) --- lockfile.json | 3 + lua/nvim-treesitter/parsers.lua | 8 ++ queries/systemtap/folds.scm | 18 ++++ queries/systemtap/highlights.scm | 153 +++++++++++++++++++++++++++++++ queries/systemtap/injections.scm | 2 + queries/systemtap/locals.scm | 35 +++++++ 6 files changed, 219 insertions(+) create mode 100644 queries/systemtap/folds.scm create mode 100644 queries/systemtap/highlights.scm create mode 100644 queries/systemtap/injections.scm create mode 100644 queries/systemtap/locals.scm diff --git a/lockfile.json b/lockfile.json index cef6a9359..c20a3c488 100644 --- a/lockfile.json +++ b/lockfile.json @@ -506,6 +506,9 @@ "sxhkdrc": { "revision": "440d5f913d9465c9c776a1bd92334d32febcf065" }, + "systemtap": { + "revision": "1af543a96d060b1f808982037bfc54cc02218edd" + }, "t32": { "revision": "4e581fcd17d76651aa92759a68f9a8186b9fe8dc" }, diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua index 3f1bc98d8..b8b14ae8f 100644 --- a/lua/nvim-treesitter/parsers.lua +++ b/lua/nvim-treesitter/parsers.lua @@ -1491,6 +1491,14 @@ list.sxhkdrc = { maintainers = { "@RaafatTurki" }, } +list.systemtap = { + install_info = { + url = "https://github.com/ok-ryoko/tree-sitter-systemtap", + files = { "src/parser.c" }, + }, + maintainers = { "@ok-ryoko" }, +} + list.t32 = { install_info = { url = "https://codeberg.org/xasc/tree-sitter-t32", diff --git a/queries/systemtap/folds.scm b/queries/systemtap/folds.scm new file mode 100644 index 000000000..58bb03e51 --- /dev/null +++ b/queries/systemtap/folds.scm @@ -0,0 +1,18 @@ +[ + (preprocessor_macro_definition) + (preprocessor_macro_expansion) + (conditional_preprocessing) + (embedded_code) + (probe_point_definition) + (probe_point_alias_prologue) + (probe_point_alias_epilogue) + (variable_declaration) + (function_definition) + (if_statement) + (while_statement) + (for_statement) + (foreach_statement) + (try_statement) + (catch_clause) + (comment) +] @fold diff --git a/queries/systemtap/highlights.scm b/queries/systemtap/highlights.scm new file mode 100644 index 000000000..54a27b897 --- /dev/null +++ b/queries/systemtap/highlights.scm @@ -0,0 +1,153 @@ +(identifier) @variable + +(preprocessor_macro_definition + name: (identifier) @function.macro) + +(preprocessor_macro_expansion) @function.macro + +(preprocessor_constant) @constant.macro + +(number) @number +(string) @string +(escape_sequence) @string.escape + +[ + (script_argument_string) + (script_argument_number) +] @constant + +(probe_point_component) @function + +(function_definition + name: (identifier) @function) + +(parameter + name: (identifier) @parameter) + +(type) @type.builtin + +(aggregation_operator) @attribute + +(member_expression + member: (identifier) @field) + +(call_expression + function: (identifier) @function.call) + +((call_expression + function: (identifier) @function.builtin) + (#any-of? @function.builtin + "print" "printd" "printdln" "printf" "println" + "sprint" "sprintd" "sprintdln" "sprintf" "sprintln")) + +((identifier) @variable.builtin + (#lua-match? @variable.builtin "^\$+[0-9A-Z_a-z]+\$*$")) + +(shebang_line) @preproc + +(comment) @comment @spell + +[ + "!" + "!=" + "!~" + "$" + "$$" + "%" + "%=" + "&" + "&&" + "&=" + "*" + "*=" + "+" + "++" + "+=" + "-" + "--" + "-=" + "->" + "." + ".=" + "/" + "/=" + ":" + "<" + "<<" + "<<<" + "<<=" + "<=" + "=" + "==" + "=~" + ">" + ">=" + ">>" + ">>=" + "?" + "^" + "^=" + "|" + "|=" + "||" + "~" +] @operator + +[ + "," + (null_statement) +] @punctuation.delimiter + +[ + "%{" + "%}" + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +[ + "delete" + "limit" + "next" + "probe" +] @keyword + +"function" @keyword.function +"in" @keyword.operator +"return" @keyword.return + +[ + "if" + "else" +] @conditional + +[ + "break" + "continue" + "for" + "foreach" + "while" +] @repeat + +[ + "try" + "catch" +] @exception + +[ + "%(" + "%)" + "%:" + "%?" + (preprocessor_tokens) + (embedded_code) +] @preproc + +"@define" @define + +"private" @type.qualifier +"global" @storageclass diff --git a/queries/systemtap/injections.scm b/queries/systemtap/injections.scm new file mode 100644 index 000000000..1dd86c9f3 --- /dev/null +++ b/queries/systemtap/injections.scm @@ -0,0 +1,2 @@ +(comment) @comment +(embedded_code) @c diff --git a/queries/systemtap/locals.scm b/queries/systemtap/locals.scm new file mode 100644 index 000000000..5d4447e52 --- /dev/null +++ b/queries/systemtap/locals.scm @@ -0,0 +1,35 @@ +[ + (function_definition) + (statement_block) + (if_statement) + (while_statement) + (for_statement) + (foreach_statement) + (catch_clause) +] @scope + +(init_declarator + name: (identifier) @definition.var) + +(array_declarator + name: (identifier) @definition.var) + +(function_definition + name: (identifier) @definition.function) + +(parameter + name: (identifier) @definition.parameter) + +(tuple_capture + (identifier) @definition.var) + +(catch_clause + parameter: (identifier) @definition.var) + +(assignment_expression + left: (identifier) @definition.var) + +(call_expression + function: (identifier) @reference) + +(identifier) @reference