Group members under the same Access Specifier
Context This piece of C++ code:
class Test {
int a;
public:
float b;
};
parses to this syntax tree:
(translation_unit [0, 0] - [5, 0]
(class_specifier [0, 0] - [4, 1]
name: (type_identifier [0, 6] - [0, 10])
body: (field_declaration_list [0, 11] - [4, 1]
(field_declaration [1, 1] - [1, 7]
type: (primitive_type [1, 1] - [1, 4])
declarator: (field_identifier [1, 5] - [1, 6]))
(access_specifier [2, 0] - [2, 7])
(field_declaration [3, 4] - [3, 12]
type: (primitive_type [3, 4] - [3, 9])
declarator: (field_identifier [3, 10] - [3, 11])))))
I'm wondering about how hard it is to group members by access specifier; which would produce something like this:
(translation_unit [0, 0] - [5, 0]
(class_specifier [0, 0] - [4, 1]
name: (type_identifier [0, 6] - [0, 10])
body: (field_declaration_list [0, 11] - [4, 1]
(field_declaration [1, 1] - [1, 7]
type: (primitive_type [1, 1] - [1, 4])
declarator: (field_identifier [1, 5] - [1, 6]))
(access_specifier [2, 0] - [3, 11]
(field_declaration [3, 4] - [3, 12]
type: (primitive_type [3, 4] - [3, 9])
declarator: (field_identifier [3, 10] - [3, 11]))))))
Note that the second
field_declarationis inside theaccess_specifierthing.
I see two aspects for this:
- Backward compatibility; where we still need the "implicitly-defined-access-specifier" members.
- I assume this is not hard to implement (boils down to modifying the
access_modifiergrammar rule only)
Benefits
I'm trying to write a tool to generate customizable class/object diagrams from C++ headers; using tree-sitter-graph. And having
the access information of members bundled into the syntax tree will enormously simplify things.
Interested in this as it should also allow this feature to be implemented in nvim-treesitter-context: https://github.com/nvim-treesitter/nvim-treesitter-context/issues/217