mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
nimpretty: detect '; vs ,' style based on the first usage of the token in parameter lists
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user