tree-sitter / tree-sitter-c

C grammar for tree-sitter
MIT License
225 stars 100 forks source link

[bug] Failed to recognize ancient c function declaration style #177

Closed riusksk closed 9 months ago

riusksk commented 9 months ago

for example:

1308 static void
1309 eap_request(esp, inp, id, len)
1310 eap_state *esp;
1311 u_char *inp;
1312 int id;
1313 int len;
1314 {
...
1377 }

The node types identified by tree-sitter are as follows:

2023-11-17 09:08:52 [INFO] declaration: 1308 - 1309
2023-11-17 09:08:52 [INFO] storage_class_specifier: 1308 - 1308
2023-11-17 09:08:52 [INFO] static: 1308 - 1308
2023-11-17 09:08:52 [INFO] primitive_type: 1308 - 1308
2023-11-17 09:08:52 [INFO] function_declarator: 1309 - 1309
2023-11-17 09:08:52 [INFO] identifier: 1309 - 1309
2023-11-17 09:08:52 [INFO] parameter_list: 1309 - 1309
2023-11-17 09:08:52 [INFO] (: 1309 - 1309
2023-11-17 09:08:52 [INFO] parameter_declaration: 1309 - 1309
2023-11-17 09:08:52 [INFO] type_identifier: 1309 - 1309
2023-11-17 09:08:52 [INFO] ,: 1309 - 1309
2023-11-17 09:08:52 [INFO] parameter_declaration: 1309 - 1309
2023-11-17 09:08:52 [INFO] type_identifier: 1309 - 1309
2023-11-17 09:08:52 [INFO] ,: 1309 - 1309
2023-11-17 09:08:52 [INFO] parameter_declaration: 1309 - 1309
2023-11-17 09:08:52 [INFO] type_identifier: 1309 - 1309
2023-11-17 09:08:52 [INFO] ,: 1309 - 1309
2023-11-17 09:08:52 [INFO] parameter_declaration: 1309 - 1309
2023-11-17 09:08:52 [INFO] type_identifier: 1309 - 1309
2023-11-17 09:08:52 [INFO] ): 1309 - 1309
2023-11-17 09:08:52 [INFO] ;: 1309 - 1309
....

Failed to recognize function_definition eap_request

amaanq commented 9 months ago

It does parse correctly, if you're including those line numbers when parsing then that's your issue

riusksk commented 9 months ago

It does parse correctly, if you're including those line numbers when parsing then that's your issue

The code does not include line numbers; I'm just providing an example with corresponding line numbers. You can try parsing the file: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/io_uring/filetable.c?id=9d94c04c0db024922e886c9fd429659f22f48ea4 to see if tree_sitter_c can recognize the io_install_fixed_file function.

static int io_install_fixed_file(struct io_ring_ctx *ctx, struct file *file,
                 u32 slot_index)
    __must_hold(&req->ctx->uring_lock)
{
...
}

and this eap_request function

static void
eap_request(esp, inp, id, len)
eap_state *esp;
u_char *inp;
int id;
int len;
{
...
}

They can't recognize the starting and ending ranges of functions properly.

Expected behavior

The above two functions are identified as function_definition, and the corresponding function definitions have line number ranges of 1718 ~ 2008 and 60 ~ 107, respectively.