2024-04-15 22:16:14 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ccl/rslang/SyntaxTree.h"
|
|
|
|
|
|
|
|
namespace ccl::rslang {
|
|
|
|
|
|
|
|
//! Generate string from AST of RS expression
|
|
|
|
class GeneratorImplAST final : public ASTVisitor<GeneratorImplAST> {
|
|
|
|
friend class SyntaxTree::Cursor;
|
|
|
|
friend class ASTVisitor<GeneratorImplAST>;
|
|
|
|
|
|
|
|
std::string rsText{};
|
|
|
|
Syntax syntax{ Syntax::MATH };
|
|
|
|
|
|
|
|
public:
|
|
|
|
static std::string FromTree(const SyntaxTree& ast, Syntax syntax);
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool VisitDefault(Cursor iter);
|
|
|
|
|
2024-05-10 02:23:57 +03:00
|
|
|
bool ViGlobalDeclaration(Cursor iter);
|
2024-04-15 22:16:14 +03:00
|
|
|
|
|
|
|
bool ViFunctionDefinition(Cursor iter);
|
|
|
|
bool ViFunctionCall(Cursor iter);
|
|
|
|
|
|
|
|
// bool ViGlobal(Cursor iter);
|
2024-05-10 02:23:57 +03:00
|
|
|
// bool ViRadical(Cursor iter);
|
2024-04-15 22:16:14 +03:00
|
|
|
// bool ViLocal(Cursor iter);
|
|
|
|
// bool ViInteger(Cursor /*iter*/);
|
|
|
|
// bool ViIntegerSet(Cursor iter)
|
|
|
|
// bool ViEmptySet(Cursor iter);
|
|
|
|
|
2024-05-10 02:23:57 +03:00
|
|
|
bool ViTupleDeclaration(Cursor iter);
|
|
|
|
bool ViEnumDeclaration(Cursor iter);
|
2024-04-15 22:16:14 +03:00
|
|
|
bool ViArgumentsEnum(Cursor iter);
|
|
|
|
bool ViArgument(Cursor iter);
|
|
|
|
|
|
|
|
bool ViArithmetic(Cursor iter);
|
|
|
|
bool ViCard(Cursor iter);
|
|
|
|
|
|
|
|
bool ViQuantifier(Cursor iter);
|
|
|
|
bool ViNegation(Cursor iter);
|
|
|
|
bool ViLogicBinary(Cursor iter);
|
2024-05-13 11:47:08 +03:00
|
|
|
bool ViEquals(Cursor iter) { return OutputBinary(iter); }
|
|
|
|
bool ViIntegerPredicate(Cursor iter) { return OutputBinary(iter); }
|
|
|
|
bool ViSetexprPredicate(Cursor iter) { return OutputBinary(iter); }
|
2024-04-15 22:16:14 +03:00
|
|
|
|
|
|
|
bool ViDeclarative(Cursor iter);
|
|
|
|
bool ViRecursion(Cursor iter);
|
2024-05-13 11:47:08 +03:00
|
|
|
bool ViImperative(Cursor iter);
|
|
|
|
bool ViIterate(Cursor iter) { return OutputBinary(iter); }
|
|
|
|
bool ViAssign(Cursor iter) { return OutputBinary(iter); }
|
2024-04-15 22:16:14 +03:00
|
|
|
|
|
|
|
bool ViDecart(Cursor iter);
|
|
|
|
bool ViBoolean(Cursor iter);
|
|
|
|
|
|
|
|
bool ViTuple(Cursor iter);
|
2024-05-10 02:23:57 +03:00
|
|
|
bool ViEnumeration(Cursor iter);
|
2024-04-15 22:16:14 +03:00
|
|
|
bool ViBool(Cursor iter) { return ViCard(iter); }
|
|
|
|
bool ViDebool(Cursor iter) { return ViCard(iter); }
|
|
|
|
|
2024-05-10 02:23:57 +03:00
|
|
|
bool ViSetexprBinary(Cursor iter) { return ViArithmetic(iter); }
|
2024-04-15 22:16:14 +03:00
|
|
|
bool ViProjectSet(Cursor iter) { return ViCard(iter); }
|
|
|
|
bool ViProjectTuple(Cursor iter) { return ViCard(iter); }
|
|
|
|
bool ViFilter(Cursor iter);
|
|
|
|
bool ViReduce(Cursor iter) { return ViCard(iter); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
void SetSyntax(const Syntax newSyntax) noexcept { syntax = newSyntax; }
|
|
|
|
void Clear() noexcept;
|
|
|
|
|
|
|
|
void OutputChild(const Cursor& iter, Index index, bool addBrackets = false);
|
2024-05-13 11:47:08 +03:00
|
|
|
bool OutputBinary(const Cursor& iter);
|
2024-04-15 22:16:14 +03:00
|
|
|
|
2024-05-13 11:47:08 +03:00
|
|
|
bool EnumChildren(const Cursor& iter, const std::string& separator);
|
|
|
|
bool EnumChildren(const Cursor& iter, char left, char right, const std::string& separator);
|
2024-04-15 22:16:14 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace ccl::rslang
|