New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TODO] [WIP] allow customizing AST: using clang's AST instead of treesitter's AST #28
Comments
While it is certainly possible, I'm not sure the current implementation will immediately translate since the two ASTs might be different. The engine can be leveraged but the AST grammar and node data structure will need to be handled separately. I'm also not sure this is really warranted, especially since we are only focusing on wrapping and not full-fledged translation. That being said, I'm not a C++ expert so if you could give me specific examples of where the tree-sitter AST is not good enough, it will be helpful. Take this simple subset of code I got from here: template<class T>
class Item
{
T Data;
public:
Item() : Data( T() )
{}
void SetData(T nValue)
{
Data = nValue;
}
T GetData() const
{
return Data;
}
void PrintData()
{
cout << Data;
}
};
template<class T>
void PrintNumbers(T array[], int array_size, T filter = T()); The tree-sitter AST output is as follows:
As you can see, there's enough information to figure out what's going on and while it is far from trivial, we can certainly generate a Nim wrapper once the equivalent Nimisms are understood. Let me know what you think. |
I'm closing this for now. The engine can definitely be leveraged for a different AST structure so it isn't unimaginable. |
@genotrance see also There could be something worth investigating there. |
Wondering how much work it'd be to abstract away the source AST to allow using clang's AST instead of treesitter's AST
clang -Xclang -ast-dump -fno-color-diagnostics -fsyntax-only tests/include/test.h
motivation
dealing with treesitter's shortcomings, especially wrt lack of semantic analysis making it hard to deal with C++ templates etc
note
it may be even easier to write a binary using libclang that outputs the AST in json directly instead of having to custom parse it in nimterop
The text was updated successfully, but these errors were encountered: