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
commit def1f99289
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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{=} 'of' exprList ':' stmt
#| | IND{=} 'elif' expr ':' stmt #| | IND{=} 'elif' expr ':' stmt
#| | IND{=} 'except' exprList ':' stmt #| | IND{=} 'except' exprList ':' stmt
#| | IND{=} 'finally' ':' stmt
#| | IND{=} 'else' ':' stmt )* #| | IND{=} 'else' ':' stmt )*
result = x result = x
if p.tok.indent >= 0: return if p.tok.indent >= 0: return
@ -1362,6 +1363,9 @@ proc postExprBlocks(p: var Parser, x: PNode): PNode =
of tkExcept: of tkExcept:
nextBlock = newNodeP(nkExceptBranch, p) nextBlock = newNodeP(nkExceptBranch, p)
exprList(p, tkColon, nextBlock) exprList(p, tkColon, nextBlock)
of tkFinally:
nextBlock = newNodeP(nkFinally, p)
getTok(p)
of tkElse: of tkElse:
nextBlock = newNodeP(nkElse, p) nextBlock = newNodeP(nkElse, p)
getTok(p) getTok(p)
@ -1372,7 +1376,7 @@ proc postExprBlocks(p: var Parser, x: PNode): PNode =
nextBlock.flags.incl nfBlockArg nextBlock.flags.incl nfBlockArg
result.add nextBlock result.add nextBlock
if nextBlock.kind == nkElse: break if nextBlock.kind in {nkElse, nkFinally}: break
else: else:
if openingParams.kind != nkEmpty: if openingParams.kind != nkEmpty:
parMessage(p, "expected ':'") parMessage(p, "expected ':'")

View file

@ -406,6 +406,98 @@ StmtList
DiscardStmt DiscardStmt
Empty Empty
IntLit 0 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: foo380.add((quote do:
discard discard
)[0]) )[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