Allow explicit constructors

Co-Authored-By: Thomas Johansen <thomasjo@gmail.com>
edge_only_predecessors
Max Brunsfeld 2018-05-14 12:52:14 +07:00
parent 06e557ada7
commit dfd266b27f
4 changed files with 107087 additions and 106285 deletions

@ -50,6 +50,34 @@ T::T() : f1(0), f2(1, 2) {
(compound_statement
(expression_statement (call_expression (identifier) (argument_list (string_literal)))))))
=====================================
Explicit constructor definitions
=====================================
class C {
explicit C(int f) : f_(f) {}
private:
int f_;
};
---
(translation_unit
(class_specifier
(type_identifier)
(field_declaration_list
(function_definition
(type_qualifier)
(function_declarator
(identifier)
(parameter_list (parameter_declaration (primitive_type) (identifier))))
(field_initializer_list
(field_initializer (field_identifier) (argument_list (identifier))))
(compound_statement))
(access_specifier)
(field_declaration (primitive_type) (field_identifier)))))
=====================================
Destructor definitions
=====================================

@ -221,7 +221,8 @@ module.exports = grammar(C, {
$.friend_declaration,
$.access_specifier,
$.alias_declaration,
$.using_declaration
$.using_declaration,
$.type_definition
)),
'}'
),
@ -233,6 +234,10 @@ module.exports = grammar(C, {
),
constructor_or_destructor_definition: $ => seq(
repeat(choice(
$.storage_class_specifier,
$.type_qualifier
)),
prec(1, seq(
$.function_declarator,
optional($.field_initializer_list)

20
src/grammar.json vendored

@ -2278,6 +2278,10 @@
{
"type": "SYMBOL",
"name": "using_declaration"
},
{
"type": "SYMBOL",
"name": "type_definition"
}
]
}
@ -5026,6 +5030,22 @@
"constructor_or_destructor_definition": {
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "storage_class_specifier"
},
{
"type": "SYMBOL",
"name": "type_qualifier"
}
]
}
},
{
"type": "PREC",
"value": 1,

213317
src/parser.c vendored

File diff suppressed because it is too large Load Diff