fixes #1144
This commit is contained in:
parent
0339b9d386
commit
c41e099118
1 changed files with 13 additions and 12 deletions
|
|
@ -146,28 +146,29 @@ proc makeNimString(s: string): string =
|
||||||
for i in countup(0, len(s)-1): add(result, toNimChar(s[i]))
|
for i in countup(0, len(s)-1): add(result, toNimChar(s[i]))
|
||||||
add(result, '\"')
|
add(result, '\"')
|
||||||
|
|
||||||
proc putComment(g: var TSrcGen, s: string) =
|
proc putComment(g: var TSrcGen, s: string) =
|
||||||
|
if s.isNil: return
|
||||||
var i = 0
|
var i = 0
|
||||||
var comIndent = 1
|
var comIndent = 1
|
||||||
var isCode = (len(s) >= 2) and (s[1] != ' ')
|
var isCode = (len(s) >= 2) and (s[1] != ' ')
|
||||||
var ind = g.lineLen
|
var ind = g.lineLen
|
||||||
var com = ""
|
var com = ""
|
||||||
while true:
|
while true:
|
||||||
case s[i]
|
case s[i]
|
||||||
of '\0':
|
of '\0':
|
||||||
break
|
break
|
||||||
of '\x0D':
|
of '\x0D':
|
||||||
put(g, tkComment, com)
|
put(g, tkComment, com)
|
||||||
com = ""
|
com = ""
|
||||||
inc(i)
|
inc(i)
|
||||||
if s[i] == '\x0A': inc(i)
|
if s[i] == '\x0A': inc(i)
|
||||||
optNL(g, ind)
|
optNL(g, ind)
|
||||||
of '\x0A':
|
of '\x0A':
|
||||||
put(g, tkComment, com)
|
put(g, tkComment, com)
|
||||||
com = ""
|
com = ""
|
||||||
inc(i)
|
inc(i)
|
||||||
optNL(g, ind)
|
optNL(g, ind)
|
||||||
of '#':
|
of '#':
|
||||||
add(com, s[i])
|
add(com, s[i])
|
||||||
inc(i)
|
inc(i)
|
||||||
comIndent = 0
|
comIndent = 0
|
||||||
|
|
@ -175,10 +176,10 @@ proc putComment(g: var TSrcGen, s: string) =
|
||||||
add(com, s[i])
|
add(com, s[i])
|
||||||
inc(i)
|
inc(i)
|
||||||
inc(comIndent)
|
inc(comIndent)
|
||||||
of ' ', '\x09':
|
of ' ', '\x09':
|
||||||
add(com, s[i])
|
add(com, s[i])
|
||||||
inc(i)
|
inc(i)
|
||||||
else:
|
else:
|
||||||
# we may break the comment into a multi-line comment if the line
|
# we may break the comment into a multi-line comment if the line
|
||||||
# gets too long:
|
# gets too long:
|
||||||
# compute length of the following word:
|
# compute length of the following word:
|
||||||
|
|
@ -195,10 +196,10 @@ proc putComment(g: var TSrcGen, s: string) =
|
||||||
optNL(g)
|
optNL(g)
|
||||||
|
|
||||||
proc maxLineLength(s: string): int =
|
proc maxLineLength(s: string): int =
|
||||||
result = 0
|
if s.isNil: return 0
|
||||||
var i = 0
|
var i = 0
|
||||||
var lineLen = 0
|
var lineLen = 0
|
||||||
while true:
|
while true:
|
||||||
case s[i]
|
case s[i]
|
||||||
of '\0':
|
of '\0':
|
||||||
break
|
break
|
||||||
|
|
@ -459,7 +460,7 @@ proc lsub(n: PNode): int =
|
||||||
of nkBreakStmt: result = lsub(n.sons[0]) + len("break_")
|
of nkBreakStmt: result = lsub(n.sons[0]) + len("break_")
|
||||||
of nkContinueStmt: result = lsub(n.sons[0]) + len("continue_")
|
of nkContinueStmt: result = lsub(n.sons[0]) + len("continue_")
|
||||||
of nkPragma: result = lcomma(n) + 4
|
of nkPragma: result = lcomma(n) + 4
|
||||||
of nkCommentStmt: result = len(n.comment)
|
of nkCommentStmt: result = if n.comment.isNil: 0 else: len(n.comment)
|
||||||
of nkOfBranch: result = lcomma(n, 0, - 2) + lsub(lastSon(n)) + len("of_:_")
|
of nkOfBranch: result = lcomma(n, 0, - 2) + lsub(lastSon(n)) + len("of_:_")
|
||||||
of nkImportAs: result = lsub(n.sons[0]) + len("_as_") + lsub(n.sons[1])
|
of nkImportAs: result = lsub(n.sons[0]) + len("_as_") + lsub(n.sons[1])
|
||||||
of nkElifBranch: result = lsons(n) + len("elif_:_")
|
of nkElifBranch: result = lsons(n) + len("elif_:_")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue