diff options
-rw-r--r-- | compiler/layouter.nim | 16 | ||||
-rw-r--r-- | nimpretty/nimpretty.nim | 3 | ||||
-rw-r--r-- | nimpretty/tests/expected/exhaustive.nim | 2 | ||||
-rw-r--r-- | nimpretty/tests/expected/wrong_ind.nim | 38 | ||||
-rw-r--r-- | nimpretty/tests/wrong_ind.nim | 38 |
5 files changed, 86 insertions, 11 deletions
diff --git a/compiler/layouter.nim b/compiler/layouter.nim index 367d2aead..0c888b455 100644 --- a/compiler/layouter.nim +++ b/compiler/layouter.nim @@ -9,10 +9,7 @@ ## Layouter for nimpretty. -import idents, lexer, lineinfos, llstream, options, msgs, strutils, - pathutils -from os import changeFileExt -from sequtils import delete +import idents, lexer, lineinfos, llstream, options, msgs, strutils, pathutils const MinLineLen = 15 @@ -314,11 +311,11 @@ proc removeSpaces(em: var Emitter) = const openPars = {tkParLe, tkParDotLe, - tkBracketLe, tkBracketLeColon, tkCurlyDotLe, - tkCurlyLe} + tkBracketLe, tkBracketDotLe, tkBracketLeColon, + tkCurlyDotLe, tkCurlyLe} closedPars = {tkParRi, tkParDotRi, - tkBracketRi, tkCurlyDotRi, - tkCurlyRi, tkBracketDotRi} + tkBracketRi, tkBracketDotRi, + tkCurlyDotRi, tkCurlyRi} splitters = openPars + {tkComma, tkSemiColon} # do not add 'tkColon' here! 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 elif (em.lastTok in (splitters + oprSet) and 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: let alignment = max(tok.indent - em.indentStack[^1], 0) em.indentLevel = alignment + em.indentStack.high * em.indWidth diff --git a/nimpretty/nimpretty.nim b/nimpretty/nimpretty.nim index aa6784c82..95f428598 100644 --- a/nimpretty/nimpretty.nim +++ b/nimpretty/nimpretty.nim @@ -12,8 +12,7 @@ when not defined(nimpretty): {.error: "This needs to be compiled with --define:nimPretty".} -import ../compiler / [idents, msgs, ast, syntaxes, renderer, options, - pathutils, layouter] +import ../compiler / [idents, msgs, syntaxes, options, pathutils, layouter] import parseopt, strutils, os diff --git a/nimpretty/tests/expected/exhaustive.nim b/nimpretty/tests/expected/exhaustive.nim index 247ece887..3c2355707 100644 --- a/nimpretty/tests/expected/exhaustive.nim +++ b/nimpretty/tests/expected/exhaustive.nim @@ -812,7 +812,7 @@ let foo = if cond: let a = [[aaadsfas, bbb], - [ccc, ddd]] + [ccc, ddd]] let b = [ [aaa, bbb], diff --git a/nimpretty/tests/expected/wrong_ind.nim b/nimpretty/tests/expected/wrong_ind.nim index 9855e0c4d..95a35a8fd 100644 --- a/nimpretty/tests/expected/wrong_ind.nim +++ b/nimpretty/tests/expected/wrong_ind.nim @@ -71,3 +71,41 @@ proc a() = # comment 2 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 + } diff --git a/nimpretty/tests/wrong_ind.nim b/nimpretty/tests/wrong_ind.nim index 930f696bb..3c7544cdb 100644 --- a/nimpretty/tests/wrong_ind.nim +++ b/nimpretty/tests/wrong_ind.nim @@ -71,3 +71,41 @@ proc a() = # comment 2 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 + } |