fix(bindings): correct Zig bindings to expose a language function
Instead of having users declare the extern function themselves, they can pass in the language to `Language.create` in the zig bindings. If they really want, they can always opt into the `extern fn tree_sitter_LANG() *const ts.Language` approach.
This commit is contained in:
parent
9ad096ef22
commit
eed662df98
4 changed files with 62 additions and 13 deletions
19
cli/src/templates/root.zig
Normal file
19
cli/src/templates/root.zig
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
const testing = @import("std").testing;
|
||||
|
||||
const ts = @import("tree-sitter");
|
||||
const Language = ts.Language;
|
||||
const Parser = ts.Parser;
|
||||
|
||||
pub extern fn tree_sitter_PARSER_NAME() callconv(.C) *const Language;
|
||||
|
||||
pub export fn language() *const Language {
|
||||
return tree_sitter_PARSER_NAME();
|
||||
}
|
||||
|
||||
test "can load grammar" {
|
||||
const parser = Parser.create();
|
||||
defer parser.destroy();
|
||||
try testing.expectEqual(parser.setLanguage(language()), void{});
|
||||
try testing.expectEqual(parser.getLanguage(), tree_sitter_PARSER_NAME());
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue