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

39 lines
812 B
JavaScript
Raw Normal View History

2024-04-21 02:25:56 -07:00
module.exports = grammar({
name: "TestLang",
rules: {
2024-04-21 03:01:13 -07:00
source_file: $ => repeat($._definition),
_definition: $ => choice(
$.function_definition
//TODO others
2024-04-21 03:08:05 -07:00
),
2024-04-21 03:01:13 -07:00
2024-04-21 03:08:05 -07:00
function_definition: $ => seq(
"fn",
$.identifier,
$.parameter_list,
$._type,
$.block,
),
parameter_list: $ => seq("(", /* TODO */ ")"),
2024-04-21 03:01:13 -07:00
2024-04-21 03:08:05 -07:00
block: $ => seq(
"{",
repeat($._statement),
"}"
),
2024-04-21 03:01:13 -07:00
2024-04-21 03:08:05 -07:00
_statement: $ => choice(
$._return_statement
),
_return_statement: $ => seq("return", $._expression, ";"),
_expression: $ => choice($.identifier),
_type: $ => "bool",
identifier: $ => /[a-z]+/,
2024-04-21 02:25:56 -07:00
}
});