From cf59fb63b347367ecf5ea0bba066aa68b01906ab Mon Sep 17 00:00:00 2001 From: RobWalt Date: Wed, 4 May 2022 18:31:26 +0200 Subject: [PATCH 1/3] feat(languages): add odin language This commit adds the odin language by using the grammar and highlighting queries written by MineBill from github This commit resolves #2340 by just applying all the changes already discussed in the issue --- languages.toml | 13 +++ runtime/queries/odin/highlights.scm | 140 ++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 runtime/queries/odin/highlights.scm diff --git a/languages.toml b/languages.toml index 9d3ad27bcbb7..7e2f2c630ee1 100644 --- a/languages.toml +++ b/languages.toml @@ -1303,3 +1303,16 @@ indent = { tab-width = 2, unit = " " } [[grammar]] name = "cpon" source = { git = "https://github.com/fvacek/tree-sitter-cpon", rev = "11ba46a4de3eb86934003133099c9963a60f9687" } + +[[language]] +name = "odin" +auto-format = false +scope = "source.odin" +file-types = ["odin"] +roots = [] +comment-token = "//" +indent = { tab-width = 4, unit = " " } + +[[grammar]] +name = "odin" +source = { git = "https://github.com/MineBill/tree-sitter-odin", rev = "da885f4a387f169b9b69fe0968259ee257a8f69a" } diff --git a/runtime/queries/odin/highlights.scm b/runtime/queries/odin/highlights.scm new file mode 100644 index 000000000000..b74553eb963c --- /dev/null +++ b/runtime/queries/odin/highlights.scm @@ -0,0 +1,140 @@ +; Function calls + +(call_expression + function: (identifier) @function) + +(call_expression + function: (selector_expression + field: (field_identifier) @function)) + + +; ; Function definitions + +(function_declaration + name: (identifier) @function) + +(proc_group + (identifier) @function) + +; ; Identifiers + +(type_identifier) @type +(field_identifier) @property +(identifier) @variable + +(const_declaration + (identifier) @constant) +(const_declaration_with_type + (identifier) @constant) + +"any" @type + +(directive_identifier) @constant + +; ; Operators + +[ + "?" + "-" + "-=" + ":=" + "!" + "!=" + "*" + "*" + "*=" + "/" + "/=" + "&" + "&&" + "&=" + "%" + "%=" + "^" + "+" + "+=" + "<-" + "<" + "<<" + "<<=" + "<=" + "=" + "==" + ">" + ">=" + ">>" + ">>=" + "|" + "|=" + "||" + "~" + ".." + "..<" + "..=" + "::" +] @operator + +; ; Keywords + +[ + ; "asm" + "auto_cast" + ; "bit_set" + "cast" + ; "context" + ; "or_else" + ; "or_return" + "in" + ; "not_in" + "distinct" + "foreign" + "transmute" + ; "typeid" + + "break" + "case" + "continue" + "defer" + "else" + "using" + "when" + "where" + "fallthrough" + "for" + "proc" + "if" + "import" + "map" + "package" + "return" + "struct" + "union" + "enum" + "switch" + "dynamic" +] @keyword + +; ; Literals + +[ + (interpreted_string_literal) + (raw_string_literal) + (rune_literal) +] @string + +(escape_sequence) @escape + +[ + (int_literal) + (float_literal) + (imaginary_literal) +] @number + +[ + (true) + (false) + (nil) + (undefined) +] @constant + +(comment) @comment From 6b0d69c964e3aecfeb881a65d4797035aa47b4f3 Mon Sep 17 00:00:00 2001 From: RobWalt Date: Thu, 5 May 2022 18:49:57 +0200 Subject: [PATCH 2/3] feat(languages): add auto-generated docs --- book/src/generated/lang-support.md | 1 + 1 file changed, 1 insertion(+) diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 5c5ecaafe57c..83e67f27534f 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -57,6 +57,7 @@ | nu | ✓ | | | | | ocaml | ✓ | | ✓ | `ocamllsp` | | ocaml-interface | ✓ | | | `ocamllsp` | +| odin | ✓ | | | | | org | ✓ | | | | | perl | ✓ | ✓ | ✓ | | | php | ✓ | ✓ | ✓ | `intelephense` | From b302ca97b330122173ff7f5faacc896d00c48676 Mon Sep 17 00:00:00 2001 From: RobWalt Date: Thu, 5 May 2022 18:59:01 +0200 Subject: [PATCH 3/3] feat(languages): adjust highlighting - mostly apply changes from review by the-mikedavis (thanks) extra changes listed below - change true/false to @constant.builtin.boolean - change comment to @comment.line --- runtime/queries/odin/highlights.scm | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/runtime/queries/odin/highlights.scm b/runtime/queries/odin/highlights.scm index b74553eb963c..1d801ff1b823 100644 --- a/runtime/queries/odin/highlights.scm +++ b/runtime/queries/odin/highlights.scm @@ -19,7 +19,7 @@ ; ; Identifiers (type_identifier) @type -(field_identifier) @property +(field_identifier) @variable.other.member (identifier) @variable (const_declaration @@ -122,19 +122,20 @@ (rune_literal) ] @string -(escape_sequence) @escape +(escape_sequence) @constant.character.escape -[ - (int_literal) - (float_literal) - (imaginary_literal) -] @number +(int_literal) @constant.numeric.integer +(float_literal) @constant.numeric.float +(imaginary_literal) @constant.numeric [ (true) (false) +] @constant.builtin.boolean + +[ (nil) (undefined) -] @constant +] @constant.builtin -(comment) @comment +(comment) @comment.line