diff options
-rw-r--r-- | compiler/parser.nim | 39 | ||||
-rw-r--r-- | compiler/semstmts.nim | 2 | ||||
-rw-r--r-- | lib/core/macros.nim | 4 |
3 files changed, 24 insertions, 21 deletions
diff --git a/compiler/parser.nim b/compiler/parser.nim index f15449c85..9f1b947f6 100644 --- a/compiler/parser.nim +++ b/compiler/parser.nim @@ -537,7 +537,7 @@ proc parsePar(p: var TParser): PNode = flexComment(p, result) if p.tok.tokType in {tkDiscard, tkInclude, tkIf, tkWhile, tkCase, tkTry, tkDefer, tkFinally, tkExcept, tkFor, tkBlock, - tkConst, tkLet, tkWhen, tkVar, + tkConst, tkLet, tkWhen, tkVar, tkFor, tkMixin}: # XXX 'bind' used to be an expression, so we exclude it here; # tests/reject/tbind2 fails otherwise. @@ -1112,7 +1112,7 @@ proc parseProcExpr(p: var TParser; isExpr: bool; kind: TNodeKind): PNode = proc isExprStart(p: TParser): bool = case p.tok.tokType - of tkSymbol, tkAccent, tkOpr, tkNot, tkNil, tkCast, tkIf, + of tkSymbol, tkAccent, tkOpr, tkNot, tkNil, tkCast, tkIf, tkFor, tkProc, tkFunc, tkIterator, tkBind, tkBuiltInMagics, tkParLe, tkBracketLe, tkCurlyLe, tkIntLit..tkCharLit, tkVar, tkRef, tkPtr, tkTuple, tkObject, tkWhen, tkCase, tkOut: @@ -1152,16 +1152,35 @@ proc parseTypeDescKAux(p: var TParser, kind: TNodeKind, result.addSon list parseSymbolList(p, list) +proc parseFor(p: var TParser): PNode = + #| forStmt = 'for' (identWithPragma ^+ comma) 'in' expr colcom stmt + #| forExpr = forStmt + result = newNodeP(nkForStmt, p) + getTokNoInd(p) + var a = identWithPragma(p) + addSon(result, a) + while p.tok.tokType == tkComma: + getTok(p) + optInd(p, a) + a = identWithPragma(p) + addSon(result, a) + eat(p, tkIn) + addSon(result, parseExpr(p)) + colcom(p, result) + addSon(result, parseStmt(p)) + proc parseExpr(p: var TParser): PNode = #| expr = (blockExpr #| | ifExpr #| | whenExpr #| | caseExpr + #| | forExpr #| | tryExpr) #| / simpleExpr case p.tok.tokType: of tkBlock: result = parseBlock(p) of tkIf: result = parseIfExpr(p, nkIfExpr) + of tkFor: result = parseFor(p) of tkWhen: result = parseIfExpr(p, nkWhenExpr) of tkCase: result = parseCase(p) of tkTry: result = parseTry(p, isExpr=true) @@ -1568,22 +1587,6 @@ proc parseExceptBlock(p: var TParser, kind: TNodeKind): PNode = colcom(p, result) addSon(result, parseStmt(p)) -proc parseFor(p: var TParser): PNode = - #| forStmt = 'for' (identWithPragma ^+ comma) 'in' expr colcom stmt - result = newNodeP(nkForStmt, p) - getTokNoInd(p) - var a = identWithPragma(p) - addSon(result, a) - while p.tok.tokType == tkComma: - getTok(p) - optInd(p, a) - a = identWithPragma(p) - addSon(result, a) - eat(p, tkIn) - addSon(result, parseExpr(p)) - colcom(p, result) - addSon(result, parseStmt(p)) - proc parseBlock(p: var TParser): PNode = #| blockStmt = 'block' symbol? colcom stmt #| blockExpr = 'block' symbol? colcom stmt diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index fb01127fc..9a218f225 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -601,7 +601,7 @@ proc semForVars(c: PContext, n: PNode): PNode = addForVarDecl(c, v) inc(c.p.nestedLoopCounter) openScope(c) - n.sons[length-1] = semStmt(c, n.sons[length-1]) + n.sons[length-1] = semExprBranch(c, n.sons[length-1]) closeScope(c) dec(c.p.nestedLoopCounter) diff --git a/lib/core/macros.nim b/lib/core/macros.nim index 4d76d60c2..aec766068 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -240,7 +240,7 @@ else: # bootstrapping substitute when defined(nimHasSymOwnerInMacro): proc owner*(sym: NimNode): NimNode {.magic: "SymOwner", noSideEffect.} ## accepts node of kind nnkSym and returns its owner's symbol. - ## result is also mnde of kind nnkSym if owner exists otherwise + ## result is also mnde of kind nnkSym if owner exists otherwise ## nnkNilLit is returned proc getType*(n: NimNode): NimNode {.magic: "NGetType", noSideEffect.} @@ -977,7 +977,7 @@ proc newIfStmt*(branches: varargs[tuple[cond, body: NimNode]]): ## result = newNimNode(nnkIfStmt) for i in branches: - result.add(newNimNode(nnkElifBranch).add(i.cond, i.body)) + result.add(newTree(nnkElifBranch, i.cond, i.body)) proc newEnum*(name: NimNode, fields: openArray[NimNode], public, pure: bool): NimNode {.compileTime.} = |