C++ grammar for tree-sitter (tree-sitter/tree-sitter-cpp v0.23.4), for the MoonBit port of Tree-sitter (moonbit-community/treesitter).
| MoonBit | Rust |
|---|---|
| language() -> @treesitter.Language | LANGUAGE |
| node_types : String | NODE_TYPES (src/node-types.json) |
| highlight_query : String | HIGHLIGHT_QUERY (queries/highlights.scm) |
| tags_query : String | TAGS_QUERY (queries/tags.scm) |
moon add moonbit-community/tree-sitter-cppimport {
"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"))
}let highlight_query : Stringlet node_types : Stringlet tags_query : StringInstall
Download zipC++ grammar for tree-sitter (tree-sitter/tree-sitter-cpp v0.23.4), for the MoonBit port of Tree-sitter (moonbit-community/treesitter).