diff options
author | Zahary Karadjov <zahary@gmail.com> | 2017-04-10 12:08:36 +0300 |
---|---|---|
committer | Zahary Karadjov <zahary@gmail.com> | 2017-04-10 12:08:40 +0300 |
commit | e7eb01ed4887ffb15a308b3599461ba42f4d7f8a (patch) | |
tree | 4e9454364fb63e9de2ddc085cd366681bfea957e | |
parent | 9ffaee3f8803a6fce35bf784c8870ea238747e13 (diff) | |
download | Nim-e7eb01ed4887ffb15a308b3599461ba42f4d7f8a.tar.gz |
fix a parsing regression (calls with do inside param lists)
This treatment is applied only when "do" is used, because the code foo(x: bar) is recognized as object construction.
-rw-r--r-- | compiler/parser.nim | 7 | ||||
-rw-r--r-- | tests/parser/tpostexprblocks.nim | 19 |
2 files changed, 24 insertions, 2 deletions
diff --git a/compiler/parser.nim b/compiler/parser.nim index 110f4a43d..d549e1358 100644 --- a/compiler/parser.nim +++ b/compiler/parser.nim @@ -67,6 +67,7 @@ proc parseTry(p: var TParser; isExpr: bool): PNode proc parseCase(p: var TParser): PNode proc parseStmtPragma(p: var TParser): PNode proc parsePragma(p: var TParser): PNode +proc postExprBlocks(p: var TParser, x: PNode): PNode # implementation proc getTok(p: var TParser) = @@ -364,7 +365,10 @@ proc colonOrEquals(p: var TParser, a: PNode): PNode = proc exprColonEqExpr(p: var TParser): PNode = #| exprColonEqExpr = expr (':'|'=' expr)? var a = parseExpr(p) - result = colonOrEquals(p, a) + if p.tok.tokType == tkDo: + result = postExprBlocks(p, a) + else: + result = colonOrEquals(p, a) proc exprList(p: var TParser, endTok: TTokType, result: PNode) = #| exprList = expr ^+ comma @@ -668,7 +672,6 @@ proc namedParams(p: var TParser, callee: PNode, # progress guaranteed exprColonEqExprListAux(p, endTok, result) -proc postExprBlocks(p: var TParser, x: PNode): PNode proc primarySuffix(p: var TParser, r: PNode, baseIndent: int): PNode = #| primarySuffix = '(' (exprColonEqExpr comma?)* ')' doBlocks? #| | doBlocks diff --git a/tests/parser/tpostexprblocks.nim b/tests/parser/tpostexprblocks.nim index 785ecdd89..b7f97785b 100644 --- a/tests/parser/tpostexprblocks.nim +++ b/tests/parser/tpostexprblocks.nim @@ -211,6 +211,18 @@ StmtList StmtList DiscardStmt Empty + Call + Ident !"foo" + Ident !"x" + Call + Ident !"bar" + StmtList + DiscardStmt + Empty + Else + StmtList + DiscardStmt + Empty VarSection IdentDefs Ident !"a" @@ -432,6 +444,13 @@ dumpTree: else: discard + # call with blocks as a param + foo(x, bar do: + discard + else: + discard + ) + # introduce a variable var a = foo var a = foo() |