add finally as post expr block [backport:1.4] (#16896)

This commit is contained in:
hlaaftana
2021-02-01 22:14:20 +03:00
committed by GitHub
parent 91ace2188a
commit def1f99289
2 changed files with 120 additions and 1 deletions

View File

@@ -1308,6 +1308,7 @@ proc postExprBlocks(p: var Parser, x: PNode): PNode =
#| | IND{=} 'of' exprList ':' stmt
#| | IND{=} 'elif' expr ':' stmt
#| | IND{=} 'except' exprList ':' stmt
#| | IND{=} 'finally' ':' stmt
#| | IND{=} 'else' ':' stmt )*
result = x
if p.tok.indent >= 0: return
@@ -1362,6 +1363,9 @@ proc postExprBlocks(p: var Parser, x: PNode): PNode =
of tkExcept:
nextBlock = newNodeP(nkExceptBranch, p)
exprList(p, tkColon, nextBlock)
of tkFinally:
nextBlock = newNodeP(nkFinally, p)
getTok(p)
of tkElse:
nextBlock = newNodeP(nkElse, p)
getTok(p)
@@ -1372,7 +1376,7 @@ proc postExprBlocks(p: var Parser, x: PNode): PNode =
nextBlock.flags.incl nfBlockArg
result.add nextBlock
if nextBlock.kind == nkElse: break
if nextBlock.kind in {nkElse, nkFinally}: break
else:
if openingParams.kind != nkEmpty:
parMessage(p, "expected ':'")

View File

@@ -406,6 +406,98 @@ StmtList
DiscardStmt
Empty
IntLit 0
Command
Ident "foo390"
Call
Ident "x"
Do
Empty
Empty
Empty
FormalParams
Empty
IdentDefs
Ident "y"
Empty
Empty
Empty
Empty
StmtList
DiscardStmt
Empty
Do
Empty
Empty
Empty
FormalParams
Ident "int"
IdentDefs
Ident "z"
Empty
Empty
Empty
Empty
StmtList
DiscardStmt
Empty
Do
Empty
Empty
Empty
FormalParams
Ident "int"
IdentDefs
Ident "w"
Ident "int"
Empty
Empty
Empty
StmtList
DiscardStmt
Empty
StmtList
DiscardStmt
Empty
OfBranch
Ident "a"
StmtList
DiscardStmt
Empty
OfBranch
Par
Ident "a"
Ident "b"
StmtList
DiscardStmt
Empty
ElifBranch
Ident "a"
StmtList
DiscardStmt
Empty
ElifBranch
Par
Ident "a"
Ident "b"
StmtList
DiscardStmt
Empty
ExceptBranch
Ident "a"
StmtList
DiscardStmt
Empty
ExceptBranch
Par
Ident "a"
Ident "b"
StmtList
DiscardStmt
Empty
Finally
StmtList
DiscardStmt
Empty
'''
"""
@@ -540,3 +632,26 @@ dumpTree:
foo380.add((quote do:
discard
)[0])
foo390 x do (y):
discard
do (z) -> int:
discard
do (w: int) -> int:
discard
do:
discard
of a:
discard
of (a, b):
discard
elif a:
discard
elif (a, b):
discard
except a:
discard
except (a, b):
discard
finally:
discard