schala/experiments/tree-sitter-test/grammar.js

39 lines
812 B
JavaScript

module.exports = grammar({
name: "TestLang",
rules: {
source_file: $ => repeat($._definition),
_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]+/,
}
});