-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix parsing of calls of overloaded operators #253
Open
j0le
wants to merge
1
commit into
tree-sitter:master
Choose a base branch
from
j0le:fix-operator-calls
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```c++ struct base{ }; struct other{ int i{}; int square(){return i*i;} }; struct derived : public base { derived & operator=(const base& b){ this-> base::operator= // HERE: qualified_field_identifier (b); return *this; } operator other(){ return other{4}; } int square(){ return this-> operator other // HERE: operator_cast ().square(); } }; ``` tree with errors: ``` (struct_specifier) ; [2:1 - 4:1] name: (type_identifier) ; [2:8 - 11] body: (field_declaration_list) ; [2:12 - 4:1] (struct_specifier) ; [6:1 - 9:1] name: (type_identifier) ; [6:8 - 12] body: (field_declaration_list) ; [6:13 - 9:1] (field_declaration) ; [7:5 - 12] type: (primitive_type) ; [7:5 - 7] declarator: (field_identifier) ; [7:9 - 9] default_value: (initializer_list) ; [7:10 - 11] (function_definition) ; [8:5 - 29] type: (primitive_type) ; [8:5 - 7] declarator: (function_declarator) ; [8:9 - 16] declarator: (field_identifier) ; [8:9 - 14] parameters: (parameter_list) ; [8:15 - 16] body: (compound_statement) ; [8:17 - 29] (return_statement) ; [8:18 - 28] (binary_expression) ; [8:25 - 27] left: (identifier) ; [8:25 - 25] right: (identifier) ; [8:27 - 27] (struct_specifier) ; [11:1 - 29:1] name: (type_identifier) ; [11:8 - 14] (base_class_clause) ; [11:16 - 28] (access_specifier) ; [11:18 - 23] (type_identifier) ; [11:25 - 28] body: (field_declaration_list) ; [11:30 - 29:1] (function_definition) ; [12:5 - 17:5] type: (type_identifier) ; [12:5 - 11] declarator: (reference_declarator) ; [12:13 - 38] (function_declarator) ; [12:15 - 38] declarator: (operator_name) ; [12:15 - 23] parameters: (parameter_list) ; [12:24 - 38] (parameter_declaration) ; [12:25 - 37] (type_qualifier) ; [12:25 - 29] type: (type_identifier) ; [12:31 - 34] declarator: (reference_declarator) ; [12:35 - 37] (identifier) ; [12:37 - 37] body: (compound_statement) ; [12:39 - 17:5] (expression_statement) ; [13:9 - 15:16] (call_expression) ; [13:9 - 15:15] function: (this) ; [13:9 - 12] (ERROR) ; [13:13 - 14:27] scope: (namespace_identifier) ; [14:13 - 16] (operator_name) ; [14:19 - 27] (comment) ; [14:29 - 63] arguments: (argument_list) ; [15:13 - 15] (identifier) ; [15:14 - 14] (return_statement) ; [16:9 - 21] (pointer_expression) ; [16:16 - 20] argument: (this) ; [16:17 - 20] (function_definition) ; [19:5 - 21:5] declarator: (operator_cast) ; [19:5 - 20] type: (type_identifier) ; [19:14 - 18] declarator: (abstract_function_declarator) ; [19:19 - 20] parameters: (parameter_list) ; [19:19 - 20] body: (compound_statement) ; [19:21 - 21:5] (return_statement) ; [20:9 - 24] (compound_literal_expression) ; [20:16 - 23] type: (type_identifier) ; [20:16 - 20] value: (initializer_list) ; [20:21 - 23] (number_literal) ; [20:22 - 22] (function_definition) ; [23:5 - 27:5] type: (primitive_type) ; [23:5 - 7] declarator: (function_declarator) ; [23:9 - 16] declarator: (field_identifier) ; [23:9 - 14] parameters: (parameter_list) ; [23:15 - 16] body: (compound_statement) ; [23:17 - 27:5] (return_statement) ; [24:9 - 26:24] (call_expression) ; [24:16 - 26:23] function: (field_expression) ; [24:16 - 26:21] argument: (call_expression) ; [24:16 - 26:14] function: (field_expression) ; [24:16 - 25:26] argument: (this) ; [24:16 - 19] (ERROR) ; [25:13 - 20] field: (field_identifier) ; [25:22 - 26] (comment) ; [25:28 - 49] arguments: (argument_list) ; [26:13 - 14] field: (field_identifier) ; [26:16 - 21] arguments: (argument_list) ; [26:22 - 23] ``` fixed tree: ``` (struct_specifier) ; [2:1 - 4:1] name: (type_identifier) ; [2:8 - 11] body: (field_declaration_list) ; [2:12 - 4:1] (struct_specifier) ; [6:1 - 9:1] name: (type_identifier) ; [6:8 - 12] body: (field_declaration_list) ; [6:13 - 9:1] (field_declaration) ; [7:5 - 12] type: (primitive_type) ; [7:5 - 7] declarator: (field_identifier) ; [7:9 - 9] default_value: (initializer_list) ; [7:10 - 11] (function_definition) ; [8:5 - 29] type: (primitive_type) ; [8:5 - 7] declarator: (function_declarator) ; [8:9 - 16] declarator: (field_identifier) ; [8:9 - 14] parameters: (parameter_list) ; [8:15 - 16] body: (compound_statement) ; [8:17 - 29] (return_statement) ; [8:18 - 28] (binary_expression) ; [8:25 - 27] left: (identifier) ; [8:25 - 25] right: (identifier) ; [8:27 - 27] (struct_specifier) ; [11:1 - 29:1] name: (type_identifier) ; [11:8 - 14] (base_class_clause) ; [11:16 - 28] (access_specifier) ; [11:18 - 23] (type_identifier) ; [11:25 - 28] body: (field_declaration_list) ; [11:30 - 29:1] (function_definition) ; [12:5 - 17:5] type: (type_identifier) ; [12:5 - 11] declarator: (reference_declarator) ; [12:13 - 38] (function_declarator) ; [12:15 - 38] declarator: (operator_name) ; [12:15 - 23] parameters: (parameter_list) ; [12:24 - 38] (parameter_declaration) ; [12:25 - 37] (type_qualifier) ; [12:25 - 29] type: (type_identifier) ; [12:31 - 34] declarator: (reference_declarator) ; [12:35 - 37] (identifier) ; [12:37 - 37] body: (compound_statement) ; [12:39 - 17:5] (expression_statement) ; [13:9 - 15:16] (call_expression) ; [13:9 - 15:15] function: (field_expression) ; [13:9 - 14:27] argument: (this) ; [13:9 - 12] field: (qualified_identifier) ; [14:13 - 27] scope: (namespace_identifier) ; [14:13 - 16] name: (operator_name) ; [14:19 - 27] (comment) ; [14:29 - 63] arguments: (argument_list) ; [15:13 - 15] (identifier) ; [15:14 - 14] (return_statement) ; [16:9 - 21] (pointer_expression) ; [16:16 - 20] argument: (this) ; [16:17 - 20] (function_definition) ; [19:5 - 21:5] declarator: (operator_cast) ; [19:5 - 20] type: (type_identifier) ; [19:14 - 18] declarator: (abstract_function_declarator) ; [19:19 - 20] parameters: (parameter_list) ; [19:19 - 20] body: (compound_statement) ; [19:21 - 21:5] (return_statement) ; [20:9 - 24] (compound_literal_expression) ; [20:16 - 23] type: (type_identifier) ; [20:16 - 20] value: (initializer_list) ; [20:21 - 23] (number_literal) ; [20:22 - 22] (function_definition) ; [23:5 - 27:5] type: (primitive_type) ; [23:5 - 7] declarator: (function_declarator) ; [23:9 - 16] declarator: (field_identifier) ; [23:9 - 14] parameters: (parameter_list) ; [23:15 - 16] body: (compound_statement) ; [23:17 - 27:5] (return_statement) ; [24:9 - 26:24] (call_expression) ; [24:16 - 26:23] function: (field_expression) ; [24:16 - 26:21] argument: (field_expression) ; [24:16 - 26:14] argument: (this) ; [24:16 - 19] field: (operator_cast) ; [25:13 - 26:14] type: (type_identifier) ; [25:22 - 26] (comment) ; [25:28 - 49] declarator: (abstract_function_declarator) ; [26:13 - 14] parameters: (parameter_list) ; [26:13 - 14] field: (field_identifier) ; [26:16 - 21] arguments: (argument_list) ; [26:22 - 23] ```
ghost
approved these changes
May 2, 2024
ghost
approved these changes
May 2, 2024
ghost
reviewed
May 2, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Here is a shortened version of my code, which couldn't be parsed correctly.
This is my first time editing a tree-sitter grammar. Maybe I accidentally broke the parsing of other code.
tree with errors:
fixed tree: