Live data from Hacker News

Tbsp – treesitter-based source processing language

git.peppe.rs

1–10 of 47 posts

Re: Tbsp – treesitter-based source processing language

#4
post #2

So an awk but that knows how to walk structures instead of just lines. Excellent! I'm a big fan of semgrep letting me query ASTs, this feels like something in a similar space. Down with lines, up with everything being trees!

Have you checked ast-grep and gritql?

Re: Tbsp – treesitter-based source processing language

#6
post #4
post #2

So an awk but that knows how to walk structures instead of just lines. Excellent! I'm a big fan of semgrep letting me query ASTs, this feels like something in a similar space. Down with lines, up with everything being trees!

Have you checked ast-grep and gritql?

Are these alternatives to semgrep?

Re: Tbsp – treesitter-based source processing language

#8
This is so cool.

Question (caveat: first export to treesitter and tools like this): Is there a reason the example demonstrates the use of depth as a variable instead of it being built in?

Nesting level of a particular "type" is general enough that it might be included OOTB. What you want to do with this might be generalizable - for example instead of

```

    enter section {
        depth += 1;
    }
    leave section {
        depth -= 1;
    }

    enter atx_heading {
        print("");
    }
    leave atx_heading {
        print("\n");
    }
```

It could simply be:

```

    enter atx_heading {
        print("");
    }
    leave atx_heading {
        print("\n");
    }
```

So depth is always of the nested levels of the same node type, but available out of the box. For markdown, it's headings, sections and lists come to mind - but I might be wrong.

In any event, this looks really well thought-out and now to checkout the other tools mentioned in the comments.....

Re: Tbsp – treesitter-based source processing language

#9
post #4

Earlier quoted context omitted.

Have you checked ast-grep and gritql?

Are these alternatives to semgrep?

More or less, yes. CLI, offline, no need for a cloud account. Used ast-grep successfully to locate bad code blocks (dynamic typing, don't even get me started) and also to replace them with others. Highly recommended.

Re: Tbsp – treesitter-based source processing language

#10
post #9

Earlier quoted context omitted.

Are these alternatives to semgrep?

More or less, yes. CLI, offline, no need for a cloud account. Used ast-grep successfully to locate bad code blocks (dynamic typing, don't even get me started) and also to replace them with others. Highly recommended.

Semgrep also a CLI, that can run offline and without a cloud account.

At work, we use it for enforcing a bunch of custom lint rules configured as a yaml file committed directly to our repo, entirely cloud-free.

(I may be overreading your comment as suggesting that these were reasons to use ast-grep over semgrep.)

Post reply on HN