Compare commits
No commits in common. "dc771fc7adda661fc0aa7f8896dc59fcfdc39051" and "f33195ab2834f86f95aed67e9c68cfdf6c6e5575" have entirely different histories.
dc771fc7ad
...
f33195ab28
@ -9,20 +9,17 @@ module.exports = grammar({
|
||||
),
|
||||
|
||||
function_definition: $ => seq(
|
||||
'fn',
|
||||
"fn",
|
||||
$.identifier,
|
||||
$.parameter_list,
|
||||
field("return_type", optional($._type)),
|
||||
$._type,
|
||||
$.block,
|
||||
),
|
||||
parameter_list: $ => seq("(", /* TODO */ ")"),
|
||||
|
||||
block: $ => seq(
|
||||
"{",
|
||||
choice(
|
||||
repeat($._statement),
|
||||
"",
|
||||
),
|
||||
repeat($._statement),
|
||||
"}"
|
||||
),
|
||||
|
||||
@ -32,16 +29,9 @@ module.exports = grammar({
|
||||
|
||||
_return_statement: $ => seq("return", $._expression, ";"),
|
||||
|
||||
_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))),
|
||||
_expression: $ => choice($.identifier),
|
||||
|
||||
_type: $ => "bool",
|
||||
_type: $ => choice(
|
||||
$.primitive_type,
|
||||
),
|
||||
primitive_type: $ => choice("bool", "int"),
|
||||
|
||||
identifier: $ => /[a-z]+/,
|
||||
}
|
||||
|
@ -1,8 +0,0 @@
|
||||
_default:
|
||||
just --list
|
||||
|
||||
# Test out the grammar
|
||||
test-grammar:
|
||||
#!/usr/bin/env bash
|
||||
tree-sitter generate
|
||||
tree-sitter test
|
@ -1,26 +1,19 @@
|
||||
=============
|
||||
Initial test
|
||||
=============
|
||||
fn main() {
|
||||
|
||||
}
|
||||
----
|
||||
(source_file
|
||||
(function_definition
|
||||
(identifier)
|
||||
(parameter_list)
|
||||
(block)
|
||||
)
|
||||
)
|
||||
|
||||
====
|
||||
Another test
|
||||
====
|
||||
|
||||
fn yolo() bool { }
|
||||
hello
|
||||
|
||||
----
|
||||
|
||||
(source_file
|
||||
(function_definition
|
||||
(identifier) (parameter_list) (primitive_type) (block)))
|
||||
(source_file)
|
||||
|
||||
|
||||
=====
|
||||
Another
|
||||
====
|
||||
|
||||
fn main() { }
|
||||
|
||||
------
|
||||
()
|
||||
|
Loading…
Reference in New Issue
Block a user