diff options
author | John Hodge <tpg@mutabah.net> | 2016-09-25 21:23:07 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-09-25 21:23:07 +0800 |
commit | 36e197f903ba19229b35cdd7c5bea045ca34dcdc (patch) | |
tree | 547ffd0f02cf00ebaba9dd40caf51c809d65cb0e /src/macro_rules | |
parent | adc6e7e42f05724d031c50d6d0092753e87cc79d (diff) | |
download | mrust-36e197f903ba19229b35cdd7c5bea045ca34dcdc.tar.gz |
Parse+AST - Support capturing :item (requires cloning AST items)
Diffstat (limited to 'src/macro_rules')
-rw-r--r-- | src/macro_rules/eval.cpp | 6 | ||||
-rw-r--r-- | src/macro_rules/macro_rules.hpp | 2 |
2 files changed, 5 insertions, 3 deletions
diff --git a/src/macro_rules/eval.cpp b/src/macro_rules/eval.cpp index f850ae95..966c1149 100644 --- a/src/macro_rules/eval.cpp +++ b/src/macro_rules/eval.cpp @@ -13,6 +13,7 @@ #include <limits.h> #include "pattern_checks.hpp" #include <parse/interpolated_fragment.hpp> +#include <ast/expr.hpp> class ParameterMappings { @@ -499,7 +500,7 @@ void Macro_HandlePatternCap(TTStream& lex, unsigned int index, MacroPatEnt::Type bound_tts.insert( index, iterations, InterpolatedFragment( Parse_MetaItem(lex) ) ); break; case MacroPatEnt::PAT_ITEM: - TODO(lex.getPosition(), "Parse :item"); + bound_tts.insert( index, iterations, InterpolatedFragment( Parse_Mod_Item_S(lex, false, "!", lex.parse_state().module->path(), false, AST::MetaItems{}) ) ); break; case MacroPatEnt::PAT_IDENT: GET_CHECK_TOK(tok, lex, TOK_IDENT); @@ -562,7 +563,7 @@ bool Macro_HandlePattern(TTStream& lex, const MacroPatEnt& pat, ::std::vector<un } /// Parse the input TokenTree according to the `macro_rules!` patterns and return a token stream of the replacement -::std::unique_ptr<TokenStream> Macro_InvokeRules(const char *name, const MacroRules& rules, const TokenTree& input) +::std::unique_ptr<TokenStream> Macro_InvokeRules(const char *name, const MacroRules& rules, const TokenTree& input, AST::Module& mod) { TRACE_FUNCTION; Span sp;// = input @@ -579,6 +580,7 @@ bool Macro_HandlePattern(TTStream& lex, const MacroPatEnt& pat, ::std::vector<un unsigned int rule_index; TTStream lex(input); + SET_MODULE(lex, mod); while(true) { // 1. Get concrete patterns for all active rules (i.e. no If* patterns) diff --git a/src/macro_rules/macro_rules.hpp b/src/macro_rules/macro_rules.hpp index 7846f4ba..7f93edf9 100644 --- a/src/macro_rules/macro_rules.hpp +++ b/src/macro_rules/macro_rules.hpp @@ -149,7 +149,7 @@ public: SERIALISABLE_PROTOTYPES();
};
-extern ::std::unique_ptr<TokenStream> Macro_InvokeRules(const char *name, const MacroRules& rules, const TokenTree& input);
+extern ::std::unique_ptr<TokenStream> Macro_InvokeRules(const char *name, const MacroRules& rules, const TokenTree& input, AST::Module& mod);
extern MacroRulesPtr Parse_MacroRules(TokenStream& lex);
#endif // MACROS_HPP_INCLUDED
|