Skip to content

Commit

Permalink
feat: support pure virtual destructors
Browse files Browse the repository at this point in the history
  • Loading branch information
amaanq committed Apr 14, 2024
1 parent aa79a17 commit 1c3c93d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 4 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ module.exports = grammar(C, {
field('body', choice($.compound_statement, $.try_statement)),
$.default_method_clause,
$.delete_method_clause,
$.pure_virtual_clause,
),
),

Expand Down Expand Up @@ -542,6 +543,7 @@ module.exports = grammar(C, {
alias($.constructor_try_statement, $.try_statement),
$.default_method_clause,
$.delete_method_clause,
$.pure_virtual_clause,
),
),

Expand All @@ -553,6 +555,7 @@ module.exports = grammar(C, {

default_method_clause: _ => seq('=', 'default', ';'),
delete_method_clause: _ => seq('=', 'delete', ';'),
pure_virtual_clause: _ => seq('=', '0', ';'),

friend_declaration: $ => seq(
'friend',
Expand Down Expand Up @@ -1170,7 +1173,7 @@ module.exports = grammar(C, {
];

return choice(
...original.members,
original,
...table.map(([operator, precedence]) => {
return prec.left(precedence, seq(
field('left', $._expression),
Expand Down
11 changes: 9 additions & 2 deletions test/corpus/definitions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class C {
(identifier))))))))

================================================================================
Default and deleted methods
Default, delete, and pure virtual methods
================================================================================

class A : public B {
Expand All @@ -188,6 +188,7 @@ class A : public B {
void f() = delete;
A& operator=(const A&) = default;
A& operator=(A&&) = delete;
~A() = 0;
};

--------------------------------------------------------------------------------
Expand Down Expand Up @@ -238,7 +239,13 @@ class A : public B {
(parameter_declaration
(type_identifier)
(abstract_reference_declarator)))))
(delete_method_clause)))))
(delete_method_clause))
(function_definition
(function_declarator
(destructor_name
(identifier))
(parameter_list))
(pure_virtual_clause)))))

================================================================================
Destructor definitions
Expand Down

0 comments on commit 1c3c93d

Please sign in to comment.