Compare commits

...

19 commits

Author SHA1 Message Date
Bruno BELANYI 1cfcc43469 Add queries to rust bindings
All checks were successful
continuous-integration/drone/push Build is passing
I should try using those bindings to write tests for currently untested
queries...
2022-06-04 11:02:13 +02:00
Bruno BELANYI 79413a9624 Do not indent inside strings 2022-06-04 11:00:41 +02:00
Bruno BELANYI 6732ec0994 Add loop indents 2022-06-04 10:58:14 +02:00
Bruno BELANYI 8ffe530561 Add conditional indents 2022-06-04 10:57:27 +02:00
Bruno BELANYI 83356398f9 Add comment indents
Yet another un-testable query with the vanilla tooling...
2022-06-04 10:54:36 +02:00
Bruno BELANYI e8883aaf5d Add loop text objects 2022-06-04 10:52:47 +02:00
Bruno BELANYI 0bb177a05e Add conditional text objects 2022-06-04 10:52:47 +02:00
Bruno BELANYI c31f249d4a Add function parameter text objects 2022-06-04 10:52:47 +02:00
Bruno BELANYI 221904815a Add function call text objects 2022-06-04 10:48:19 +02:00
Bruno BELANYI a871263996 Add function text objects 2022-06-04 10:43:35 +02:00
Bruno BELANYI c2dcb86e78 Add comment text objects
Once again, something that isn't testable with 'tree-sitter' tooling...
2022-06-04 10:43:35 +02:00
Bruno BELANYI 2bd24cceb4 Add folds
Unfortunately it seems like this is not really testable with the
'tree-sitter' tooling.

If I want to check that this is working correctly, I should explore how
to make use of, e.g., neovim to automate testing.
2022-06-04 10:43:35 +02:00
Bruno BELANYI 9214ca7c35 Add 'foldmethod' to grammar modeline 2022-06-04 10:43:35 +02:00
Bruno BELANYI 545d090540 Mark 'comment' as injecting 'comment'
Neovim defines queries for the 'comment' language, to match 'TODO',
'FIXME', etc...
2022-06-04 10:43:35 +02:00
Bruno BELANYI 10dae1ab92 Add scanner to bindings 2022-06-04 10:43:35 +02:00
Bruno BELANYI c4af009a8d Fix Cargo manifest 2022-06-04 10:43:35 +02:00
Bruno BELANYI efe0a2800b Add comment about 'locals' queries limitations
This is not enough of an issue to avoid using the functionality however,
for example variable declarations are thankfully not affected by this
issue, since they *must* be declared before their use.
2022-06-04 10:43:35 +02:00
Bruno BELANYI 184d3b9953 Add function tags 2022-06-04 10:43:35 +02:00
Bruno BELANYI 3e1068a336 Add built-in types
Not sure why it seems like the 'is-not? local' is not working.

Will investigate later
2022-06-03 22:04:30 +02:00
15 changed files with 129 additions and 16 deletions

View file

@ -1,10 +1,10 @@
[package]
name = "tree-sitter-tiger"
description = "tiger grammar for the tree-sitter parsing library"
description = "Tiger grammar for the tree-sitter parsing library"
version = "0.0.1"
keywords = ["incremental", "parsing", "tiger"]
categories = ["parsing", "text-editors"]
repository = "https://github.com/tree-sitter/tree-sitter-tiger"
repository = "https://gitea.belanyi.fr/ambroisie/tree-sitter-tiger"
edition = "2018"
license = "MIT"

View file

@ -9,7 +9,7 @@
"sources": [
"bindings/node/binding.cc",
"src/parser.c",
# If your language uses an external scanner, add it here.
"src/scanner.c",
],
"cflags_c": [
"-std=c99",

View file

@ -13,11 +13,9 @@ fn main() {
// If your language uses an external scanner written in C,
// then include this block of code:
/*
let scanner_path = src_dir.join("scanner.c");
c_config.file(&scanner_path);
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
*/
c_config.compile("parser");
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());

View file

@ -35,10 +35,13 @@ pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json");
// Uncomment these to include any queries that this grammar contains
// pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
// pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm");
// pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
// pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm");
pub const FOLDS_QUERY: &'static str = include_str!("../../queries/folds.scm");
pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
pub const INDENTS_QUERY: &'static str = include_str!("../../queries/indents.scm");
pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm");
pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm");
pub const TEXTOBJECTS_QUERY: &'static str = include_str!("../../queries/textobjects.scm");
#[cfg(test)]
mod tests {

View file

@ -338,4 +338,4 @@ module.exports = grammar({
}
});
// vim: sw=2
// vim: foldmethod=marker sw=2

18
queries/folds.scm Normal file
View file

@ -0,0 +1,18 @@
[
(array_expression)
(record_expression)
(sequence_expression)
(if_expression)
(while_expression)
(for_expression)
(let_expression)
(function_declaration)
(primitive_declaration)
] @fold
[
(comment)
(string_literal)
] @ignore
; vim: sw=2 foldmethod=marker

View file

@ -3,6 +3,10 @@
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)$")
(#is-not? local))
; }}}
; Keywords {{{

18
queries/indents.scm Normal file
View file

@ -0,0 +1,18 @@
; Control flow {{{
(if_expression
consequence: (_) @indent)
"else" @branch
(while_expression
body: (_) @indent)
(for_expression
body: (_) @indent)
; }}}
; Misc{{{
(comment) @ignore
(string_literal) @ignore
; }}}
; vim: sw=2 foldmethod=marker

3
queries/injections.scm Normal file
View file

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

View file

@ -1,3 +1,9 @@
; 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)

11
queries/tags.scm Normal file
View file

@ -0,0 +1,11 @@
; Functions {{{
(function_declaration
name: (identifier) @name) @definition.function
(primitive_declaration
name: (identifier) @name) @definition.function
(function_call
function: (identifier) @name) @reference.call
; }}}
; vim: sw=2 foldmethod=marker

28
queries/textobjects.scm Normal file
View file

@ -0,0 +1,28 @@
; Functions {{{
(function_declaration
parameters: ((_) @parameter.inner)* @parameter.outer
body: (_) @function.inner) @function.outer
(primitive_declaration
parameters: ((_) @parameter.inner)* @parameter.outer) @function.outer
(function_call
arguments: ((_) @call.inner)*) @call.outer
; }}}
; Control flow {{{
(if_expression
consequence: (_) @conditional.inner
alternative: (_)? @conditional.inner) @conditional.outer
(while_expression
body: (_) @loop.inner) @loop.outer
(for_expression
body: (_) @loop.inner) @loop.outer
; }}}
; Misc {{{
(comment) @comment.outer
; }}}
; vim: sw=2 foldmethod=marker

View file

@ -3,11 +3,23 @@ let
/* ^ function.builtin */
primitive exit(ret: int) /* Shadowing the prelude-included built-in */
/* ^ type.builtin */
var b := exit(0)
/* ^ function */
type int = string /* Shadowing the built-in type */
/* ^ type.builtin */
var c : int := "This is an \"int\""
/* ^ type.builtin (not sure why it isn't 'type')*/
in
let
var c : int := "This is an int"
/* ^ type.builtin (not sure why it isn't 'type')*/
in
end;
exit(1);
/* <- function */

View file

@ -1,15 +1,15 @@
type int = int
/* ^ variable */
/* ^ type */
/* ^ type.builtin */
type int_array = array of int
/* ^ type */
/* ^ type.builtin */
type record = {a: int, b: string}
/* ^ property */
/* ^ type */
/* ^ type.builtin */
/* ^ property */
/* ^ type */
/* ^ type.builtin */
var record := record {a = 12, b = "27"}
/* ^ variable */
@ -23,7 +23,7 @@ var array := int_array[12] of 27;
primitive func(a: int, b: string) : array
/* ^ variable.parameter */
/* ^ type */
/* ^ type.builtin */
/* ^ variable.parameter */
/* ^ type */
/* ^ type.builtin */
/* ^ type */

12
test/tags/functions.tig Normal file
View file

@ -0,0 +1,12 @@
let
primitive print(s: string)
/* ^ definition.function */
function func(a: int) : int = (print("Hello World!"); a)
/* ^ definition.function */
in
print("Hello World!\n");
/* <- reference.call */
func(42)
/* <- reference.call */
end