nimpretty: detect '; vs ,' style based on the first usage of the token in parameter lists

This commit is contained in:
Araq 2018-06-26 01:43:41 +02:00
commit 5976bd96be
2 changed files with 8 additions and 2 deletions

View file

@ -20,11 +20,15 @@ type
SplitKind = enum SplitKind = enum
splitComma, splitParLe, splitAnd, splitOr, splitIn, splitBinary splitComma, splitParLe, splitAnd, splitOr, splitIn, splitBinary
SemicolonKind = enum
detectSemicolonKind, useSemicolon, dontTouch
Emitter* = object Emitter* = object
config: ConfigRef config: ConfigRef
fid: FileIndex fid: FileIndex
lastTok: TTokType lastTok: TTokType
inquote: bool inquote: bool
semicolons: SemicolonKind
col, lastLineNumber, lineSpan, indentLevel, indWidth: int col, lastLineNumber, lineSpan, indentLevel, indWidth: int
nested: int nested: int
doIndentMore*: int doIndentMore*: int
@ -258,7 +262,9 @@ proc starWasExportMarker*(em: var Emitter) =
dec em.col, 2 dec em.col, 2
proc commaWasSemicolon*(em: var Emitter) = 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) setLen(em.content, em.content.len-2)
em.content.add("; ") em.content.add("; ")

View file

@ -122,7 +122,7 @@ type
fixedUntil: int # marks where we must not go in the content fixedUntil: int # marks where we must not go in the content
altSplitPos: array[SplitKind, int] # alternative split positions 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") let outfile = changeFileExt(config.toFullPath(fileIdx), ".pretty.nim")
em.f = llStreamOpen(outfile, fmWrite) em.f = llStreamOpen(outfile, fmWrite)
em.config = config em.config = config