implements final version of multiline comments

This commit is contained in:
Andreas Rumpf
2016-01-17 20:29:50 +01:00
parent 2e71bd50b2
commit a4aeb6fbec
4 changed files with 63 additions and 43 deletions

View File

@@ -174,19 +174,38 @@ proc nimNextToken(g: var GeneralTokenizer) =
of '#':
g.kind = gtComment
inc(pos)
if g.buf[pos] == '#': inc(pos)
var isDoc = false
if g.buf[pos] == '#':
inc(pos)
isDoc = true
if g.buf[pos] == '[':
g.kind = gtLongComment
var brackets = 0
while g.buf[pos] == '[':
inc(pos)
inc(brackets)
while g.buf[pos] != '\0':
if g.buf[pos] == ']':
var q = pos
while g.buf[pos] == ']': inc(pos)
if pos-q == brackets: break
inc(pos)
var nesting = 0
while true:
case g.buf[pos]
of '\0': break
of '#':
if isDoc:
if g.buf[pos+1] == '#' and g.buf[pos+2] == '[':
inc nesting
elif g.buf[pos+1] == '[':
inc nesting
inc pos
of ']':
if isDoc:
if g.buf[pos+1] == '#' and g.buf[pos+2] == '#':
if nesting == 0:
inc(pos, 3)
break
dec nesting
elif g.buf[pos+1] == '#':
if nesting == 0:
inc(pos, 2)
break
dec nesting
inc pos
else:
inc pos
else:
while g.buf[pos] notin {'\0', '\x0A', '\x0D'}: inc(pos)
of 'a'..'z', 'A'..'Z', '_', '\x80'..'\xFF':