nimpretty: bugfixes; refs #8078
This commit is contained in:
parent
9adfaa7f07
commit
1be82d96a6
4 changed files with 42 additions and 5 deletions
|
|
@ -74,9 +74,10 @@ template wr(x) =
|
||||||
template goodCol(col): bool = col in 40..MaxLineLen
|
template goodCol(col): bool = col in 40..MaxLineLen
|
||||||
|
|
||||||
const
|
const
|
||||||
splitters = {tkComma, tkSemicolon, tkParLe, tkParDotLe,
|
openPars = {tkParLe, tkParDotLe,
|
||||||
tkBracketLe, tkBracketLeColon, tkCurlyDotLe,
|
tkBracketLe, tkBracketLeColon, tkCurlyDotLe,
|
||||||
tkCurlyLe}
|
tkCurlyLe}
|
||||||
|
splitters = openPars + {tkComma, tkSemicolon}
|
||||||
oprSet = {tkOpr, tkDiv, tkMod, tkShl, tkShr, tkIn, tkNotin, tkIs,
|
oprSet = {tkOpr, tkDiv, tkMod, tkShl, tkShr, tkIn, tkNotin, tkIs,
|
||||||
tkIsnot, tkNot, tkOf, tkAs, tkDotDot, tkAnd, tkOr, tkXor}
|
tkIsnot, tkNot, tkOf, tkAs, tkDotDot, tkAnd, tkOr, tkXor}
|
||||||
|
|
||||||
|
|
@ -169,7 +170,9 @@ proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
|
||||||
of tokKeywordLow..tokKeywordHigh:
|
of tokKeywordLow..tokKeywordHigh:
|
||||||
if endsInAlpha(em):
|
if endsInAlpha(em):
|
||||||
wr(" ")
|
wr(" ")
|
||||||
elif not em.inquote and not endsInWhite(em) and tok.tokType in oprSet:
|
elif not em.inquote and not endsInWhite(em) and
|
||||||
|
em.lastTok notin openPars:
|
||||||
|
#and tok.tokType in oprSet
|
||||||
wr(" ")
|
wr(" ")
|
||||||
|
|
||||||
if not em.inquote:
|
if not em.inquote:
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ proc test(infile, outfile: string) =
|
||||||
let produced = dir / nimFile & ".pretty"
|
let produced = dir / nimFile & ".pretty"
|
||||||
if strip(readFile(expected)) != strip(readFile(produced)):
|
if strip(readFile(expected)) != strip(readFile(produced)):
|
||||||
echo "FAILURE: files differ: ", nimFile
|
echo "FAILURE: files differ: ", nimFile
|
||||||
discard execShellCmd("diff -uNdr " & produced & " " & expected)
|
discard execShellCmd("diff -uNdr " & expected & " " & produced)
|
||||||
failures += 1
|
failures += 1
|
||||||
else:
|
else:
|
||||||
echo "SUCCESS: files identical: ", nimFile
|
echo "SUCCESS: files identical: ", nimFile
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,22 @@ import verylongnamehere,verylongnamehere,verylongnamehereverylongnamehereverylon
|
||||||
proc `[]=`() = discard "index setter"
|
proc `[]=`() = discard "index setter"
|
||||||
proc `putter=`() = discard cast[pointer](cast[int](buffer) + size)
|
proc `putter=`() = discard cast[pointer](cast[int](buffer) + size)
|
||||||
|
|
||||||
|
(not false)
|
||||||
|
|
||||||
|
let expr = if true: "true" else: "false"
|
||||||
|
|
||||||
|
var body = newNimNode(nnkIfExpr).add(
|
||||||
|
newNimNode(nnkElifBranch).add(
|
||||||
|
infix(newDotExpr(ident("a"), ident("kind")), "==", newDotExpr(ident("b"), ident("kind"))),
|
||||||
|
condition
|
||||||
|
),
|
||||||
|
newNimNode(nnkElse).add(newStmtList(newNimNode(nnkReturnStmt).add(ident("false"))))
|
||||||
|
)
|
||||||
|
|
||||||
|
# comment
|
||||||
|
|
||||||
|
var x = 1
|
||||||
|
|
||||||
type
|
type
|
||||||
GeneralTokenizer* = object of RootObj ## comment here
|
GeneralTokenizer* = object of RootObj ## comment here
|
||||||
kind*: TokenClass ## and here
|
kind*: TokenClass ## and here
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,24 @@ import verylongnamehere, verylongnamehere,
|
||||||
proc `[]=`() = discard "index setter"
|
proc `[]=`() = discard "index setter"
|
||||||
proc `putter=`() = discard cast[pointer](cast[int](buffer) + size)
|
proc `putter=`() = discard cast[pointer](cast[int](buffer) + size)
|
||||||
|
|
||||||
|
(not false)
|
||||||
|
|
||||||
|
let expr = if true: "true" else: "false"
|
||||||
|
|
||||||
|
var body = newNimNode(nnkIfExpr).add(
|
||||||
|
newNimNode(nnkElifBranch).add(
|
||||||
|
infix(newDotExpr(ident("a"), ident("kind")), "==", newDotExpr(ident("b"),
|
||||||
|
ident("kind"))),
|
||||||
|
condition
|
||||||
|
),
|
||||||
|
newNimNode(nnkElse).add(newStmtList(newNimNode(nnkReturnStmt).add(ident(
|
||||||
|
"false"))))
|
||||||
|
)
|
||||||
|
|
||||||
|
# comment
|
||||||
|
|
||||||
|
var x = 1
|
||||||
|
|
||||||
type
|
type
|
||||||
GeneralTokenizer* = object of RootObj ## comment here
|
GeneralTokenizer* = object of RootObj ## comment here
|
||||||
kind*: TokenClass ## and here
|
kind*: TokenClass ## and here
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue