fixes #21144; try expression will not match the less indent except
This commit is contained in:
parent
81d8ea95af
commit
d0721eadf8
2 changed files with 30 additions and 1 deletions
|
|
@ -1770,11 +1770,13 @@ proc parseTry(p: var Parser; isExpr: bool): PNode =
|
||||||
#| (optInd 'except' optionalExprList colcom stmt)*
|
#| (optInd 'except' optionalExprList colcom stmt)*
|
||||||
#| (optInd 'finally' colcom stmt)?
|
#| (optInd 'finally' colcom stmt)?
|
||||||
result = newNodeP(nkTryStmt, p)
|
result = newNodeP(nkTryStmt, p)
|
||||||
|
let parentIndent = p.currInd # isExpr
|
||||||
getTok(p)
|
getTok(p)
|
||||||
colcom(p, result)
|
colcom(p, result)
|
||||||
result.add(parseStmt(p))
|
result.add(parseStmt(p))
|
||||||
var b: PNode = nil
|
var b: PNode = nil
|
||||||
while sameOrNoInd(p) or isExpr:
|
|
||||||
|
while sameOrNoInd(p) or (isExpr and parentIndent <= p.tok.indent):
|
||||||
case p.tok.tokType
|
case p.tok.tokType
|
||||||
of tkExcept:
|
of tkExcept:
|
||||||
b = newNodeP(nkExceptBranch, p)
|
b = newNodeP(nkExceptBranch, p)
|
||||||
|
|
|
||||||
27
tests/parser/ttry.nim
Normal file
27
tests/parser/ttry.nim
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
# bug #21144
|
||||||
|
block:
|
||||||
|
try:
|
||||||
|
let c = try:
|
||||||
|
10
|
||||||
|
except ValueError as exc:
|
||||||
|
10
|
||||||
|
except ValueError as exc:
|
||||||
|
discard
|
||||||
|
|
||||||
|
if true:
|
||||||
|
block:
|
||||||
|
let c = try:
|
||||||
|
10
|
||||||
|
except ValueError as exc:
|
||||||
|
10
|
||||||
|
except OSError:
|
||||||
|
99
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
let c = try:
|
||||||
|
10
|
||||||
|
except ValueError as exc:
|
||||||
|
10
|
||||||
|
except ValueError as exc:
|
||||||
|
discard
|
||||||
Loading…
Add table
Add a link
Reference in a new issue