Compare commits

..

No commits in common. "wip-update-queries" and "main" have entirely different histories.

16 changed files with 1250 additions and 1275 deletions

View file

@ -1,17 +1,16 @@
.PHONY: all .PHONE: all
all: all:
tree-sitter generate tree-sitter generate
.PHONY: test .PHONE: test
test: all test: all
tree-sitter test tree-sitter test
nvim-test nvim-test
.PHONY: update-tests .PHONE: update-tests
update-tests: all update-tests: all
tree-sitter test -u tree-sitter test -u
.PHONY: playground
playground: playground:
nix shell pkgs#emscripten --command tree-sitter build-wasm nix shell pkgs#emscripten --command tree-sitter build-wasm
tree-sitter playground tree-sitter playground

32
flake.lock generated
View file

@ -1,31 +1,28 @@
{ {
"nodes": { "nodes": {
"flake-utils": { "flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": { "locked": {
"lastModified": 1731533236, "lastModified": 1667395993,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "numtide", "owner": "numtide",
"ref": "main", "ref": "master",
"repo": "flake-utils", "repo": "flake-utils",
"type": "github" "type": "github"
} }
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1712482522, "lastModified": 1669045945,
"narHash": "sha256-Ai/xNgZpbwGcw0TSXwEPwwbPi8Iu906sB9M9z3o6UgA=", "narHash": "sha256-BQxzijvZpLQ7R+KuQzCPcFgIS6OK0Onb29pYFe2pzJo=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "efe8ce06ca261f370d672def5b1e0be300c726e1", "rev": "6b5019a48f876f3288efc626fa8b70ad0c64eb46",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -65,21 +62,6 @@
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"pre-commit-hooks": "pre-commit-hooks" "pre-commit-hooks": "pre-commit-hooks"
} }
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
} }
}, },
"root": "root", "root": "root",

View file

@ -6,7 +6,7 @@
type = "github"; type = "github";
owner = "numtide"; owner = "numtide";
repo = "flake-utils"; repo = "flake-utils";
ref = "main"; ref = "master";
}; };
nixpkgs = { nixpkgs = {

View file

@ -8,7 +8,9 @@
(let_expression) (let_expression)
(function_declaration) (function_declaration)
(primitive_declaration) (primitive_declaration)
(record_type) (record_type)
(class_declaration) (class_declaration)
(class_type) (class_type)
(method_declaration) (method_declaration)

View file

@ -1,22 +1,23 @@
; Built-ins {{{ ; Built-ins {{{
((function_call ((function_call
function: (identifier) @function.builtin) function: (identifier) @function.builtin)
(#any-of? @function.builtin (#match? @function.builtin "^(chr|concat|exit|flush|getchar|not|ord|print|print_err|print_int|size|strcmp|streq|substring)$")
"chr" "concat" "exit" "flush" "getchar" "not" "ord" "print" "print_err" "print_int" "size" (#is-not? local))
"strcmp" "streq" "substring"))
((type_identifier) @type.builtin ((type_identifier) @type.builtin
(#any-of? @type.builtin "int" "string" "Object")) (#match? @type.builtin "^(int|string|Object)$")
(#is-not? local))
((identifier) @variable.builtin ((identifier) @variable.builtin
(#eq? @variable.builtin "self")) (#match? @variable.builtin "^self$")
(#is-not? local))
; }}} ; }}}
; Keywords {{{ ; Keywords {{{
[ [
"function" "function"
"primitive" "method"
"method" "primitive"
] @keyword.function ] @keyword.function
[ [
@ -26,9 +27,14 @@
"while" "while"
] @keyword.repeat ] @keyword.repeat
"new" @keyword.operator [
"new"
] @keyword.constructor
"import" @keyword.import
[
"import"
] @include
[ [
"array" "array"
@ -42,80 +48,73 @@
"then" "then"
"type" "type"
"var" "var"
"class"
"extends" "extends"
"_cast" "_cast"
"_chunks" "_chunks"
"_exp" "_exp"
"_lvalue" "_lvalue"
"_namety" "_namety"
] @keyword ] @keyword
"class" @keyword.type
; }}} ; }}}
; Operators {{{ ; Operators {{{
(operator) @operator (operator) @operator
[ [
"," ","
";" ";"
":" ":"
"." "."
] @punctuation.delimiter ] @punctuation.delimiter
[ [
"(" "("
")" ")"
"[" "["
"]" "]"
"{" "{"
"}" "}"
] @punctuation.bracket ] @punctuation.bracket
; }}} ; }}}
; Functions and methods {{{ ; Functions and methods {{{
(function_call (function_call
function: (identifier) @function) function: (identifier) @function)
(function_declaration (function_declaration
name: (identifier) @function) name: (identifier) @function)
(primitive_declaration (primitive_declaration
name: (identifier) @function) name: (identifier) @function)
(method_call (method_call
method: (identifier) @function.method) method: (identifier) @method)
(method_declaration (method_declaration
name: (identifier) @function.method) name: (identifier) @method)
(parameters (parameters
name: (identifier) @variable.parameter) name: (identifier) @parameter)
; }}} ; }}}
; Declarations {{{ ; Declarations {{{
(import_declaration (import_declaration
file: (string_literal) @string.special.path) file: (string_literal) @string.special.path)
; }}} ; }}}
; Literals {{{ ; Literals {{{
(nil_literal) @constant.builtin (nil_literal) @constant.builtin
(integer_literal) @number (integer_literal) @number
(string_literal) @string (string_literal) @string
(escape_sequence) @string.escape (escape_sequence) @string.escape
; }}} ; }}}
; Misc {{{ ; Misc {{{
(comment) @comment ; @spell (comment) @comment
(type_identifier) @type (type_identifier) @type
(field_identifier) @property
(field_identifier) @variable.member
(identifier) @variable (identifier) @variable
; }}} ; }}}
; vim: sw=2 foldmethod=marker ; vim: sw=2 foldmethod=marker

View file

@ -1,104 +1,69 @@
; Control flow {{{ ; Control flow {{{
(if_expression) @indent.begin (if_expression) @indent
"then" @branch
"else" @branch
"then" @indent.branch (while_expression) @indent
"do" @branch
"else" @indent.branch
(while_expression) @indent.begin
"do" @indent.branch
(for_expression) @indent.begin
"to" @indent.branch
(for_expression) @indent
"to" @branch
; }}} ; }}}
; Class {{{ ; Class {{{
(class_declaration) @indent.begin (class_declaration) @indent
(class_declaration "}" @indent_end)
(class_declaration
"}" @indent.end)
(class_type) @indent.begin
(class_type
"}" @indent.end)
(class_type) @indent
(class_type "}" @indent_end)
; }}} ; }}}
; Groups {{{ ; Groups {{{
(let_expression) @indent.begin (let_expression) @indent
"in" @branch
"in" @indent.branch "end" @branch
(let_expression "end" @indent_end)
"end" @indent.branch
(let_expression
"end" @indent.end)
(sequence_expression) @indent.begin
")" @indent.branch
(sequence_expression
")" @indent.end)
(sequence_expression) @indent
")" @branch
(sequence_expression ")" @indent_end)
; }}} ; }}}
; Functions and methods {{{ ; Functions and methods {{{
(parameters) @indent.begin (parameters) @indent
(parameters ")" @indent_end)
(parameters (function_call) @indent
")" @indent.end) (method_call) @indent
")" @branch
(function_call) @indent.begin
(function_call
")" @indent.end)
(method_call) @indent.begin
")" @indent.branch
(function_declaration) @indent.begin
(primitive_declaration) @indent.begin
(method_declaration) @indent.begin
(function_declaration) @indent
(primitive_declaration) @indent
(method_declaration) @indent
; }}} ; }}}
; Values and expressions {{{ ; Values and expressions {{{
(array_value) @indent.begin (array_value) @indent
"]" @branch
(array_value "]" @indent_end)
"]" @indent.branch (array_expression) @indent
"of" @branch
(array_value (record_expression) @indent
"]" @indent.end) "}" @branch
(record_expression "}" @indent_end)
(array_expression) @indent.begin (record_type) @indent
"}" @branch
"of" @indent.branch (record_type "}" @indent_end)
(record_expression) @indent.begin
"}" @indent.branch
(record_expression
"}" @indent.end)
(record_type) @indent.begin
"}" @indent.branch
(record_type
"}" @indent.end)
(variable_declaration) @indent.begin
(variable_declaration) @indent
; }}} ; }}}
; Misc{{{ ; Misc{{{
(comment) @indent.ignore (comment) @ignore
(string_literal) @ignore
(string_literal) @indent.ignore
; }}} ; }}}
; vim: sw=2 foldmethod=marker ; vim: sw=2 foldmethod=marker

View file

@ -1,4 +1,3 @@
((comment) @injection.content (comment) @comment
(#set! injection.language "comment"))
; vim: sw=2 foldmethod=marker ; vim: sw=2 foldmethod=marker

35
queries/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

2178
src/parser.c generated

File diff suppressed because it is too large Load diff

View file

@ -13,8 +13,9 @@ extern "C" {
#define ts_builtin_sym_end 0 #define ts_builtin_sym_end 0
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024 #define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
#ifndef TREE_SITTER_API_H_
typedef uint16_t TSStateId; typedef uint16_t TSStateId;
#ifndef TREE_SITTER_API_H_
typedef uint16_t TSSymbol; typedef uint16_t TSSymbol;
typedef uint16_t TSFieldId; typedef uint16_t TSFieldId;
typedef struct TSLanguage TSLanguage; typedef struct TSLanguage TSLanguage;
@ -129,16 +130,9 @@ struct TSLanguage {
* Lexer Macros * Lexer Macros
*/ */
#ifdef _MSC_VER
#define UNUSED __pragma(warning(suppress : 4101))
#else
#define UNUSED __attribute__((unused))
#endif
#define START_LEXER() \ #define START_LEXER() \
bool result = false; \ bool result = false; \
bool skip = false; \ bool skip = false; \
UNUSED \
bool eof = false; \ bool eof = false; \
int32_t lookahead; \ int32_t lookahead; \
goto start; \ goto start; \
@ -172,7 +166,7 @@ struct TSLanguage {
* Parse Table Macros * Parse Table Macros
*/ */
#define SMALL_STATE(id) ((id) - LARGE_STATE_COUNT) #define SMALL_STATE(id) id - LARGE_STATE_COUNT
#define STATE(id) id #define STATE(id) id
@ -182,7 +176,7 @@ struct TSLanguage {
{{ \ {{ \
.shift = { \ .shift = { \
.type = TSParseActionTypeShift, \ .type = TSParseActionTypeShift, \
.state = (state_value) \ .state = state_value \
} \ } \
}} }}
@ -190,7 +184,7 @@ struct TSLanguage {
{{ \ {{ \
.shift = { \ .shift = { \
.type = TSParseActionTypeShift, \ .type = TSParseActionTypeShift, \
.state = (state_value), \ .state = state_value, \
.repetition = true \ .repetition = true \
} \ } \
}} }}

View file

@ -6,7 +6,7 @@ let
/* ^ type.builtin */ /* ^ type.builtin */
var b := exit(0) var b := exit(0)
/* ^ function.builtin */ /* ^ function */
type int = string /* Shadowing the built-in type */ type int = string /* Shadowing the built-in type */
/* ^ type.builtin */ /* ^ type.builtin */
@ -30,13 +30,13 @@ in
end; end;
exit(1); exit(1);
/* <- function.builtin */ /* <- function */
print("shadowing is fun"); print("shadowing is fun");
/* <- function.builtin */ /* <- function.builtin */
self; self;
/* <- variable.builtin */ /* <- variable */
b := print b := print
/* ^ variable */ /* ^ variable */

View file

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

View file

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

View file

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

View file

@ -10,7 +10,7 @@ let
/* <- keyword.function */ /* <- keyword.function */
import "lib.tih" import "lib.tih"
/* <- keyword.import */ /* <- include */
type array_of_int = array of int type array_of_int = array of int
/* <- keyword */ /* <- keyword */

View file

@ -1,11 +1,11 @@
let let
class A extends Object {} class A extends Object {}
/* <- keyword.type */ /* <- keyword */
/* ^ keyword */ /* ^ keyword */
/* ^ type.builtin */ /* ^ type.builtin */
type B = class extends A { type B = class extends A {
/* ^ keyword.type */ /* ^ keyword */
/* ^ keyword */ /* ^ keyword */
/* ^ type */ /* ^ type */
@ -13,16 +13,16 @@ let
method meth() : int = self.a method meth() : int = self.a
/* <- keyword.function */ /* <- keyword.function */
/* ^ function.method */ /* ^ method */
/* ^ variable.builtin */ /* ^ variable.builtin */
} }
var object := new B var object := new B
/* ^ keyword.operator */ /* ^ keyword.constructor */
in in
object.a := 27; object.a := 27;
/* ^ variable.member */ /* ^ property */
object.meth() object.meth()
/* ^ function.method */ /* ^ method */
end end