From 45add73fb1d2c4f2b0c544117c2d83b7081a2a4a Mon Sep 17 00:00:00 2001 From: ath3 <45574139+ath3@users.noreply.github.com> Date: Wed, 24 Aug 2022 18:58:15 +0200 Subject: [PATCH] AWK support (#3528) --- book/src/generated/lang-support.md | 1 + languages.toml | 14 ++++ runtime/queries/awk/highlights.scm | 122 ++++++++++++++++++++++++++++ runtime/queries/awk/injections.scm | 2 + runtime/queries/awk/textobjects.scm | 10 +++ runtime/queries/bash/injections.scm | 6 ++ 6 files changed, 155 insertions(+) create mode 100644 runtime/queries/awk/highlights.scm create mode 100644 runtime/queries/awk/injections.scm create mode 100644 runtime/queries/awk/textobjects.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 12a429317..8c1d82089 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -1,5 +1,6 @@ | Language | Syntax Highlighting | Treesitter Textobjects | Auto Indent | Default LSP | | --- | --- | --- | --- | --- | +| awk | ✓ | ✓ | | `awk-language-server` | | bash | ✓ | | | `bash-language-server` | | beancount | ✓ | | | | | c | ✓ | ✓ | ✓ | `clangd` | diff --git a/languages.toml b/languages.toml index 38af13103..bac2c8d09 100644 --- a/languages.toml +++ b/languages.toml @@ -66,6 +66,20 @@ indent = { tab-width = 2, unit = " " } name = "toml" source = { git = "https://github.com/ikatyang/tree-sitter-toml", rev = "7cff70bbcbbc62001b465603ca1ea88edd668704" } +[[language]] +name = "awk" +scope = "source.awk" +injection-regex = "awk" +file-types = ["awk", "gawk", "nawk", "mawk"] +roots = [] +comment-token = "#" +language-server = { command = "awk-language-server" } +indent = { tab-width = 2, unit = " " } + +[[grammar]] +name = "awk" +source = { git = "https://github.com/Beaglefoot/tree-sitter-awk", rev = "a799bc5da7c2a84bc9a06ba5f3540cf1191e4ee3" } + [[language]] name = "protobuf" scope = "source.proto" diff --git a/runtime/queries/awk/highlights.scm b/runtime/queries/awk/highlights.scm new file mode 100644 index 000000000..34d660ad5 --- /dev/null +++ b/runtime/queries/awk/highlights.scm @@ -0,0 +1,122 @@ +; tree-sitter-awk v0.5.1 + +; https://tree-sitter.github.io/tree-sitter/using-parsers#pattern-matching-with-queries + +; Order matters + +[ + ";" + "," + "(" + ")" + "[" + "]" + "{" + "}" +] @operator + +(piped_io_statement [ + "|" + "|&" +] @operator) + +(redirected_io_statement [ + ">" + ">>" +] @operator) + +(update_exp [ + "++" + "--" +] @operator) + +(ternary_exp [ + "?" + ":" +] @operator) + +(assignment_exp [ + "=" + "+=" + "-=" + "*=" + "/=" + "%=" + "^=" +] @operator) + +(unary_exp [ + "!" + "+" + "-" +] @operator) + +(binary_exp [ + "^" + "**" + "*" + "/" + "%" + "+" + "-" + "<" + ">" + "<=" + ">=" + "==" + "!=" + "~" + "!~" + "in" + "&&" + "||" +] @operator) + +[ + "@include" + "@load" + "@namespace" + (pattern) +] @namespace + +[ + "function" + "func" + "print" + "printf" + "if" + "else" + "do" + "while" + "for" + "in" + "delete" + "return" + "exit" + "switch" + "case" + "default" + (break_statement) + (continue_statement) + (next_statement) + (nextfile_statement) + (getline_input) + (getline_file) +] @keyword + +(comment) @comment +(regex) @string.regexp +(number) @constant.numeric +(string) @string + +(func_call name: (identifier) @function) +(func_def name: (identifier) @function) + +(field_ref (_) @variable) +[ + (identifier) + (field_ref) +] @variable + +(ns_qualified_name "::" @operator) +(ns_qualified_name (namespace) @namespace) diff --git a/runtime/queries/awk/injections.scm b/runtime/queries/awk/injections.scm new file mode 100644 index 000000000..321c90add --- /dev/null +++ b/runtime/queries/awk/injections.scm @@ -0,0 +1,2 @@ +((comment) @injection.content + (#set! injection.language "comment")) diff --git a/runtime/queries/awk/textobjects.scm b/runtime/queries/awk/textobjects.scm new file mode 100644 index 000000000..467a89823 --- /dev/null +++ b/runtime/queries/awk/textobjects.scm @@ -0,0 +1,10 @@ + +(func_def name: (identifier) (block) @function.inside) @function.around + +(param_list (_) @parameter.inside) @parameter.around + +(args (_) @parameter.inside) @parameter.around + +(comment) @comment.inside + +(comment)+ @comment.around diff --git a/runtime/queries/bash/injections.scm b/runtime/queries/bash/injections.scm index 321c90add..0fddb10ff 100644 --- a/runtime/queries/bash/injections.scm +++ b/runtime/queries/bash/injections.scm @@ -1,2 +1,8 @@ ((comment) @injection.content (#set! injection.language "comment")) + +(command + name: (command_name (word) @_command) + argument: (raw_string) @injection.content + (#match? @_command "^[gnm]?awk$") + (#set! injection.language "awk")) \ No newline at end of file