the new blocks without 'do' produce compatible AST with 'do blocks'

This commit is contained in:
Zahary Karadjov 2017-04-09 23:43:29 +03:00
commit 34b2527441
2 changed files with 10 additions and 12 deletions

View file

@ -1172,7 +1172,7 @@ proc parseMacroColon(p: var TParser, x: PNode): PNode =
result = makeCall(result)
getTok(p)
skipComment(p, result)
let stmtList = newNodeP(nkStmtList, p)
var stmtList = newNodeP(nkStmtList, p)
if p.tok.tokType notin {tkOf, tkElif, tkElse, tkExcept}:
let body = parseStmt(p)
stmtList.add body
@ -1202,9 +1202,9 @@ proc parseMacroColon(p: var TParser, x: PNode): PNode =
if b.kind == nkElse: break
if stmtList.len == 1 and stmtList[0].kind == nkStmtList:
# to keep backwards compatibility (see tests/vm/tstringnil)
result.add stmtList[0]
else:
result.add stmtList
stmtList = stmtList[0]
result.add newProcNode(nkDo, stmtList.info, stmtList,
params = emptyNode, pragmas = emptyNode)
proc parseExprStmt(p: var TParser): PNode =
#| exprStmt = simpleExpr

View file

@ -1,8 +1,10 @@
discard """
output: '''
click at 10,20
lost focus 1
lost focus 2
registered handler for UserEvent 1
registered handler for UserEvent 2
registered handler for UserEvent 3'''
"""
@ -27,10 +29,8 @@ var b = Button()
b.onClick do (e: Event):
echo "click at ", e.x, ",", e.y
when false:
# this syntax doesn't work yet
b.onFocusLost:
echo "lost focus 1"
b.onFocusLost:
echo "lost focus 1"
b.onFocusLost do:
echo "lost focus 2"
@ -38,10 +38,8 @@ b.onFocusLost do:
b.onUserEvent("UserEvent 1") do:
discard
when false:
# this syntax doesn't work yet
b.onUserEvent("UserEvent 2"):
discard
b.onUserEvent("UserEvent 2"):
discard
b.onUserEvent("UserEvent 3", () => echo "event 2")