summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2018-06-17 14:25:23 +0200
committerAndreas Rumpf <rumpf_a@web.de>2018-06-17 14:25:23 +0200
commit98f3daea651b5e2f9ef620f6b9bb5a55e3530358 (patch)
tree57e5eaba3b59386c39cfe8a4f09427a324f27408
parentdbcdc4331a2d87aafa06ce49d50277474595064d (diff)
downloadNim-98f3daea651b5e2f9ef620f6b9bb5a55e3530358.tar.gz
nimpretty: don't touch dense binary operators
-rw-r--r--compiler/layouter.nim22
1 files changed, 13 insertions, 9 deletions
diff --git a/compiler/layouter.nim b/compiler/layouter.nim
index ec5d3d088..45ae8d305 100644
--- a/compiler/layouter.nim
+++ b/compiler/layouter.nim
@@ -104,7 +104,7 @@ proc softLinebreak(em: var Emitter, lit: string) =
 proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
 
   template endsInWhite(em): bool =
-    em.content.len > 0 and em.content[em.content.high] in {' ', '\L'}
+    em.content.len == 0 or em.content[em.content.high] in {' ', '\L'}
   template endsInAlpha(em): bool =
     em.content.len > 0 and em.content[em.content.high] in SymChars+{'_'}
 
@@ -203,14 +203,18 @@ proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
     wr(TokTypeToStr[tok.tokType])
     wr(" ")
   of tkOpr, tkDotDot:
-    if not em.endsInWhite: wr(" ")
-    wr(tok.ident.s)
-    template isUnary(tok): bool =
-      tok.strongSpaceB == 0 and tok.strongSpaceA > 0
-
-    if not isUnary(tok) or em.lastTok in {tkOpr, tkDotDot}:
-      wr(" ")
-      rememberSplit(splitBinary)
+    if tok.strongSpaceA == 0 and tok.strongSpaceB == 0:
+      # if not surrounded by whitespace, don't produce any whitespace either:
+      wr(tok.ident.s)
+    else:
+      if not em.endsInWhite: wr(" ")
+      wr(tok.ident.s)
+      template isUnary(tok): bool =
+        tok.strongSpaceB == 0 and tok.strongSpaceA > 0
+
+      if not isUnary(tok) or em.lastTok in {tkOpr, tkDotDot}:
+        wr(" ")
+        rememberSplit(splitBinary)
   of tkAccent:
     wr(TokTypeToStr[tok.tokType])
     em.inquote = not em.inquote