nimpretty: bugfix [bugfix]
This commit is contained in:
parent
d72edfb14b
commit
284a8cb58a
4 changed files with 106 additions and 12 deletions
|
|
@ -143,14 +143,21 @@ proc closeEmitter*(em: var Emitter) =
|
||||||
maxLhs = computeMax(em, lineBegin)
|
maxLhs = computeMax(em, lineBegin)
|
||||||
of ltEndSection:
|
of ltEndSection:
|
||||||
maxLhs = 0
|
maxLhs = 0
|
||||||
|
lineBegin = i+1
|
||||||
of ltTab:
|
of ltTab:
|
||||||
if maxLhs == 0 or computeRhs(em, i+1)+maxLhs > MaxLineLen:
|
if maxLhs == 0:
|
||||||
content.add em.tokens[i]
|
content.add em.tokens[i]
|
||||||
inc lineLen, em.tokens[i].len
|
inc lineLen, em.tokens[i].len
|
||||||
else:
|
else:
|
||||||
let spaces = maxLhs - lineLen #max(maxLhs - lineLen, 1)
|
# pick the shorter indentation token:
|
||||||
for j in 1..spaces: content.add ' '
|
var spaces = maxLhs - lineLen
|
||||||
inc lineLen, spaces
|
if spaces < em.tokens[i].len or computeRhs(em, i+1)+maxLhs <= MaxLineLen:
|
||||||
|
if spaces <= 0 and content[^1] notin {' ', '\L'}: spaces = 1
|
||||||
|
for j in 1..spaces: content.add ' '
|
||||||
|
inc lineLen, spaces
|
||||||
|
else:
|
||||||
|
content.add em.tokens[i]
|
||||||
|
inc lineLen, em.tokens[i].len
|
||||||
of ltNewline:
|
of ltNewline:
|
||||||
content.add em.tokens[i]
|
content.add em.tokens[i]
|
||||||
lineLen = 0
|
lineLen = 0
|
||||||
|
|
@ -217,8 +224,16 @@ proc wrSpace(em: var Emitter) =
|
||||||
proc wrTab(em: var Emitter) =
|
proc wrTab(em: var Emitter) =
|
||||||
wr(em, " ", ltTab)
|
wr(em, " ", ltTab)
|
||||||
|
|
||||||
proc beginSection*(em: var Emitter) = wr(em, "", ltBeginSection)
|
proc beginSection*(em: var Emitter) =
|
||||||
proc endSection*(em: var Emitter) = wr(em, "", ltEndSection)
|
em.tokens.insert "", em.tokens.len-2
|
||||||
|
em.kinds.insert ltBeginSection, em.kinds.len-2
|
||||||
|
|
||||||
|
#wr(em, "", ltBeginSection)
|
||||||
|
proc endSection*(em: var Emitter) =
|
||||||
|
em.tokens.insert "", em.tokens.len-2
|
||||||
|
em.kinds.insert ltEndSection, em.kinds.len-2
|
||||||
|
|
||||||
|
#wr(em, "", ltEndSection)
|
||||||
|
|
||||||
proc removeSpaces(em: var Emitter) =
|
proc removeSpaces(em: var Emitter) =
|
||||||
while em.kinds.len > 0 and em.kinds[^1] == ltSpaces:
|
while em.kinds.len > 0 and em.kinds[^1] == ltSpaces:
|
||||||
|
|
@ -262,7 +277,8 @@ proc emitMultilineComment(em: var Emitter, lit: string, col: int) =
|
||||||
var a = 0
|
var a = 0
|
||||||
while a < commentLine.len and commentLine[a] == ' ': inc a
|
while a < commentLine.len and commentLine[a] == ' ': inc a
|
||||||
if i == 0:
|
if i == 0:
|
||||||
wr(em, "", ltTab)
|
if em.kinds.len > 0 and em.kinds[^1] != ltTab:
|
||||||
|
wr(em, "", ltTab)
|
||||||
elif stripped.len == 0:
|
elif stripped.len == 0:
|
||||||
wrNewline em
|
wrNewline em
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -160,11 +160,11 @@ type
|
||||||
cmdArgument, ## An argument such as a filename
|
cmdArgument, ## An argument such as a filename
|
||||||
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* =
|
OptParser* = object of RootObj ## \
|
||||||
object of RootObj ## Implementation of the command line parser.
|
## Implementation of the command line parser.
|
||||||
##
|
##
|
||||||
## 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
|
||||||
|
|
|
||||||
|
|
@ -618,3 +618,42 @@ veryLongVariableName.createVar("future" & $node[1][0].toStrLit, node[1], futureV
|
||||||
|
|
||||||
veryLongVariableName.createVar("future" & $node[1][0].toStrLit, node[1], futureValue1,
|
veryLongVariableName.createVar("future" & $node[1][0].toStrLit, node[1], futureValue1,
|
||||||
futureValue2, node)
|
futureValue2, node)
|
||||||
|
|
||||||
|
type
|
||||||
|
CmdLineKind* = enum ## The detected command line token.
|
||||||
|
cmdEnd, ## End of command line reached
|
||||||
|
cmdArgument, ## An argument such as a filename
|
||||||
|
cmdLongOption, ## A long option such as --option
|
||||||
|
cmdShortOption ## A short option such as -c
|
||||||
|
OptParser* = object of RootObj ## \
|
||||||
|
## Implementation of the command line parser. Here is even more text yad.
|
||||||
|
##
|
||||||
|
## To initialize it, use the
|
||||||
|
## `initOptParser proc<#initOptParser,string,set[char],seq[string]>`_.
|
||||||
|
pos*: int
|
||||||
|
inShortState: bool
|
||||||
|
allowWhitespaceAfterColon: bool
|
||||||
|
shortNoVal: set[char]
|
||||||
|
longNoVal: seq[string]
|
||||||
|
cmds: seq[string]
|
||||||
|
idx: int
|
||||||
|
kind*: CmdLineKind ## The detected command line token
|
||||||
|
key*, val*: TaintedString ## Key and value pair; the key is the option
|
||||||
|
## or the argument, and the value is not "" if
|
||||||
|
## the option was given a value
|
||||||
|
|
||||||
|
OptParserDifferently* = object of RootObj ## Implementation of the command line parser.
|
||||||
|
##
|
||||||
|
## To initialize it, use the
|
||||||
|
## `initOptParser proc<#initOptParser,string,set[char],seq[string]>`_.
|
||||||
|
pos*: int
|
||||||
|
inShortState: bool
|
||||||
|
allowWhitespaceAfterColon: bool
|
||||||
|
shortNoVal: set[char]
|
||||||
|
longNoVal: seq[string]
|
||||||
|
cmds: seq[string]
|
||||||
|
idx: int
|
||||||
|
kind*: CmdLineKind ## The detected command line token
|
||||||
|
key*, val*: TaintedString ## Key and value pair; the key is the option
|
||||||
|
## or the argument, and the value is not "" if
|
||||||
|
## the option was given a value
|
||||||
|
|
|
||||||
|
|
@ -624,3 +624,42 @@ veryLongVariableName.createVar("future" & $node[1][0].toStrLit, node[1],
|
||||||
|
|
||||||
veryLongVariableName.createVar("future" & $node[1][0].toStrLit, node[1], futureValue1,
|
veryLongVariableName.createVar("future" & $node[1][0].toStrLit, node[1], futureValue1,
|
||||||
futureValue2, node)
|
futureValue2, node)
|
||||||
|
|
||||||
|
type
|
||||||
|
CmdLineKind* = enum ## The detected command line token.
|
||||||
|
cmdEnd, ## End of command line reached
|
||||||
|
cmdArgument, ## An argument such as a filename
|
||||||
|
cmdLongOption, ## A long option such as --option
|
||||||
|
cmdShortOption ## A short option such as -c
|
||||||
|
OptParser* = object of RootObj ## \
|
||||||
|
## Implementation of the command line parser. Here is even more text yad.
|
||||||
|
##
|
||||||
|
## To initialize it, use the
|
||||||
|
## `initOptParser proc<#initOptParser,string,set[char],seq[string]>`_.
|
||||||
|
pos*: int
|
||||||
|
inShortState: bool
|
||||||
|
allowWhitespaceAfterColon: bool
|
||||||
|
shortNoVal: set[char]
|
||||||
|
longNoVal: seq[string]
|
||||||
|
cmds: seq[string]
|
||||||
|
idx: int
|
||||||
|
kind*: CmdLineKind ## The detected command line token
|
||||||
|
key*, val*: TaintedString ## Key and value pair; the key is the option
|
||||||
|
## or the argument, and the value is not "" if
|
||||||
|
## the option was given a value
|
||||||
|
|
||||||
|
OptParserDifferently* = object of RootObj ## Implementation of the command line parser.
|
||||||
|
##
|
||||||
|
## To initialize it, use the
|
||||||
|
## `initOptParser proc<#initOptParser,string,set[char],seq[string]>`_.
|
||||||
|
pos*: int
|
||||||
|
inShortState: bool
|
||||||
|
allowWhitespaceAfterColon: bool
|
||||||
|
shortNoVal: set[char]
|
||||||
|
longNoVal: seq[string]
|
||||||
|
cmds: seq[string]
|
||||||
|
idx: int
|
||||||
|
kind*: CmdLineKind ## The detected command line token
|
||||||
|
key*, val*: TaintedString ## Key and value pair; the key is the option
|
||||||
|
## or the argument, and the value is not "" if
|
||||||
|
## the option was given a value
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue