From f33195ab2834f86f95aed67e9c68cfdf6c6e5575 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sun, 21 Apr 2024 03:08:05 -0700 Subject: [PATCH] Trying out a thing --- experiments/tree-sitter-test/grammar.js | 26 ++++++++++++++++++- .../tree-sitter-test/test/corpus/test.txt | 10 +++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/experiments/tree-sitter-test/grammar.js b/experiments/tree-sitter-test/grammar.js index 0af49df..5fb773f 100644 --- a/experiments/tree-sitter-test/grammar.js +++ b/experiments/tree-sitter-test/grammar.js @@ -6,9 +6,33 @@ module.exports = grammar({ _definition: $ => choice( $.function_definition //TODO others - ) + ), + function_definition: $ => seq( + "fn", + $.identifier, + $.parameter_list, + $._type, + $.block, + ), + parameter_list: $ => seq("(", /* TODO */ ")"), + block: $ => seq( + "{", + repeat($._statement), + "}" + ), + _statement: $ => choice( + $._return_statement + ), + + _return_statement: $ => seq("return", $._expression, ";"), + + _expression: $ => choice($.identifier), + + _type: $ => "bool", + + identifier: $ => /[a-z]+/, } }); diff --git a/experiments/tree-sitter-test/test/corpus/test.txt b/experiments/tree-sitter-test/test/corpus/test.txt index 3120d8e..3c0a61c 100644 --- a/experiments/tree-sitter-test/test/corpus/test.txt +++ b/experiments/tree-sitter-test/test/corpus/test.txt @@ -7,3 +7,13 @@ hello ---- (source_file) + + +===== +Another +==== + +fn main() { } + +------ +()