diff options
author | metagn <metagngn@gmail.com> | 2023-12-24 17:22:10 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-24 15:22:10 +0100 |
commit | fc49c6e3ba5081593e4d9af7e04bfb84e97a39f5 (patch) | |
tree | 3dc9135f02957e34c4dc14ffcaf27491d48b6c79 | |
parent | 6fee2240cd327fbe65548eaed9ca21355a1a24b5 (diff) | |
download | Nim-fc49c6e3ba5081593e4d9af7e04bfb84e97a39f5.tar.gz |
fix spurious indent and newlines in rendering of nkRecList (#23121)
Rendering of `nkRecList` produces an indent and adds a new line at the end. However for things like case object `of`/`else` branches or `when` branches this is already done, so this produces 2 indents and an extra new line. Instead, just add an indent in the place where the indent that `nkRecList` produces is needed, for the rendering of the final node of `nkObjectTy`. There doesn't seem to be a need to add the newline. Before: ```nim case x*: bool of true: y*: int of false: nil ``` After: ```nim case x*: bool of true: y*: int of false: nil ```
-rw-r--r-- | compiler/renderer.nim | 5 | ||||
-rw-r--r-- | lib/core/macros.nim | 3 | ||||
-rw-r--r-- | nimdoc/extlinks/project/expected/main.html | 3 | ||||
-rw-r--r-- | nimdoc/testproject/expected/subdir/subdir_b/utils.html | 3 | ||||
-rw-r--r-- | nimdoc/testproject/expected/testproject.html | 16 |
5 files changed, 10 insertions, 20 deletions
diff --git a/compiler/renderer.nim b/compiler/renderer.nim index e9f0d2be9..3a7c60953 100644 --- a/compiler/renderer.nim +++ b/compiler/renderer.nim @@ -1531,17 +1531,16 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext, fromStmtList = false) = gsub(g, n[0]) gsub(g, n[1]) gcoms(g) + indentNL(g) gsub(g, n[2]) + dedent(g) else: put(g, tkObject, "object") of nkRecList: - indentNL(g) for i in 0..<n.len: optNL(g) gsub(g, n[i], c) gcoms(g) - dedent(g) - putNL(g) of nkOfInherit: putWithSpace(g, tkOf, "of") gsub(g, n, 0) diff --git a/lib/core/macros.nim b/lib/core/macros.nim index fe911ffbf..bd1de9cd7 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -347,8 +347,7 @@ proc getTypeImpl*(n: NimNode): NimNode {.magic: "NGetType", noSideEffect.} = newLit(x.getTypeImpl.repr) let t = """ object - arr: array[0 .. 3, float32] -""" + arr: array[0 .. 3, float32]""" doAssert(dumpTypeImpl(a) == t) doAssert(dumpTypeImpl(b) == t) doAssert(dumpTypeImpl(c) == t) diff --git a/nimdoc/extlinks/project/expected/main.html b/nimdoc/extlinks/project/expected/main.html index 1a58ea2ac..f46d72115 100644 --- a/nimdoc/extlinks/project/expected/main.html +++ b/nimdoc/extlinks/project/expected/main.html @@ -95,8 +95,7 @@ <h1><a class="toc-backref" href="#7">Types</a></h1> <dl class="item"> <div id="A"> - <dt><pre><a href="main.html#A"><span class="Identifier">A</span></a> <span class="Other">=</span> <span class="Keyword">object</span> - </pre></dt> + <dt><pre><a href="main.html#A"><span class="Identifier">A</span></a> <span class="Other">=</span> <span class="Keyword">object</span></pre></dt> <dd> diff --git a/nimdoc/testproject/expected/subdir/subdir_b/utils.html b/nimdoc/testproject/expected/subdir/subdir_b/utils.html index ba9512d5a..5969e48bb 100644 --- a/nimdoc/testproject/expected/subdir/subdir_b/utils.html +++ b/nimdoc/testproject/expected/subdir/subdir_b/utils.html @@ -253,8 +253,7 @@ Ref. <a class="reference internal nimdoc" title="proc `[]`[T](x: G[T]): T" href= <h1><a class="toc-backref" href="#7">Types</a></h1> <dl class="item"> <div id="G"> - <dt><pre><a href="utils.html#G"><span class="Identifier">G</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span> <span class="Other">=</span> <span class="Keyword">object</span> - </pre></dt> + <dt><pre><a href="utils.html#G"><span class="Identifier">G</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span> <span class="Other">=</span> <span class="Keyword">object</span></pre></dt> <dd> diff --git a/nimdoc/testproject/expected/testproject.html b/nimdoc/testproject/expected/testproject.html index db49102f8..dfd10390a 100644 --- a/nimdoc/testproject/expected/testproject.html +++ b/nimdoc/testproject/expected/testproject.html @@ -59,8 +59,7 @@ <li><a class="reference" href="#AnotherObject" title="AnotherObject = object case x*: bool of true: - y*: proc (x: string) - + y*: proc (x: string) of false:">AnotherObject</a></li> <li><a class="reference" href="#B" title="B {.inject.} = enum bB">B</a></li> @@ -380,11 +379,8 @@ <dt><pre><a href="testproject.html#AnotherObject"><span class="Identifier">AnotherObject</span></a> <span class="Other">=</span> <span class="Keyword">object</span> <span class="Keyword">case</span> <span class="Identifier">x</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">bool</span> <span class="Keyword">of</span> <span class="Identifier">true</span><span class="Other">:</span> - <span class="Identifier">y</span><span class="Operator">*</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span> - - <span class="Keyword">of</span> <span class="Identifier">false</span><span class="Other">:</span> - - </pre></dt> + <span class="Identifier">y</span><span class="Operator">*</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span> + <span class="Keyword">of</span> <span class="Identifier">false</span><span class="Other">:</span></pre></dt> <dd> @@ -423,8 +419,7 @@ <div id="MyObject"> <dt><pre><a href="testproject.html#MyObject"><span class="Identifier">MyObject</span></a> <span class="Other">=</span> <span class="Keyword">object</span> <span class="Identifier">someString</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">string</span> <span class="Comment">## This is a string</span> - <span class="Identifier">annotated</span><span class="Operator">*</span> {.<span class="Identifier">somePragma</span>.}<span class="Other">:</span> <span class="Identifier">string</span> <span class="Comment">## This is an annotated string</span> - </pre></dt> + <span class="Identifier">annotated</span><span class="Operator">*</span> {.<span class="Identifier">somePragma</span>.}<span class="Other">:</span> <span class="Identifier">string</span> <span class="Comment">## This is an annotated string</span></pre></dt> <dd> @@ -444,8 +439,7 @@ </div> <div id="T19396"> <dt><pre><a href="testproject.html#T19396"><span class="Identifier">T19396</span></a> <span class="Other">=</span> <span class="Keyword">object</span> - <span class="Identifier">a</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">int</span> - </pre></dt> + <span class="Identifier">a</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">int</span></pre></dt> <dd> |