-
-
Notifications
You must be signed in to change notification settings - Fork 142
Open
Labels
Description
Did you check existing issues?
- I have read all the tree-sitter docs if it relates to using the parser
- I have searched the existing issues of tree-sitter-cpp
Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)
No response
Describe the bug
Consider the following example:
export module cpp_module;
namespace X {
export int var_decl = 42;
export class ClassDecl {};
export void function_decl() {}
} // namespace XAccording to the C++ standard, the export keyword can be used to export any declaration. Also, the code above can be successfully compiled using Clang 20.
However, tree-sitter-cpp does not parse these exported declarations correctly when they appear inside a namespace.
Steps To Reproduce/Bad Parse Tree
(translation_unit
(module_declaration export module
name: (module_name (identifier))
;)
(namespace_definition namespace name: (namespace_identifier)
body:
(declaration_list {
(declaration type: (type_identifier)
(ERROR (identifier))
declarator: (init_declarator declarator: (identifier) = value: (number_literal))
;)
(declaration type: (type_identifier)
(ERROR (identifier))
declarator:
(init_declarator declarator: (identifier)
value: (initializer_list { }))
;)
(function_definition type: (type_identifier)
(ERROR (identifier))
declarator:
(function_declarator declarator: (identifier)
parameters: (parameter_list ( )))
body: (compound_statement { }))
}))
(comment))
Expected Behavior/Parse Tree
(translation_unit
(module_declaration export module
name: (module_name (identifier))
;)
(namespace_definition namespace name: (namespace_identifier)
body:
(declaration_list {
(export_declaration export
(declaration type: (primitive_type)
declarator: (init_declarator declarator: (identifier) = value: (number_literal))
;))
(export_declaration export
(class_specifier class name: (type_identifier)
body: (field_declaration_list { }))
;)
(export_declaration export
(function_definition type: (primitive_type)
declarator:
(function_declarator declarator: (identifier)
parameters: (parameter_list ( )))
body: (compound_statement { })))
}))
(comment))
Repro
export module cpp_module;
namespace X {
export int var_decl = 42;
export class ClassDecl {};
export void function_decl() {}
} // namespace X