-
Notifications
You must be signed in to change notification settings - Fork 158
Description
Problem Description
After running the print_all_node_types function, the named_types list contains duplicate node types. Based on the provided output, the following types are duplicated:
block: Appears 2 times
tuple_pattern: Appears 2 times
list_pattern: Appears 2 times
as_pattern: Appears 2 times
lambda: Appears 2 times
These duplicate definitions may cause anomalies in logic that relies on the uniqueness of node types (e.g., type checking, index mapping), affecting the correctness and consistency of the library.
import tree_sitter_python as tspython
import tree_sitter_java as tsjava
PY_LANGUAGE = Language(tspython.language(), "python")
JAVA_LANGUAGE = Language(tsjava.language(), "java")
def print_all_node_types(lang='python'):
if lang == 'python':
language = PY_LANGUAGE
elif lang == 'java':
language = JAVA_LANGUAGE
else:
assert False, "Language not supported"
all_types = []
named_types = []
kind_count = language.node_kind_count
for kind_id in range(kind_count):
type_name = language.node_kind_for_id(kind_id)
all_types.append(type_name)
if language.node_kind_is_named(kind_id):
named_types.append(type_name)
print(f"All node types ({kind_count}) in {lang}:")
print(all_types)
print(f"{len(named_types)} named types:")
print(named_types)
And the output of named_types:
['identifier', 'ellipsis', 'escape_sequence', 'type_conversion', 'integer', 'float', 'true', 'false', 'none', 'comment', 'line_continuation', 'string_start', 'escape_interpolation', 'string_end', 'module', 'import_statement', 'import_prefix', 'relative_import', 'future_import_statement', 'import_from_statement', 'aliased_import', 'wildcard_import', 'print_statement', 'chevron', 'assert_statement', 'expression_statement', 'named_expression', 'return_statement', 'delete_statement', 'raise_statement', 'pass_statement', 'break_statement', 'continue_statement', 'if_statement', 'elif_clause', 'else_clause', 'match_statement', 'block', 'case_clause', 'for_statement', 'while_statement', 'try_statement', 'except_clause', 'except_group_clause', 'finally_clause', 'with_statement', 'with_clause', 'with_item', 'function_definition', 'parameters', 'lambda_parameters', 'list_splat', 'dictionary_splat', 'global_statement', 'nonlocal_statement', 'exec_statement', 'type_alias_statement', 'class_definition', 'type_parameter', 'parenthesized_list_splat', 'argument_list', 'decorated_definition', 'decorator', 'block', 'expression_list', 'dotted_name', 'case_pattern', 'as_pattern', 'union_pattern', 'list_pattern', 'tuple_pattern', 'dict_pattern', 'keyword_pattern', 'splat_pattern', 'class_pattern', 'complex_pattern', 'tuple_pattern', 'list_pattern', 'default_parameter', 'typed_default_parameter', 'list_splat_pattern', 'dictionary_splat_pattern', 'as_pattern', 'not_operator', 'boolean_operator', 'binary_operator', 'unary_operator', 'comparison_operator', 'lambda', 'lambda', 'assignment', 'augmented_assignment', 'pattern_list', 'yield', 'attribute', 'subscript', 'slice', 'call', 'typed_parameter', 'type', 'splat_type', 'generic_type', 'union_type', 'constrained_type', 'member_type', 'keyword_argument', 'list', 'set', 'tuple', 'dictionary', 'pair', 'list_comprehension', 'dictionary_comprehension', 'set_comprehension', 'generator_expression', 'parenthesized_expression', 'for_in_clause', 'if_clause', 'conditional_expression', 'concatenated_string', 'string', 'string_content', 'interpolation', 'format_specifier', 'await', 'positional_separator', 'keyword_separator', 'as_pattern_target', 'format_expression']
Version
tree-sitter-cpp==0.21.0
tree_sitter_java==0.21.0
Could you clear up my confusion for me?Thanks!