Skip to content

Commit

Permalink
Make section postfix comment sticky at the right indent (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnetheduck committed Feb 25, 2024
1 parent d354433 commit 79ddac7
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/phparser.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/phrenderer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
10 changes: 10 additions & 0 deletions tests/after/comments.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions tests/after/comments.nim.nph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions tests/before/a00empty.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

10 changes: 10 additions & 0 deletions tests/before/comments.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions tests/before/comments.nim.nph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 79ddac7

Please sign in to comment.