#ifndef MACROS_HPP_INCLUDED #define MACROS_HPP_INCLUDED #include "parse/lex.hpp" #include "parse/tokentree.hpp" #include #include #include class MacroExpander; class MacroRuleEnt: public Serialisable { friend class MacroExpander; Token tok; ::std::string name; ::std::vector subpats; public: MacroRuleEnt(): tok(TOK_NULL), name("") { } MacroRuleEnt(Token tok): tok(tok), name("") { } MacroRuleEnt(::std::string name): name(name) { } MacroRuleEnt(Token tok, ::std::vector subpats): tok(tok), subpats(subpats) { } friend ::std::ostream& operator<<(::std::ostream& os, const MacroRuleEnt& x) { os << "MacroRuleEnt("; if(x.name.size()) os << "'"< subpats; enum Type { PAT_TOKEN, PAT_TT, PAT_IDENT, PAT_PATH, PAT_TYPE, PAT_EXPR, PAT_STMT, PAT_BLOCK, PAT_LOOP, // Enables use of subpats } type; MacroPatEnt(): tok(TOK_NULL), type(PAT_TOKEN) { } MacroPatEnt(Token tok): tok(tok), type(PAT_TOKEN) { } MacroPatEnt(::std::string name, Type type): name(name), tok(), type(type) { } MacroPatEnt(Token sep, bool need_once, ::std::vector ents): name( need_once ? "+" : "*" ), tok(sep), subpats( move(ents) ), type(PAT_LOOP) { } friend ::std::ostream& operator<<(::std::ostream& os, const MacroPatEnt& x) { os << "MacroPatEnt("; if(x.name.size()) os << "'"< m_pattern; ::std::vector m_contents; SERIALISABLE_PROTOTYPES(); }; /// A sigle 'macro_rules!' block typedef ::std::vector MacroRules; extern const LList* Macro_GetModule(); extern void Macro_SetModule(const LList& mod); extern ::std::unique_ptr Macro_Invoke(const TokenStream& lex, const ::std::string& name, TokenTree input); #endif // MACROS_HPP_INCLUDED