Unnamed repository; edit this file 'description' to name the repository.
Add support for `yara` language (#12753)
Abhi 2025-02-11
parent 199dc05 · commit 7a3470c
-rw-r--r--book/src/generated/lang-support.md1
-rw-r--r--languages.toml14
-rw-r--r--runtime/queries/yara/highlights.scm136
-rw-r--r--runtime/queries/yara/injections.scm2
-rw-r--r--runtime/queries/yara/locals.scm21
5 files changed, 174 insertions, 0 deletions
diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md
index 7445021d..171a6861 100644
--- a/book/src/generated/lang-support.md
+++ b/book/src/generated/lang-support.md
@@ -249,5 +249,6 @@
| xml | ✓ | | ✓ | |
| xtc | ✓ | | | |
| yaml | ✓ | ✓ | ✓ | `yaml-language-server`, `ansible-language-server` |
+| yara | ✓ | | | `yls` |
| yuck | ✓ | | | |
| zig | ✓ | ✓ | ✓ | `zls` |
diff --git a/languages.toml b/languages.toml
index 174032a0..8bb9dee5 100644
--- a/languages.toml
+++ b/languages.toml
@@ -123,6 +123,7 @@ vscode-json-language-server = { command = "vscode-json-language-server", args =
vuels = { command = "vue-language-server", args = ["--stdio"], config = { typescript = { tsdk = "node_modules/typescript/lib/" } } }
wgsl_analyzer = { command = "wgsl_analyzer" }
yaml-language-server = { command = "yaml-language-server", args = ["--stdio"] }
+yls = { command = "yls", args = ["-vv"] }
zls = { command = "zls" }
blueprint-compiler = { command = "blueprint-compiler", args = ["lsp"] }
typst-lsp = { command = "typst-lsp" }
@@ -4148,3 +4149,16 @@ scope = "source.csv"
[[grammar]]
name = "csv"
source = { git = "https://github.com/weartist/rainbow-csv-tree-sitter", rev = "d3dbf916446131417e4c2ea9eb8591b23b466d27" }
+
+[[language]]
+name = "yara"
+scope = "source.yara"
+file-types = ["yara", "yar"]
+indent = { tab-width = 2, unit = " " }
+comment-tokens = "//"
+block-comment-tokens = { start = "/*", end = "*/"}
+language-servers = [ "yls" ]
+
+[[grammar]]
+name = "yara"
+source = { git = "https://github.com/egibs/tree-sitter-yara", rev = "eb3ede203275c38000177f72ec0f9965312806ef" }
diff --git a/runtime/queries/yara/highlights.scm b/runtime/queries/yara/highlights.scm
new file mode 100644
index 00000000..f483215e
--- /dev/null
+++ b/runtime/queries/yara/highlights.scm
@@ -0,0 +1,136 @@
+; Comments
+(comment) @comment
+
+; Keywords
+[
+ "global"
+ "import"
+ "private"
+] @constant.builtin
+
+[
+ "rule"
+] @function
+
+[
+ "meta"
+ "strings"
+ "condition"
+] @attribute
+
+; Operators
+[
+ "matches"
+ "contains"
+ "icontains"
+ "imatches"
+ "startswith"
+ "istartswith"
+ "endswith"
+ "iendswith"
+ "and"
+ "or"
+ "not"
+ "=="
+ "!="
+ "<"
+ ">"
+ ">="
+ "<="
+ "of"
+ "for"
+ "all"
+ "any"
+ "none"
+ "in"
+] @string.special
+
+; String modifiers
+[
+ "wide"
+ "ascii"
+ "nocase"
+ "fullword"
+ "xor"
+ "base64"
+ "base64wide"
+] @keyword.storage.modifier
+
+; Numbers and sizes
+(integer_literal) @constant.numeric
+(size_unit) @constant.numeric
+
+; Strings
+(double_quoted_string) @string
+(single_quoted_string) @string
+(escape_sequence) @constant.character.escape
+
+; Hex strings
+(hex_string) @string.special
+(hex_byte) @constant.numeric
+(hex_wildcard) @constant.builtin
+(hex_jump) @constant.numeric
+
+; Regular expressions
+(regex_string) @string.regexp
+(pattern) @string.regexp
+
+; Boolean literals
+[
+ "true"
+ "false"
+] @constant.builtin.boolean
+
+; Keywords and special identifiers
+[
+ "them"
+ "all"
+ "any"
+ "none"
+] @keyword.operator
+
+
+; String identifiers
+"$" @string.special.symbol
+(identifier) @string
+(string_identifier) @string.special.symbol
+
+; Built-ins
+[
+ (filesize_keyword)
+ (entrypoint_keyword)
+] @constant.builtin
+
+; Tags
+(tag_list
+ [(identifier) (tag)] @tag)
+
+; Punctuation and delimiters
+[
+ "="
+ ":"
+ "{"
+ "}"
+ "["
+ "]"
+ "("
+ ")"
+ "#"
+ "@"
+ ".."
+ "|"
+ ","
+ "!"
+ "/"
+ "\""
+ "'"
+ "*"
+] @string.special.symbol
+
+; Rule names
+(rule_definition
+ name: (identifier) @string.special)
+
+; Meta definitions
+(meta_definition
+ key: (identifier) @string.special)
diff --git a/runtime/queries/yara/injections.scm b/runtime/queries/yara/injections.scm
new file mode 100644
index 00000000..321c90ad
--- /dev/null
+++ b/runtime/queries/yara/injections.scm
@@ -0,0 +1,2 @@
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/runtime/queries/yara/locals.scm b/runtime/queries/yara/locals.scm
new file mode 100644
index 00000000..16f8768a
--- /dev/null
+++ b/runtime/queries/yara/locals.scm
@@ -0,0 +1,21 @@
+(rule_definition) @local.definition
+(string_identifier) @local.definition
+
+(for_expression
+ (string_identifier) @local.reference)
+
+(for_of_expression
+ (string_identifier) @local.reference)
+
+(of_expression
+ (string_set
+ (string_identifier) @local.reference))
+
+(string_count
+ (string_identifier) @local.reference)
+
+(string_offset
+ (string_identifier) @local.reference)
+
+(string_length
+ (string_identifier) @local.reference)