mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-24 03:46:50 +00:00
proper scoping for 'if'
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
2
todo.txt
2
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:
|
||||
|
||||
Reference in New Issue
Block a user