nimpretty: detect '; vs ,' style based on the first usage of the token in parameter lists
This commit is contained in:
parent
c68d52b69d
commit
5976bd96be
2 changed files with 8 additions and 2 deletions
|
|
@ -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("; ")
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue