A MoonBit binding to the tree-sitter parsing library
moon update # Update the mooncakes.io package index
moon add tonyfettes/tree_sitter{
"import": [
"tonyfettes/tree_sitter"
]
}moon add tonyfettes/tree_sitter_moonbitAnd then import the tonyfettes/tree_sitter_moonbit package in your
moon.pkg.json file as well:{
"import": [
"tonyfettes/tree_sitter",
"tonyfettes/tree_sitter_moonbit"
]
}fn main {
let moonbit = @tree_sitter_moonbit.language()
let parser = @tree_sitter.Parser::new()
parser.set_language(moonbit)
let source_code =
#|fn main {
#| println("Hello, World!")
#|}
let tree = parser.parse_string(None, source_code)
let root_node = tree.root_node()
println(root_node.string())
}# Initialize the tree-sitter submodule
git submodule update --init --recursive
moon update
moon build --target nativepython scripts/prepare.pycd test && moon test --target native[!NOTE] You may find that the LSP is not working when you are editing files under the test/ directory. This is because test/ is a MoonBit module itself, and therefore the LSP process has to be spawned in the test/ directory to work properly. In most cases, this means you need to spin up a new editor instance inside the test/ directory.