Messing with treesitter grammar

doesn't work yet
This commit is contained in:
Greg Shuflin 2024-04-23 02:13:44 -07:00
parent f33195ab28
commit 77257d0eb7
2 changed files with 9 additions and 5 deletions

View File

@ -12,14 +12,14 @@ module.exports = grammar({
"fn",
$.identifier,
$.parameter_list,
$._type,
optional($._type),
$.block,
),
parameter_list: $ => seq("(", /* TODO */ ")"),
block: $ => seq(
"{",
repeat($._statement),
repeat(optional($._statement)),
"}"
),
@ -29,7 +29,10 @@ module.exports = grammar({
_return_statement: $ => seq("return", $._expression, ";"),
_expression: $ => choice($.identifier),
_expression: $ => choice($.identifier, $.unary, $.binary),
unary: $ => prec(4, choice(seq("-", $._expression), seq("!", $._expression))),
binary: $ => choice(prec.left(2, seq($._expression, "*", $._expression)), prec.left(1, seq($._expression, "+", $._expression))),
_type: $ => "bool",

View File

@ -1,8 +1,9 @@
=============
Initial test
=============
fn main() {
hello
}
----
@ -13,7 +14,7 @@ hello
Another
====
fn main() { }
fn main() bool { }
------
()