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.

199
src/grammar.json vendored

@ -1316,8 +1316,13 @@
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SEQ",
"name": "identifier" "members": [
{
"type": "SYMBOL",
"name": "_class_name"
}
]
}, },
{ {
"type": "SEQ", "type": "SEQ",
@ -1326,21 +1331,20 @@
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "CHOICE", "type": "SYMBOL",
"members": [ "name": "_class_name"
{ },
"type": "SYMBOL", {
"name": "identifier" "type": "BLANK"
}, }
{ ]
"type": "SYMBOL", },
"name": "scoped_identifier" {
}, "type": "CHOICE",
{ "members": [
"type": "SYMBOL", {
"name": "template_call" "type": "SYMBOL",
} "name": "base_class_clause"
]
}, },
{ {
"type": "BLANK" "type": "BLANK"
@ -1372,8 +1376,13 @@
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SEQ",
"name": "identifier" "members": [
{
"type": "SYMBOL",
"name": "_class_name"
}
]
}, },
{ {
"type": "SEQ", "type": "SEQ",
@ -1382,21 +1391,20 @@
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "CHOICE", "type": "SYMBOL",
"members": [ "name": "_class_name"
{ },
"type": "SYMBOL", {
"name": "identifier" "type": "BLANK"
}, }
{ ]
"type": "SYMBOL", },
"name": "scoped_identifier" {
}, "type": "CHOICE",
{ "members": [
"type": "SYMBOL", {
"name": "template_call" "type": "SYMBOL",
} "name": "base_class_clause"
]
}, },
{ {
"type": "BLANK" "type": "BLANK"
@ -3721,8 +3729,13 @@
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SEQ",
"name": "identifier" "members": [
{
"type": "SYMBOL",
"name": "_class_name"
}
]
}, },
{ {
"type": "SEQ", "type": "SEQ",
@ -3731,21 +3744,20 @@
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "CHOICE", "type": "SYMBOL",
"members": [ "name": "_class_name"
{ },
"type": "SYMBOL", {
"name": "identifier" "type": "BLANK"
}, }
{ ]
"type": "SYMBOL", },
"name": "scoped_identifier" {
}, "type": "CHOICE",
{ "members": [
"type": "SYMBOL", {
"name": "template_call" "type": "SYMBOL",
} "name": "base_class_clause"
]
}, },
{ {
"type": "BLANK" "type": "BLANK"
@ -3763,6 +3775,91 @@
] ]
} }
}, },
"_class_name": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "scoped_identifier"
},
{
"type": "SYMBOL",
"name": "template_call"
}
]
},
"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": "SYMBOL",
"name": "_class_name"
}
]
}
]
}
}
]
}
]
},
"auto": { "auto": {
"type": "STRING", "type": "STRING",
"value": "auto" "value": "auto"

134370
src/parser.c vendored

File diff suppressed because it is too large Load Diff