htsparse

Nim wrappers for tree-sitter parser grammars


Keywords
library, wrapper, parser
License
Apache-2.0
Install
nimble install htsparse@#0.1.2

Documentation

readme

Installation and setup

nimble install htsparse

Links

Usage

import htsparse/cpp/cpp

let str = """
int main () {
  std::cout << "Hello world";
}
"""

let node = parseCppString(str)

echo node[0].kind

echo node.treeRepr(str)
cppFunctionDefinition
TranslationUnit
  FunctionDefinition
    PrimitiveType int
    FunctionDeclarator
      Identifier main
      ParameterList ()
    CompoundStatement
      ExpressionStatement
        BinaryExpression
          ScopedIdentifier
            NamespaceIdentifier std
            Identifier cout
          StringLiteral "Hello world"

Tree-sitter library

You need to have tree-sitter runtime library installed. For arch linux it can be done by installing tree-sitter, otherwise you can install it manually:

wget https://github.com/tree-sitter/tree-sitter/archive/0.17.3.tar.gz
tar -xvf 0.17.3.tar.gz && cd tree-sitter-0.17.3
sudo make install PREFIX=/usr