From 028b7dfbddffdd4738a25a76b280d9b26f38ce42 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Thu, 23 Feb 2023 04:42:37 -0500 Subject: feat: add bicep --- README.md | 1 + lockfile.json | 3 + lua/nvim-treesitter/parsers.lua | 8 ++ queries/bicep/folds.scm | 25 +++++ queries/bicep/highlights.scm | 230 ++++++++++++++++++++++++++++++++++++++++ queries/bicep/indents.scm | 18 ++++ queries/bicep/injections.scm | 4 + queries/bicep/locals.scm | 74 +++++++++++++ 8 files changed, 363 insertions(+) create mode 100644 queries/bicep/folds.scm create mode 100644 queries/bicep/highlights.scm create mode 100644 queries/bicep/indents.scm create mode 100644 queries/bicep/injections.scm create mode 100644 queries/bicep/locals.scm diff --git a/README.md b/README.md index fdc603100..7510dfc07 100644 --- a/README.md +++ b/README.md @@ -181,6 +181,7 @@ We are looking for maintainers to add more parsers and to write query files for - [x] [bash](https://github.com/tree-sitter/tree-sitter-bash) (maintained by @TravonteD) - [x] [beancount](https://github.com/polarmutex/tree-sitter-beancount) (maintained by @polarmutex) - [x] [bibtex](https://github.com/latex-lsp/tree-sitter-bibtex) (maintained by @theHamsta, @clason) +- [x] [bicep](https://github.com/amaanq/tree-sitter-bicep) (maintained by @amaanq) - [x] [blueprint](https://gitlab.com/gabmus/tree-sitter-blueprint.git) (experimental, maintained by @gabmus) - [x] [c](https://github.com/tree-sitter/tree-sitter-c) (maintained by @vigoux) - [x] [c_sharp](https://github.com/tree-sitter/tree-sitter-c-sharp) (maintained by @Luxed) diff --git a/lockfile.json b/lockfile.json index ca9770ad7..4e685055d 100644 --- a/lockfile.json +++ b/lockfile.json @@ -23,6 +23,9 @@ "bibtex": { "revision": "ccfd77db0ed799b6c22c214fe9d2937f47bc8b34" }, + "bicep": { + "revision": "b94a0983b69ebb75e9129329a188199ad6ebcec0" + }, "blueprint": { "revision": "6ef91ca8270f0112b9c6d27ecb9966c741a5d103" }, diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua index 0eec2f116..4d7f9baf4 100644 --- a/lua/nvim-treesitter/parsers.lua +++ b/lua/nvim-treesitter/parsers.lua @@ -144,6 +144,14 @@ list.bibtex = { maintainers = { "@theHamsta", "@clason" }, } +list.bicep = { + install_info = { + url = "https://github.com/amaanq/tree-sitter-bicep", + files = { "src/parser.c" }, + }, + maintainers = { "@amaanq" }, +} + list.blueprint = { install_info = { url = "https://gitlab.com/gabmus/tree-sitter-blueprint.git", diff --git a/queries/bicep/folds.scm b/queries/bicep/folds.scm new file mode 100644 index 000000000..8ec5ba200 --- /dev/null +++ b/queries/bicep/folds.scm @@ -0,0 +1,25 @@ +[ + (module_declaration) + (metadata_declaration) + (output_declaration) + (parameter_declaration) + (resource_declaration) + (type_declaration) + (variable_declaration) + + (parenthesized_expression) + + (decorators) + (array) + (object) + + (if_statement) + (for_statement) + + (subscript_expression) + (ternary_expression) + + (string) + + (comment) +] @fold diff --git a/queries/bicep/highlights.scm b/queries/bicep/highlights.scm new file mode 100644 index 000000000..07c2c4efa --- /dev/null +++ b/queries/bicep/highlights.scm @@ -0,0 +1,230 @@ +; Includes + +(import_statement + "import" @include) + +(import_with_statement + "import" @include + "with" @include) + +; Namespaces + +(module_declaration + (identifier) @namespace) + +; Builtins + +(primitive_type) @type.builtin + +((member_expression + object: (identifier) @type.builtin) + (#match? @type.builtin "^sys$")) + +; Functions + +(call_expression + function: (identifier) @function.call) + +; Properties + +(object_property + (identifier) @property + ":" @punctuation.delimiter + (_)) + +(object_property + (compatible_identifier) @property + ":" @punctuation.delimiter + (_)) + +(property_identifier) @property + +; Attributes + +(decorator + "@" @attribute) + +(decorator + (call_expression (identifier) @attribute)) + +(decorator + (call_expression + (member_expression + object: (identifier) @attribute + property: (property_identifier) @attribute))) + +; Types + +(type_declaration + (identifier) @type) + +(type_declaration + (identifier) + "=" + (identifier) @type) + +(type_declaration + (identifier) + "=" + (array_type (identifier) @type)) + +(type + (identifier) @type) + +(resource_declaration + (identifier) @type) + +(resource_expression + (identifier) @type) + +; Parameters + +(parameter_declaration + (identifier) @parameter + (_)) + +(call_expression + function: (_) + (arguments (identifier) @parameter)) + +(call_expression + function: (_) + (arguments (member_expression object: (identifier) @parameter))) + +; Variables + +(variable_declaration + (identifier) @variable + (_)) + +(metadata_declaration + (identifier) @variable + (_)) + +(output_declaration + (identifier) @variable + (_)) + +(object_property + (_) + ":" + (identifier) @variable) + +(for_statement + "for" + (for_loop_parameters + (loop_variable) @variable + (loop_enumerator) @variable)) + +; Conditionals + +"if" @conditional + +(ternary_expression + "?" @conditional.ternary + ":" @conditional.ternary) + +; Loops + +(for_statement + "for" @repeat + "in" + ":" @punctuation.delimiter) + +; Keywords + +[ + "module" + "metadata" + "output" + "param" + "resource" + "existing" + "targetScope" + "type" + "var" +] @keyword + +; Operators + +[ + "+" + "-" + "*" + "/" + "%" + "||" + "&&" + "|" + "==" + "!=" + "=~" + "!~" + ">" + ">=" + "<=" + "<" + "??" + "=" + "!" +] @operator + +[ + "in" +] @keyword.operator + + +; Literals + +(string) @string +(import_string + "'" @string + (import_name) @namespace + "@" @symbol + (import_version) @string.special) + +(escape_sequence) @string.escape + +(number) @number + +(boolean) @boolean + +(null) @constant.builtin + +; Misc + +(compatible_identifier + "?" @punctuation.special) + +(nullable_return_type) @punctuation.special + +["{" "}"] @punctuation.bracket + +["[" "]"] @punctuation.bracket + +["(" ")"] @punctuation.bracket + +[ + "." + "::" + "=>" +] @punctuation.delimiter + + +; Interpolation + +(interpolation) @none + +(interpolation + "${" @punctuation.special + "}" @punctuation.special) + +(interpolation + (identifier) @variable) + +; Comments + +[ + (comment) + (diagnostic_comment) +] @comment @spell diff --git a/queries/bicep/indents.scm b/queries/bicep/indents.scm new file mode 100644 index 000000000..7fcf7ffb9 --- /dev/null +++ b/queries/bicep/indents.scm @@ -0,0 +1,18 @@ +[ + (array) + (object) +] @indent + +"}" @indent_end + +[ "{" "}" ] @branch + +[ "[" "]" ] @branch + +[ "(" ")" ] @branch + +[ + (ERROR) + (comment) + (diagnostic_comment) +] @auto diff --git a/queries/bicep/injections.scm b/queries/bicep/injections.scm new file mode 100644 index 000000000..c85cfe3b6 --- /dev/null +++ b/queries/bicep/injections.scm @@ -0,0 +1,4 @@ +[ + (comment) + (diagnostic_comment) +] @comment diff --git a/queries/bicep/locals.scm b/queries/bicep/locals.scm new file mode 100644 index 000000000..361be94fb --- /dev/null +++ b/queries/bicep/locals.scm @@ -0,0 +1,74 @@ +; Scopes + +[ + (infrastructure) + (call_expression) + + (lambda_expression) + (subscript_expression) + + (if_statement) + (for_statement) + + (array) + (object) + (interpolation) +] @scope + +; References + +(property_identifier) @reference + +(call_expression + (identifier) @reference) + +(object_property + (_) + ":" + (identifier) @reference) + +(resource_expression + (identifier) @reference) + +; Definitions + +(type) @definition.associated + +(object_property + (identifier) @definition.field + (_)) + +(object_property + (compatible_identifier) @definition.field + (_)) + +(import_name) @definition.import + +(module_declaration + (identifier) @definition.namespace) + +(parameter_declaration + (identifier) @definition.parameter + (_)) + +(type_declaration + (identifier) @definition.type + (_)) + +(variable_declaration + (identifier) @definition.var + (_)) + +(metadata_declaration + (identifier) @definition.var + (_)) + +(output_declaration + (identifier) @definition.var + (_)) + +(for_statement + "for" + (for_loop_parameters + (loop_variable) @definition.var + (loop_enumerator) @definition.var)) -- cgit v1.2.3-70-g09d2