nimpretty: don't touch formatted multiline comments (#11663)
This commit is contained in:
parent
d1f6c820dd
commit
176eaf5c90
3 changed files with 87 additions and 23 deletions
|
|
@ -300,29 +300,37 @@ proc emitMultilineComment(em: var Emitter, lit: string, col: int) =
|
||||||
var i = 0
|
var i = 0
|
||||||
var lastIndent = em.indentStack[^1]
|
var lastIndent = em.indentStack[^1]
|
||||||
var b = 0
|
var b = 0
|
||||||
|
var dontIndent = false
|
||||||
for commentLine in splitLines(lit):
|
for commentLine in splitLines(lit):
|
||||||
let stripped = commentLine.strip()
|
if i == 0 and (commentLine.endsWith("\\") or commentLine.endsWith("[")):
|
||||||
var a = 0
|
dontIndent = true
|
||||||
while a < commentLine.len and commentLine[a] == ' ': inc a
|
wr em, commentLine, ltComment
|
||||||
if i == 0:
|
elif dontIndent:
|
||||||
if em.kinds.len > 0 and em.kinds[^1] != ltTab:
|
|
||||||
wr(em, "", ltTab)
|
|
||||||
elif stripped.len == 0:
|
|
||||||
wrNewline em
|
wrNewline em
|
||||||
|
wr em, commentLine, ltComment
|
||||||
else:
|
else:
|
||||||
if a > lastIndent:
|
let stripped = commentLine.strip()
|
||||||
b += em.indWidth
|
var a = 0
|
||||||
lastIndent = a
|
while a < commentLine.len and commentLine[a] == ' ': inc a
|
||||||
elif a < lastIndent:
|
if i == 0:
|
||||||
b -= em.indWidth
|
if em.kinds.len > 0 and em.kinds[^1] != ltTab:
|
||||||
lastIndent = a
|
wr(em, "", ltTab)
|
||||||
wrNewline em
|
elif stripped.len == 0:
|
||||||
#wrSpaces em, col + b
|
wrNewline em
|
||||||
if col + b > 0:
|
|
||||||
wr(em, repeat(' ', col+b), ltTab)
|
|
||||||
else:
|
else:
|
||||||
wr(em, "", ltTab)
|
if a > lastIndent:
|
||||||
wr em, stripped, ltComment
|
b += em.indWidth
|
||||||
|
lastIndent = a
|
||||||
|
elif a < lastIndent:
|
||||||
|
b -= em.indWidth
|
||||||
|
lastIndent = a
|
||||||
|
wrNewline em
|
||||||
|
#wrSpaces em, col + b
|
||||||
|
if col + b > 0:
|
||||||
|
wr(em, repeat(' ', col+b), ltTab)
|
||||||
|
else:
|
||||||
|
wr(em, "", ltTab)
|
||||||
|
wr em, stripped, ltComment
|
||||||
inc i
|
inc i
|
||||||
|
|
||||||
proc lastChar(s: string): char =
|
proc lastChar(s: string): char =
|
||||||
|
|
|
||||||
|
|
@ -689,6 +689,34 @@ proc newRecordGen(ctx: Context; typ: TypRef): PNode =
|
||||||
typ.recFields.map(newRecFieldGen))))
|
typ.recFields.map(newRecFieldGen))))
|
||||||
|
|
||||||
|
|
||||||
|
##[
|
||||||
|
String `interpolation`:idx: / `format`:idx: inspired by
|
||||||
|
Python's ``f``-strings.
|
||||||
|
|
||||||
|
.. code-block:: nim
|
||||||
|
|
||||||
|
import strformat
|
||||||
|
let msg = "hello"
|
||||||
|
doAssert fmt"{msg}\n" == "hello\\n"
|
||||||
|
|
||||||
|
Because the literal is a raw string literal, the ``\n`` is not interpreted as
|
||||||
|
an escape sequence.
|
||||||
|
|
||||||
|
|
||||||
|
================= ====================================================
|
||||||
|
Sign Meaning
|
||||||
|
================= ====================================================
|
||||||
|
``+`` Indicates that a sign should be used for both
|
||||||
|
positive as well as negative numbers.
|
||||||
|
``-`` Indicates that a sign should be used only for
|
||||||
|
negative numbers (this is the default behavior).
|
||||||
|
(space) Indicates that a leading space should be used on
|
||||||
|
positive numbers.
|
||||||
|
================= ====================================================
|
||||||
|
|
||||||
|
]##
|
||||||
|
|
||||||
|
|
||||||
let
|
let
|
||||||
lla = 42394219 - 42429849 + 1293293 - 13918391 + 424242 # this here is an okayish comment
|
lla = 42394219 - 42429849 + 1293293 - 13918391 + 424242 # this here is an okayish comment
|
||||||
llb = 42394219 - 42429849 + 1293293 - 13918391 + 424242 # this here is a very long comment which should be split
|
llb = 42394219 - 42429849 + 1293293 - 13918391 + 424242 # this here is a very long comment which should be split
|
||||||
|
|
|
||||||
|
|
@ -631,10 +631,10 @@ type
|
||||||
cmdLongOption, ## A long option such as --option
|
cmdLongOption, ## A long option such as --option
|
||||||
cmdShortOption ## A short option such as -c
|
cmdShortOption ## A short option such as -c
|
||||||
OptParser* = object of RootObj ## \
|
OptParser* = object of RootObj ## \
|
||||||
## Implementation of the command line parser. Here is even more text yad.
|
## Implementation of the command line parser. Here is even more text yad.
|
||||||
##
|
##
|
||||||
## To initialize it, use the
|
## To initialize it, use the
|
||||||
## `initOptParser proc<#initOptParser,string,set[char],seq[string]>`_.
|
## `initOptParser proc<#initOptParser,string,set[char],seq[string]>`_.
|
||||||
pos*: int
|
pos*: int
|
||||||
inShortState: bool
|
inShortState: bool
|
||||||
allowWhitespaceAfterColon: bool
|
allowWhitespaceAfterColon: bool
|
||||||
|
|
@ -695,6 +695,34 @@ proc newRecordGen(ctx: Context; typ: TypRef): PNode =
|
||||||
typ.recFields.map(newRecFieldGen))))
|
typ.recFields.map(newRecFieldGen))))
|
||||||
|
|
||||||
|
|
||||||
|
##[
|
||||||
|
String `interpolation`:idx: / `format`:idx: inspired by
|
||||||
|
Python's ``f``-strings.
|
||||||
|
|
||||||
|
.. code-block:: nim
|
||||||
|
|
||||||
|
import strformat
|
||||||
|
let msg = "hello"
|
||||||
|
doAssert fmt"{msg}\n" == "hello\\n"
|
||||||
|
|
||||||
|
Because the literal is a raw string literal, the ``\n`` is not interpreted as
|
||||||
|
an escape sequence.
|
||||||
|
|
||||||
|
|
||||||
|
================= ====================================================
|
||||||
|
Sign Meaning
|
||||||
|
================= ====================================================
|
||||||
|
``+`` Indicates that a sign should be used for both
|
||||||
|
positive as well as negative numbers.
|
||||||
|
``-`` Indicates that a sign should be used only for
|
||||||
|
negative numbers (this is the default behavior).
|
||||||
|
(space) Indicates that a leading space should be used on
|
||||||
|
positive numbers.
|
||||||
|
================= ====================================================
|
||||||
|
|
||||||
|
]##
|
||||||
|
|
||||||
|
|
||||||
let
|
let
|
||||||
lla = 42394219 - 42429849 + 1293293 - 13918391 + 424242 # this here is an okayish comment
|
lla = 42394219 - 42429849 + 1293293 - 13918391 + 424242 # this here is an okayish comment
|
||||||
llb = 42394219 - 42429849 + 1293293 - 13918391 +
|
llb = 42394219 - 42429849 + 1293293 - 13918391 +
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue