httpserver supports a fixed port number

This commit is contained in:
Andreas Rumpf
2010-02-06 12:24:54 +01:00
parent eca05d2a33
commit fd522aa406
9 changed files with 278 additions and 201 deletions

View File

@@ -1,5 +1,4 @@
Advanced commands::
pas convert a Pascal file to Nimrod syntax
pretty pretty print the inputfile
genDepend generate a DOT file containing the
module dependency graph

View File

@@ -6,6 +6,10 @@
:Version: |nimrodversion|
.. contents::
**Note:** ENDB has not been maintained/tested since several versions. Help if
you want this debugger to survive.
Nimrod comes with a platform independant debugger -
the `Embedded Nimrod Debugger`:idx: (`ENDB`:idx:). The debugger is

View File

@@ -50,22 +50,22 @@ proc dbQuote(s: string): string =
else: add(result, c)
add(result, '\'')
proc dbFormat(formatstr: string, args: openarray[string]): string =
proc dbFormat(formatstr: TSqlQuery, args: openarray[string]): string =
result = ""
var a = 0
for c in items(formatstr):
for c in items(string(formatstr)):
if c == '?':
add(result, dbQuote(args[a]))
inc(a)
else:
add(result, c)
proc TryQuery*(db: TDbConn, query: string, args: openarray[string]): bool =
proc TryQuery*(db: TDbConn, query: TSqlQuery, args: openarray[string]): bool =
## tries to execute the query and returns true if successful, false otherwise.
var q = dbFormat(query, args)
return mysqlRealQuery(db, q, q.len) == 0'i32
proc Query*(db: TDbConn, query: string, args: openarray[string]) =
proc Query*(db: TDbConn, query: TSqlQuery, args: openarray[string]) =
## executes the query and raises EDB if not successful.
var q = dbFormat(query, args)
if mysqlRealQuery(db, q, q.len) != 0'i32: dbError(db)
@@ -79,7 +79,7 @@ proc properFreeResult(sqlres: PMYSQL_RES, row: cstringArray) =
while mysqlFetchRow(sqlres) != nil: nil
mysqlFreeResult(sqlres)
iterator FastRows*(db: TDbConn, query: string,
iterator FastRows*(db: TDbConn, query: TSqlQuery,
args: openarray[string]): TRow =
## executes the query and iterates over the result dataset. This is very
## fast, but potenially dangerous: If the for-loop-body executes another
@@ -99,7 +99,7 @@ iterator FastRows*(db: TDbConn, query: string,
yield result
properFreeResult(sqlres, row)
proc GetAllRows*(db: TDbConn, query: string,
proc GetAllRows*(db: TDbConn, query: TSqlQuery,
args: openarray[string]): seq[TRow] =
## executes the query and returns the whole result dataset.
result = @[]
@@ -118,12 +118,12 @@ proc GetAllRows*(db: TDbConn, query: string,
inc(j)
mysqlFreeResult(sqlres)
iterator Rows*(db: TDbConn, query: string,
iterator Rows*(db: TDbConn, query: TSqlQuery,
args: openarray[string]): TRow =
## same as `FastRows`, but slower and safe.
for r in items(GetAllRows(db, query, args)): yield r
proc GetValue*(db: TDbConn, query: string,
proc GetValue*(db: TDbConn, query: TSqlQuery,
args: openarray[string]): string =
## executes the query and returns the result dataset's the first column
## of the first row. Returns "" if the dataset contains no rows. This uses
@@ -133,7 +133,7 @@ proc GetValue*(db: TDbConn, query: string,
result = row[0]
break
proc TryInsertID*(db: TDbConn, query: string,
proc TryInsertID*(db: TDbConn, query: TSqlQuery,
args: openarray[string]): int64 =
## executes the query (typically "INSERT") and returns the
## generated ID for the row or -1 in case of an error.
@@ -143,13 +143,13 @@ proc TryInsertID*(db: TDbConn, query: string,
else:
result = mysql_insert_id(db)
proc InsertID*(db: TDbConn, query: string, args: openArray[string]): int64 =
proc InsertID*(db: TDbConn, query: TSqlQuery, args: openArray[string]): int64 =
## executes the query (typically "INSERT") and returns the
## generated ID for the row.
result = TryInsertID(db, query, args)
if result < 0: dbError(db)
proc QueryAffectedRows*(db: TDbConn, query: string,
proc QueryAffectedRows*(db: TDbConn, query: TSqlQuery,
args: openArray[string]): int64 =
## runs the query (typically "UPDATE") and returns the
## number of affected rows

39
lib/devel/httpserver.nim → lib/pure/httpserver.nim Executable file → Normal file
View File

@@ -8,6 +8,20 @@
#
## This module implements a simple HTTP-Server.
##
## Example:
##
## .. code-block:: nimrod
## import strutils, sockets, httpserver
##
## var counter = 0
## proc handleRequest(client: TSocket, path, query: string): bool {.procvar.} =
## inc(counter)
## client.send("Hallo for the $#th time." % $counter & wwwNL)
## return false # do not stop processing
##
## run(handleRequest, TPort(80))
##
import strutils, os, osproc, strtabs, streams, sockets
@@ -180,15 +194,18 @@ type
client*: TSocket ## the socket to write the file data to
path*, query*: string ## path and query the client requested
proc open*(s: var TServer, port = TPort(0)) =
proc open*(s: var TServer, port = TPort(80)) =
## creates a new server at port `port`. If ``port == 0`` a free port is
## aquired that can be accessed later by the ``port`` proc.
s.socket = socket(AF_INET)
if s.socket == InvalidSocket: OSError()
bindAddr(s.socket)
bindAddr(s.socket, port)
listen(s.socket)
s.port = getSockName(s.socket)
if port == TPort(0):
s.port = getSockName(s.socket)
else:
s.port = port
s.client = InvalidSocket
s.path = ""
s.query = ""
@@ -220,7 +237,7 @@ proc close*(s: TServer) =
close(s.socket)
proc run*(handleRequest: proc (client: TSocket, path, query: string): bool,
port = TPort(0)) =
port = TPort(80)) =
## encapsulates the server object and main loop
var s: TServer
open(s, port)
@@ -231,18 +248,6 @@ proc run*(handleRequest: proc (client: TSocket, path, query: string): bool,
close(s.client)
close(s)
when false:
proc main =
var (server, port) = startup()
echo("httpserver running on port ", int16(port))
while true:
var client = accept(server)
if client == InvalidSocket: OSError()
acceptRequest(client)
close(client)
close(server)
when isMainModule:
var counter = 0
proc handleRequest(client: TSocket, path, query: string): bool {.procvar.} =
@@ -250,5 +255,5 @@ when isMainModule:
client.send("Hallo, Andreas for the $#th time." % $counter & wwwNL)
return false # do not stop processing
run(handleRequest)
run(handleRequest, TPort(80))

View File

@@ -1,7 +1,7 @@
#
#
# Nimrod's Runtime Library
# (c) Copyright 2009 Andreas Rumpf
# (c) Copyright 2010 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.

View File

@@ -9,28 +9,171 @@
## Regular expression support for Nimrod. Consider using the pegs module
## instead.
## Currently this module is implemented by providing a wrapper around the
## `PRCE (Perl-Compatible Regular Expressions) <http://www.pcre.org>`_
## C library. This means that your application will depend on the PRCE
## library's licence when using this module, which should not be a problem
## though.
## PRCE's licence follows:
##
## .. include:: ../doc/regexprs.txt
##
{.compile: "tre/tre_all.c".}
from strutils import addf
type
TRegExDesc {.pure, final.} = object
re_nsub: int # Number of parenthesized subexpressions.
value: pointer # For internal use only.
TRegEx* = ref TRegExDesc ## a compiled regular expression
EInvalidRegEx* = object of EInvalidValue
## is raised if the pattern is no valid regular expression.
TRegMatch {.pure.} = object
so, eo: cint
import
pcre, strutils
const
MaxSubpatterns* = 10
## defines the maximum number of subpatterns that can be captured.
## More subpatterns cannot be captured!
type
TRegExOptions* = enum ## options for regular expressions
reIgnoreCase = 0, ## do caseless matching
reMultiLine = 1, ## ``^`` and ``$`` match newlines within data
reDotAll = 2, ## ``.`` matches anything including NL
reExtended = 3, ## ignore whitespace and ``#`` comments
PCRE_ANCHORED* = 0x00000010
PCRE_DOLLAR_ENDONLY* = 0x00000020
PCRE_EXTRA* = 0x00000040
PCRE_NOTBOL* = 0x00000080
PCRE_NOTEOL* = 0x00000100
PCRE_UNGREEDY* = 0x00000200
PCRE_NOTEMPTY* = 0x00000400
PCRE_UTF8* = 0x00000800
PCRE_NO_AUTO_CAPTURE* = 0x00001000
TRegExDesc {.pure, final.} = object
h: PPcre
TRegEx* = ref TRegExDesc ## a compiled regular expression
EInvalidRegEx* = object of EInvalidValue
## is raised if the pattern is no valid regular expression.
proc rawCompile(pattern: string, flags: cint): PPcre =
var
msg: CString
offset: int
com = pcreCompile(pattern, flags, addr(msg), addr(offset), nil)
if com == nil:
var e: ref EInvalidRegEx
new(e)
e.msg = $msg & "\n" & pattern & "\n" & repeatChar(offset) & "^\n"
raise e
return com
proc finalizeRegEx(x: TRegEx) = dealloc(x.h)
proc re*(s: string): TRegEx =
## Constructor of regular expressions. Note that Nimrod's
## extended raw string literals supports this syntax ``re"[abc]"`` as
## a short form for ``re(r"[abc]")``.
new(result, finalizeRegEx)
result.h = rawCompile(s,
var err = int(regncomp(addr(result^), s, s.len,
cint(REG_EXTENDED or REG_NEWLINE)))
if err != 0:
var e: ref EInvalidRegEx
new(e)
e.msg = ErrorMessages[err]
raise e
proc xre*(pattern: string): TRegEx =
## deletes whitespace from a pattern that is not escaped or in a character
## class. Then it constructs a regular expresion object via `re`.
## This is modelled after Perl's ``/x`` modifier.
var p = ""
var i = 0
while i < pattern.len:
case pattern[i]
of ' ', '\t':
inc i
of '\\':
add p, '\\'
add p, pattern[i+1]
inc i, 2
of '[':
while pattern[i] != ']' and pattern[i] != '\0':
add p, pattern[i]
inc i
else:
add p, pattern[i]
inc i
result = re(p)
proc matchOrFind(s: string, pattern: PPcre, matches: var openarray[string],
start: cint): cint =
var
rawMatches: array [0..maxSubpatterns * 3 - 1, cint]
res = int(pcreExec(pattern, nil, s, len(s), start, 0,
cast[ptr cint](addr(rawMatches)), maxSubpatterns * 3))
dealloc(pattern)
if res < 0: return res
for i in 0..res-1:
var
a = rawMatches[i * 2]
b = rawMatches[i * 2 + 1]
if a >= 0'i32: matches[i] = copy(s, a, int(b)-1)
else: matches[i] = ""
return res
proc matchOrFind(s: string, pattern: PPcre, start: cint): cint =
var
rawMatches: array [0..maxSubpatterns * 3 - 1, cint]
res = pcreExec(pattern, nil, s, len(s), start, 0,
cast[ptr cint](addr(rawMatches)), maxSubpatterns * 3)
dealloc(pattern)
return res
proc match(s, pattern: string, matches: var openarray[string],
start: int = 0): bool =
return matchOrFind(s, rawCompile(pattern, PCRE_ANCHORED),
matches, start) >= 0'i32
proc matchLen(s, pattern: string, matches: var openarray[string],
start: int = 0): int =
return matchOrFind(s, rawCompile(pattern, PCRE_ANCHORED), matches, start)
proc find(s, pattern: string, matches: var openarray[string],
start: int = 0): bool =
return matchOrFind(s, rawCompile(pattern, PCRE_MULTILINE),
matches, start) >= 0'i32
proc match(s, pattern: string, start: int = 0): bool =
return matchOrFind(s, rawCompile(pattern, PCRE_ANCHORED), start) >= 0'i32
proc find(s, pattern: string, start: int = 0): bool =
return matchOrFind(s, rawCompile(pattern, PCRE_MULTILINE), start) >= 0'i32
template `=~` *(s, pattern: expr): expr =
## This calls ``match`` with an implicit declared ``matches`` array that
## can be used in the scope of the ``=~`` call:
##
## .. code-block:: nimrod
##
## if line =~ r"\s*(\w+)\s*\=\s*(\w+)":
## # matches a key=value pair:
## echo("Key: ", matches[1])
## echo("Value: ", matches[2])
## elif line =~ r"\s*(\#.*)":
## # matches a comment
## # note that the implicit ``matches`` array is different from the
## # ``matches`` array of the first branch
## echo("comment: ", matches[1])
## else:
## echo("syntax error")
##
when not definedInScope(matches):
var matches: array[0..maxSubPatterns-1, string]
match(s, pattern, matches)
proc regnexec(preg: ptr TRegExDesc, s: cstring, len, nmatch: int,
pmatch: ptr array [0..maxSubpatterns-1, TRegMatch],
eflags: cint): cint {.importc.}
@@ -75,44 +218,6 @@ const
"Invalid use of repetition operators"
]
proc finalizeRegEx(x: TRegEx) = regfree(addr(x^))
proc re*(s: string): TRegEx =
## Constructor of regular expressions. Note that Nimrod's
## extended raw string literals supports this syntax ``re"[abc]"`` as
## a short form for ``re(r"[abc]")``.
new(result, finalizeRegEx)
var err = int(regncomp(addr(result^), s, s.len,
cint(REG_EXTENDED or REG_NEWLINE)))
if err != 0:
var e: ref EInvalidRegEx
new(e)
e.msg = ErrorMessages[err]
raise e
proc xre*(pattern: string): TRegEx =
## deletes whitespace from a pattern that is not escaped or in a character
## class. Then it constructs a regular expresion object via `re`.
## This is modelled after Perl's ``/x`` modifier.
var p = ""
var i = 0
while i < pattern.len:
case pattern[i]
of ' ', '\t':
inc i
of '\\':
add p, '\\'
add p, pattern[i+1]
inc i, 2
of '[':
while pattern[i] != ']' and pattern[i] != '\0':
add p, pattern[i]
inc i
else:
add p, pattern[i]
inc i
result = re(p)
proc rawmatch(s: string, pattern: TRegEx, matches: var openarray[string],
start: int): tuple[first, last: int] =
var

View File

@@ -223,6 +223,8 @@ proc allocParam(p: BProc, s: PSym) =
proc localDebugInfo(p: BProc, s: PSym) =
var name, a: PRope
if {optStackTrace, optEndb} * p.options != {optStackTrace, optEndb}: return
# XXX work around a bug: No type information for open arrays possible:
if skipTypes(s.typ, abstractVar).kind == tyOpenArray: return
if gCmd == cmdCompileToLLVM:
# "address" is the 0th field
# "typ" is the 1rst field

View File

@@ -1,7 +1,7 @@
#
#
# The Nimrod Compiler
# (c) Copyright 2009 Andreas Rumpf
# (c) Copyright 2010 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
@@ -14,36 +14,30 @@ import
proc genDependPass*(): TPass
proc generateDot*(project: string)
# implementation
type
TGen = object of TPassContext
module*: PSym
filename*: string
PGen = ref TGen
var gDotGraph: PRope
var gDotGraph: PRope # the generated DOT file; we need a global variable
proc addDependencyAux(importing, imported: string) =
# the generated DOT file; we need a global variable
appf(gDotGraph, "$1 -> $2;$n", [toRope(importing), toRope(imported)]) # s1 -> s2_4
# [label="[0-9]"];
appf(gDotGraph, "$1 -> $2;$n", [toRope(importing), toRope(imported)])
# s1 -> s2_4[label="[0-9]"];
proc addDotDependency(c: PPassContext, n: PNode): PNode =
var
g: PGen
imported: string
result = n
if n == nil: return
g = PGen(c)
var g = PGen(c)
case n.kind
of nkImportStmt:
for i in countup(0, sonsLen(n) - 1):
imported = splitFile(getModuleFile(n.sons[i])).name
var imported = splitFile(getModuleFile(n.sons[i])).name
addDependencyAux(g.module.name.s, imported)
of nkFromStmt:
imported = splitFile(getModuleFile(n.sons[0])).name
var imported = splitFile(getModuleFile(n.sons[0])).name
addDependencyAux(g.module.name.s, imported)
of nkStmtList, nkBlockStmt, nkStmtListExpr, nkBlockExpr:
for i in countup(0, sonsLen(n) - 1): discard addDotDependency(c, n.sons[i])

View File

@@ -1,7 +1,7 @@
#
#
# The Nimrod Compiler
# (c) Copyright 2009 Andreas Rumpf
# (c) Copyright 2010 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
@@ -92,7 +92,7 @@ proc initIndexFile(d: PDoc) =
proc newDocumentor(filename: string): PDoc =
new(result)
result.tocPart = @ []
result.tocPart = @[]
result.filename = filename
result.id = 100
result.splitAfter = 20
@@ -203,24 +203,21 @@ proc nextSplitPoint(s: string, start: int): int =
result = start
while result < len(s) + 0:
case s[result]
of '_':
return
of '_': return
of 'a'..'z':
if result + 1 < len(s) + 0:
if s[result + 1] in {'A'..'Z'}: return
else:
nil
else: nil
inc(result)
dec(result) # last valid index
proc esc(s: string, splitAfter: int = - 1): string =
var j, k, partLen: int
result = ""
if splitAfter >= 0:
partLen = 0
j = 0
while j < len(s) + 0:
k = nextSplitPoint(s, j)
var partLen = 0
var j = 0
while j < len(s):
var k = nextSplitPoint(s, j)
if (splitter != " ") or (partLen + k - j + 1 > splitAfter):
partLen = 0
add(result, splitter)
@@ -249,10 +246,9 @@ proc renderAux(d: PDoc, n: PRstNode, outer: string = "$1"): PRope =
result = ropef(outer, [result])
proc setIndexForSourceTerm(d: PDoc, name: PRstNode, id: int) =
var a, h: PRstNode
if d.theIndex == nil: return
h = newRstNode(rnHyperlink)
a = newRstNode(rnLeaf, d.indexValFilename & disp("#", "") & $(id))
var h = newRstNode(rnHyperlink)
var a = newRstNode(rnLeaf, d.indexValFilename & disp("#", "") & $id)
addSon(h, a)
addSon(h, a)
a = newRstNode(rnIdx)
@@ -260,12 +256,11 @@ proc setIndexForSourceTerm(d: PDoc, name: PRstNode, id: int) =
setIndexPair(d.theIndex, a, h)
proc renderIndexTerm(d: PDoc, n: PRstNode): PRope =
var a, h: PRstNode
inc(d.id)
result = dispF("<em id=\"$1\">$2</em>", "$2\\label{$1}",
[toRope(d.id), renderAux(d, n)])
h = newRstNode(rnHyperlink)
a = newRstNode(rnLeaf, d.indexValFilename & disp("#", "") & $(d.id))
var h = newRstNode(rnHyperlink)
var a = newRstNode(rnLeaf, d.indexValFilename & disp("#", "") & $d.id)
addSon(h, a)
addSon(h, a)
setIndexPair(d.theIndex, n, h)
@@ -530,12 +525,13 @@ proc renderRstToRst(d: PDoc, n: PRstNode): PRope =
else: rawMessage(errCannotRenderX, $n.kind)
proc renderTocEntry(d: PDoc, e: TTocEntry): PRope =
result = dispF("<li><a class=\"reference\" id=\"$1_toc\" href=\"#$1\">$2</a></li>$n",
"\\item\\label{$1_toc} $2\\ref{$1}$n", [e.refname, e.header])
result = dispF(
"<li><a class=\"reference\" id=\"$1_toc\" href=\"#$1\">$2</a></li>$n",
"\\item\\label{$1_toc} $2\\ref{$1}$n", [e.refname, e.header])
proc renderTocEntries(d: PDoc, j: var int, lvl: int): PRope =
result = nil
while (j <= high(d.tocPart)):
while j <= high(d.tocPart):
var a = abs(d.tocPart[j].n.level)
if (a == lvl):
app(result, renderTocEntry(d, d.tocPart[j]))
@@ -552,12 +548,9 @@ proc fieldAux(s: string): PRope =
result = toRope(strip(s))
proc renderImage(d: PDoc, n: PRstNode): PRope =
var
s, scale: string
options: PRope
options = nil
s = getFieldValue(n, "scale")
if s != "": dispA(options, " scale=\"$1\"", " scale=$1", [fieldAux(scale)])
var options: PRope = nil
var s = getFieldValue(n, "scale")
if s != "": dispA(options, " scale=\"$1\"", " scale=$1", [fieldAux(s)])
s = getFieldValue(n, "height")
if s != "": dispA(options, " height=\"$1\"", " height=$1", [fieldAux(s)])
s = getFieldValue(n, "width")
@@ -614,14 +607,10 @@ proc texColumns(n: PRstNode): string =
for i in countup(1, rsonsLen(n)): add(result, "|X")
proc renderField(d: PDoc, n: PRstNode): PRope =
var
fieldname: string
fieldval: PRope
b: bool
b = false
var b = false
if gCmd == cmdRst2Tex:
fieldname = addNodes(n.sons[0])
fieldval = toRope(esc(strip(addNodes(n.sons[1]))))
var fieldname = addNodes(n.sons[0])
var fieldval = toRope(esc(strip(addNodes(n.sons[1]))))
if cmpIgnoreStyle(fieldname, "author") == 0:
if d.meta[metaAuthor] == nil:
d.meta[metaAuthor] = fieldval
@@ -637,45 +626,39 @@ proc renderRstToOut(d: PDoc, n: PRstNode): PRope =
if n == nil:
return nil
case n.kind
of rnInner:
result = renderAux(d, n)
of rnHeadline:
result = renderHeadline(d, n)
of rnOverline:
result = renderOverline(d, n)
of rnTransition:
result = renderAux(d, n, disp("<hr />" & "\n", "\\hrule" & "\n"))
of rnParagraph:
result = renderAux(d, n, disp("<p>$1</p>" & "\n", "$1$n$n"))
of rnInner: result = renderAux(d, n)
of rnHeadline: result = renderHeadline(d, n)
of rnOverline: result = renderOverline(d, n)
of rnTransition: result = renderAux(d, n, disp("<hr />\n", "\\hrule\n"))
of rnParagraph: result = renderAux(d, n, disp("<p>$1</p>\n", "$1$n$n"))
of rnBulletList:
result = renderAux(d, n, disp("<ul class=\"simple\">$1</ul>" & "\n",
"\\begin{itemize}$1\\end{itemize}" & "\n"))
result = renderAux(d, n, disp("<ul class=\"simple\">$1</ul>\n",
"\\begin{itemize}$1\\end{itemize}\n"))
of rnBulletItem, rnEnumItem:
result = renderAux(d, n, disp("<li>$1</li>" & "\n", "\\item $1" & "\n"))
of rnEnumList:
result = renderAux(d, n, disp("<ol class=\"simple\">$1</ol>" & "\n",
"\\begin{enumerate}$1\\end{enumerate}" & "\n"))
of rnDefList:
result = renderAux(d, n, disp("<dl class=\"docutils\">$1</dl>" & "\n", "\\begin{description}$1\\end{description}" &
"\n"))
of rnDefItem:
result = renderAux(d, n)
of rnDefName:
result = renderAux(d, n, disp("<dt>$1</dt>" & "\n", "\\item[$1] "))
of rnDefBody:
result = renderAux(d, n, disp("<dd>$1</dd>" & "\n", "$1" & "\n"))
result = renderAux(d, n, disp("<dl class=\"docutils\">$1</dl>\n",
"\\begin{description}$1\\end{description}\n"))
of rnDefItem: result = renderAux(d, n)
of rnDefName: result = renderAux(d, n, disp("<dt>$1</dt>\n", "\\item[$1] "))
of rnDefBody: result = renderAux(d, n, disp("<dd>$1</dd>\n", "$1\n"))
of rnFieldList:
result = nil
for i in countup(0, rsonsLen(n) - 1):
app(result, renderRstToOut(d, n.sons[i]))
if result != nil:
result = dispf("<table class=\"docinfo\" frame=\"void\" rules=\"none\">" &
result = dispf(
"<table class=\"docinfo\" frame=\"void\" rules=\"none\">" &
"<col class=\"docinfo-name\" />" &
"<col class=\"docinfo-content\" />" & "<tbody valign=\"top\">$1" &
"</tbody></table>", "\\begin{description}$1\\end{description}" & "\n",
[result])
of rnField:
result = renderField(d, n)
"<col class=\"docinfo-content\" />" &
"<tbody valign=\"top\">$1" &
"</tbody></table>",
"\\begin{description}$1\\end{description}\n",
[result])
of rnField: result = renderField(d, n)
of rnFieldName:
result = renderAux(d, n, disp("<th class=\"docinfo-name\">$1:</th>",
"\\item[$1:]"))
@@ -684,8 +667,8 @@ proc renderRstToOut(d: PDoc, n: PRstNode): PRope =
of rnIndex:
result = renderRstToOut(d, n.sons[2])
of rnOptionList:
result = renderAux(d, n, disp("<table frame=\"void\">$1</table>", "\\begin{description}$n$1\\end{description}" &
"\n"))
result = renderAux(d, n, disp("<table frame=\"void\">$1</table>",
"\\begin{description}$n$1\\end{description}\n"))
of rnOptionListItem:
result = renderAux(d, n, disp("<tr>$1</tr>$n", "$1"))
of rnOptionGroup:
@@ -707,7 +690,9 @@ proc renderRstToOut(d: PDoc, n: PRstNode): PRope =
result = renderAux(d, n, disp("<blockquote><p>$1</p></blockquote>$n",
"\\begin{quote}$1\\end{quote}$n"))
of rnTable, rnGridTable:
result = renderAux(d, n, disp("<table border=\"1\" class=\"docutils\">$1</table>", "\\begin{table}\\begin{rsttab}{" &
result = renderAux(d, n, disp(
"<table border=\"1\" class=\"docutils\">$1</table>",
"\\begin{table}\\begin{rsttab}{" &
texColumns(n) & "|}$n\\hline$n$1\\end{rsttab}\\end{table}"))
of rnTableRow:
if rsonsLen(n) >= 1:
@@ -717,8 +702,7 @@ proc renderRstToOut(d: PDoc, n: PRstNode): PRope =
result = dispf("<tr>$1</tr>$n", "$1\\\\$n\\hline$n", [result])
else:
result = nil
of rnTableDataCell:
result = renderAux(d, n, disp("<td>$1</td>", "$1"))
of rnTableDataCell: result = renderAux(d, n, disp("<td>$1</td>", "$1"))
of rnTableHeaderCell:
result = renderAux(d, n, disp("<th>$1</th>", "\\textbf{$1}"))
of rnLabel:
@@ -731,20 +715,17 @@ proc renderRstToOut(d: PDoc, n: PRstNode): PRope =
result = dispF("<a class=\"reference external\" href=\"#$2\">$1</a>",
"$1\\ref{$2}", [renderAux(d, n), toRope(rstnodeToRefname(n))])
of rnStandaloneHyperlink:
result = renderAux(d, n, disp("<a class=\"reference external\" href=\"$1\">$1</a>",
"\\href{$1}{$1}"))
result = renderAux(d, n, disp(
"<a class=\"reference external\" href=\"$1\">$1</a>",
"\\href{$1}{$1}"))
of rnHyperlink:
result = dispF("<a class=\"reference external\" href=\"$2\">$1</a>",
"\\href{$2}{$1}",
[renderRstToOut(d, n.sons[0]), renderRstToOut(d, n.sons[1])])
of rnDirArg, rnRaw:
result = renderAux(d, n)
of rnImage, rnFigure:
result = renderImage(d, n)
of rnCodeBlock:
result = renderCodeBlock(d, n)
of rnContainer:
result = renderContainer(d, n)
of rnDirArg, rnRaw: result = renderAux(d, n)
of rnImage, rnFigure: result = renderImage(d, n)
of rnCodeBlock: result = renderCodeBlock(d, n)
of rnContainer: result = renderContainer(d, n)
of rnSubstitutionReferences, rnSubstitutionDef:
result = renderAux(d, n, disp("|$1|", "|$1|"))
of rnDirective:
@@ -752,13 +733,10 @@ proc renderRstToOut(d: PDoc, n: PRstNode): PRope =
of rnGeneralRole:
result = dispF("<span class=\"$2\">$1</span>", "\\span$2{$1}",
[renderRstToOut(d, n.sons[0]), renderRstToOut(d, n.sons[1])])
of rnSub:
result = renderAux(d, n, disp("<sub>$1</sub>", "\\rstsub{$1}"))
of rnSup:
result = renderAux(d, n, disp("<sup>$1</sup>", "\\rstsup{$1}"))
of rnEmphasis:
result = renderAux(d, n, disp("<em>$1</em>", "\\emph{$1}"))
of rnStrongEmphasis:
of rnSub: result = renderAux(d, n, disp("<sub>$1</sub>", "\\rstsub{$1}"))
of rnSup: result = renderAux(d, n, disp("<sup>$1</sup>", "\\rstsup{$1}"))
of rnEmphasis: result = renderAux(d, n, disp("<em>$1</em>", "\\emph{$1}"))
of rnStrongEmphasis:
result = renderAux(d, n, disp("<strong>$1</strong>", "\\textbf{$1}"))
of rnInterpretedText:
result = renderAux(d, n, disp("<cite>$1</cite>", "\\emph{$1}"))
@@ -768,33 +746,24 @@ proc renderRstToOut(d: PDoc, n: PRstNode): PRope =
else:
result = renderIndexTerm(d, n)
of rnInlineLiteral:
result = renderAux(d, n, disp("<tt class=\"docutils literal\"><span class=\"pre\">$1</span></tt>",
"\\texttt{$1}"))
of rnLeaf:
result = toRope(esc(n.text))
of rnContents:
d.hasToc = true
of rnTitle:
d.meta[metaTitle] = renderRstToOut(d, n.sons[0])
result = renderAux(d, n, disp(
"<tt class=\"docutils literal\"><span class=\"pre\">$1</span></tt>",
"\\texttt{$1}"))
of rnLeaf: result = toRope(esc(n.text))
of rnContents: d.hasToc = true
of rnTitle: d.meta[metaTitle] = renderRstToOut(d, n.sons[0])
else: InternalError("renderRstToOut")
proc generateDoc(d: PDoc, n: PNode) =
if n == nil: return
case n.kind
of nkCommentStmt:
app(d.modDesc, genComment(d, n))
of nkProcDef:
genItem(d, n, n.sons[namePos], skProc)
of nkMethodDef:
genItem(d, n, n.sons[namePos], skMethod)
of nkIteratorDef:
genItem(d, n, n.sons[namePos], skIterator)
of nkMacroDef:
genItem(d, n, n.sons[namePos], skMacro)
of nkTemplateDef:
genItem(d, n, n.sons[namePos], skTemplate)
of nkConverterDef:
genItem(d, n, n.sons[namePos], skConverter)
of nkCommentStmt: app(d.modDesc, genComment(d, n))
of nkProcDef: genItem(d, n, n.sons[namePos], skProc)
of nkMethodDef: genItem(d, n, n.sons[namePos], skMethod)
of nkIteratorDef: genItem(d, n, n.sons[namePos], skIterator)
of nkMacroDef: genItem(d, n, n.sons[namePos], skMacro)
of nkTemplateDef: genItem(d, n, n.sons[namePos], skTemplate)
of nkConverterDef: genItem(d, n, n.sons[namePos], skConverter)
of nkVarSection:
for i in countup(0, sonsLen(n) - 1):
if n.sons[i].kind != nkCommentStmt:
@@ -812,8 +781,7 @@ proc generateDoc(d: PDoc, n: PNode) =
of nkWhenStmt:
# generate documentation for the first branch only:
generateDoc(d, lastSon(n.sons[0]))
else:
nil
else: nil
proc genSection(d: PDoc, kind: TSymKind) =
if d.section[kind] == nil: return