Parser: Make exprList() not comsume endToken

This makes use single comcol or eat for multiple cases. Also this makes
exprList responsible for consuming only list of expressions, nothing else which
is more logical.

As a side-effect compiler is now more consistent about errors, eg.:

    try # <- missing something
      echo "try"
    finally:
      echo "finally"

Triggers: test.nim(2, 6) Error: ':' expected

    try:
      echo "try"
    finally # <- missing something
      echo "finally"

Previously triggered: test.nim(4, 6) Error: invalid indentation

But now we got: Error: ':' expected - same as in 1st case
This commit is contained in:
Adam Strzelecki
2015-04-14 21:24:35 +02:00
parent 8a6df889d0
commit 0da4d6b755

View File

@@ -389,7 +389,6 @@ proc exprList(p: var TParser, endTok: TTokType, result: PNode) =
if p.tok.tokType != tkComma: break
getTok(p)
optInd(p, a)
eat(p, endTok)
proc dotExpr(p: var TParser, a: PNode): PNode =
#| dotExpr = expr '.' optInd symbol
@@ -1155,16 +1154,14 @@ proc parseMacroColon(p: var TParser, x: PNode): PNode =
getTok(p)
optInd(p, b)
addSon(b, parseExpr(p))
eat(p, tkColon)
of tkExcept:
b = newNodeP(nkExceptBranch, p)
exprList(p, tkColon, b)
skipComment(p, b)
of tkElse:
b = newNodeP(nkElse, p)
getTok(p)
eat(p, tkColon)
else: break
eat(p, tkColon)
addSon(b, parseStmt(p))
addSon(stmtList, b)
if b.kind == nkElse: break
@@ -1373,13 +1370,11 @@ proc parseCase(p: var TParser): PNode =
getTok(p)
optInd(p, b)
addSon(b, parseExpr(p))
eat(p, tkColon)
of tkElse:
b = newNodeP(nkElse, p)
getTok(p)
eat(p, tkColon)
else: break
skipComment(p, b)
colcom(p, b)
addSon(b, parseStmt(p))
addSon(result, b)
if b.kind == nkElse: break
@@ -1406,10 +1401,9 @@ proc parseTry(p: var TParser; isExpr: bool): PNode =
exprList(p, tkColon, b)
of tkFinally:
b = newNodeP(nkFinally, p)
getTokNoInd(p)
eat(p, tkColon)
getTok(p)
else: break
skipComment(p, b)
colcom(p, b)
addSon(b, parseStmt(p))
addSon(result, b)
if b.kind == nkFinally: break
@@ -1418,7 +1412,7 @@ proc parseTry(p: var TParser; isExpr: bool): PNode =
proc parseExceptBlock(p: var TParser, kind: TNodeKind): PNode =
#| exceptBlock = 'except' colcom stmt
result = newNodeP(kind, p)
getTokNoInd(p)
getTok(p)
colcom(p, result)
addSon(result, parseStmt(p))
@@ -1451,7 +1445,7 @@ proc parseStaticOrDefer(p: var TParser; k: TNodeKind): PNode =
#| staticStmt = 'static' colcom stmt
#| deferStmt = 'defer' colcom stmt
result = newNodeP(k, p)
getTokNoInd(p)
getTok(p)
colcom(p, result)
addSon(result, parseStmt(p))
@@ -1690,9 +1684,8 @@ proc parseObjectCase(p: var TParser): PNode =
of tkElse:
b = newNodeP(nkElse, p)
getTok(p)
eat(p, tkColon)
else: break
skipComment(p, b)
colcom(p, b)
var fields = parseObjectPart(p)
if fields.kind == nkEmpty:
parMessage(p, errIdentifierExpected, p.tok)