tree-sitter-zig

    Zig grammar for tree-sitter (tree-sitter-grammars/tree-sitter-zig v1.1.2), for the MoonBit port of Tree-sitter (moonbit-community/treesitter).

    tree-sitter
    parser
    grammar
    zig
    Download zip
    Version
    0.101.2
    License
    MIT
    Last updated
    21 days ago
    Downloads
    24

    #tree-sitter-zig for MoonBit

    Zig grammar for tree-sitter.

    This module packages tree-sitter-grammars/tree-sitter-zig v1.1.2 for moonbit-community/treesitter, the pure MoonBit port of Tree-sitter. The parse tables are generated from the grammar's src/grammar.json by the port's generator, which produces the same tables as tree-sitter generate 0.28.0.

    The module version 0.101.2 stands for the grammar's release v1.1.2: Mooncakes only accepts 0.x.y versions for now, so releases M.m.p with M >= 1 are published as 0.(100*M + m).p.

    #API

    The package mirrors the grammar's Rust binding (bindings/rust/lib.rs):

    MoonBitRust
    language() -> @treesitter.LanguageLANGUAGE
    node_types : StringNODE_TYPES (src/node-types.json)
    highlights_query : StringHIGHLIGHTS_QUERY (queries/highlights.scm)
    injections_query : StringINJECTIONS_QUERY (queries/injections.scm)

    #Usage

    moon add moonbit-community/tree-sitter-zig

    In moon.pkg:

    import { "moonbit-community/treesitter", "moonbit-community/tree-sitter-zig" @tree_sitter_zig, }

    ///|
    test "parse zig" {
    let language = @tree_sitter_zig.language()
    let parser = @treesitter.Parser::new()
    parser.set_language(language)
    let source =
    #|const std = @import("std");
    #|
    #|pub fn main() void {
    #| std.debug.print("Hello, {s}!\n", .{"world"});
    #|}
    #|
    guard parser.parse(@utf8.encode(source)) is Some(tree) else {
    fail("parse failed")
    }
    let root = tree.root_node()
    assert_false(root.has_error())
    assert_false(root.to_sexp().contains("ERROR"))
    }

    #License

    The grammar and the files copied from it (src/grammar.json, queries, test corpus) are under the license of tree-sitter-grammars/tree-sitter-zig, in LICENSE.

    highlights_query

    let highlights_query : String

    The content of queries/highlights.scm (HIGHLIGHTS_QUERY in the Rust binding).

    injections_query

    let injections_query : String

    The content of queries/injections.scm (INJECTIONS_QUERY in the Rust binding).

    language

    The tree-sitter language for the zig grammar (LANGUAGE in the Rust binding), generated from src/grammar.json.

    node_types

    let node_types : String

    The content of src/node-types.json (NODE_TYPES in the Rust binding).