From a55a69d69c8159c83fedbac97dcff682cd9cf8a7 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Mon, 26 Sep 2016 14:47:25 +0800 Subject: Parse - Fix bugs with :stmt capture and use --- src/parse/expr.cpp | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) (limited to 'src/parse') diff --git a/src/parse/expr.cpp b/src/parse/expr.cpp index c632ed55..9d7748eb 100644 --- a/src/parse/expr.cpp +++ b/src/parse/expr.cpp @@ -27,6 +27,7 @@ static inline ExprNodeP mk_exprnodep(const TokenStream& lex, AST::ExprNode* en){ //ExprNodeP Parse_ExprBlockLine(TokenStream& lex, bool *add_silence); ExprNodeP Parse_ExprBlockLine_Stmt(TokenStream& lex, bool *add_silence); //ExprNodeP Parse_Stmt(TokenStream& lex); // common.hpp +ExprNodeP Parse_Stmt_Let(TokenStream& lex); ExprNodeP Parse_Expr0(TokenStream& lex); ExprNodeP Parse_IfStmt(TokenStream& lex); ExprNodeP Parse_WhileStmt(TokenStream& lex, ::std::string lifetime); @@ -177,19 +178,10 @@ ExprNodeP Parse_ExprBlockLine(TokenStream& lex, bool *add_silence) return NEWNODE(AST::ExprNode_Tuple, ::std::vector()); // let binding - case TOK_RWORD_LET: { - AST::Pattern pat = Parse_Pattern(lex, false); // irrefutable - TypeRef type; - if( GET_TOK(tok, lex) == TOK_COLON ) { - type = Parse_Type(lex); - GET_TOK(tok, lex); - } - ExprNodeP val; - if( tok.type() == TOK_EQUAL ) { - val = Parse_Expr0(lex); - } - return NEWNODE( AST::ExprNode_LetBinding, ::std::move(pat), ::std::move(type), ::std::move(val) ); - } + case TOK_RWORD_LET: + ret = Parse_Stmt_Let(lex); + GET_CHECK_TOK(tok, lex, TOK_SEMICOLON); + return ret; // Blocks that don't need semicolons // NOTE: If these are followed by a small set of tokens (`.` and `?`) then they are actually the start of an expression @@ -432,6 +424,11 @@ ExprNodeP Parse_Stmt(TokenStream& lex) switch(GET_TOK(tok, lex)) { + case TOK_INTERPOLATED_STMT: + return tok.take_frag_node(); + // Duplicated here for the :stmt pattern fragment. + case TOK_RWORD_LET: + return Parse_Stmt_Let(lex); case TOK_RWORD_RETURN: { ExprNodeP val; switch(LOOK_AHEAD(lex)) @@ -491,6 +488,25 @@ ExprNodeP Parse_Stmt(TokenStream& lex) } } +ExprNodeP Parse_Stmt_Let(TokenStream& lex) +{ + Token tok; + AST::Pattern pat = Parse_Pattern(lex, false); // irrefutable + TypeRef type; + if( GET_TOK(tok, lex) == TOK_COLON ) { + type = Parse_Type(lex); + GET_TOK(tok, lex); + } + ExprNodeP val; + if( tok.type() == TOK_EQUAL ) { + val = Parse_Expr0(lex); + } + else { + PUTBACK(tok, lex); + } + return NEWNODE( AST::ExprNode_LetBinding, ::std::move(pat), ::std::move(type), ::std::move(val) ); +} + ::std::vector Parse_ParenList(TokenStream& lex) { TRACE_FUNCTION; -- cgit v1.2.3