From 4831dc0e309d964abcab367d3d9eb714a4646764 Mon Sep 17 00:00:00 2001 From: Itamar Date: Mon, 19 Apr 2021 19:41:43 +0300 Subject: LibCpp: Support parsing class declarations --- Userland/Libraries/LibCpp/Parser.cpp | 9 +++++++++ Userland/Libraries/LibCpp/Parser.h | 2 ++ 2 files changed, 11 insertions(+) (limited to 'Userland/Libraries/LibCpp') diff --git a/Userland/Libraries/LibCpp/Parser.cpp b/Userland/Libraries/LibCpp/Parser.cpp index a78baac06b..f5bbc13e50 100644 --- a/Userland/Libraries/LibCpp/Parser.cpp +++ b/Userland/Libraries/LibCpp/Parser.cpp @@ -128,6 +128,8 @@ NonnullRefPtr Parser::parse_declaration(ASTNode& parent, Declaratio return parse_variable_declaration(parent); case DeclarationType::Enum: return parse_enum_declaration(parent); + case DeclarationType::Class: + return parse_struct_or_class_declaration(parent, StructOrClassDeclaration::Type::Class); case DeclarationType::Struct: return parse_struct_or_class_declaration(parent, StructOrClassDeclaration::Type::Struct); case DeclarationType::Namespace: @@ -640,6 +642,8 @@ Optional Parser::match_declaration_in_translation_unit( return DeclarationType::Function; if (match_enum_declaration()) return DeclarationType::Enum; + if (match_class_declaration()) + return DeclarationType::Class; if (match_struct_declaration()) return DeclarationType::Struct; if (match_namespace_declaration()) @@ -654,6 +658,11 @@ bool Parser::match_enum_declaration() return match_keyword("enum"); } +bool Parser::match_class_declaration() +{ + return match_keyword("class"); +} + bool Parser::match_struct_declaration() { return match_keyword("struct"); diff --git a/Userland/Libraries/LibCpp/Parser.h b/Userland/Libraries/LibCpp/Parser.h index aad21bd9d0..64bc114bc8 100644 --- a/Userland/Libraries/LibCpp/Parser.h +++ b/Userland/Libraries/LibCpp/Parser.h @@ -69,6 +69,7 @@ private: Enum, Struct, Namespace, + Class, }; Optional match_declaration_in_translation_unit(); @@ -80,6 +81,7 @@ private: bool match_expression(); bool match_secondary_expression(); bool match_enum_declaration(); + bool match_class_declaration(); bool match_struct_declaration(); bool match_literal(); bool match_unary_expression(); -- cgit v1.2.3