Skip to content

Commit

Permalink
AWK support (#3528)
Browse files Browse the repository at this point in the history
  • Loading branch information
ath3 authored Aug 24, 2022
1 parent facde9f commit 45add73
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 0 deletions.
1 change: 1 addition & 0 deletions book/src/generated/lang-support.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
| Language | Syntax Highlighting | Treesitter Textobjects | Auto Indent | Default LSP |
| --- | --- | --- | --- | --- |
| awk ||| | `awk-language-server` |
| bash || | | `bash-language-server` |
| beancount || | | |
| c |||| `clangd` |
Expand Down
14 changes: 14 additions & 0 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
122 changes: 122 additions & 0 deletions runtime/queries/awk/highlights.scm
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions runtime/queries/awk/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
((comment) @injection.content
(#set! injection.language "comment"))
10 changes: 10 additions & 0 deletions runtime/queries/awk/textobjects.scm
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions runtime/queries/bash/injections.scm
Original file line number Diff line number Diff line change
@@ -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"))

0 comments on commit 45add73

Please sign in to comment.