Compare commits

...

10 commits

Author SHA1 Message Date
Bruno BELANYI 2d89ec8b20 Add built-in functions
All checks were successful
continuous-integration/drone/push Build is passing
This is a good proxy test to ensure that scope queries work correctly.
2022-06-03 21:09:11 +02:00
Bruno BELANYI 073ff80adb Add basic scoping queries 2022-06-03 21:02:40 +02:00
Bruno BELANYI 64ff9dd944 Add import path high-lighting
I don't think this group is supported by neovim, but 'tree-sitter-nix'
makes use of it, and I think it makes sense to add it.
2022-06-03 20:35:53 +02:00
Bruno BELANYI bd42c2c9c1 Move 'literals' high-lighting to end of file
Once again, seems like order matters, and I want to be able to write more specific queries.
2022-06-03 20:30:45 +02:00
Bruno BELANYI aff11eefce More specific loop keyword high-lighting 2022-06-03 20:28:28 +02:00
Bruno BELANYI b22ca8cd67 More specific function keyword high-lighting
I learnt about this group by reading the nvim-treesitter source [1].

[1]: see 'lua/nvim-treesitter/highlight.lua'
2022-06-03 20:15:09 +02:00
Bruno BELANYI 5f38f649bd Ignore WASM artifact 2022-06-03 20:02:00 +02:00
Bruno BELANYI b998075f2d Use play-ground enabled 'tree-sitter' in devShell
This is actually quite useful for debugging it turns out :-).
2022-06-03 20:00:32 +02:00
Bruno BELANYI 62a601469e Add functions high-lighting 2022-06-03 19:59:56 +02:00
Bruno BELANYI 67b555c381 Move 'misc' high-lighting to end of file
Turns out that order *matters* for queries.

Tree-sitter will stop at the first match it seems. So I want the
hyper-general 'identifier' matching right at the end to avoid overriding
more specific rules.
2022-06-03 19:58:19 +02:00
9 changed files with 121 additions and 23 deletions

3
.gitignore vendored
View file

@ -1,3 +1,6 @@
# Nix files
/result
/.pre-commit-config.yaml
# Tree-sitter artifact
/tree-sitter-tiger.wasm

View file

@ -115,7 +115,7 @@
default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
nodejs
tree-sitter
(tree-sitter.override { webUISupport = true; })
];
inherit (checks.pre-commit) shellHook;

View file

@ -1,12 +1,23 @@
; Misc {{{
(comment) @comment
(type_identifier) @type
(field_identifier) @property
(identifier) @variable
; 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))
; }}}
; Keywords {{{
[
"function"
"primitive"
] @keyword.function
[
"do"
"for"
"to"
"while"
] @keyword.repeat
[
"array"
(break_expression)
@ -29,13 +40,6 @@
] @keyword
; }}}
; Literals {{{
(nil_literal) @constant.builtin
(integer_literal) @number
(string_literal) @string
(escape_sequence) @string.escape
; }}}
; Operators {{{
(operator) @operator
@ -56,4 +60,36 @@
] @punctuation.bracket
; }}}
; Functions {{{
(function_call
function: (identifier) @function)
(function_declaration
name: (identifier) @function)
(primitive_declaration
name: (identifier) @function)
(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

29
queries/locals.scm Normal file
View file

@ -0,0 +1,29 @@
; 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

View file

@ -0,0 +1,19 @@
let
var a := exit(0)
/* ^ function.builtin */
primitive exit(ret: int) /* Shadowing the prelude-included built-in */
var b := exit(0)
/* ^ function */
in
exit(1);
/* <- function */
print("shadowing is fun");
/* <- function.builtin */
b := print
/* ^ variable */
end

View file

@ -0,0 +1,8 @@
primitive print(s: string)
/* ^ function */
/* ^ variable.parameter */
function func(a: int) : int = (print("Hello World!"); a)
/* ^ function */
/* ^ variable.parameter */
/* ^ function */

View file

@ -22,8 +22,8 @@ var array := int_array[12] of 27;
/* ^ type */
primitive func(a: int, b: string) : array
/* ^ variable */
/* ^ variable.parameter */
/* ^ type */
/* ^ variable */
/* ^ variable.parameter */
/* ^ type */
/* ^ type */

View file

@ -0,0 +1,3 @@
import "lib.tih"
/* <- keyword */
/* ^ string.special.path */

View file

@ -5,9 +5,9 @@ let
/* <- keyword */
function f() : int = a
/* <- keyword */
/* <- keyword.function */
primitive g()
/* <- keyword */
/* <- keyword.function */
import "lib.tih"
/* <- keyword */
@ -28,13 +28,13 @@ in
/* ^ keyword */
for i := 12 to 27 do 42;
/* <- keyword */
/* ^ keyword */
/* ^ keyword */
/* <- keyword.repeat */
/* ^ keyword.repeat */
/* ^ keyword.repeat */
while 12 do break
/* <- keyword */
/* ^ keyword */
/* <- keyword.repeat */
/* ^ keyword.repeat */
/* ^ keyword */
end