parser hotfix: don't run into endless loops; regression (#15468)

This commit is contained in:
Andreas Rumpf 2020-10-02 18:26:52 +02:00 • committed by GitHub
commit 7d8c1be8fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -529,15 +529,21 @@ proc semiStmtList(p: var Parser, result: PNode) =
inc p.inSemiStmtList inc p.inSemiStmtList
withInd(p): withInd(p):
# Be lenient with the first stmt/expr # Be lenient with the first stmt/expr
result.add if p.tok.tokType == tkIf: parseIfExpr(p, nkIfStmt) else: complexOrSimpleStmt(p) let a = if p.tok.tokType == tkIf: parseIfExpr(p, nkIfStmt) else: complexOrSimpleStmt(p)
while true: result.add a
while p.tok.tokType != tkEof:
if p.tok.tokType == tkSemiColon: if p.tok.tokType == tkSemiColon:
getTok(p) getTok(p)
if p.tok.tokType == tkParRi: if p.tok.tokType == tkParRi:
break break
elif not (sameInd(p) or realInd(p)): elif not (sameInd(p) or realInd(p)):
parMessage(p, errInvalidIndentation) parMessage(p, errInvalidIndentation)
result.add complexOrSimpleStmt(p) let a = complexOrSimpleStmt(p)
if a.kind == nkEmpty:
parMessage(p, errExprExpected, p.tok)
else:
result.add a
dec p.inSemiStmtList dec p.inSemiStmtList
result.transitionSonsKind(nkStmtListExpr) result.transitionSonsKind(nkStmtListExpr)
@ -2244,7 +2250,13 @@ proc parseStmt(p: var Parser): PNode =
if p.tok.tokType in {tkElse, tkElif}: if p.tok.tokType in {tkElse, tkElif}:
break # Allow this too, see tests/parser/tifexprs break # Allow this too, see tests/parser/tifexprs
result.add complexOrSimpleStmt(p) let a = complexOrSimpleStmt(p)
if a.kind == nkEmpty and not p.hasProgress:
parMessage(p, errExprExpected, p.tok)
break
else:
result.add a
if not p.hasProgress and p.tok.tokType == tkEof: break if not p.hasProgress and p.tok.tokType == tkEof: break
else: else:
# the case statement is only needed for better error messages: # the case statement is only needed for better error messages: