syntax compatibility between do blocks and stmt blocks
See the section `do notation` in the manual for more info. * nkMacroStmt has been removed Macro statements are now mapped to regular nkCall nodes. The support for additional clauses (such as else, except, of, etc) have been restored - they will now appear as additional arguments for the nkCall node (as nkElse, nkExcept, etc nodes) * fixed some regressions in the `is` operator and semCompiles
This commit is contained in:
parent
a6d5707faf
commit
d9d82fb0af
21 changed files with 142 additions and 168 deletions
|
|
@ -693,20 +693,15 @@ proc optPragmas(p: var TParser): PNode =
|
|||
else: result = ast.emptyNode
|
||||
|
||||
proc parseDoBlock(p: var TParser): PNode =
|
||||
var info = parLineInfo(p)
|
||||
let info = parLineInfo(p)
|
||||
getTok(p)
|
||||
var params = parseParamList(p, retColon=false)
|
||||
var pragmas = optPragmas(p)
|
||||
let params = parseParamList(p, retColon=false)
|
||||
let pragmas = optPragmas(p)
|
||||
eat(p, tkColon)
|
||||
result = newNodeI(nkDo, info)
|
||||
addSon(result, ast.emptyNode) # no name part
|
||||
addSon(result, ast.emptyNode) # no pattern part
|
||||
addSon(result, ast.emptyNode) # no generic parameters
|
||||
addSon(result, params)
|
||||
addSon(result, pragmas)
|
||||
skipComment(p, result)
|
||||
addSon(result, ast.emptyNode) # no exception list
|
||||
addSon(result, parseStmt(p))
|
||||
result = newProcNode(nkDo, info, parseStmt(p),
|
||||
params = params,
|
||||
pragmas = pragmas)
|
||||
|
||||
proc parseDoBlocks(p: var TParser, call: PNode) =
|
||||
while p.tok.tokType == tkDo:
|
||||
|
|
@ -723,16 +718,11 @@ proc parseProcExpr(p: var TParser, isExpr: bool): PNode =
|
|||
params = parseParamList(p)
|
||||
pragmas = optPragmas(p)
|
||||
if p.tok.tokType == tkEquals and isExpr:
|
||||
result = newNodeI(nkLambda, info)
|
||||
addSon(result, ast.emptyNode) # no name part
|
||||
addSon(result, ast.emptyNode) # no pattern
|
||||
addSon(result, ast.emptyNode) # no generic parameters
|
||||
addSon(result, params)
|
||||
addSon(result, pragmas)
|
||||
getTok(p)
|
||||
skipComment(p, result)
|
||||
addSon(result, ast.emptyNode) # no exception list
|
||||
addSon(result, parseStmt(p))
|
||||
result = newProcNode(nkLambda, info, parseStmt(p),
|
||||
params = params,
|
||||
pragmas = pragmas)
|
||||
else:
|
||||
result = newNodeI(nkProcTy, info)
|
||||
if hasSignature:
|
||||
|
|
@ -822,7 +812,7 @@ proc primary(p: var TParser, skipSuffix = false): PNode =
|
|||
proc parseTypeDesc(p: var TParser): PNode =
|
||||
if p.tok.toktype == tkProc: result = parseProcExpr(p, false)
|
||||
else: result = parseExpr(p)
|
||||
|
||||
|
||||
proc parseExprStmt(p: var TParser): PNode =
|
||||
var a = lowestExpr(p)
|
||||
if p.tok.tokType == tkEquals:
|
||||
|
|
@ -832,32 +822,29 @@ proc parseExprStmt(p: var TParser): PNode =
|
|||
result = newNodeI(nkAsgn, a.info)
|
||||
addSon(result, a)
|
||||
addSon(result, b)
|
||||
else:
|
||||
result = newNodeP(nkCommand, p)
|
||||
result.info = a.info
|
||||
addSon(result, a)
|
||||
while true:
|
||||
else:
|
||||
var call = if a.kind == nkCall: a
|
||||
else: newNode(nkCommand, a.info, @[a])
|
||||
while true:
|
||||
if not isExprStart(p): break
|
||||
var e = parseExpr(p)
|
||||
addSon(result, e)
|
||||
addSon(call, e)
|
||||
if p.tok.tokType != tkComma: break
|
||||
getTok(p)
|
||||
optInd(p, a)
|
||||
if p.tok.tokType == tkDo:
|
||||
parseDoBlocks(p, result)
|
||||
parseDoBlocks(p, call)
|
||||
return
|
||||
if sonsLen(result) <= 1: result = a
|
||||
else: a = result
|
||||
result = if call.sonsLen <= 1: a
|
||||
else: call
|
||||
if p.tok.tokType == tkColon:
|
||||
# macro statement
|
||||
result = newNodeP(nkMacroStmt, p)
|
||||
result.info = a.info
|
||||
addSon(result, a)
|
||||
result = call
|
||||
getTok(p)
|
||||
skipComment(p, result)
|
||||
if p.tok.tokType == tkSad: getTok(p)
|
||||
if not (p.tok.TokType in {tkOf, tkElif, tkElse, tkExcept}):
|
||||
addSon(result, parseStmt(p))
|
||||
if not (p.tok.TokType in {tkOf, tkElif, tkElse, tkExcept}):
|
||||
let body = parseStmt(p)
|
||||
addSon(result, newProcNode(nkDo, body.info, body))
|
||||
while true:
|
||||
if p.tok.tokType == tkSad: getTok(p)
|
||||
var b: PNode
|
||||
|
|
@ -882,7 +869,7 @@ proc parseExprStmt(p: var TParser): PNode =
|
|||
else: break
|
||||
addSon(b, parseStmt(p))
|
||||
addSon(result, b)
|
||||
if b.kind == nkElse: break
|
||||
if b.kind == nkElse: break
|
||||
|
||||
proc parseImportOrIncludeStmt(p: var TParser, kind: TNodeKind): PNode =
|
||||
var a: PNode
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue