diff options
author | John Hodge <tpg@ucc.asn.au> | 2017-05-15 12:14:05 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2017-05-15 12:14:05 +0800 |
commit | 9e2a6a73c9cb629e1143691885e48eb9b0fb2119 (patch) | |
tree | b44956d20363cce58c376b977ae013a78ee299e4 /src | |
parent | 53095a15c500b5bb216727a86f21cd7fc9530e3f (diff) | |
download | mrust-9e2a6a73c9cb629e1143691885e48eb9b0fb2119.tar.gz |
Parse - Handle `Struct { var }` initialisation
Diffstat (limited to 'src')
-rw-r--r-- | src/parse/expr.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/parse/expr.cpp b/src/parse/expr.cpp index 27d122ce..ab863600 100644 --- a/src/parse/expr.cpp +++ b/src/parse/expr.cpp @@ -999,9 +999,18 @@ ExprNodeP Parse_ExprVal_StructLiteral(TokenStream& lex, AST::Path path) while( GET_TOK(tok, lex) == TOK_IDENT ) { auto name = mv$(tok.str()); - GET_CHECK_TOK(tok, lex, TOK_COLON); - ExprNodeP val = Parse_Stmt(lex); - items.push_back( ::std::make_pair(::std::move(name), ::std::move(val)) ); + + if( lex.lookahead(0) != TOK_COLON ) + { + ExprNodeP val = NEWNODE( AST::ExprNode_NamedValue, ::AST::Path(name) ); + items.push_back( ::std::make_pair(::std::move(name), ::std::move(val)) ); + } + else + { + GET_CHECK_TOK(tok, lex, TOK_COLON); + ExprNodeP val = Parse_Stmt(lex); + items.push_back( ::std::make_pair(::std::move(name), ::std::move(val)) ); + } if( GET_TOK(tok,lex) == TOK_BRACE_CLOSE ) break; |