summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2020-10-02 18:26:52 +0200
committerGitHub <noreply@github.com>2020-10-02 18:26:52 +0200
commit7d8c1be8fb1ba96dd16c40df990d4c2639515173 (patch)
tree76371d25220639845cb13b5535646dbca3ba1af3
parent1f4b9cebd4a073024f68e70156be1d8ceab7344f (diff)
downloadNim-7d8c1be8fb1ba96dd16c40df990d4c2639515173.tar.gz
parser hotfix: don't run into endless loops; regression (#15468)
-rw-r--r--compiler/parser.nim20
1 files changed, 16 insertions, 4 deletions
diff --git a/compiler/parser.nim b/compiler/parser.nim
index 17dd092a4..1ec708057 100644
--- a/compiler/parser.nim
+++ b/compiler/parser.nim
@@ -529,15 +529,21 @@ proc semiStmtList(p: var Parser, result: PNode) =
   inc p.inSemiStmtList
   withInd(p):
     # Be lenient with the first stmt/expr
-    result.add if p.tok.tokType == tkIf: parseIfExpr(p, nkIfStmt) else: complexOrSimpleStmt(p)
-    while true:
+    let a = if p.tok.tokType == tkIf: parseIfExpr(p, nkIfStmt) else: complexOrSimpleStmt(p)
+    result.add a
+
+    while p.tok.tokType != tkEof:
       if p.tok.tokType == tkSemiColon:
         getTok(p)
       if p.tok.tokType == tkParRi:
         break
       elif not (sameInd(p) or realInd(p)):
         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
   result.transitionSonsKind(nkStmtListExpr)
 
@@ -2244,7 +2250,13 @@ proc parseStmt(p: var Parser): PNode =
         if p.tok.tokType in {tkElse, tkElif}:
           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
   else:
     # the case statement is only needed for better error messages: