From d1d84ced588b40bdec67ee8bdb184a31d3ae9e7d Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 27 Feb 2016 10:06:54 +0800 Subject: Parse/impl - Handle macro invocations --- src/parse/root.cpp | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) (limited to 'src/parse') diff --git a/src/parse/root.cpp b/src/parse/root.cpp index c8fabc01..74d919c9 100644 --- a/src/parse/root.cpp +++ b/src/parse/root.cpp @@ -894,8 +894,18 @@ void Parse_Impl(TokenStream& lex, AST::Module& mod, AST::MetaItems attrs, bool i // A sequence of method implementations while( GET_TOK(tok, lex) != TOK_BRACE_CLOSE ) { - lex.putback(tok); - Parse_Impl_Item(lex, impl); + if( tok.type() == TOK_MACRO ) + { + impl.add_macro_invocation( Parse_MacroInvocation( AST::MetaItems(), mv$(tok.str()), lex ) ); + // - Silently consume ';' after the macro + if( GET_TOK(tok, lex) != TOK_SEMICOLON ) + lex.putback(tok); + } + else + { + lex.putback(tok); + Parse_Impl_Item(lex, impl); + } } mod.add_impl( ::std::move(impl) ); @@ -930,25 +940,6 @@ void Parse_Impl_Item(TokenStream& lex, AST::Impl& impl) ::std::string abi = "rust"; switch(tok.type()) { - //case TOK_MACRO: - // { - // TokenTree tt = Parse_TT(lex, true); - // if( tt.is_token() ) { - // DEBUG("TT was a single token (not a sub-tree)"); - // throw ParseError::Unexpected(lex, tt.tok()); - // } - // - // auto expanded_macro = Macro_Invoke(lex, tok.str().c_str(), tt); - // auto& lex = *expanded_macro; - // while( GET_TOK(tok, lex) != TOK_EOF ) - // { - // lex.putback(tok); - // Parse_Impl_Item(lex, impl); - // } - // } - // if(GET_TOK(tok, lex) != TOK_SEMICOLON) - // lex.putback(tok); - // break; case TOK_RWORD_TYPE: { GET_CHECK_TOK(tok, lex, TOK_IDENT); ::std::string name = tok.str(); -- cgit v1.2.3