diff options
author | Araq <rumpf_a@web.de> | 2013-04-30 14:40:54 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2013-04-30 14:40:54 +0200 |
commit | e70cc64e906a0562f1dc6fe64336b04da2c53acd (patch) | |
tree | c1b9c6fbb536c5cda744131e4b9970c36534c462 | |
parent | d64d6a70d40191d8c8f102110213432e60d654e3 (diff) | |
download | Nim-e70cc64e906a0562f1dc6fe64336b04da2c53acd.tar.gz |
proper scoping for 'if'
-rw-r--r-- | compiler/parser.nim | 19 | ||||
-rw-r--r-- | compiler/semexprs.nim | 2 | ||||
-rw-r--r-- | todo.txt | 2 |
3 files changed, 12 insertions, 11 deletions
diff --git a/compiler/parser.nim b/compiler/parser.nim index f9f7f7fad..1aaff3616 100644 --- a/compiler/parser.nim +++ b/compiler/parser.nim @@ -454,10 +454,6 @@ proc complexOrSimpleStmt(p: var TParser): PNode proc simpleExpr(p: var TParser, mode = pmNormal): PNode proc semiStmtList(p: var TParser, result: PNode) = - if p.tok.tokType == tkSemicolon: - # '(;' enforces 'stmt' context: - getTok(p) - optInd(p, result) result.add(complexOrSimpleStmt(p)) while p.tok.tokType == tkSemicolon: getTok(p) @@ -468,7 +464,7 @@ proc semiStmtList(p: var TParser, result: PNode) = proc parsePar(p: var TParser): PNode = #| parKeyw = 'discard' | 'include' | 'if' | 'while' | 'case' | 'try' #| | 'finally' | 'except' | 'for' | 'block' | 'const' | 'let' - #| | 'when' | 'var' | 'bind' | 'mixin' + #| | 'when' | 'var' | 'mixin' #| par = '(' optInd (&parKeyw complexOrSimpleStmt ^+ ';' #| | simpleExpr ('=' expr (';' complexOrSimpleStmt ^+ ';' )? )? #| | (':' expr)? (',' (exprColonEqExpr comma?)*)? )? @@ -481,8 +477,15 @@ proc parsePar(p: var TParser): PNode = optInd(p, result) if p.tok.tokType in {tkDiscard, tkInclude, tkIf, tkWhile, tkCase, tkTry, tkFinally, tkExcept, tkFor, tkBlock, - tkConst, tkLet, tkWhen, tkVar, tkBind, - tkMixin, tkSemicolon}: + tkConst, tkLet, tkWhen, tkVar, + tkMixin}: + # XXX 'bind' used to be an expression, so we exclude it here; + # tests/reject/tbind2 fails otherwise. + semiStmtList(p, result) + elif p.tok.tokType == tkSemicolon: + # '(;' enforces 'stmt' context: + getTok(p) + optInd(p, result) semiStmtList(p, result) elif p.tok.tokType != tkParRi: var a = simpleExpr(p) @@ -1778,7 +1781,7 @@ proc parseStmt(p: var TParser): PNode = if p.tok.indent >= 0: parMessage(p, errInvalidIndentation) result = simpleStmt(p) if result.kind == nkEmpty: parMessage(p, errExprExpected, p.tok) - while p.tok.tokType == tkSemicolon: getTok(p) + #while p.tok.tokType == tkSemicolon: getTok(p) proc parseAll(p: var TParser): PNode = result = newNodeP(nkStmtList, p) diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 9b7318e62..477cc98b4 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -1504,8 +1504,8 @@ proc semIf(c: PContext, n: PNode): PNode = for i in countup(0, sonsLen(n) - 1): var it = n.sons[i] if it.len == 2: - it.sons[0] = forceBool(c, semExprWithType(c, it.sons[0])) openScope(c.tab) + it.sons[0] = forceBool(c, semExprWithType(c, it.sons[0])) it.sons[1] = semExprBranch(c, it.sons[1]) typ = commonType(typ, it.sons[1].typ) closeScope(c.tab) diff --git a/todo.txt b/todo.txt index b827b56cb..46f557dfb 100644 --- a/todo.txt +++ b/todo.txt @@ -8,8 +8,6 @@ version 0.9.2 - CGEN: ``restrict`` pragma + backend support; computed goto support - document NimMain and check whether it works for threading - parser/grammar: - * check that of branches can only receive even simpler expressions, don't - allow 'of (var x = 23; nkIdent)' * document (var x = 12; for i in ... ; x) construct - make use of commonType relation in expressions - further expr/stmt unification: |