Skip to content
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

Query for function definitions #103

Open
dan1338 opened this issue May 18, 2022 · 1 comment
Open

Query for function definitions #103

dan1338 opened this issue May 18, 2022 · 1 comment

Comments

@dan1338
Copy link

dan1338 commented May 18, 2022

I tried to construct a query that would match a function_definition with a capture for the identifier,
but I wasn't able to make a one that would reliably match the name of a defined function regardless of it's return type (mostly to do with the way pointers are handled, #14)

The code to query

void func1(void)
{
}

void* func2(void)
{
}

void** func3(void)
{
}

The query

(function_definition (_ (identifier) @name)) @func

The resulting tree structure is something like

function_definition
    declarator: pointer_declarator
        declarator: function_declarator
            declarator: identifier

Without the ability to recursively match an arbitrary number of pointer_declarators I don't see how one could use the query language for any useful purpose with this grammar.

@innerout
Copy link

innerout commented Jun 25, 2022

I have started playing with tree-sitter for a short time and am trying to parse function declarations; however, I have not found a way to parse the function's return type. Therefore, the query I have constructed at the moment is:

(function_declarator) @func

But it lacks the part of the return type, which I don't know how to fix yet. I don't think there should be a special case if the return type is a pointer or any other type. I guess the type_identifier rule would be the one that will help us. Still, I may be wrong since I am entirely new to tree-sitter queries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants