Compare commits
19 commits
2d89ec8b20
...
1cfcc43469
Author | SHA1 | Date | |
---|---|---|---|
Bruno BELANYI | 1cfcc43469 | ||
Bruno BELANYI | 79413a9624 | ||
Bruno BELANYI | 6732ec0994 | ||
Bruno BELANYI | 8ffe530561 | ||
Bruno BELANYI | 83356398f9 | ||
Bruno BELANYI | e8883aaf5d | ||
Bruno BELANYI | 0bb177a05e | ||
Bruno BELANYI | c31f249d4a | ||
Bruno BELANYI | 221904815a | ||
Bruno BELANYI | a871263996 | ||
Bruno BELANYI | c2dcb86e78 | ||
Bruno BELANYI | 2bd24cceb4 | ||
Bruno BELANYI | 9214ca7c35 | ||
Bruno BELANYI | 545d090540 | ||
Bruno BELANYI | 10dae1ab92 | ||
Bruno BELANYI | c4af009a8d | ||
Bruno BELANYI | efe0a2800b | ||
Bruno BELANYI | 184d3b9953 | ||
Bruno BELANYI | 3e1068a336 |
|
@ -1,10 +1,10 @@
|
||||||
[package]
|
[package]
|
||||||
name = "tree-sitter-tiger"
|
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"
|
version = "0.0.1"
|
||||||
keywords = ["incremental", "parsing", "tiger"]
|
keywords = ["incremental", "parsing", "tiger"]
|
||||||
categories = ["parsing", "text-editors"]
|
categories = ["parsing", "text-editors"]
|
||||||
repository = "https://github.com/tree-sitter/tree-sitter-tiger"
|
repository = "https://gitea.belanyi.fr/ambroisie/tree-sitter-tiger"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
"sources": [
|
"sources": [
|
||||||
"bindings/node/binding.cc",
|
"bindings/node/binding.cc",
|
||||||
"src/parser.c",
|
"src/parser.c",
|
||||||
# If your language uses an external scanner, add it here.
|
"src/scanner.c",
|
||||||
],
|
],
|
||||||
"cflags_c": [
|
"cflags_c": [
|
||||||
"-std=c99",
|
"-std=c99",
|
||||||
|
|
|
@ -13,11 +13,9 @@ fn main() {
|
||||||
// If your language uses an external scanner written in C,
|
// If your language uses an external scanner written in C,
|
||||||
// then include this block of code:
|
// then include this block of code:
|
||||||
|
|
||||||
/*
|
|
||||||
let scanner_path = src_dir.join("scanner.c");
|
let scanner_path = src_dir.join("scanner.c");
|
||||||
c_config.file(&scanner_path);
|
c_config.file(&scanner_path);
|
||||||
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
|
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
|
||||||
*/
|
|
||||||
|
|
||||||
c_config.compile("parser");
|
c_config.compile("parser");
|
||||||
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
|
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
|
||||||
|
|
|
@ -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
|
// Uncomment these to include any queries that this grammar contains
|
||||||
|
|
||||||
// pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
|
pub const FOLDS_QUERY: &'static str = include_str!("../../queries/folds.scm");
|
||||||
// pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm");
|
pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
|
||||||
// pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
|
pub const INDENTS_QUERY: &'static str = include_str!("../../queries/indents.scm");
|
||||||
// pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
|
@ -338,4 +338,4 @@ module.exports = grammar({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// vim: sw=2
|
// vim: foldmethod=marker sw=2
|
||||||
|
|
18
queries/folds.scm
Normal file
18
queries/folds.scm
Normal 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
|
|
@ -3,6 +3,10 @@
|
||||||
function: (identifier) @function.builtin)
|
function: (identifier) @function.builtin)
|
||||||
(#match? @function.builtin "^(chr|concat|exit|flush|getchar|not|ord|print|print_err|print_int|size|strcmp|streq|substring)$")
|
(#match? @function.builtin "^(chr|concat|exit|flush|getchar|not|ord|print|print_err|print_int|size|strcmp|streq|substring)$")
|
||||||
(#is-not? local))
|
(#is-not? local))
|
||||||
|
|
||||||
|
((type_identifier) @type.builtin
|
||||||
|
(#match? @type.builtin "^(int|string)$")
|
||||||
|
(#is-not? local))
|
||||||
; }}}
|
; }}}
|
||||||
|
|
||||||
; Keywords {{{
|
; Keywords {{{
|
||||||
|
|
18
queries/indents.scm
Normal file
18
queries/indents.scm
Normal 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
3
queries/injections.scm
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
(comment) @comment
|
||||||
|
|
||||||
|
; vim: sw=2 foldmethod=marker
|
|
@ -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 {{{
|
; Scopes {{{
|
||||||
[
|
[
|
||||||
(for_expression)
|
(for_expression)
|
||||||
|
|
11
queries/tags.scm
Normal file
11
queries/tags.scm
Normal 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
28
queries/textobjects.scm
Normal 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
|
|
@ -3,11 +3,23 @@ let
|
||||||
/* ^ function.builtin */
|
/* ^ function.builtin */
|
||||||
|
|
||||||
primitive exit(ret: int) /* Shadowing the prelude-included built-in */
|
primitive exit(ret: int) /* Shadowing the prelude-included built-in */
|
||||||
|
/* ^ type.builtin */
|
||||||
|
|
||||||
var b := exit(0)
|
var b := exit(0)
|
||||||
/* ^ function */
|
/* ^ 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
|
in
|
||||||
|
let
|
||||||
|
var c : int := "This is an int"
|
||||||
|
/* ^ type.builtin (not sure why it isn't 'type')*/
|
||||||
|
in
|
||||||
|
end;
|
||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
/* <- function */
|
/* <- function */
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
type int = int
|
type int = int
|
||||||
/* ^ variable */
|
/* ^ variable */
|
||||||
/* ^ type */
|
/* ^ type.builtin */
|
||||||
|
|
||||||
type int_array = array of int
|
type int_array = array of int
|
||||||
/* ^ type */
|
/* ^ type.builtin */
|
||||||
|
|
||||||
type record = {a: int, b: string}
|
type record = {a: int, b: string}
|
||||||
/* ^ property */
|
/* ^ property */
|
||||||
/* ^ type */
|
/* ^ type.builtin */
|
||||||
/* ^ property */
|
/* ^ property */
|
||||||
/* ^ type */
|
/* ^ type.builtin */
|
||||||
|
|
||||||
var record := record {a = 12, b = "27"}
|
var record := record {a = 12, b = "27"}
|
||||||
/* ^ variable */
|
/* ^ variable */
|
||||||
|
@ -23,7 +23,7 @@ var array := int_array[12] of 27;
|
||||||
|
|
||||||
primitive func(a: int, b: string) : array
|
primitive func(a: int, b: string) : array
|
||||||
/* ^ variable.parameter */
|
/* ^ variable.parameter */
|
||||||
/* ^ type */
|
/* ^ type.builtin */
|
||||||
/* ^ variable.parameter */
|
/* ^ variable.parameter */
|
||||||
/* ^ type */
|
/* ^ type.builtin */
|
||||||
/* ^ type */
|
/* ^ type */
|
||||||
|
|
12
test/tags/functions.tig
Normal file
12
test/tags/functions.tig
Normal 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
|
Loading…
Reference in a new issue