conservative approach to fix #15184 (#16723)

This commit is contained in:
Andrey Makarov 2021-01-15 02:53:36 +03:00 • committed by GitHub
commit 554fe8f88f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 61 additions and 11 deletions

View file

@ -955,8 +955,10 @@ proc skipMultiLineComment(L: var Lexer; tok: var Token; start: int;
# detect the amount of indentation:
if isDoc:
toStrip = getColNumber(L, pos)
while L.buf[pos] == ' ': inc pos
if L.buf[pos] in {CR, LF}:
while L.buf[pos] == ' ':
inc pos
inc toStrip
while L.buf[pos] in {CR, LF}: # skip blank lines
pos = handleCRLF(L, pos)
toStrip = 0
while L.buf[pos] == ' ':
@ -1028,11 +1030,17 @@ proc scanComment(L: var Lexer, tok: var Token) =
inc(pos, 2)
var toStrip = 0
while L.buf[pos] == ' ':
inc pos
inc toStrip
var stripInit = false
while true:
if not stripInit: # find baseline indentation inside comment
while L.buf[pos] == ' ':
inc pos
inc toStrip
if L.buf[pos] in {CR, LF}: # don't set toStrip in blank comment lines
toStrip = 0
else: # found first non-whitespace character
stripInit = true
var lastBackslash = -1
while L.buf[pos] notin {CR, LF, nimlexbase.EndOfFile}:
if L.buf[pos] == '\\': lastBackslash = pos+1
@ -1048,11 +1056,12 @@ proc scanComment(L: var Lexer, tok: var Token) =
if L.buf[pos] == '#' and L.buf[pos+1] == '#':
tok.literal.add "\n"
inc(pos, 2)
var c = toStrip
while L.buf[pos] == ' ' and c > 0:
inc pos
dec c
inc tok.iNumber
if stripInit:
var c = toStrip
while L.buf[pos] == ' ' and c > 0:
inc pos
dec c
inc tok.iNumber
else:
if L.buf[pos] > ' ':
L.indentAhead = indent