Working simple tree-sitter grammar
This commit is contained in:
parent
45c4d08fb9
commit
dc771fc7ad
@ -9,17 +9,20 @@ module.exports = grammar({
|
|||||||
),
|
),
|
||||||
|
|
||||||
function_definition: $ => seq(
|
function_definition: $ => seq(
|
||||||
"fn",
|
'fn',
|
||||||
$.identifier,
|
$.identifier,
|
||||||
$.parameter_list,
|
$.parameter_list,
|
||||||
optional($._type),
|
field("return_type", optional($._type)),
|
||||||
$.block,
|
$.block,
|
||||||
),
|
),
|
||||||
parameter_list: $ => seq("(", /* TODO */ ")"),
|
parameter_list: $ => seq("(", /* TODO */ ")"),
|
||||||
|
|
||||||
block: $ => seq(
|
block: $ => seq(
|
||||||
"{",
|
"{",
|
||||||
repeat(optional($._statement)),
|
choice(
|
||||||
|
repeat($._statement),
|
||||||
|
"",
|
||||||
|
),
|
||||||
"}"
|
"}"
|
||||||
),
|
),
|
||||||
|
|
||||||
@ -35,6 +38,10 @@ module.exports = grammar({
|
|||||||
binary: $ => choice(prec.left(2, seq($._expression, "*", $._expression)), prec.left(1, seq($._expression, "+", $._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]+/,
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
|
_default:
|
||||||
|
just --list
|
||||||
|
|
||||||
# Test out the grammar
|
# Test out the grammar
|
||||||
test-grammar:
|
test-grammar:
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
tree-sitter generate
|
||||||
tree-sitter test
|
tree-sitter test
|
||||||
|
@ -4,17 +4,23 @@ Initial test
|
|||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
----
|
||||||
|
(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() bool { }
|
|
||||||
|
|
||||||
------
|
|
||||||
()
|
|
||||||
|
Loading…
Reference in New Issue
Block a user