diff --git a/src/phparser.nim b/src/phparser.nim index 5c3e89c..a3a921a 100644 --- a/src/phparser.nim +++ b/src/phparser.nim @@ -2202,7 +2202,7 @@ proc parseSection( case p.tok.tokType of tkSymbol, tkAccent, tkParLe: var a = defparser(p) - splitLookahead(p, a, clPostfix) + splitLookahead(p, a, p.currInd, clPostfix) result.add(a) of tkComment: var a = parseCommentStmt(p) diff --git a/src/phrenderer.nim b/src/phrenderer.nim index 63ab6f5..7019974 100644 --- a/src/phrenderer.nim +++ b/src/phrenderer.nim @@ -917,6 +917,7 @@ proc gsection(g: var TOutput, n: PNode, kind: TokType, k: string) = optNL(g) gsub(g, n[i]) + optNL(g) dedent(g) else: gsub(g, n[0]) diff --git a/tests/after/comments.nim b/tests/after/comments.nim index 963be4b..d50bfce 100644 --- a/tests/after/comments.nim +++ b/tests/after/comments.nim @@ -314,6 +314,16 @@ const # const eol # const ident after equals 42 # const ident after value +let + a = 4 + b = 5 + # let section postfix + +const + a = 4 + b = 5 + # const section postfix + discard # discard eol # discard first line diff --git a/tests/after/comments.nim.nph.yaml b/tests/after/comments.nim.nph.yaml index 1283185..23fa6fc 100644 --- a/tests/after/comments.nim.nph.yaml +++ b/tests/after/comments.nim.nph.yaml @@ -1144,6 +1144,42 @@ sons: intVal: 42 postfix: - "# const ident after value" + - kind: "nkLetSection" + sons: + - kind: "nkIdentDefs" + sons: + - kind: "nkIdent" + ident: "a" + - kind: "nkEmpty" + - kind: "nkIntLit" + intVal: 4 + - kind: "nkIdentDefs" + sons: + - kind: "nkIdent" + ident: "b" + - kind: "nkEmpty" + - kind: "nkIntLit" + intVal: 5 + postfix: + - "# let section postfix" + - kind: "nkConstSection" + sons: + - kind: "nkConstDef" + sons: + - kind: "nkIdent" + ident: "a" + - kind: "nkEmpty" + - kind: "nkIntLit" + intVal: 4 + - kind: "nkConstDef" + sons: + - kind: "nkIdent" + ident: "b" + - kind: "nkEmpty" + - kind: "nkIntLit" + intVal: 5 + postfix: + - "# const section postfix" - kind: "nkDiscardStmt" sons: - kind: "nkIntLit" diff --git a/tests/before/a00empty.nim b/tests/before/a00empty.nim index e69de29..8b13789 100644 --- a/tests/before/a00empty.nim +++ b/tests/before/a00empty.nim @@ -0,0 +1 @@ + diff --git a/tests/before/comments.nim b/tests/before/comments.nim index 201a12d..c2c0d58 100644 --- a/tests/before/comments.nim +++ b/tests/before/comments.nim @@ -300,6 +300,16 @@ const # const eol = # const ident after equals 42 # const ident after value +let + a = 4 + b = 5 + # let section postfix + +const + a = 4 + b = 5 + # const section postfix + discard # discard eol # discard first line 54 # discard value diff --git a/tests/before/comments.nim.nph.yaml b/tests/before/comments.nim.nph.yaml index 88f03ec..e6aa8a9 100644 --- a/tests/before/comments.nim.nph.yaml +++ b/tests/before/comments.nim.nph.yaml @@ -1143,6 +1143,42 @@ sons: intVal: 42 postfix: - "# const ident after value" + - kind: "nkLetSection" + sons: + - kind: "nkIdentDefs" + sons: + - kind: "nkIdent" + ident: "a" + - kind: "nkEmpty" + - kind: "nkIntLit" + intVal: 4 + - kind: "nkIdentDefs" + sons: + - kind: "nkIdent" + ident: "b" + - kind: "nkEmpty" + - kind: "nkIntLit" + intVal: 5 + postfix: + - "# let section postfix" + - kind: "nkConstSection" + sons: + - kind: "nkConstDef" + sons: + - kind: "nkIdent" + ident: "a" + - kind: "nkEmpty" + - kind: "nkIntLit" + intVal: 4 + - kind: "nkConstDef" + sons: + - kind: "nkIdent" + ident: "b" + - kind: "nkEmpty" + - kind: "nkIntLit" + intVal: 5 + postfix: + - "# const section postfix" - kind: "nkDiscardStmt" sons: - kind: "nkIntLit"