nimpretty: don't touch dense binary operators
This commit is contained in:
parent
dbcdc4331a
commit
98f3daea65
1 changed files with 12 additions and 8 deletions
|
|
@ -104,7 +104,7 @@ proc softLinebreak(em: var Emitter, lit: string) =
|
||||||
proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
|
proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
|
||||||
|
|
||||||
template endsInWhite(em): bool =
|
template endsInWhite(em): bool =
|
||||||
em.content.len > 0 and em.content[em.content.high] in {' ', '\L'}
|
em.content.len == 0 or em.content[em.content.high] in {' ', '\L'}
|
||||||
template endsInAlpha(em): bool =
|
template endsInAlpha(em): bool =
|
||||||
em.content.len > 0 and em.content[em.content.high] in SymChars+{'_'}
|
em.content.len > 0 and em.content[em.content.high] in SymChars+{'_'}
|
||||||
|
|
||||||
|
|
@ -203,14 +203,18 @@ proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
|
||||||
wr(TokTypeToStr[tok.tokType])
|
wr(TokTypeToStr[tok.tokType])
|
||||||
wr(" ")
|
wr(" ")
|
||||||
of tkOpr, tkDotDot:
|
of tkOpr, tkDotDot:
|
||||||
if not em.endsInWhite: wr(" ")
|
if tok.strongSpaceA == 0 and tok.strongSpaceB == 0:
|
||||||
wr(tok.ident.s)
|
# if not surrounded by whitespace, don't produce any whitespace either:
|
||||||
template isUnary(tok): bool =
|
wr(tok.ident.s)
|
||||||
tok.strongSpaceB == 0 and tok.strongSpaceA > 0
|
else:
|
||||||
|
if not em.endsInWhite: wr(" ")
|
||||||
|
wr(tok.ident.s)
|
||||||
|
template isUnary(tok): bool =
|
||||||
|
tok.strongSpaceB == 0 and tok.strongSpaceA > 0
|
||||||
|
|
||||||
if not isUnary(tok) or em.lastTok in {tkOpr, tkDotDot}:
|
if not isUnary(tok) or em.lastTok in {tkOpr, tkDotDot}:
|
||||||
wr(" ")
|
wr(" ")
|
||||||
rememberSplit(splitBinary)
|
rememberSplit(splitBinary)
|
||||||
of tkAccent:
|
of tkAccent:
|
||||||
wr(TokTypeToStr[tok.tokType])
|
wr(TokTypeToStr[tok.tokType])
|
||||||
em.inquote = not em.inquote
|
em.inquote = not em.inquote
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue