skip semicolon in stmtlist expr parsing (#24855)

Previously it would try to parse the semicolon as its own statement and
produce an `nkEmpty` node

Also more than 1 semicolon in an expression list i.e. `(a;; b)` gives an
"expression expected" error in `semiStmtList` when multiple semicolons
are allowed in normal statements, this could be fixed by changing the
`if tok.kind == tokSemicolon` check to a `while` but it does not match
the grammar so not done here.
This commit is contained in:
metagn
2025-04-11 04:29:20 +03:00
committed by GitHub
parent 51166ab382
commit 918f972369
2 changed files with 25 additions and 0 deletions

View File

@@ -699,10 +699,12 @@ proc parsePar(p: var Parser): PNode =
asgn.add b
result.add(asgn)
if p.tok.tokType == tkSemiColon:
getTok(p)
semiStmtList(p, result)
elif p.tok.tokType == tkSemiColon:
# stmt context:
result.add(a)
getTok(p)
semiStmtList(p, result)
else:
a = colonOrEquals(p, a)

View File

@@ -0,0 +1,23 @@
discard """
nimout: '''
StmtList
ReturnStmt
StmtListExpr
Call
DotExpr
Ident "x"
Ident "add"
StrLit "123"
Call
DotExpr
Ident "x"
Ident "add"
StrLit "123"
Ident "x"
'''
"""
import std/macros
dumpTree:
return (x.add("123"); x.add("123"); x)