From 55f9cbb33b8a3a8398b39190612f599355967bb3 Mon Sep 17 00:00:00 2001 From: Jay Pratt Date: Sat, 5 Oct 2024 01:04:29 +1000 Subject: [PATCH] Tests for type annotations and renam ops to use snake case --- tree-sitter-tako/grammar.js | 16 +++---- tree-sitter-tako/test/corpus/definitions.tk | 53 +++++++++++++++++++++ 2 files changed, 61 insertions(+), 8 deletions(-) diff --git a/tree-sitter-tako/grammar.js b/tree-sitter-tako/grammar.js index 31e40d07..86f34835 100644 --- a/tree-sitter-tako/grammar.js +++ b/tree-sitter-tako/grammar.js @@ -7,7 +7,7 @@ const PREC = { try: 15, neg: 14, not: 14, - bitnot: 14, + bit_not: 14, cast: 13, mul: 12, div: 12, @@ -16,9 +16,9 @@ const PREC = { sub: 11, left_shift: 10, right_shift: 10, - bitand: 9, - bitxor: 8, - bitor: 7, + bit_and: 9, + bit_xor: 8, + bit_or: 7, // comparative: 6, equals: 6, not_equals: 6, @@ -44,9 +44,9 @@ const OPERATORS = [ ['has_type', ':'], ['and', '&&'], ['or', '||'], - ['bitand', '&'], - ['bitor', '|'], - ['bitxor', '^'], + ['bit_and', '&'], + ['bit_or', '|'], + ['bit_xor', '^'], ['equals', '=='], ['not_equals', '!='], ['less_than', '<'], @@ -73,7 +73,7 @@ const OPTIONALLY_POSTFIX_OPERATORS = [ const UNARY_OPERATORS = [ ['neg', '-'], ['not', '!'], - ['bitnot', '~'], + ['bit_not', '~'], ]; const ALL_OPERATORS = [ diff --git a/tree-sitter-tako/test/corpus/definitions.tk b/tree-sitter-tako/test/corpus/definitions.tk index af9f2a87..29f49707 100644 --- a/tree-sitter-tako/test/corpus/definitions.tk +++ b/tree-sitter-tako/test/corpus/definitions.tk @@ -132,3 +132,56 @@ test(a, b) = { (block (int_literal)) ) ) + +================== +Definition with type +================== +test: Num = 3 +--- +(source_file + (assign + (has_type + (ident) + (ident) + ) + (int_literal) + ) +) + +================== +Definition with type that is an expression +================== +test: Float | Int = 3 +--- +(source_file + (assign + (has_type + (ident) + (bit_or + (ident) + (ident) + ) + ) + (int_literal) + ) +) + +================== +Function Definition with arguments and types using Block +================== +test(a: AType, b: BType): TestResultType = { + 3: TestResultType +} +--- +(source_file + (assign + (has_type + (call (ident) + (has_type (ident) (ident)) + (has_type (ident) (ident)) + ) + (ident) + ) + (block (has_type (int_literal) (ident))) + ) +)