* cosmetic improvements * remove unused imports * make 'openPars' and 'closedPars' more readable * nimpretty: fix #11937 (wrong indentation)
This commit is contained in:
commit
d00c8febee
5 changed files with 86 additions and 11 deletions
|
|
@ -9,10 +9,7 @@
|
||||||
|
|
||||||
## Layouter for nimpretty.
|
## Layouter for nimpretty.
|
||||||
|
|
||||||
import idents, lexer, lineinfos, llstream, options, msgs, strutils,
|
import idents, lexer, lineinfos, llstream, options, msgs, strutils, pathutils
|
||||||
pathutils
|
|
||||||
from os import changeFileExt
|
|
||||||
from sequtils import delete
|
|
||||||
|
|
||||||
const
|
const
|
||||||
MinLineLen = 15
|
MinLineLen = 15
|
||||||
|
|
@ -314,11 +311,11 @@ proc removeSpaces(em: var Emitter) =
|
||||||
|
|
||||||
const
|
const
|
||||||
openPars = {tkParLe, tkParDotLe,
|
openPars = {tkParLe, tkParDotLe,
|
||||||
tkBracketLe, tkBracketLeColon, tkCurlyDotLe,
|
tkBracketLe, tkBracketDotLe, tkBracketLeColon,
|
||||||
tkCurlyLe}
|
tkCurlyDotLe, tkCurlyLe}
|
||||||
closedPars = {tkParRi, tkParDotRi,
|
closedPars = {tkParRi, tkParDotRi,
|
||||||
tkBracketRi, tkCurlyDotRi,
|
tkBracketRi, tkBracketDotRi,
|
||||||
tkCurlyRi, tkBracketDotRi}
|
tkCurlyDotRi, tkCurlyRi}
|
||||||
|
|
||||||
splitters = openPars + {tkComma, tkSemiColon} # do not add 'tkColon' here!
|
splitters = openPars + {tkComma, tkSemiColon} # do not add 'tkColon' here!
|
||||||
oprSet = {tkOpr, tkDiv, tkMod, tkShl, tkShr, tkIn, tkNotin, tkIs,
|
oprSet = {tkOpr, tkDiv, tkMod, tkShl, tkShr, tkIn, tkNotin, tkIs,
|
||||||
|
|
@ -444,6 +441,9 @@ proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
|
||||||
em.indentLevel = tok.indent
|
em.indentLevel = tok.indent
|
||||||
elif (em.lastTok in (splitters + oprSet) and
|
elif (em.lastTok in (splitters + oprSet) and
|
||||||
tok.tokType notin (closedPars - {tkBracketDotRi})):
|
tok.tokType notin (closedPars - {tkBracketDotRi})):
|
||||||
|
if tok.tokType in openPars and tok.indent > em.indentStack[^1]:
|
||||||
|
while em.indentStack[^1] < tok.indent:
|
||||||
|
em.indentStack.add(em.indentStack[^1] + em.indWidth)
|
||||||
# aka: we are in an expression context:
|
# aka: we are in an expression context:
|
||||||
let alignment = max(tok.indent - em.indentStack[^1], 0)
|
let alignment = max(tok.indent - em.indentStack[^1], 0)
|
||||||
em.indentLevel = alignment + em.indentStack.high * em.indWidth
|
em.indentLevel = alignment + em.indentStack.high * em.indWidth
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,7 @@
|
||||||
when not defined(nimpretty):
|
when not defined(nimpretty):
|
||||||
{.error: "This needs to be compiled with --define:nimPretty".}
|
{.error: "This needs to be compiled with --define:nimPretty".}
|
||||||
|
|
||||||
import ../compiler / [idents, msgs, ast, syntaxes, renderer, options,
|
import ../compiler / [idents, msgs, syntaxes, options, pathutils, layouter]
|
||||||
pathutils, layouter]
|
|
||||||
|
|
||||||
import parseopt, strutils, os
|
import parseopt, strutils, os
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -812,7 +812,7 @@ let foo = if cond:
|
||||||
|
|
||||||
let a =
|
let a =
|
||||||
[[aaadsfas, bbb],
|
[[aaadsfas, bbb],
|
||||||
[ccc, ddd]]
|
[ccc, ddd]]
|
||||||
|
|
||||||
let b = [
|
let b = [
|
||||||
[aaa, bbb],
|
[aaa, bbb],
|
||||||
|
|
|
||||||
|
|
@ -71,3 +71,41 @@ proc a() =
|
||||||
|
|
||||||
# comment 2
|
# comment 2
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
|
||||||
|
proc i11937() =
|
||||||
|
result = %*
|
||||||
|
{
|
||||||
|
"_comment": "pbreports-style JSON",
|
||||||
|
"attributes": [],
|
||||||
|
"dataset_uuids": [],
|
||||||
|
"id": "microbial_asm_polishing_report",
|
||||||
|
"plotGroups": [],
|
||||||
|
"tables": [
|
||||||
|
{
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"header": "Contig",
|
||||||
|
"id": "microbial",
|
||||||
|
"values": values_contig
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"header": "Length",
|
||||||
|
"id": "microbial",
|
||||||
|
"values": values_length
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"header": "Circular?",
|
||||||
|
"id": "microbial",
|
||||||
|
"values": values_circular
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"id": "microbial_asm_polishing_report.contigs_table",
|
||||||
|
"title": "Polished contigs from Microbial Assembly"
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"tags": [],
|
||||||
|
"title": "Microbial Assembly Polishing Report",
|
||||||
|
"uuid": uuid,
|
||||||
|
"version": version
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -71,3 +71,41 @@ proc a() =
|
||||||
|
|
||||||
# comment 2
|
# comment 2
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
|
||||||
|
proc i11937() =
|
||||||
|
result = %*
|
||||||
|
{
|
||||||
|
"_comment": "pbreports-style JSON",
|
||||||
|
"attributes": [],
|
||||||
|
"dataset_uuids": [],
|
||||||
|
"id": "microbial_asm_polishing_report",
|
||||||
|
"plotGroups": [],
|
||||||
|
"tables": [
|
||||||
|
{
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"header": "Contig",
|
||||||
|
"id": "microbial",
|
||||||
|
"values": values_contig
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"header": "Length",
|
||||||
|
"id": "microbial",
|
||||||
|
"values": values_length
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"header": "Circular?",
|
||||||
|
"id": "microbial",
|
||||||
|
"values": values_circular
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"id": "microbial_asm_polishing_report.contigs_table",
|
||||||
|
"title": "Polished contigs from Microbial Assembly"
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"tags": [],
|
||||||
|
"title": "Microbial Assembly Polishing Report",
|
||||||
|
"uuid": uuid,
|
||||||
|
"version": version
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue