This commit is contained in:
Andreas Rumpf 2016-10-20 21:03:49 +02:00
commit 20ee65af6d
2 changed files with 21 additions and 12 deletions

View file

@ -37,14 +37,20 @@ proc renderType(n: PNode): string =
of nkIdent: result = n.ident.s of nkIdent: result = n.ident.s
of nkSym: result = typeToString(n.sym.typ) of nkSym: result = typeToString(n.sym.typ)
of nkVarTy: of nkVarTy:
assert len(n) == 1 if n.len == 1:
result = renderType(n[0]) result = renderType(n[0])
else:
result = "var"
of nkRefTy: of nkRefTy:
assert len(n) == 1 if n.len == 1:
result = "ref." & renderType(n[0]) result = "ref." & renderType(n[0])
else:
result = "ref"
of nkPtrTy: of nkPtrTy:
assert len(n) == 1 if n.len == 1:
result = "ptr." & renderType(n[0]) result = "ptr." & renderType(n[0])
else:
result = "ptr"
of nkProcTy: of nkProcTy:
assert len(n) > 1 assert len(n) > 1
let params = n[0] let params = n[0]

View file

@ -242,14 +242,17 @@ proc nimNextToken(g: var GeneralTokenizer) =
inc(pos) inc(pos)
case g.buf[pos] case g.buf[pos]
of 'b', 'B': of 'b', 'B':
g.kind = gtBinNumber
inc(pos) inc(pos)
while g.buf[pos] in binChars: inc(pos) while g.buf[pos] in binChars: inc(pos)
pos = nimNumberPostfix(g, pos) pos = nimNumberPostfix(g, pos)
of 'x', 'X': of 'x', 'X':
g.kind = gtHexNumber
inc(pos) inc(pos)
while g.buf[pos] in hexChars: inc(pos) while g.buf[pos] in hexChars: inc(pos)
pos = nimNumberPostfix(g, pos) pos = nimNumberPostfix(g, pos)
of 'o', 'O': of 'o', 'O':
g.kind = gtOctNumber
inc(pos) inc(pos)
while g.buf[pos] in octChars: inc(pos) while g.buf[pos] in octChars: inc(pos)
pos = nimNumberPostfix(g, pos) pos = nimNumberPostfix(g, pos)
@ -700,8 +703,8 @@ proc yamlNextToken(g: var GeneralTokenizer) =
g.state = gtLongStringLit g.state = gtLongStringLit
elif g.state == gtLongStringLit: elif g.state == gtLongStringLit:
# beware, this is the only token where we actually have to parse # beware, this is the only token where we actually have to parse
# indentation. # indentation.
g.kind = gtLongStringLit g.kind = gtLongStringLit
# first, we have to find the parent indentation of the block scalar, so that # first, we have to find the parent indentation of the block scalar, so that
# we know when to stop # we know when to stop
@ -738,20 +741,20 @@ proc yamlNextToken(g: var GeneralTokenizer) =
# because lookbehind was at newline char when calculating indentation, we're # because lookbehind was at newline char when calculating indentation, we're
# off by one. fix that. top level's parent will have indentation of -1. # off by one. fix that. top level's parent will have indentation of -1.
let parentIndentation = indentation - 1 let parentIndentation = indentation - 1
# find first content # find first content
while g.buf[pos] in {' ', '\x0A', '\x0D'}: while g.buf[pos] in {' ', '\x0A', '\x0D'}:
if g.buf[pos] == ' ': inc(indentation) if g.buf[pos] == ' ': inc(indentation)
else: indentation = 0 else: indentation = 0
inc(pos) inc(pos)
var minIndentation = indentation var minIndentation = indentation
# for stupid edge cases, we must check whether an explicit indentation depth # for stupid edge cases, we must check whether an explicit indentation depth
# is given at the header. # is given at the header.
while g.buf[headerStart] in {'>', '|', '+', '-'}: inc(headerStart) while g.buf[headerStart] in {'>', '|', '+', '-'}: inc(headerStart)
if g.buf[headerStart] in {'0'..'9'}: if g.buf[headerStart] in {'0'..'9'}:
minIndentation = min(minIndentation, ord(g.buf[headerStart]) - ord('0')) minIndentation = min(minIndentation, ord(g.buf[headerStart]) - ord('0'))
# process content lines # process content lines
while indentation > parentIndentation and g.buf[pos] != '\0': while indentation > parentIndentation and g.buf[pos] != '\0':
if (indentation < minIndentation and g.buf[pos] == '#') or if (indentation < minIndentation and g.buf[pos] == '#') or
@ -766,7 +769,7 @@ proc yamlNextToken(g: var GeneralTokenizer) =
if g.buf[pos] == ' ': inc(indentation) if g.buf[pos] == ' ': inc(indentation)
else: indentation = 0 else: indentation = 0
inc(pos) inc(pos)
g.state = gtOther g.state = gtOther
elif g.state == gtOther: elif g.state == gtOther:
# gtOther means 'inside YAML document' # gtOther means 'inside YAML document'