diff options
author | Araq <rumpf_a@web.de> | 2018-06-26 01:43:41 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2018-06-26 01:43:41 +0200 |
commit | 5976bd96be3d14e033005333d8ddab85b2ee7874 (patch) | |
tree | 735a2483deed2c5a49bcca8dc8dfcee26123f2cb | |
parent | c68d52b69d479679914aa56fc7b85b25d2baba8b (diff) | |
download | Nim-5976bd96be3d14e033005333d8ddab85b2ee7874.tar.gz |
nimpretty: detect '; vs ,' style based on the first usage of the token in parameter lists
-rw-r--r-- | compiler/layouter.nim | 8 | ||||
-rw-r--r-- | nimpretty/tests/exhaustive.nim | 2 |
2 files changed, 8 insertions, 2 deletions
diff --git a/compiler/layouter.nim b/compiler/layouter.nim index 62844db4b..36ad08696 100644 --- a/compiler/layouter.nim +++ b/compiler/layouter.nim @@ -20,11 +20,15 @@ type SplitKind = enum splitComma, splitParLe, splitAnd, splitOr, splitIn, splitBinary + SemicolonKind = enum + detectSemicolonKind, useSemicolon, dontTouch + Emitter* = object config: ConfigRef fid: FileIndex lastTok: TTokType inquote: bool + semicolons: SemicolonKind col, lastLineNumber, lineSpan, indentLevel, indWidth: int nested: int doIndentMore*: int @@ -258,7 +262,9 @@ proc starWasExportMarker*(em: var Emitter) = dec em.col, 2 proc commaWasSemicolon*(em: var Emitter) = - if em.content.endsWith(", "): + if em.semicolons == detectSemicolonKind: + em.semicolons = if em.content.endsWith(", "): dontTouch else: useSemicolon + if em.semicolons == useSemicolon and em.content.endsWith(", "): setLen(em.content, em.content.len-2) em.content.add("; ") diff --git a/nimpretty/tests/exhaustive.nim b/nimpretty/tests/exhaustive.nim index 9f2141fbb..a2501a193 100644 --- a/nimpretty/tests/exhaustive.nim +++ b/nimpretty/tests/exhaustive.nim @@ -122,7 +122,7 @@ type fixedUntil: int # marks where we must not go in the content altSplitPos: array[SplitKind, int] # alternative split positions -proc openEmitter*[T, S](em: var Emitter, config: ConfigRef, fileIdx: FileIndex) {.pragmaHereWrongCurlyEnd} = +proc openEmitter*[T, S](em: var Emitter; config: ConfigRef, fileIdx: FileIndex) {.pragmaHereWrongCurlyEnd} = let outfile = changeFileExt(config.toFullPath(fileIdx), ".pretty.nim") em.f = llStreamOpen(outfile, fmWrite) em.config = config |