More work on stringification of the parse tree.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2021-01-03 15:44:53 +01:00
parent 08a0859539
commit cf09f9348c
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
1 changed files with 49 additions and 5 deletions

View File

@ -68,10 +68,23 @@ namespace MalachScript::Parser {
}
break;
}
case ParsedStatementKind::TypeDef: break;
case ParsedStatementKind::Namespace: break;
case ParsedStatementKind::Type: break;
case ParsedStatementKind::ParamList: break;
case ParsedStatementKind::TypeDef: {
const auto* td = static_cast<const ParsedTypeDefStatement*>(statement);
stream << " from: " << td->GetDefineFrom() << " --> " << td->GetDefineTo();
break;
}
case ParsedStatementKind::Namespace: {
stream << std::endl;
auto& script = static_cast<const ParsedNamespaceStatement*>(statement)->GetScript();
Stringify(script.get(), stream, prefix + (isLast ? " " : ""), true);
break;
}
case ParsedStatementKind::Type: {
throw std::logic_error("Type statements should use StringifyType");
}
case ParsedStatementKind::ParamList: {
throw std::logic_error("ParamList statements should use StringifyParamList");
}
case ParsedStatementKind::Func: {
const auto* func = static_cast<const ParsedFuncStatement*>(statement);
stream << " " << func->GetIdentifier();
@ -82,7 +95,38 @@ namespace MalachScript::Parser {
Stringify(func->GetStatBlock().get(), stream, prefix + (isLast ? " " : ""), true);
break;
}
case ParsedStatementKind::VirtProp: break;
case ParsedStatementKind::VirtProp: {
const auto* virtprop = static_cast<const ParsedVirtPropStatement*>(statement);
stream << " " << virtprop->GetIdentifier() << " : ";
StringifyType(dynamic_cast<const ParsedTypeStatement*>(virtprop->GetReturnType().get()), stream);
if (virtprop->HasGet() || virtprop->HasSet()) {
stream << std::endl;
}
if (virtprop->HasGet()) {
auto& stat = virtprop->GetGetStatement();
auto propPrefix = prefix + " ";
stream << propPrefix;
stream << (virtprop->HasSet() ? "├──" : "└──") << "Get";
stream << std::endl;
if (stat != nullptr) {
Stringify(stat.get(), stream, propPrefix + (virtprop->HasSet() ? "" : " "), true);
}
}
if (virtprop->HasSet()) {
auto& stat = virtprop->GetSetStatement();
auto propPrefix = prefix + " ";
stream << propPrefix;
stream << (virtprop->HasSet() ? "└──" : "├──") << "Set";
stream << std::endl;
if (stat != nullptr) {
Stringify(stat.get(), stream, propPrefix + " ", true);
}
}
break;
}
case ParsedStatementKind::StatBlock: {
stream << std::endl;
auto& stats = static_cast<const ParsedStatBlockStatement*>(statement)->GetStatements();