-
Notifications
You must be signed in to change notification settings - Fork 95
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
C Syntax Tree needs to be Updated #129
Comments
I think we met this situation too, while debugging these two issues: |
I just had a look at the grammar, intending to fix this issue (and issue #126 which I think is related). After exploring a bit the grammar and the C syntax, I believe the behavior of tree-sitter is actually correct in the sense that it produces a concrete syntax tree that is closer to what the syntax expressed. I think it is useful to consider the following example: int* x, y; In C, this declares a pointer (x) to an int, and an int (y), i.e. the "star" only apply to x. Although this is very uncommon, it is possible to use a similar syntax to declare functions: int* f(), g();
// Equivalent to
int* f();
int g(); // <- Note the return type I thus believe grouping the "star" with the type specifier is incorrect because the type specifier might be common to several declarators. Having one type specifier per declarator might be useful and more intuitive, but the result would be closer to an AST than a CST. |
In fact I realised what @touzeauv is correct, since tree-sitter is intended to use it as syntax highlighter. But I am using tree-sitter for the code analysis because it has flexible license and easy to expand for the other languages. Since my requirements are a little different than the actual tree-sitter purpose. Anyway there is no other library like tree-sitter, If it can serve the complete computer languages requirements it would be great. |
C Language syntax tree hierarchy should be modified for the functions which returns pointer.
C function definition with pointer type nodes are expected to be part of the "type: primitive_type". But in current implementation pointer declarator out of the primitive type node as shown in the example below.
Because of this node entry which is out of the primitive type common query to list all the function definitions is not able to identify it as a function definition.
example function definition:
const char ** fn_returns_pointer() { }
parsed AST:
The text was updated successfully, but these errors were encountered: