From 5d7c90c5cfd6887fc0a43ee695d91f0166955a64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20C=2E=20M=C3=BCller?= Date: Sun, 26 Mar 2023 17:49:37 -0400 Subject: [PATCH] Add language support for rego (OpenPolicyAgent) (#6415) --- book/src/generated/lang-support.md | 1 + languages.toml | 15 +++++++ runtime/queries/rego/highlights.scm | 68 +++++++++++++++++++++++++++++ runtime/queries/rego/injections.scm | 2 + 4 files changed, 86 insertions(+) create mode 100644 runtime/queries/rego/highlights.scm create mode 100644 runtime/queries/rego/injections.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 524c2adf6..996bdb435 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -112,6 +112,7 @@ | r | ✓ | | | `R` | | racket | ✓ | | | `racket` | | regex | ✓ | | | | +| rego | ✓ | | | `regols` | | rescript | ✓ | ✓ | | `rescript-language-server` | | rmarkdown | ✓ | | ✓ | `R` | | ron | ✓ | | ✓ | | diff --git a/languages.toml b/languages.toml index f6a54e872..fe94d6999 100644 --- a/languages.toml +++ b/languages.toml @@ -2383,3 +2383,18 @@ injection-regex = "vhdl" [[grammar]] name = "vhdl" source = { git = "https://github.com/teburd/tree-sitter-vhdl", rev = "c57313adee2231100db0a7880033f6865deeadb2" } + +[[language]] +name = "rego" +roots = [] +scope = "source.rego" +injection-regex = "rego" +file-types = ["rego"] +auto-format = true +comment-token = "#" +language-server = { command = "regols" } +grammar = "rego" + +[[grammar]] +name = "rego" +source = { git = "https://github.com/FallenAngel97/tree-sitter-rego", rev = "b2667c975f07b33be3ceb83bea5cfbad88095866" } diff --git a/runtime/queries/rego/highlights.scm b/runtime/queries/rego/highlights.scm new file mode 100644 index 000000000..0ff6de552 --- /dev/null +++ b/runtime/queries/rego/highlights.scm @@ -0,0 +1,68 @@ +[ + (import) +] @keyword.control.import + +[ + (package) +] @namespace + +[ + (with) + (as) + (every) + (some) + (in) + (default) + "null" +] @keyword.control + +[ + (not) + (if) + (contains) + (else) +] @keyword.control.conditional + +[ + (boolean) +] @constant.builtin.boolean + +[ + (assignment_operator) + (bool_operator) + (arith_operator) + (bin_operator) +] @operator + +[ + (string) + (raw_string) +] @string + +(term (ref (var))) @variable + +(comment) @comment.line + +(number) @constant.numeric.integer + +(expr_call func_name: (fn_name (var) @function .)) + +(expr_call func_arguments: (fn_args (expr) @variable.parameter)) + +(rule_args (term) @variable.parameter) + +[ + (open_paren) + (close_paren) + (open_bracket) + (close_bracket) + (open_curly) + (close_curly) +] @punctuation.bracket + +(rule (rule_head (var) @function.method)) + +(rule + (rule_head (term (ref (var) @namespace))) + (rule_body (query (literal (expr (expr_infix (expr (term (ref (var)) @_output)))))) (#eq? @_output @namespace)) +) diff --git a/runtime/queries/rego/injections.scm b/runtime/queries/rego/injections.scm new file mode 100644 index 000000000..321c90add --- /dev/null +++ b/runtime/queries/rego/injections.scm @@ -0,0 +1,2 @@ +((comment) @injection.content + (#set! injection.language "comment"))