nimpretty: fixes #9504
This commit is contained in:
parent
eb2e494a52
commit
0afca3dd6b
3 changed files with 20 additions and 3 deletions
|
|
@ -28,7 +28,7 @@ type
|
||||||
config: ConfigRef
|
config: ConfigRef
|
||||||
fid: FileIndex
|
fid: FileIndex
|
||||||
lastTok: TTokType
|
lastTok: TTokType
|
||||||
inquote: bool
|
inquote, lastTokWasTerse: bool
|
||||||
semicolons: SemicolonKind
|
semicolons: SemicolonKind
|
||||||
col, lastLineNumber, lineSpan, indentLevel, indWidth: int
|
col, lastLineNumber, lineSpan, indentLevel, indWidth: int
|
||||||
keepIndents*: int
|
keepIndents*: int
|
||||||
|
|
@ -192,12 +192,13 @@ proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
|
||||||
wr(" ")
|
wr(" ")
|
||||||
em.fixedUntil = em.content.high
|
em.fixedUntil = em.content.high
|
||||||
|
|
||||||
|
var lastTokWasTerse = false
|
||||||
case tok.tokType
|
case tok.tokType
|
||||||
of tokKeywordLow..tokKeywordHigh:
|
of tokKeywordLow..tokKeywordHigh:
|
||||||
if endsInAlpha(em):
|
if endsInAlpha(em):
|
||||||
wr(" ")
|
wr(" ")
|
||||||
elif not em.inquote and not endsInWhite(em) and
|
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
|
#and tok.tokType in oprSet
|
||||||
wr(" ")
|
wr(" ")
|
||||||
|
|
||||||
|
|
@ -233,7 +234,10 @@ proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
|
||||||
tkBracketDotRi,
|
tkBracketDotRi,
|
||||||
tkCurlyDotRi,
|
tkCurlyDotRi,
|
||||||
tkParDotRi,
|
tkParDotRi,
|
||||||
tkColonColon, tkDot:
|
tkColonColon:
|
||||||
|
wr(TokTypeToStr[tok.tokType])
|
||||||
|
of tkDot:
|
||||||
|
lastTokWasTerse = true
|
||||||
wr(TokTypeToStr[tok.tokType])
|
wr(TokTypeToStr[tok.tokType])
|
||||||
of tkEquals:
|
of tkEquals:
|
||||||
if not em.inquote and not em.endsInWhite: wr(" ")
|
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(" ")
|
if not em.inquote: wr(" ")
|
||||||
of tkOpr, tkDotDot:
|
of tkOpr, tkDotDot:
|
||||||
if tok.strongSpaceA == 0 and tok.strongSpaceB == 0:
|
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:
|
# if not surrounded by whitespace, don't produce any whitespace either:
|
||||||
wr(tok.ident.s)
|
wr(tok.ident.s)
|
||||||
else:
|
else:
|
||||||
|
|
@ -274,6 +280,7 @@ proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
|
||||||
wr lit
|
wr lit
|
||||||
|
|
||||||
em.lastTok = tok.tokType
|
em.lastTok = tok.tokType
|
||||||
|
em.lastTokWasTerse = lastTokWasTerse
|
||||||
em.lastLineNumber = tok.line + em.lineSpan
|
em.lastLineNumber = tok.line + em.lineSpan
|
||||||
em.lineSpan = 0
|
em.lineSpan = 0
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -329,3 +329,8 @@ proc getKeyAndData(cursor: int, op: int):
|
||||||
#!nimpretty on
|
#!nimpretty on
|
||||||
|
|
||||||
const test = r"C:\Users\-\Desktop\test.txt"
|
const test = r"C:\Users\-\Desktop\test.txt"
|
||||||
|
|
||||||
|
proc abcdef*[T:not (tuple|object|string|cstring|char|ref|ptr|array|seq|distinct)]() =
|
||||||
|
# bug #9504
|
||||||
|
type T2 = a.type
|
||||||
|
discard
|
||||||
|
|
|
||||||
|
|
@ -338,3 +338,8 @@ proc getKeyAndData(cursor: int; op: int):
|
||||||
#!nimpretty on
|
#!nimpretty on
|
||||||
|
|
||||||
const test = r"C:\Users\-\Desktop\test.txt"
|
const test = r"C:\Users\-\Desktop\test.txt"
|
||||||
|
|
||||||
|
proc abcdef*[T: not (tuple|object|string|cstring|char|ref|ptr|array|seq|distinct)]() =
|
||||||
|
# bug #9504
|
||||||
|
type T2 = a.type
|
||||||
|
discard
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue