bug: `[[depracated]]` with reason-string on namespace declaration not supported
Did you check existing issues?
- [X] I have read all the tree-sitter docs if it relates to using the parser
- [X] 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
It's not clear to me if there are two different bugs here or just a single bug with the same underlying cause. When parsing the [[deprecated]] reason string literal, it looks like the parser will create two different parse trees based on the length of the string. In the sample below, if you change the number of 'x's in the string literals to 1 it will be parsed as an attribute_declaration (expected) but if you leave the number of 'x's as-is it will be parsed as an attributed_statement??
This is why I am not sure if this is two different bugs or just one. So the first issue would be that [[deprecated]] is not supported on namespace declarations and the second is the odd parsing behavior in the attribute reason string literal.
Steps To Reproduce/Bad Parse Tree
- Tree sitter playground output:
translation_unit [0, 0] - [13, 0]
ERROR [0, 0] - [0, 9]
attributed_statement [0, 10] - [2, 66]
attribute_declaration [0, 10] - [0, 169]
attribute [0, 12] - [0, 167]
name: identifier [0, 12] - [0, 22]
argument_list [0, 22] - [0, 167]
string_literal [0, 23] - [0, 166]
string_content [0, 24] - [0, 165]
ERROR [0, 170] - [1, 25]
type_identifier [0, 170] - [0, 171]
ERROR [1, 13] - [1, 22]
identifier [1, 23] - [1, 24]
attribute_declaration [2, 4] - [2, 26]
attribute [2, 6] - [2, 24]
name: identifier [2, 6] - [2, 16]
argument_list [2, 16] - [2, 24]
concatenated_string [2, 17] - [2, 23]
string_literal [2, 17] - [2, 20]
string_content [2, 18] - [2, 19]
string_literal [2, 21] - [2, 23]
attribute_declaration [2, 27] - [2, 40]
attribute [2, 29] - [2, 38]
name: identifier [2, 29] - [2, 38]
ERROR [2, 41] - [2, 62]
primitive_type [2, 41] - [2, 45]
binary_expression [2, 46] - [2, 62]
left: identifier [2, 46] - [2, 54]
right: parenthesized_expression [2, 56] - [2, 62]
comma_expression [2, 57] - [2, 61]
left: identifier [2, 57] - [2, 58]
right: identifier [2, 60] - [2, 61]
compound_statement [2, 63] - [2, 66]
template_declaration [4, 4] - [5, 65]
parameters: template_parameter_list [4, 13] - [4, 25]
type_parameter_declaration [4, 14] - [4, 24]
type_identifier [4, 23] - [4, 24]
function_definition [5, 4] - [5, 65]
attribute_declaration [5, 4] - [5, 26]
attribute [5, 6] - [5, 24]
name: identifier [5, 6] - [5, 16]
argument_list [5, 16] - [5, 24]
concatenated_string [5, 17] - [5, 23]
string_literal [5, 17] - [5, 20]
string_content [5, 18] - [5, 19]
string_literal [5, 21] - [5, 23]
attribute_declaration [5, 27] - [5, 40]
attribute [5, 29] - [5, 38]
name: identifier [5, 29] - [5, 38]
type: primitive_type [5, 41] - [5, 45]
declarator: function_declarator [5, 46] - [5, 61]
declarator: operator_name [5, 46] - [5, 55]
parameters: parameter_list [5, 55] - [5, 61]
parameter_declaration [5, 56] - [5, 57]
type: type_identifier [5, 56] - [5, 57]
parameter_declaration [5, 59] - [5, 60]
type: type_identifier [5, 59] - [5, 60]
body: compound_statement [5, 62] - [5, 65]
template_declaration [7, 4] - [8, 83]
parameters: template_parameter_list [7, 13] - [7, 25]
type_parameter_declaration [7, 14] - [7, 24]
type_identifier [7, 23] - [7, 24]
function_definition [8, 4] - [8, 83]
attribute_declaration [8, 4] - [8, 26]
attribute [8, 6] - [8, 24]
name: identifier [8, 6] - [8, 16]
argument_list [8, 16] - [8, 24]
concatenated_string [8, 17] - [8, 23]
string_literal [8, 17] - [8, 20]
string_content [8, 18] - [8, 19]
string_literal [8, 21] - [8, 23]
attribute_declaration [8, 27] - [8, 40]
attribute [8, 29] - [8, 38]
name: identifier [8, 29] - [8, 38]
type: primitive_type [8, 41] - [8, 45]
declarator: function_declarator [8, 46] - [8, 65]
declarator: operator_name [8, 46] - [8, 55]
parameters: parameter_list [8, 55] - [8, 65]
parameter_declaration [8, 56] - [8, 59]
type: type_identifier [8, 56] - [8, 57]
declarator: identifier [8, 58] - [8, 59]
parameter_declaration [8, 61] - [8, 64]
type: type_identifier [8, 61] - [8, 62]
declarator: identifier [8, 63] - [8, 64]
body: compound_statement [8, 66] - [8, 83]
return_statement [8, 68] - [8, 81]
binary_expression [8, 75] - [8, 80]
left: identifier [8, 75] - [8, 76]
right: identifier [8, 79] - [8, 80]
ERROR [9, 0] - [9, 1]
template_declaration [11, 0] - [12, 13]
parameters: template_parameter_list [11, 9] - [11, 28]
optional_type_parameter_declaration [11, 10] - [11, 27]
name: type_identifier [11, 19] - [11, 20]
default_type: primitive_type [11, 23] - [11, 27]
struct_specifier [12, 0] - [12, 12]
name: type_identifier [12, 7] - [12, 8]
body: field_declaration_list [12, 9] - [12, 12]
Expected Behavior/Parse Tree
No error trees.
Repro
namespace [[deprecated("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")]] N {
template <typename T>
[[deprecated("x" "")]] [[nodiscard]] bool operator==(X, Y) { }
template <typename T>
[[deprecated("x" "")]] [[nodiscard]] bool operator<(X x, Y y) { return x < y; }
}
template <typename T = void>
struct S { };