Show neat little tree in REPL.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
0bacb981d1
commit
56538a5552
@ -42,7 +42,7 @@ if (REPL)
|
|||||||
# Create Test executable
|
# Create Test executable
|
||||||
file(GLOB_RECURSE REPL_FILES "repl/*.cpp" "repl/*.hpp")
|
file(GLOB_RECURSE REPL_FILES "repl/*.cpp" "repl/*.hpp")
|
||||||
add_executable(MalachScriptREPL ${REPL_FILES})
|
add_executable(MalachScriptREPL ${REPL_FILES})
|
||||||
target_link_libraries(MalachScriptREPL PUBLIC MalachScript curses)
|
target_link_libraries(MalachScriptREPL PUBLIC MalachScript cursesw)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ void ParseAndUpdate(const std::vector<std::u8string> lines, WINDOW* diagnosticsW
|
|||||||
const MalachScript::Diagnostics::Diagnostic* diag = nullptr;
|
const MalachScript::Diagnostics::Diagnostic* diag = nullptr;
|
||||||
wclear(diagnosticsWindow);
|
wclear(diagnosticsWindow);
|
||||||
|
|
||||||
if (logger.GetMessages().size() > 0) {
|
if (!logger.GetMessages().empty()) {
|
||||||
diag = &logger.GetMessages()[0];
|
diag = &logger.GetMessages()[0];
|
||||||
|
|
||||||
wattron(diagnosticsWindow, COLOR_PAIR(1));
|
wattron(diagnosticsWindow, COLOR_PAIR(1));
|
||||||
@ -74,9 +74,9 @@ void ParseAndUpdate(const std::vector<std::u8string> lines, WINDOW* diagnosticsW
|
|||||||
wrefresh(diagnosticsWindow);
|
wrefresh(diagnosticsWindow);
|
||||||
|
|
||||||
wclear(parsedWindow);
|
wclear(parsedWindow);
|
||||||
if (logger.GetMessages().size() == 0) {
|
if (logger.GetMessages().empty()) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
parsedResult->Stringify(ss, 0);
|
parsedResult->Stringify(ss, "", true);
|
||||||
|
|
||||||
waddstr(parsedWindow, ss.str().c_str());
|
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[]) {
|
int main([[maybe_unused]] int argc, [[maybe_unused]] const char* argv[]) {
|
||||||
|
setlocale(LC_ALL, "");
|
||||||
initscr();
|
initscr();
|
||||||
cbreak();
|
cbreak();
|
||||||
noecho();
|
noecho();
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define MALACHSCRIPT_PARSEDSTATEMENT_HPP
|
#define MALACHSCRIPT_PARSEDSTATEMENT_HPP
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <stack>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "../../CoreData/AccessModifier.hpp"
|
#include "../../CoreData/AccessModifier.hpp"
|
||||||
@ -20,10 +21,9 @@ namespace MalachScript::Parser {
|
|||||||
[[nodiscard]] virtual ParsedStatementKind GetKind() const noexcept = 0;
|
[[nodiscard]] virtual ParsedStatementKind GetKind() const noexcept = 0;
|
||||||
[[nodiscard]] inline const TextSpan& GetSpan() const noexcept { return _span; }
|
[[nodiscard]] inline const TextSpan& GetSpan() const noexcept { return _span; }
|
||||||
|
|
||||||
virtual void Stringify(std::stringstream& stream, uint8_t indents) const {
|
virtual void Stringify(std::stringstream& stream, const std::string& prefix, bool isLast) const {
|
||||||
for (uint8_t i = 0; i < indents; i++) {
|
stream << prefix;
|
||||||
stream << "\t";
|
stream << (isLast ? "└──" : "├──");
|
||||||
}
|
|
||||||
stream << ParsedStatementKindHelper::ToString(GetKind());
|
stream << ParsedStatementKindHelper::ToString(GetKind());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -48,12 +48,11 @@ namespace MalachScript::Parser {
|
|||||||
return _statements;
|
return _statements;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stringify(std::stringstream& stream, uint8_t indents) const override {
|
void Stringify(std::stringstream& stream, const std::string& prefix, bool isLast) const override {
|
||||||
ParsedStatement::Stringify(stream, indents);
|
ParsedStatement::Stringify(stream, prefix, isLast);
|
||||||
stream << std::to_string(GetStatements().size());
|
|
||||||
stream << std::endl;
|
stream << std::endl;
|
||||||
for (const auto& s : GetStatements()) {
|
for (size_t i = 0; i < _statements.size(); i++) {
|
||||||
s->Stringify(stream, indents + 1);
|
_statements[i]->Stringify(stream, prefix + (isLast ? " " : "│ "), i == _statements.size() - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -75,12 +74,12 @@ namespace MalachScript::Parser {
|
|||||||
return _body;
|
return _body;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stringify(std::stringstream& stream, uint8_t indents) const override {
|
void Stringify(std::stringstream& stream, const std::string& prefix, bool isLast) const override {
|
||||||
ParsedStatement::Stringify(stream, indents);
|
ParsedStatement::Stringify(stream, prefix, isLast);
|
||||||
stream << " " << _identifier;
|
stream << " " << _identifier;
|
||||||
stream << std::endl;
|
stream << std::endl;
|
||||||
for (const auto& s : GetBody()) {
|
for (size_t i = 0; i < _body.size(); i++) {
|
||||||
s->Stringify(stream, indents + 1);
|
_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 bool IsHandle() const noexcept { return _isHandle; }
|
||||||
[[nodiscard]] inline const ScopedIdentifier& GetScopedIdentifier() const noexcept { return _scopedIdentifier; }
|
[[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) {
|
if (_isConst) {
|
||||||
stream << "const ";
|
stream << "const ";
|
||||||
}
|
}
|
||||||
@ -204,10 +204,10 @@ namespace MalachScript::Parser {
|
|||||||
return _parameters;
|
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 << "(";
|
stream << "(";
|
||||||
for (auto& param : GetParameters()) {
|
for (auto& param : GetParameters()) {
|
||||||
param->GetTypeStatement()->Stringify(stream, indents);
|
param->GetTypeStatement()->Stringify(stream, prefix, isLast);
|
||||||
stream << " " << param->GetIdentifier();
|
stream << " " << param->GetIdentifier();
|
||||||
}
|
}
|
||||||
stream << ")";
|
stream << ")";
|
||||||
@ -253,12 +253,13 @@ namespace MalachScript::Parser {
|
|||||||
return _statBlock;
|
return _statBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stringify(std::stringstream& stream, uint8_t indents) const override {
|
void Stringify(std::stringstream& stream, const std::string& prefix, bool isLast) const override {
|
||||||
ParsedStatement::Stringify(stream, indents);
|
ParsedStatement::Stringify(stream, prefix, isLast);
|
||||||
stream << " " << _identifier;
|
stream << " " << _identifier;
|
||||||
GetParamList()->Stringify(stream, 0);
|
GetParamList()->Stringify(stream, prefix, isLast);
|
||||||
stream << std::endl;
|
stream << std::endl;
|
||||||
GetStatBlock()->Stringify(stream, indents + 1);
|
|
||||||
|
GetStatBlock()->Stringify(stream, prefix + (isLast ? " " : "│ "), true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -323,6 +324,14 @@ namespace MalachScript::Parser {
|
|||||||
return _statements;
|
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:
|
private:
|
||||||
std::vector<std::unique_ptr<const ParsedStatement>> _statements;
|
std::vector<std::unique_ptr<const ParsedStatement>> _statements;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user