You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dev quality of life C++ bindings out of a custom grammar for walking/traversing nodes
Don't think this really belongs in tree-sitter main but sharing for fun/maybe others have similar uses
I love the bare C, dependency free nature of tree-sitter. But overtime, found traversing the parse tree being a chore especially since tree-sitter is used as the primary layer for parsing/AST manipulation in a custom compiler (i.e. not just syntax highlighting)
Needs
traversing the AST for semantic analysis
lowering to mlir/llvm
generating AST transformers, UI debug, etc
Result
So hacked together a little proof of concept generator from the node-types.js + made some C++ adapters caveat: it's hackishly ghetto so ignore the mess of code, especially the js. not a js dev
From a day of use, it's been a net positive
I liked the mlir architecture so applied the same model (ie the strong typed Tree-Sitter nodes are just adapters of the core TSNode so they can just be typecast back & forth, modulo special compiler settings of struct layout/packing)
This discussion was converted from issue #808 on February 09, 2024 12:57.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
TLDR
I love the bare C, dependency free nature of tree-sitter. But overtime, found traversing the parse tree being a chore especially since tree-sitter is used as the primary layer for parsing/AST manipulation in a custom compiler (i.e. not just syntax highlighting)
Needs
Result
So hacked together a little proof of concept generator from the node-types.js + made some C++ adapters
caveat: it's hackishly ghetto so ignore the mess of code, especially the js. not a js dev
From a day of use, it's been a net positive
I liked the mlir architecture so applied the same model (ie the strong typed Tree-Sitter nodes are just adapters of the core TSNode so they can just be typecast back & forth, modulo special compiler settings of struct layout/packing)
Sample Use
Code
hacked generator + generated code for a custom c like grammar
https://gist.github.com/ikrima/3345769249993cafd7851390966089cb
Beta Was this translation helpful? Give feedback.
All reactions