mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-20 06:20:38 +00:00
render stmtlistExpr using semicolon
This commit is contained in:
@@ -624,10 +624,13 @@ proc longMode(g: TSrcGen; n: PNode, start: int = 0, theEnd: int = - 1): bool =
|
||||
proc gstmts(g: var TSrcGen, n: PNode, c: TContext, doIndent=true) =
|
||||
if n.kind == nkEmpty: return
|
||||
if n.kind in {nkStmtList, nkStmtListExpr, nkStmtListType}:
|
||||
if n.kind == nkStmtListExpr:
|
||||
put(g, tkParLe, "(")
|
||||
if doIndent: indentNL(g)
|
||||
let L = n.len
|
||||
for i in 0 .. L-1:
|
||||
if i > 0:
|
||||
if n.kind == nkStmtListExpr: put(g, tkSemiColon, ";")
|
||||
optNL(g, n[i-1], n[i])
|
||||
else:
|
||||
optNL(g)
|
||||
@@ -637,6 +640,8 @@ proc gstmts(g: var TSrcGen, n: PNode, c: TContext, doIndent=true) =
|
||||
gsub(g, n[i])
|
||||
gcoms(g)
|
||||
if doIndent: dedent(g)
|
||||
if n.kind == nkStmtListExpr:
|
||||
put(g, tkParRi, ")")
|
||||
else:
|
||||
indentNL(g)
|
||||
gsub(g, n)
|
||||
@@ -644,17 +649,9 @@ proc gstmts(g: var TSrcGen, n: PNode, c: TContext, doIndent=true) =
|
||||
dedent(g)
|
||||
optNL(g)
|
||||
|
||||
|
||||
proc gcond(g: var TSrcGen, n: PNode) =
|
||||
if n.kind == nkStmtListExpr:
|
||||
put(g, tkParLe, "(")
|
||||
gsub(g, n)
|
||||
if n.kind == nkStmtListExpr:
|
||||
put(g, tkParRi, ")")
|
||||
|
||||
proc gif(g: var TSrcGen, n: PNode) =
|
||||
var c: TContext
|
||||
gcond(g, n.sons[0].sons[0])
|
||||
gsub(g, n.sons[0].sons[0])
|
||||
initContext(c)
|
||||
putWithSpace(g, tkColon, ":")
|
||||
if longMode(g, n) or (lsub(g, n.sons[0].sons[1]) + g.lineLen > MaxLineLen):
|
||||
@@ -669,7 +666,7 @@ proc gif(g: var TSrcGen, n: PNode) =
|
||||
proc gwhile(g: var TSrcGen, n: PNode) =
|
||||
var c: TContext
|
||||
putWithSpace(g, tkWhile, "while")
|
||||
gcond(g, n.sons[0])
|
||||
gsub(g, n.sons[0])
|
||||
putWithSpace(g, tkColon, ":")
|
||||
initContext(c)
|
||||
if longMode(g, n) or (lsub(g, n.sons[1]) + g.lineLen > MaxLineLen):
|
||||
@@ -733,7 +730,7 @@ proc gcase(g: var TSrcGen, n: PNode) =
|
||||
var last = if n.sons[length-1].kind == nkElse: -2 else: -1
|
||||
if longMode(g, n, 0, last): incl(c.flags, rfLongMode)
|
||||
putWithSpace(g, tkCase, "case")
|
||||
gcond(g, n.sons[0])
|
||||
gsub(g, n.sons[0])
|
||||
gcoms(g)
|
||||
optNL(g)
|
||||
gsons(g, n, c, 1, last)
|
||||
@@ -1168,13 +1165,13 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) =
|
||||
put(g, tkAccent, "`")
|
||||
of nkIfExpr:
|
||||
putWithSpace(g, tkIf, "if")
|
||||
if n.len > 0: gcond(g, n.sons[0].sons[0])
|
||||
if n.len > 0: gsub(g, n.sons[0].sons[0])
|
||||
putWithSpace(g, tkColon, ":")
|
||||
if n.len > 0: gsub(g, n.sons[0], 1)
|
||||
gsons(g, n, emptyContext, 1)
|
||||
of nkElifExpr:
|
||||
putWithSpace(g, tkElif, " elif")
|
||||
gcond(g, n[0])
|
||||
gsub(g, n[0])
|
||||
putWithSpace(g, tkColon, ":")
|
||||
gsub(g, n, 1)
|
||||
of nkElseExpr:
|
||||
|
||||
Reference in New Issue
Block a user