tree-sitter / tree-sitter-c

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

bug: Errors seem to occur when #ifdef, #endif, struct, static int __init, static int __exit, and void exist in the code. #213

Closed wjlcc closed 3 weeks ago

wjlcc commented 1 month ago

Describe the bug

In the following code, void is parsed as Node type=ERROR. Is it because some syntax is not supported?

Steps To Reproduce/Bad Parse Tree

from tree_sitter import Language, Parser
language = Language('xxx.so', 'c')
parser = Parser()
parser.set_language(language)
tree = parser.parse(content.encode("utf8"))
root_node: Node = tree.root_node
recur_print(root_node)

content = """#include "sigma_io_defs.h"

define RTC_HZ_BASE 500

define RTC_TICKS_DFLT 500

t_stat rtc_show_events (FILE of, UNIT uptr, int32 val, CONST void *desc); """

Expected Behavior/Parse Tree

<Node type=translation_unit, start_point=(1, 0), end_point=(7, 0)> <Node type=preproc_include, start_point=(1, 0), end_point=(2, 0)> <Node type="#include", start_point=(1, 0), end_point=(1, 8)> <Node type=string_literal, start_point=(1, 9), end_point=(1, 26)> <Node type=""", start_point=(1, 9), end_point=(1, 10)> <Node type=string_content, start_point=(1, 10), end_point=(1, 25)> <Node type=""", start_point=(1, 25), end_point=(1, 26)> <Node type=preproc_def, start_point=(3, 0), end_point=(4, 0)> <Node type="#define", start_point=(3, 0), end_point=(3, 7)> <Node type=identifier, start_point=(3, 8), end_point=(3, 19)> <Node type=preproc_arg, start_point=(3, 24), end_point=(3, 27)> <Node type=preproc_def, start_point=(4, 0), end_point=(5, 0)> <Node type="#define", start_point=(4, 0), end_point=(4, 7)> <Node type=identifier, start_point=(4, 8), end_point=(4, 22)> <Node type=preproc_arg, start_point=(4, 24), end_point=(4, 27)> <Node type=declaration, start_point=(6, 0), end_point=(6, 75)> <Node type=type_identifier, start_point=(6, 0), end_point=(6, 6)> <Node type=function_declarator, start_point=(6, 7), end_point=(6, 74)> <Node type=identifier, start_point=(6, 7), end_point=(6, 22)> <Node type=parameter_list, start_point=(6, 23), end_point=(6, 74)> <Node type="(", start_point=(6, 23), end_point=(6, 24)> <Node type=parameter_declaration, start_point=(6, 24), end_point=(6, 32)> <Node type=type_identifier, start_point=(6, 24), end_point=(6, 28)> <Node type=pointer_declarator, start_point=(6, 29), end_point=(6, 32)> <Node type="", start_point=(6, 29), end_point=(6, 30)> <Node type=identifier, start_point=(6, 30), end_point=(6, 32)> <Node type=",", start_point=(6, 32), end_point=(6, 33)> <Node type=parameter_declaration, start_point=(6, 34), end_point=(6, 44)> <Node type=type_identifier, start_point=(6, 34), end_point=(6, 38)> <Node type=pointer_declarator, start_point=(6, 39), end_point=(6, 44)> <Node type="", start_point=(6, 39), end_point=(6, 40)> <Node type=identifier, start_point=(6, 40), end_point=(6, 44)> <Node type=",", start_point=(6, 44), end_point=(6, 45)> <Node type=parameter_declaration, start_point=(6, 46), end_point=(6, 55)> <Node type=type_identifier, start_point=(6, 46), end_point=(6, 51)> <Node type=identifier, start_point=(6, 52), end_point=(6, 55)> <Node type=",", start_point=(6, 55), end_point=(6, 56)> <Node type=parameter_declaration, start_point=(6, 57), end_point=(6, 73)> <Node type=type_identifier, start_point=(6, 57), end_point=(6, 62)> <Node type=ERROR, start_point=(6, 63), end_point=(6, 67)> <Node type=identifier, start_point=(6, 63), end_point=(6, 67)> <Node type=pointer_declarator, start_point=(6, 68), end_point=(6, 73)> <Node type="*", start_point=(6, 68), end_point=(6, 69)> <Node type=identifier, start_point=(6, 69), end_point=(6, 73)> <Node type=")", start_point=(6, 73), end_point=(6, 74)> <Node type=";", start_point=(6, 74), end_point=(6, 75)>

amaanq commented 3 weeks ago

Your issue is really hard to read through due to the improper usage of code blocks and the parsing output not looking like the typical parse tree...it also looks like it's not typical C (all caps const?) so i'm going to close this as not planned unless the issue is a little more clear and is an actual issue