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