doc2 improvements

This commit is contained in:
Araq
2012-06-24 02:34:11 +02:00
parent 2d8138768a
commit 869a5aa90d
10 changed files with 27 additions and 22 deletions

View File

@@ -322,12 +322,12 @@ proc generateIndex*(d: PDoc) =
writeIndexFile(d[], splitFile(options.outFile).dir /
splitFile(d.filename).name & indexExt)
proc writeOutput*(d: PDoc, filename, outExt: string) =
proc writeOutput*(d: PDoc, filename, outExt: string, useWarning = false) =
var content = genOutFile(d)
if optStdout in gGlobalOptions:
writeRope(stdout, content)
else:
writeRope(content, getOutFile(filename, outExt))
writeRope(content, getOutFile(filename, outExt), useWarning)
proc CommandDoc*() =
var ast = parseFile(addFileExt(gProjectFull, nimExt))

View File

@@ -22,8 +22,12 @@ type
proc close(p: PPassContext, n: PNode): PNode =
var g = PGen(p)
writeOutput(g.doc, g.filename, HtmlExt)
generateIndex(g.doc)
let useWarning = sfMainModule notin g.module.flags
writeOutput(g.doc, g.filename, HtmlExt, useWarning)
try:
generateIndex(g.doc)
except EIO:
nil
proc processNode(c: PPassContext, n: PNode): PNode =
result = n

View File

@@ -82,7 +82,6 @@ proc prepend*(a: var PRope, b: PRope)
proc toRope*(s: string): PRope
proc toRope*(i: BiggestInt): PRope
proc ropeLen*(a: PRope): int
proc WriteRope*(head: PRope, filename: string)
proc writeRopeIfNotEqual*(r: PRope, filename: string): bool
proc ropeToStr*(p: PRope): string
proc ropef*(frmt: TFormatStr, args: openarray[PRope]): PRope
@@ -204,13 +203,14 @@ proc writeRope*(f: TFile, c: PRope) =
assert(it.data != nil)
write(f, it.data)
proc WriteRope(head: PRope, filename: string) =
proc WriteRope*(head: PRope, filename: string, useWarning = false) =
var f: tfile
if open(f, filename, fmWrite):
if open(f, filename, fmWrite):
if head != nil: WriteRope(f, head)
close(f)
else:
rawMessage(errCannotOpenFile, filename)
else:
rawMessage(if useWarning: warnCannotOpenFile else: errCannotOpenFile,
filename)
proc ropef(frmt: TFormatStr, args: openarray[PRope]): PRope =
var i = 0

View File

@@ -267,7 +267,7 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
GlobalError(a.info, errWrongNumberOfVariables)
b = newNodeI(nkVarTuple, a.info)
newSons(b, length)
b.sons[length-2] = ast.emptyNode # no type desc
b.sons[length-2] = a.sons[length-2] # keep type desc for doc generator
b.sons[length-1] = def
addSon(result, b)
for j in countup(0, length-3):
@@ -286,7 +286,7 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
v.typ = typ
b = newNodeI(nkIdentDefs, a.info)
addSon(b, newSymNode(v))
addSon(b, ast.emptyNode) # no type description
addSon(b, a.sons[length-2]) # keep type desc for doc generator
addSon(b, copyTree(def))
addSon(result, b)
else:

View File

@@ -897,7 +897,7 @@ proc semGenericParamList(c: PContext, n: PNode, father: PType = nil): PNode =
s = newSymS(skType, a.sons[j], c)
s.typ = newTypeS(tyGenericParam, c)
of tyExpr:
echo "GENERIC EXPR ", a.info.toFileLineCol
#echo "GENERIC EXPR ", a.info.toFileLineCol
# not a type param, but an expression
# proc foo[x: expr](bar: int) what is this?
s = newSymS(skGenericParam, a.sons[j], c)

View File

@@ -703,8 +703,11 @@ proc transform(c: PTransf, n: PNode): PTransNode =
of nkConstSection:
# do not replace ``const c = 3`` with ``const 3 = 3``
return transformConstSection(c, n)
of nkTypeSection:
# no need to transform type sections:
return PTransNode(n)
of nkVarSection, nkLetSection:
if c.inlining > 0:
if c.inlining > 0:
# we need to copy the variables for multiple yield statements:
result = transformVarSection(c, n)
else: