Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/arthurweinmann/treesitter-simple-cli

Just a very simple way of parsing and printing the code CST with tree-sitter.
https://github.com/arthurweinmann/treesitter-simple-cli

json normal tree-sitter xml

Last synced: 5 days ago
JSON representation

Just a very simple way of parsing and printing the code CST with tree-sitter.

Awesome Lists containing this project

README

        

# Simpler Tree-Sitter CLI to just print the CST

Just a very simple way of parsing and printing the code CST with tree-sitter.

You may use the compiled binary from the releases section of this repository or compile it yourself.

# Build from source

Clone this repository and run `make`. The cli binary is then located in the generated `build` repository.

# Example

For example, in this repository after running `make`:

For help, run:

```bash
arthur@pop-os:$ ./build/treesittercli help

Usage:
```

For a full example of a normal output, see [./example_output/example.txt](./example_output/example.txt)
```bash
arthur@pop-os:$ ./build/treesittercli rust ./src/main.rs

(source_file [0, 0] - [209, 0]
(inner_attribute_item [0, 0] - [0, 64]
(attribute [0, 3] - [0, 63]
(identifier [0, 3] - [0, 11])
arguments: (token_tree [0, 11] - [0, 63]
(identifier [0, 12] - [0, 28])
(identifier [0, 30] - [0, 35])
(token_tree [0, 35] - [0, 62]
(identifier [0, 36] - [0, 45])
(identifier [0, 47] - [0, 61])))))

[...]
```

For a full example of an xml output, see [./example_output/example.xml](./example_output/example.xml)
```bash
arthur@pop-os:$ ./build/treesittercli rust ./src/main.rs xml

#![

cfg_attr

(
debug_assertions

allow

(
dead_code

[...]
```

For a full example of an xml output, see [./example_output/example.json](./example_output/example.json)
```bash
arthur@pop-os:$ ./build/treesittercli rust ./src/main.rs json

{
"children": [
{
"children": [
{
"children": [],
"end": {
"column": 1,
"row": 0
},
"kind": "#",
"start": {
"column": 0,
"row": 0
},
"value": "#"
},
{
"children": [],
"end": {
"column": 2,
"row": 0
},
"kind": "!",
"start": {
"column": 1,
"row": 0
},
"value": "!"

[...]
```