mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-21 23:05:27 +00:00
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:
@@ -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)
|
||||
|
||||
23
tests/parser/tstmtlistexprempty.nim
Normal file
23
tests/parser/tstmtlistexprempty.nim
Normal 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)
|
||||
Reference in New Issue
Block a user