tree-sitter-cpp

repository·master·Indexed 19 days ago

https://github.com/tree-sitter/tree-sitter-cpp

A concrete syntax tree grammar for the C++ programming language designed for the tree-sitter incremental parsing engine. It enables syntax highlighting, code navigation, and structural analysis, and provides Node.js bindings including nodeTypeInfo for accessing grammar metadata.

Tokens
337
Snippets
1
Records
3
Agent score
16%

What's inside tree-sitter-cpp

  1. Import the tree-sitter-cpp Node.js bindings

    master

    To use the C++ grammar in a Node.js or Bun environment, require the tree-sitter-cpp package. The module automatically selects the correct prebuilt binary based on your platform and architecture. If you are using Bun with bun build --compile, the module is designed to be statically analyzable to locate the required .node file.

    Note that the module also exports nodeTypeInfo, which provides metadata about the C++ node types defined in the grammar.

    const parser = require('tree-sitter-cpp');
    
    // Access node type metadata if needed
    const nodeTypes = parser.nodeTypeInfo;
  2. Access C++ node type metadata via nodeTypeInfo

    master
    The tree-sitter-cpp module exports an optional property nodeTypeInfo. This property contains a JSON object mapping node types to their specific information, sourced from the grammar's src/node-types.json. This is useful for inspecting the structure of the C++ grammar programmatically.