feat(tiger): initial support

This commit is contained in:
Bruno BELANYI 2022-06-14 17:24:28 +02:00 committed by Stephan Seitz
parent 6227ae19b8
commit ef385991b6
6 changed files with 270 additions and 0 deletions

View file

@ -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,

24
queries/tiger/folds.scm Normal file
View file

@ -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

View file

@ -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

69
queries/tiger/indents.scm Normal file
View file

@ -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

View file

@ -0,0 +1,3 @@
(comment) @comment
; vim: sw=2 foldmethod=marker

35
queries/tiger/locals.scm Normal file
View file

@ -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