Add classes with inheritance

edge_only_predecessors
Max Brunsfeld 2017-06-22 22:07:29 +07:00
parent 53a18a46ae
commit 8694f5beb2
4 changed files with 67776 additions and 66856 deletions

@ -119,6 +119,28 @@ class C {
(parameter_declaration (identifier))))) (parameter_declaration (identifier)))))
(member_declaration (function_declarator (destructor_name (identifier))))))) (member_declaration (function_declarator (destructor_name (identifier)))))))
=========================================
Classes with inheritance
=========================================
class A : public B {
};
class C : C::D, public E {
};
---
(translation_unit
(class_specifier
(identifier)
(base_class_clause (identifier))
(member_declaration_list))
(class_specifier
(identifier)
(base_class_clause (scoped_identifier (identifier) (identifier)) (identifier))
(member_declaration_list)))
========================================= =========================================
Friend declarations Friend declarations
========================================= =========================================

@ -78,13 +78,10 @@ module.exports = grammar(C, {
class_specifier: $ => prec.left(seq( class_specifier: $ => prec.left(seq(
'class', 'class',
choice( choice(
$.identifier, $._class_name,
seq( seq(
optional(choice( optional($._class_name),
$.identifier, optional($.base_class_clause),
$.scoped_identifier,
$.template_call
)),
$.member_declaration_list $.member_declaration_list
) )
) )
@ -93,13 +90,10 @@ module.exports = grammar(C, {
union_specifier: $ => prec.left(seq( union_specifier: $ => prec.left(seq(
'union', 'union',
choice( choice(
$.identifier, $._class_name,
seq( seq(
optional(choice( optional($._class_name),
$.identifier, optional($.base_class_clause),
$.scoped_identifier,
$.template_call
)),
$.member_declaration_list $.member_declaration_list
) )
) )
@ -108,18 +102,29 @@ module.exports = grammar(C, {
struct_specifier: $ => prec.left(seq( struct_specifier: $ => prec.left(seq(
'struct', 'struct',
choice( choice(
$.identifier, $._class_name,
seq( seq(
optional(choice( optional($._class_name),
$.identifier, optional($.base_class_clause),
$.scoped_identifier,
$.template_call
)),
$.member_declaration_list $.member_declaration_list
) )
) )
)), )),
_class_name: $ => choice(
$.identifier,
$.scoped_identifier,
$.template_call
),
base_class_clause: $ => seq(
':',
commaSep1(seq(
optional('public'),
$._class_name
))
),
enum_specifier: ($, original) => prec.left(original), enum_specifier: ($, original) => prec.left(original),
// The `auto` storage class is removed in C++0x in order to allow for the `auto` type. // The `auto` storage class is removed in C++0x in order to allow for the `auto` type.

141
src/grammar.json vendored

@ -1314,33 +1314,37 @@
}, },
{ {
"type": "CHOICE", "type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "identifier" "name": "_class_name"
}
]
}, },
{ {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{
"type": "CHOICE",
"members": [
{ {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "identifier" "name": "_class_name"
}, },
{ {
"type": "SYMBOL", "type": "BLANK"
"name": "scoped_identifier" }
]
}, },
{
"type": "CHOICE",
"members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "template_call" "name": "base_class_clause"
}
]
}, },
{ {
"type": "BLANK" "type": "BLANK"
@ -1370,33 +1374,37 @@
}, },
{ {
"type": "CHOICE", "type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "identifier" "name": "_class_name"
}
]
}, },
{ {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{
"type": "CHOICE",
"members": [
{ {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "identifier" "name": "_class_name"
}, },
{ {
"type": "SYMBOL", "type": "BLANK"
"name": "scoped_identifier" }
]
}, },
{
"type": "CHOICE",
"members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "template_call" "name": "base_class_clause"
}
]
}, },
{ {
"type": "BLANK" "type": "BLANK"
@ -3719,10 +3727,15 @@
}, },
{ {
"type": "CHOICE", "type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "identifier" "name": "_class_name"
}
]
}, },
{ {
"type": "SEQ", "type": "SEQ",
@ -3731,6 +3744,38 @@
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "SYMBOL",
"name": "_class_name"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "base_class_clause"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "member_declaration_list"
}
]
}
]
}
]
}
},
"_class_name": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
@ -3747,6 +3792,56 @@
} }
] ]
}, },
"base_class_clause": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ":"
},
{
"type": "SEQ",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "public"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "_class_name"
}
]
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "public"
},
{ {
"type": "BLANK" "type": "BLANK"
} }
@ -3754,14 +3849,16 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "member_declaration_list" "name": "_class_name"
} }
] ]
} }
] ]
} }
}
] ]
} }
]
}, },
"auto": { "auto": {
"type": "STRING", "type": "STRING",

134370
src/parser.c vendored

File diff suppressed because it is too large Load Diff