Adds more parse tree stringification.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
dbef09f4bb
commit
5c086ee066
|
@ -264,7 +264,7 @@ namespace MalachScript::Parser {
|
|||
[[nodiscard]] const std::vector<std::unique_ptr<const ParsedStatement>>& GetStatements() const noexcept {
|
||||
return _statements;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<const ParsedStatement>> _statements;
|
||||
};
|
||||
|
@ -293,6 +293,14 @@ namespace MalachScript::Parser {
|
|||
const ParsedStatement* elseStatement)
|
||||
: ParsedStatementImpl(span), _condition(condition), _body(body), _elseStatement(elseStatement) {}
|
||||
|
||||
[[nodiscard]] inline const std::unique_ptr<const ParsedStatement>& GetCondition() const noexcept {
|
||||
return _condition;
|
||||
}
|
||||
[[nodiscard]] inline const std::unique_ptr<const ParsedStatement>& GetBody() const noexcept { return _body; }
|
||||
[[nodiscard]] inline const std::unique_ptr<const ParsedStatement>& GetElseStatement() const noexcept {
|
||||
return _elseStatement;
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<const ParsedStatement> _condition;
|
||||
std::unique_ptr<const ParsedStatement> _body;
|
||||
|
|
|
@ -104,7 +104,7 @@ namespace MalachScript::Parser {
|
|||
}
|
||||
if (virtprop->HasGet()) {
|
||||
auto& stat = virtprop->GetGetStatement();
|
||||
auto propPrefix = prefix + " ";
|
||||
auto propPrefix = prefix + (isLast ? " " : "│ ");
|
||||
stream << propPrefix;
|
||||
stream << (virtprop->HasSet() ? "├──" : "└──") << "Get";
|
||||
stream << std::endl;
|
||||
|
@ -115,7 +115,7 @@ namespace MalachScript::Parser {
|
|||
}
|
||||
if (virtprop->HasSet()) {
|
||||
auto& stat = virtprop->GetSetStatement();
|
||||
auto propPrefix = prefix + " ";
|
||||
auto propPrefix = prefix + (isLast ? " " : "│ ");
|
||||
stream << propPrefix;
|
||||
stream << (virtprop->HasSet() ? "└──" : "├──") << "Set";
|
||||
stream << std::endl;
|
||||
|
@ -133,9 +133,32 @@ namespace MalachScript::Parser {
|
|||
for (size_t i = 0; i < stats.size(); i++) {
|
||||
Stringify(stats[i].get(), stream, prefix + (isLast ? " " : "│ "), i == stats.size() - 1);
|
||||
}
|
||||
if (!stats.empty()) {
|
||||
stream << std::endl;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ParsedStatementKind::If: {
|
||||
auto s = static_cast<const ParsedIfStatement*>(statement);
|
||||
auto propPrefix = prefix + (isLast ? " " : "│ ");
|
||||
stream << std::endl;
|
||||
stream << propPrefix << "├──"
|
||||
<< "Condition";
|
||||
stream << std::endl;
|
||||
Stringify(s->GetCondition().get(), stream, propPrefix + "│ ", true);
|
||||
stream << std::endl;
|
||||
stream << propPrefix << (s->GetElseStatement() == nullptr ? "└──" : "├──") << "When True";
|
||||
stream << std::endl;
|
||||
Stringify(s->GetBody().get(), stream,
|
||||
propPrefix + (s->GetElseStatement() == nullptr ? " " : "│ "), true);
|
||||
if (s->GetElseStatement() != nullptr) {
|
||||
stream << propPrefix << "└──"
|
||||
<< "Else";
|
||||
stream << std::endl;
|
||||
Stringify(s->GetElseStatement().get(), stream, propPrefix + " ", true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ParsedStatementKind::If: break;
|
||||
case ParsedStatementKind::Assign: break;
|
||||
case ParsedStatementKind::BinaryExpression: break;
|
||||
case ParsedStatementKind::Void: break;
|
||||
|
|
Loading…
Reference in New Issue