summaryrefslogtreecommitdiff
path: root/src/parse
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-09-25 23:09:17 +0800
committerJohn Hodge <tpg@mutabah.net>2016-09-25 23:09:17 +0800
commit6c16703e6a3be274c4fe183ffde10fd7a20f8236 (patch)
tree8a9b0ad911f73b9e2f6357fa6534e4583165dd40 /src/parse
parent72e2a322f52edd7bf3f37ad840f2d48be4192d62 (diff)
downloadmrust-6c16703e6a3be274c4fe183ffde10fd7a20f8236.tar.gz
AST - Convert use statements to normal items
Diffstat (limited to 'src/parse')
-rw-r--r--src/parse/root.cpp33
1 files changed, 25 insertions, 8 deletions
diff --git a/src/parse/root.cpp b/src/parse/root.cpp
index 1b6bf15a..3a942b6c 100644
--- a/src/parse/root.cpp
+++ b/src/parse/root.cpp
@@ -1300,7 +1300,22 @@ void Parse_Use(TokenStream& lex, ::std::function<void(AST::UseStmt, ::std::strin
switch( GET_TOK(tok, lex) )
{
case TOK_RWORD_USE:
+ #if 0
TODO(lex.getPosition(), "Encode a single use statement as a single Item");
+ #else
+ // NOTE: The only problem here is with things like `use foo::{a, b, c}` - all others are a single statement.
+ // - These are caught by the condition in the closure
+ Parse_Use(lex, [&](AST::UseStmt p, std::string s) {
+ DEBUG(mod_path << " - use " << p << " as '" << s << "'");
+ if( !item_data.is_None() )
+ TODO(lex.getPosition(), "Encode multi-item use statements as a single Item");
+ item_data = ::AST::Item(mv$(p));
+ item_name = mv$(s);
+ });
+ assert( !item_data.is_None() );
+ GET_CHECK_TOK(tok, lex, TOK_SEMICOLON);
+ break;
+ #endif
case TOK_RWORD_EXTERN:
switch( GET_TOK(tok, lex) )
@@ -1639,6 +1654,7 @@ void Parse_Mod_Item(TokenStream& lex, AST::Module& mod, AST::MetaItems meta_item
});
GET_CHECK_TOK(tok, lex, TOK_SEMICOLON);
}
+ //else if( LOOKAHEAD2(lex, TOK_RWORD_EXTERN, TOK_BRACE_OPEN) || LOOKAHEAD3(lex, TOK_RWORD_EXTERN, TOK_STRING, TOK_BRACE_OPEN) )
else if( lex.lookahead(0) == TOK_RWORD_EXTERN && ( (lex.lookahead(1) == TOK_STRING && lex.lookahead(2) == TOK_BRACE_OPEN) || lex.lookahead(1) == TOK_BRACE_OPEN ) )
{
// `extern "<ABI>" { ...`
@@ -1652,17 +1668,18 @@ void Parse_Mod_Item(TokenStream& lex, AST::Module& mod, AST::MetaItems meta_item
Parse_ExternBlock(lex, mod, mv$(abi), mv$(meta_items));
}
+ // `unsafe impl`
// TODO: Move these two into Parse_Mod_Item_S
- else if( lex.lookahead(0) == TOK_RWORD_UNSAFE && lex.lookahead(1) == TOK_RWORD_IMPL )
- {
- GET_CHECK_TOK(tok, lex, TOK_RWORD_UNSAFE);
- GET_CHECK_TOK(tok, lex, TOK_RWORD_IMPL);
- Parse_Impl(lex, mod, mv$(meta_items), true);
- }
- else if( lex.lookahead(0) == TOK_RWORD_IMPL )
+ //else if( LOOKAHEAD1(lex, TOK_RWORD_IMPL) || LOOKAHEAD2(lex, TOK_RWORD_UNSAFE, TOK_RWORD_IMPL) )
+ else if( lex.lookahead(0) == TOK_RWORD_IMPL || (lex.lookahead(0) == TOK_RWORD_UNSAFE && lex.lookahead(1) == TOK_RWORD_IMPL) )
{
+ bool is_unsafe = false;
+ if( lex.lookahead(0) == TOK_RWORD_UNSAFE ) {
+ GET_CHECK_TOK(tok, lex, TOK_RWORD_UNSAFE);
+ is_unsafe = true;
+ }
GET_CHECK_TOK(tok, lex, TOK_RWORD_IMPL);
- Parse_Impl(lex, mod, mv$(meta_items), true);
+ Parse_Impl(lex, mod, mv$(meta_items), is_unsafe);
}
else
{