//#include "interpolate.h" #include "srell/srell.hpp" #include #include #include namespace fs = std::filesystem; namespace parser { class TokenStream; namespace AST { struct ASTNode { // virtual void parse(TokenStream& input) = 0; virtual ~ASTNode() = default; static constexpr std::size_t max_derived_size = 64; }; template struct List : B { std::vector vals; static_assert(std::is_base_of_v); }; template struct Map : B { std::map vals; static_assert(std::is_base_of_v); }; template struct BTuple : B { std::tuple vals; static_assert(std::is_base_of_v); }; template using Tuple = BTuple; struct TExpr : ASTNode { static constexpr std::size_t max_derived_size = sizeof(ASTNode) + sizeof(std::string) + sizeof(std::vector); }; struct TLiteral : TExpr { std::string val; }; struct TFCall : TExpr { std::string fname; std::vector> args; }; struct TArgRef : TExpr { std::string name; }; struct TDots : TArgRef {}; struct String : ASTNode { template auto refine() const -> std::tuple...>; static constexpr std::size_t max_derived_size = sizeof(ASTNode) + sizeof(std::vector); }; struct tname : String { std::string name; int argc; bool variadic; }; struct LString final : String { std::string val; }; struct IString : String {}; struct TString : String { std::vector> contents; }; struct replace_stage : ASTNode {}; struct regex_action final : ASTNode { srell::regex r; std::string m; }; struct regex_stage final : List {}; struct state_machine final : replace_stage {}; struct Replacement_group final : ASTNode { std::map>> actions; }; struct Control final : ASTNode { std::map channel_names; std::map functions; std::vector replacements; IString entry_point; // void parse(TokenStream& input) override; }; struct Alternative : ASTNode { auto val() const -> String&; std::variant freq; Map> channels; }; struct Node {}; struct NormalNode final : List {}; struct LiteralNode final : Alternative {}; struct Datafile final : ASTNode { Control control; Map> nodes; }; } // namespace AST } // namespace parser