diff options
| author | Bruno BELANYI <bruno@belanyi.fr> | 2022-06-14 17:24:28 +0200 |
|---|---|---|
| committer | Stephan Seitz <stephan.seitz@fau.de> | 2022-06-14 22:34:03 +0200 |
| commit | ef385991b615807df3731b5f0779895515999f33 (patch) | |
| tree | 6c0aa246b08798d9c33a3e2b6faf3660c75d076b | |
| parent | Update lockfile.json (diff) | |
| download | nvim-treesitter-ef385991b615807df3731b5f0779895515999f33.tar nvim-treesitter-ef385991b615807df3731b5f0779895515999f33.tar.gz nvim-treesitter-ef385991b615807df3731b5f0779895515999f33.tar.bz2 nvim-treesitter-ef385991b615807df3731b5f0779895515999f33.tar.lz nvim-treesitter-ef385991b615807df3731b5f0779895515999f33.tar.xz nvim-treesitter-ef385991b615807df3731b5f0779895515999f33.tar.zst nvim-treesitter-ef385991b615807df3731b5f0779895515999f33.zip | |
feat(tiger): initial support
| -rw-r--r-- | lua/nvim-treesitter/parsers.lua | 12 | ||||
| -rw-r--r-- | queries/tiger/folds.scm | 24 | ||||
| -rw-r--r-- | queries/tiger/highlights.scm | 127 | ||||
| -rw-r--r-- | queries/tiger/indents.scm | 69 | ||||
| -rw-r--r-- | queries/tiger/injections.scm | 3 | ||||
| -rw-r--r-- | queries/tiger/locals.scm | 35 |
6 files changed, 270 insertions, 0 deletions
diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua index 670524c4e..ac66029e2 100644 --- a/lua/nvim-treesitter/parsers.lua +++ b/lua/nvim-treesitter/parsers.lua @@ -1081,6 +1081,18 @@ list.v = { maintainers = { "@tami5" }, } +list.tiger = { + install_info = { + url = "https://github.com/ambroisie/tree-sitter-tiger", + files = { "src/parser.c", "src/scanner.c" }, + branch = "main", + generate_requires_npm = false, + requires_generate_from_grammar = false, + }, + filetype = "tiger", + maintainers = { "@ambroisie" }, +} + local M = { list = list, filetype_to_parsername = filetype_to_parsername, diff --git a/queries/tiger/folds.scm b/queries/tiger/folds.scm new file mode 100644 index 000000000..994c936e5 --- /dev/null +++ b/queries/tiger/folds.scm @@ -0,0 +1,24 @@ +[ + (array_expression) + (record_expression) + (sequence_expression) + (if_expression) + (while_expression) + (for_expression) + (let_expression) + (function_declaration) + (primitive_declaration) + + (record_type) + + (class_declaration) + (class_type) + (method_declaration) +] @fold + +[ + (comment) + (string_literal) +] @ignore + +; vim: sw=2 foldmethod=marker diff --git a/queries/tiger/highlights.scm b/queries/tiger/highlights.scm new file mode 100644 index 000000000..cadeed7b9 --- /dev/null +++ b/queries/tiger/highlights.scm @@ -0,0 +1,127 @@ +; Built-ins {{{ +((function_call + function: (identifier) @function.builtin) + (#match? @function.builtin "^(chr|concat|exit|flush|getchar|not|ord|print|print_err|print_int|size|strcmp|streq|substring)$") + (#is-not? local)) + +((type_identifier) @type.builtin + (#match? @type.builtin "^(int|string|Object)$") + (#is-not? local)) + +((identifier) @variable.builtin + (#match? @variable.builtin "^self$") + (#is-not? local)) +; }}} + +; Keywords {{{ +[ + "function" + "primitive" +] @keyword.function + +[ + "do" + "for" + "to" + "while" +] @keyword.repeat + +[ + "new" +] @keyword.constructor + +[ + "method" +] @keyword.method + +[ + "array" + (break_expression) + "do" + "else" + "end" + "for" + "function" + "if" + "import" + "in" + "let" + "of" + "primitive" + "then" + "to" + "type" + "var" + "while" + + "class" + "extends" + "method" + "new" + + "_cast" + "_chunks" + "_exp" + "_lvalue" + "_namety" +] @keyword +; }}} + +; Operators {{{ +(operator) @operator + +[ + "," + ";" + ":" + "." +] @punctuation.delimiter + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket +; }}} + +; Functions and methods {{{ +(function_call + function: (identifier) @function) +(function_declaration + name: (identifier) @function) +(primitive_declaration + name: (identifier) @function) + +(method_call + method: (identifier) @method) +(method_declaration + name: (identifier) @method) + +(parameters + name: (identifier) @variable.parameter) +; }}} + +; Declarations {{{ +(import_declaration + file: (string_literal) @string.special.path) +; }}} + +; Literals {{{ +(nil_literal) @constant.builtin +(integer_literal) @number +(string_literal) @string +(escape_sequence) @string.escape +; }}} + +; Misc {{{ +(comment) @comment + +(type_identifier) @type +(field_identifier) @property +(identifier) @variable +; }}} + +; vim: sw=2 foldmethod=marker diff --git a/queries/tiger/indents.scm b/queries/tiger/indents.scm new file mode 100644 index 000000000..4ac8d2452 --- /dev/null +++ b/queries/tiger/indents.scm @@ -0,0 +1,69 @@ +; Control flow {{{ +(if_expression) @indent +"then" @branch +"else" @branch + +(while_expression) @indent +"do" @branch + +(for_expression) @indent +"to" @branch +; }}} + +; Class {{{ +(class_declaration) @indent +(class_declaration "}" @indent_end) + +(class_type) @indent +(class_type "}" @indent_end) +; }}} + +; Groups {{{ +(let_expression) @indent +"in" @branch +"end" @branch +(let_expression "end" @indent_end) + +(sequence_expression) @indent +")" @branch +(sequence_expression ")" @indent_end) +; }}} + +; Functions and methods {{{ +(parameters) @indent +(parameters ")" @indent_end) + +(function_call) @indent +(method_call) @indent +")" @branch + +(function_declaration) @indent +(primitive_declaration) @indent +(method_declaration) @indent +; }}} + +; Values and expressions {{{ +(array_value) @indent +"]" @branch +(array_value "]" @indent_end) + +(array_expression) @indent +"of" @branch + +(record_expression) @indent +"}" @branch +(record_expression "}" @indent_end) + +(record_type) @indent +"}" @branch +(record_type "}" @indent_end) + +(variable_declaration) @indent +; }}} + +; Misc{{{ +(comment) @ignore +(string_literal) @ignore +; }}} + +; vim: sw=2 foldmethod=marker diff --git a/queries/tiger/injections.scm b/queries/tiger/injections.scm new file mode 100644 index 000000000..21350312a --- /dev/null +++ b/queries/tiger/injections.scm @@ -0,0 +1,3 @@ +(comment) @comment + +; vim: sw=2 foldmethod=marker diff --git a/queries/tiger/locals.scm b/queries/tiger/locals.scm new file mode 100644 index 000000000..70baf8743 --- /dev/null +++ b/queries/tiger/locals.scm @@ -0,0 +1,35 @@ +; See this issue [1] for support for "lazy scoping" which is somewhat needed +; for Tiger semantics (e.g: one can call a function before it has been defined +; top-to-bottom). +; +; [1]: https://github.com/tree-sitter/tree-sitter/issues/918 + +; Scopes {{{ +[ + (for_expression) + (let_expression) + (function_declaration) +] @local.scope +; }}} + +; Definitions {{{ +(type_declaration + name: (identifier) @local.definition) + +(parameters + name: (identifier) @local.definition) + +(function_declaration + name: (identifier) @local.definition) +(primitive_declaration + name: (identifier) @local.definition) + +(variable_declaration + name: (identifier) @local.definition) +; }}} + +; References {{{ +(identifier) @local.reference +; }}} + +; vim: sw=2 foldmethod=marker |
