nimpretty: fixes #9398
This commit is contained in:
parent
72370c8dfa
commit
e3a0415650
4 changed files with 21 additions and 2 deletions
|
|
@ -1118,6 +1118,7 @@ proc skip(L: var TLexer, tok: var TToken) =
|
||||||
tok.strongSpaceA = 0
|
tok.strongSpaceA = 0
|
||||||
when defined(nimpretty):
|
when defined(nimpretty):
|
||||||
var hasComment = false
|
var hasComment = false
|
||||||
|
var commentIndent = L.currLineIndent
|
||||||
tok.commentOffsetA = L.offsetBase + pos
|
tok.commentOffsetA = L.offsetBase + pos
|
||||||
tok.commentOffsetB = tok.commentOffsetA
|
tok.commentOffsetB = tok.commentOffsetA
|
||||||
tok.line = -1
|
tok.line = -1
|
||||||
|
|
@ -1146,6 +1147,8 @@ proc skip(L: var TLexer, tok: var TToken) =
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
tok.strongSpaceA = 0
|
tok.strongSpaceA = 0
|
||||||
|
when defined(nimpretty):
|
||||||
|
if buf[pos] == '#': commentIndent = indent
|
||||||
if buf[pos] > ' ' and (buf[pos] != '#' or buf[pos+1] == '#'):
|
if buf[pos] > ' ' and (buf[pos] != '#' or buf[pos+1] == '#'):
|
||||||
tok.indent = indent
|
tok.indent = indent
|
||||||
L.currLineIndent = indent
|
L.currLineIndent = indent
|
||||||
|
|
@ -1155,7 +1158,9 @@ proc skip(L: var TLexer, tok: var TToken) =
|
||||||
if buf[pos+1] == '#': break
|
if buf[pos+1] == '#': break
|
||||||
when defined(nimpretty):
|
when defined(nimpretty):
|
||||||
hasComment = true
|
hasComment = true
|
||||||
if tok.line < 0: tok.line = L.lineNumber
|
if tok.line < 0:
|
||||||
|
tok.line = L.lineNumber
|
||||||
|
#commentIndent = L.currLineIndent # if tok.strongSpaceA == 0: -1 else: tok.strongSpaceA
|
||||||
|
|
||||||
if buf[pos+1] == '[':
|
if buf[pos+1] == '[':
|
||||||
skipMultiLineComment(L, tok, pos+2, false)
|
skipMultiLineComment(L, tok, pos+2, false)
|
||||||
|
|
@ -1177,6 +1182,7 @@ proc skip(L: var TLexer, tok: var TToken) =
|
||||||
if hasComment:
|
if hasComment:
|
||||||
tok.commentOffsetB = L.offsetBase + pos - 1
|
tok.commentOffsetB = L.offsetBase + pos - 1
|
||||||
tok.tokType = tkComment
|
tok.tokType = tkComment
|
||||||
|
tok.indent = commentIndent
|
||||||
if gIndentationWidth <= 0:
|
if gIndentationWidth <= 0:
|
||||||
gIndentationWidth = tok.indent
|
gIndentationWidth = tok.indent
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
|
|
||||||
var x: int = 2
|
var x: int = 2
|
||||||
|
|
||||||
echo x # bug #9144
|
echo x
|
||||||
|
# bug #9144
|
||||||
|
|
|
||||||
|
|
@ -7,3 +7,9 @@ proc fun*() =
|
||||||
echo "ok"
|
echo "ok"
|
||||||
## doc comment
|
## doc comment
|
||||||
# regular comment
|
# regular comment
|
||||||
|
|
||||||
|
proc funB() =
|
||||||
|
echo "ok1"
|
||||||
|
# echo "ok2"
|
||||||
|
|
||||||
|
fun()
|
||||||
|
|
|
||||||
|
|
@ -7,3 +7,9 @@ proc fun*()=
|
||||||
echo "ok"
|
echo "ok"
|
||||||
## doc comment
|
## doc comment
|
||||||
# regular comment
|
# regular comment
|
||||||
|
|
||||||
|
proc funB() =
|
||||||
|
echo "ok1"
|
||||||
|
# echo "ok2"
|
||||||
|
|
||||||
|
fun()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue