node-tree-sitter icon indicating copy to clipboard operation
node-tree-sitter copied to clipboard

Docs for how to transpile one language to another using tree-sitter?

Open lancejpollard opened this issue 2 years ago • 1 comments

I can't seem to find any docs about what I can access through the Node.js API. I would like to convert C++ to TypeScript, as an experiment, and thought I could use the AST produced from tree-sitter for C++, but all it gives me are nodes with a type property, but no function names, variable names, etc..

How can I get access to all that information and traverse the tree? I don't see any examples for this. Thank you!

lancejpollard avatar Jan 21 '23 07:01 lancejpollard

You need to implement this yourself. You can extract the concrete syntax tree of a C++ code file and generate TypeScript code based on it. there are differences between the two languages, and you'll need to define your own conversion rules.

liaodalin19903 avatar Aug 17 '24 06:08 liaodalin19903

The upstream docs (https://tree-sitter.github.io/tree-sitter) give the higher-level overview for querying and walking the syntax trees, and the readme + API docs for the node bindings (https://tree-sitter.github.io/node-tree-sitter) should be enough info on what methods are available to you. The rest is on you to implement

amaanq avatar Dec 20 '24 20:12 amaanq