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
commit 0da4d6b755

View file

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