summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2018-10-25 11:18:03 +0200
committerAraq <rumpf_a@web.de>2018-10-25 11:18:03 +0200
commit0afca3dd6bc7fc2e52ac78c796b0cb1bbf7d47e8 (patch)
tree952462481cd20fdbebf64ff7ae9a88570abe58ee /compiler
parenteb2e494a522a460c1018e46276e662aec00ecfe7 (diff)
downloadNim-0afca3dd6bc7fc2e52ac78c796b0cb1bbf7d47e8.tar.gz
nimpretty: fixes #9504
Diffstat (limited to 'compiler')
-rw-r--r--compiler/layouter.nim13
1 files changed, 10 insertions, 3 deletions
diff --git a/compiler/layouter.nim b/compiler/layouter.nim
index b4321463c..9f9b6fc8e 100644
--- a/compiler/layouter.nim
+++ b/compiler/layouter.nim
@@ -28,7 +28,7 @@ type
     config: ConfigRef
     fid: FileIndex
     lastTok: TTokType
-    inquote: bool
+    inquote, lastTokWasTerse: bool
     semicolons: SemicolonKind
     col, lastLineNumber, lineSpan, indentLevel, indWidth: int
     keepIndents*: int
@@ -192,12 +192,13 @@ proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
       wr(" ")
     em.fixedUntil = em.content.high
 
+  var lastTokWasTerse = false
   case tok.tokType
   of tokKeywordLow..tokKeywordHigh:
     if endsInAlpha(em):
       wr(" ")
     elif not em.inquote and not endsInWhite(em) and
-        em.lastTok notin openPars:
+        em.lastTok notin openPars and not em.lastTokWasTerse:
       #and tok.tokType in oprSet
       wr(" ")
 
@@ -233,7 +234,10 @@ proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
      tkBracketDotRi,
      tkCurlyDotRi,
      tkParDotRi,
-     tkColonColon, tkDot:
+     tkColonColon:
+    wr(TokTypeToStr[tok.tokType])
+  of tkDot:
+    lastTokWasTerse = true
     wr(TokTypeToStr[tok.tokType])
   of tkEquals:
     if not em.inquote and not em.endsInWhite: wr(" ")
@@ -241,6 +245,8 @@ proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
     if not em.inquote: wr(" ")
   of tkOpr, tkDotDot:
     if tok.strongSpaceA == 0 and tok.strongSpaceB == 0:
+      # bug #9504: remember to not spacify a keyword:
+      lastTokWasTerse = true
       # if not surrounded by whitespace, don't produce any whitespace either:
       wr(tok.ident.s)
     else:
@@ -274,6 +280,7 @@ proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
     wr lit
 
   em.lastTok = tok.tokType
+  em.lastTokWasTerse = lastTokWasTerse
   em.lastLineNumber = tok.line + em.lineSpan
   em.lineSpan = 0