Show neat little tree in REPL.
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Deukhoofd 2021-01-03 14:42:26 +01:00
parent 0bacb981d1
commit 56538a5552
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
3 changed files with 34 additions and 24 deletions

View File

@ -42,7 +42,7 @@ if (REPL)
# Create Test executable
file(GLOB_RECURSE REPL_FILES "repl/*.cpp" "repl/*.hpp")
add_executable(MalachScriptREPL ${REPL_FILES})
target_link_libraries(MalachScriptREPL PUBLIC MalachScript curses)
target_link_libraries(MalachScriptREPL PUBLIC MalachScript cursesw)
endif ()

View File

@ -52,7 +52,7 @@ void ParseAndUpdate(const std::vector<std::u8string> lines, WINDOW* diagnosticsW
const MalachScript::Diagnostics::Diagnostic* diag = nullptr;
wclear(diagnosticsWindow);
if (logger.GetMessages().size() > 0) {
if (!logger.GetMessages().empty()) {
diag = &logger.GetMessages()[0];
wattron(diagnosticsWindow, COLOR_PAIR(1));
@ -74,9 +74,9 @@ void ParseAndUpdate(const std::vector<std::u8string> lines, WINDOW* diagnosticsW
wrefresh(diagnosticsWindow);
wclear(parsedWindow);
if (logger.GetMessages().size() == 0) {
if (logger.GetMessages().empty()) {
std::stringstream ss;
parsedResult->Stringify(ss, 0);
parsedResult->Stringify(ss, "", true);
waddstr(parsedWindow, ss.str().c_str());
}
@ -86,6 +86,7 @@ void ParseAndUpdate(const std::vector<std::u8string> lines, WINDOW* diagnosticsW
}
int main([[maybe_unused]] int argc, [[maybe_unused]] const char* argv[]) {
setlocale(LC_ALL, "");
initscr();
cbreak();
noecho();

View File

@ -2,6 +2,7 @@
#define MALACHSCRIPT_PARSEDSTATEMENT_HPP
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include "../../CoreData/AccessModifier.hpp"
@ -20,10 +21,9 @@ namespace MalachScript::Parser {
[[nodiscard]] virtual ParsedStatementKind GetKind() const noexcept = 0;
[[nodiscard]] inline const TextSpan& GetSpan() const noexcept { return _span; }
virtual void Stringify(std::stringstream& stream, uint8_t indents) const {
for (uint8_t i = 0; i < indents; i++) {
stream << "\t";
}
virtual void Stringify(std::stringstream& stream, const std::string& prefix, bool isLast) const {
stream << prefix;
stream << (isLast ? "└──" : "├──");
stream << ParsedStatementKindHelper::ToString(GetKind());
}
};
@ -48,12 +48,11 @@ namespace MalachScript::Parser {
return _statements;
}
void Stringify(std::stringstream& stream, uint8_t indents) const override {
ParsedStatement::Stringify(stream, indents);
stream << std::to_string(GetStatements().size());
void Stringify(std::stringstream& stream, const std::string& prefix, bool isLast) const override {
ParsedStatement::Stringify(stream, prefix, isLast);
stream << std::endl;
for (const auto& s : GetStatements()) {
s->Stringify(stream, indents + 1);
for (size_t i = 0; i < _statements.size(); i++) {
_statements[i]->Stringify(stream, prefix + (isLast ? " " : ""), i == _statements.size() - 1);
}
}
};
@ -75,12 +74,12 @@ namespace MalachScript::Parser {
return _body;
}
void Stringify(std::stringstream& stream, uint8_t indents) const override {
ParsedStatement::Stringify(stream, indents);
void Stringify(std::stringstream& stream, const std::string& prefix, bool isLast) const override {
ParsedStatement::Stringify(stream, prefix, isLast);
stream << " " << _identifier;
stream << std::endl;
for (const auto& s : GetBody()) {
s->Stringify(stream, indents + 1);
for (size_t i = 0; i < _body.size(); i++) {
_body[i]->Stringify(stream, prefix + (isLast ? " " : ""), i == _body.size() - 1);
}
}
@ -135,7 +134,8 @@ namespace MalachScript::Parser {
[[nodiscard]] inline bool IsHandle() const noexcept { return _isHandle; }
[[nodiscard]] inline const ScopedIdentifier& GetScopedIdentifier() const noexcept { return _scopedIdentifier; }
void Stringify(std::stringstream& stream, uint8_t) const override {
void Stringify(std::stringstream& stream, [[maybe_unused]] const std::string& prefix,
[[maybe_unused]] bool isLast) const override {
if (_isConst) {
stream << "const ";
}
@ -204,10 +204,10 @@ namespace MalachScript::Parser {
return _parameters;
}
void Stringify(std::stringstream& stream, uint8_t indents) const override {
void Stringify(std::stringstream& stream, const std::string& prefix, bool isLast) const override {
stream << "(";
for (auto& param : GetParameters()) {
param->GetTypeStatement()->Stringify(stream, indents);
param->GetTypeStatement()->Stringify(stream, prefix, isLast);
stream << " " << param->GetIdentifier();
}
stream << ")";
@ -253,12 +253,13 @@ namespace MalachScript::Parser {
return _statBlock;
}
void Stringify(std::stringstream& stream, uint8_t indents) const override {
ParsedStatement::Stringify(stream, indents);
void Stringify(std::stringstream& stream, const std::string& prefix, bool isLast) const override {
ParsedStatement::Stringify(stream, prefix, isLast);
stream << " " << _identifier;
GetParamList()->Stringify(stream, 0);
GetParamList()->Stringify(stream, prefix, isLast);
stream << std::endl;
GetStatBlock()->Stringify(stream, indents + 1);
GetStatBlock()->Stringify(stream, prefix + (isLast ? " " : ""), true);
}
};
@ -323,6 +324,14 @@ namespace MalachScript::Parser {
return _statements;
}
void Stringify(std::stringstream& stream, const std::string& prefix, bool isLast) const override {
ParsedStatement::Stringify(stream, prefix, isLast);
stream << std::endl;
for (size_t i = 0; i < _statements.size(); i++) {
_statements[i]->Stringify(stream, prefix + (isLast ? " " : ""), i == _statements.size() - 1);
}
}
private:
std::vector<std::unique_ptr<const ParsedStatement>> _statements;
};