From e9d7c27d4f98a1a3c52b782b01d5de086fb25440 Mon Sep 17 00:00:00 2001 From: Username404 Date: Sat, 16 Apr 2022 21:28:20 +0200 Subject: [PATCH] Simplify parsing of functions/calls/classes and remove the Class.body variable Signed-off-by: Username404 --- src/headers/parsing/ParseComponents.hpp | 3 +-- src/headers/parsing/Parser.hpp | 19 ++++++------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/headers/parsing/ParseComponents.hpp b/src/headers/parsing/ParseComponents.hpp index a373c04..cdf2d91 100644 --- a/src/headers/parsing/ParseComponents.hpp +++ b/src/headers/parsing/ParseComponents.hpp @@ -125,8 +125,7 @@ namespace StandardComponents { ParseTree parameters; using NamedIdentifier::NamedIdentifier; }; - struct Class: NamedIdentifier { - ParseTree body; + struct Class: NamedIdentifier, ParseTree { using NamedIdentifier::NamedIdentifier; }; } diff --git a/src/headers/parsing/Parser.hpp b/src/headers/parsing/Parser.hpp index 2a9a7b6..f7aec91 100644 --- a/src/headers/parsing/Parser.hpp +++ b/src/headers/parsing/Parser.hpp @@ -119,19 +119,12 @@ namespace Parser { } if (not parseTree.empty()) { try { - const component_ptr& previous = parseTree.at(parseTree.size() - 1); - if (current.toktype == LPAR) { - dynamic_cast(*previous).ParseTree::operator=(parse(subTokens)); - } else if (current.toktype == LBRACE) { - const type_info& previous_id = previous->getId(); - if (previous_id == typeid(Function)) { - dynamic_cast(*previous).ParseTree::operator=(parse(subTokens)); - } else if (previous_id == typeid(Class)) { - dynamic_cast(*previous).body = parse(subTokens); - } - } else parseTree << parse(subTokens); - i = distance(lexed.begin(), closingCharacter); - break; + auto& previous = dynamic_cast(*parseTree.at(parseTree.size() - 1)); + if (current.toktype != LPAR or previous.getId() == typeid(Call)) { + previous = parse(subTokens); + i = distance(lexed.begin(), closingCharacter); + break; + } } catch (const out_of_range&) {} catch (const bad_cast&) {} } }