tree-sitter-cpp

    C++ grammar for tree-sitter (tree-sitter/tree-sitter-cpp v0.23.4), for the MoonBit port of Tree-sitter (moonbit-community/treesitter).

    tree-sitter
    parser
    grammar
    cpp
    Download zip
    Version
    0.23.4
    License
    MIT
    Last updated
    21 days ago
    Downloads
    23

    #tree-sitter-cpp for MoonBit

    C++ grammar for tree-sitter.

    This module packages tree-sitter/tree-sitter-cpp v0.23.4 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. External scanners come from @scanners.scanner_for in moonbit-community/treesitter/scanners, the MoonBit ports of the C scanners.

    #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)
    highlight_query : StringHIGHLIGHT_QUERY (queries/highlights.scm)
    tags_query : StringTAGS_QUERY (queries/tags.scm)

    #Usage

    moon add moonbit-community/tree-sitter-cpp

    In moon.pkg:

    import { "moonbit-community/treesitter", "moonbit-community/tree-sitter-cpp" @tree_sitter_cpp, }

    ///|
    test "parse cpp" {
    let language = @tree_sitter_cpp.language()
    let parser = @treesitter.Parser::new()
    parser.set_language(language)
    let source =
    #|T1 a = b < c > d;
    #|T2 e = f<T3>(g);
    #|int a = std::get<0>(t);
    #|if (x.y < z) break; // Not a template missing a '>'
    #|if (x.y < x->y && x.y > 50) break;
    #|if (x.foo < 0 || bar >= 1) break;
    #|if (x.Base::foo < 0 || bar >= 1) {
    #| bool i = x.Base::foo < 0 || 1 > (5); // No way to tell
    #|}
    #|
    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/tree-sitter-cpp, in LICENSE.

    highlight_query

    let highlight_query : String

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

    language

    The tree-sitter language for the cpp grammar (LANGUAGE in the Rust binding), generated from src/grammar.json. Its external scanner is @scanners.scanner_for("cpp"); without one (a scanner not ported yet) the language is not parseable (@treesitter.Language::is_parseable).

    node_types

    let node_types : String

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

    tags_query

    let tags_query : String

    The content of queries/tags.scm (TAGS_QUERY in the Rust binding).