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)))))
(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
=========================================

@ -78,13 +78,10 @@ module.exports = grammar(C, {
class_specifier: $ => prec.left(seq(
'class',
choice(
$.identifier,
$._class_name,
seq(
optional(choice(
$.identifier,
$.scoped_identifier,
$.template_call
)),
optional($._class_name),
optional($.base_class_clause),
$.member_declaration_list
)
)
@ -93,13 +90,10 @@ module.exports = grammar(C, {
union_specifier: $ => prec.left(seq(
'union',
choice(
$.identifier,
$._class_name,
seq(
optional(choice(
$.identifier,
$.scoped_identifier,
$.template_call
)),
optional($._class_name),
optional($.base_class_clause),
$.member_declaration_list
)
)
@ -108,18 +102,29 @@ module.exports = grammar(C, {
struct_specifier: $ => prec.left(seq(
'struct',
choice(
$.identifier,
$._class_name,
seq(
optional(choice(
$.identifier,
$.scoped_identifier,
$.template_call
)),
optional($._class_name),
optional($.base_class_clause),
$.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),
// 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",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
"name": "_class_name"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
"name": "_class_name"
},
{
"type": "SYMBOL",
"name": "scoped_identifier"
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "template_call"
}
]
"name": "base_class_clause"
},
{
"type": "BLANK"
@ -1370,33 +1374,37 @@
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
"name": "_class_name"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
"name": "_class_name"
},
{
"type": "SYMBOL",
"name": "scoped_identifier"
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "template_call"
}
]
"name": "base_class_clause"
},
{
"type": "BLANK"
@ -3719,10 +3727,15 @@
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
"name": "_class_name"
}
]
},
{
"type": "SEQ",
@ -3731,6 +3744,38 @@
"type": "CHOICE",
"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",
"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"
}
@ -3754,14 +3849,16 @@
},
{
"type": "SYMBOL",
"name": "member_declaration_list"
"name": "_class_name"
}
]
}
]
}
}
]
}
]
},
"auto": {
"type": "STRING",

134370
src/parser.c vendored

File diff suppressed because it is too large Load Diff