From 014ea9060b0265f72a131b68653bdc8d3b33c04e Mon Sep 17 00:00:00 2001 From: Username404 Date: Tue, 19 Apr 2022 23:23:49 +0200 Subject: [PATCH] ParserComponents.hpp: Add a "<<" operator overload (which takes a constant string reference as its argument) to the ParseTree class Signed-off-by: Username404 --- src/headers/parsing/ParseComponents.hpp | 7 ++++++- src/headers/parsing/Parser.hpp | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/headers/parsing/ParseComponents.hpp b/src/headers/parsing/ParseComponents.hpp index 79df329..603052a 100644 --- a/src/headers/parsing/ParseComponents.hpp +++ b/src/headers/parsing/ParseComponents.hpp @@ -85,6 +85,7 @@ public: IS_PARSECOMPONENT inline void add(const T& component) { addComponent(component); } IS_PARSECOMPONENT inline void addAll(const initializer_list& components) { addAllComponents(components); } IS_PARSECOMPONENT inline ParseTree& operator<<(const T& component) { add(component); return *this; } + ParseTree& operator<<(const string&); ParseTree(): subComponents() {}; IS_PARSECOMPONENT inline explicit ParseTree(const T& element): ParseTree() { addComponent(element); } IS_PARSECOMPONENT inline ParseTree(const initializer_list& elements): ParseTree() { addAllComponents(elements); } @@ -114,7 +115,7 @@ namespace StandardComponents { }; struct String: ParseComponent { const string content; - explicit String(const char* string): content(string) {} + explicit String(string content_string): content(move(content_string)) {} }; } struct Call: ParseTree, Reference { @@ -130,4 +131,8 @@ namespace StandardComponents { }; } +ParseTree& ParseTree::operator<<(const string& text) { + return *this << StandardComponents::types::String(text); +} + #endif //YERBACON_PARSECOMPONENTS_HPP \ No newline at end of file diff --git a/src/headers/parsing/Parser.hpp b/src/headers/parsing/Parser.hpp index 0e3f6af..2a69526 100644 --- a/src/headers/parsing/Parser.hpp +++ b/src/headers/parsing/Parser.hpp @@ -56,7 +56,7 @@ namespace Parser { parseTree << types::Integer(v, p); break; } - case STRING: parseTree << types::String(current.toktext.data()); break; + case STRING: parseTree << current.toktext; break; case IDENTIFIER: { if (current.toktext == "class" || current.toktext == "structure") { if (next.toktype == IDENTIFIER) {