diff options
Diffstat (limited to 'lib/pure')
-rwxr-xr-x | lib/pure/htmlparser.nim | 4 | ||||
-rwxr-xr-x | lib/pure/httpclient.nim | 6 | ||||
-rwxr-xr-x | lib/pure/macros.nim | 3 | ||||
-rwxr-xr-x | lib/pure/os.nim | 11 | ||||
-rwxr-xr-x | lib/pure/parsecfg.nim | 6 | ||||
-rwxr-xr-x | lib/pure/pegs.nim | 2 | ||||
-rwxr-xr-x | lib/pure/strtabs.nim | 6 | ||||
-rwxr-xr-x | lib/pure/unidecode/unidecode.nim | 4 | ||||
-rwxr-xr-x | lib/pure/xmltree.nim | 34 |
9 files changed, 43 insertions, 33 deletions
diff --git a/lib/pure/htmlparser.nim b/lib/pure/htmlparser.nim index 278bf9b90..892534ce1 100755 --- a/lib/pure/htmlparser.nim +++ b/lib/pure/htmlparser.nim @@ -20,7 +20,7 @@ ## ## Every tag in the resulting tree is in lower case. ## -## **Note:** The resulting ``PXmlNode``s already use the ``clientData`` field, +## **Note:** The resulting ``PXmlNode`` already use the ``clientData`` field, ## so it cannot be used by clients of this library. import strutils, streams, parsexml, xmltree, unicode, strtabs @@ -418,4 +418,4 @@ when isMainModule: f.close() else: quit("cannot write test.txt") - \ No newline at end of file + diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim index 0f9054873..c02a7a6e7 100755 --- a/lib/pure/httpclient.nim +++ b/lib/pure/httpclient.nim @@ -284,14 +284,14 @@ proc post*(url: string, extraHeaders = "", body = "", ## | POST's ``body`` to the ``url`` and returns a ``TResponse`` object. ## | This proc adds the necessary Content-Length header. ## | This proc also handles redirection. - extraHeaders.add("Content-Length: " & $len(body) & "\c\L") - result = request(url, httpPOST, extraHeaders, body) + var xh = extraHeaders & "Content-Length: " & $len(body) & "\c\L" + result = request(url, httpPOST, xh, body) for i in 1..maxRedirects: if result.status.redirection(): var locationHeader = result.headers["Location"] if locationHeader == "": httpError("location header expected") var meth = if result.status != "307": httpGet else: httpPost - result = request(locationHeader, meth, extraHeaders, body) + result = request(locationHeader, meth, xh, body) proc postContent*(url: string, extraHeaders = "", body = ""): string = ## | POST's ``body`` to ``url`` and returns the response's body as a string diff --git a/lib/pure/macros.nim b/lib/pure/macros.nim index 677469ed2..7f5dda1e5 100755 --- a/lib/pure/macros.nim +++ b/lib/pure/macros.nim @@ -108,7 +108,8 @@ type # Nodes should be reference counted to make the `copy` operation very fast! # However, this is difficult to achieve: modify(n[0][1]) should propagate to -# its father. How to do this without back references? +# its father. How to do this without back references? Hm, BS, it works without +# them. proc `[]`* (n: PNimrodNode, i: int): PNimrodNode {.magic: "NChild".} ## get `n`'s `i`'th child. diff --git a/lib/pure/os.nim b/lib/pure/os.nim index 399d62e8b..f807c39f5 100755 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -319,12 +319,12 @@ proc JoinPath*(head, tail: string): string {.noSideEffect.} = ## ## For example on Unix: ## - ## ..code-block:: nimrod + ## .. code-block:: nimrod ## JoinPath("usr", "lib") ## ## results in: ## - ## ..code-block:: nimrod + ## .. code-block:: nimrod ## "usr/lib" ## ## If head is the empty string, tail is returned. @@ -375,6 +375,7 @@ proc SplitPath*(path: string): tuple[head, tail: string] {.noSideEffect.} = ## ``JoinPath(head, tail) == path``. ## ## Examples: + ## ## .. code-block:: nimrod ## SplitPath("usr/local/bin") -> ("usr/local", "bin") ## SplitPath("usr/local/bin/") -> ("usr/local/bin", "") @@ -399,8 +400,8 @@ proc parentDir*(path: string): string {.noSideEffect.} = ## ## This is often the same as the ``head`` result of ``splitPath``. ## If there is no parent, ``path`` is returned. - ## Example: ``parentDir("/usr/local/bin") == "/usr/local"``. - ## Example: ``parentDir("/usr/local/bin/") == "/usr/local"``. + ## | Example: ``parentDir("/usr/local/bin") == "/usr/local"``. + ## | Example: ``parentDir("/usr/local/bin/") == "/usr/local"``. var sepPos = -1 q = 1 @@ -834,7 +835,7 @@ iterator walkDir*(dir: string): tuple[kind: TPathComponent, path: string] = ## for kind, path in walkDir("dirA"): ## echo(path) ## - ## produces this output (though not necessarily in this order!):: + ## produces this output (but not necessarily in this order!):: ## dirA/dirB ## dirA/dirC ## dirA/fileA1.txt diff --git a/lib/pure/parsecfg.nim b/lib/pure/parsecfg.nim index c26dab099..4f8f5347f 100755 --- a/lib/pure/parsecfg.nim +++ b/lib/pure/parsecfg.nim @@ -1,7 +1,7 @@ # # # Nimrod's Runtime Library -# (c) Copyright 2008 Andreas Rumpf +# (c) Copyright 2010 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. @@ -17,11 +17,11 @@ ## ## .. include:: doc/mytest.cfg ## :literal: -## The file ``tests/tparscfg.nim`` demonstrates how to use the +## The file ``examples/parsecfgex.nim`` demonstrates how to use the ## configuration file parser: ## ## .. code-block:: nimrod -## :file: tests/tparscfg.nim +## :file: examples/parsecfgex.nim import diff --git a/lib/pure/pegs.nim b/lib/pure/pegs.nim index e5a655b2e..969ff8106 100755 --- a/lib/pure/pegs.nim +++ b/lib/pure/pegs.nim @@ -1190,7 +1190,7 @@ proc eat(p: var TPegParser, kind: TTokKind) = proc parseExpr(p: var TPegParser): TPeg -proc getNonTerminal(p: TPegParser, name: string): PNonTerminal = +proc getNonTerminal(p: var TPegParser, name: string): PNonTerminal = for i in 0..high(p.nonterms): result = p.nonterms[i] if cmpIgnoreStyle(result.name, name) == 0: return diff --git a/lib/pure/strtabs.nim b/lib/pure/strtabs.nim index 8ea59637a..38be1e983 100755 --- a/lib/pure/strtabs.nim +++ b/lib/pure/strtabs.nim @@ -1,7 +1,7 @@ # # # Nimrod's Runtime Library -# (c) Copyright 2008 Andreas Rumpf +# (c) Copyright 2010 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. @@ -36,7 +36,7 @@ proc newStringTable*(keyValuePairs: openarray[string], ## var mytab = newStringTable("key1", "val1", "key2", "val2", ## modeCaseInsensitive) -proc newStringTable*(mode: TStringTableMode = modeCaseSensitive): PStringTable +proc newStringTable*(mode: TStringTableMode): PStringTable ## creates a new string table that is empty. proc `[]=`*(t: PStringTable, key, val: string) @@ -79,7 +79,7 @@ const growthFactor = 2 startSize = 64 -proc newStringTable(mode: TStringTableMode = modeCaseSensitive): PStringTable = +proc newStringTable(mode: TStringTableMode): PStringTable = new(result) result.mode = mode result.counter = 0 diff --git a/lib/pure/unidecode/unidecode.nim b/lib/pure/unidecode/unidecode.nim index a665dd73e..52f9b6b1a 100755 --- a/lib/pure/unidecode/unidecode.nim +++ b/lib/pure/unidecode/unidecode.nim @@ -10,7 +10,7 @@ ## This module is based on Python's Unidecode module by Tomaz Solc, ## which in turn is based on the ``Text::Unidecode`` Perl module by ## Sean M. Burke -## (http://search.cpan.org/~sburke/Text-Unidecode-0.04/lib/Text/Unidecode.pm). +## (http://search.cpan.org/~sburke/Text-Unidecode-0.04/lib/Text/Unidecode.pm ). ## ## It provides a single proc that does Unicode to ASCII transliterations: ## It finds the sequence of ASCII characters that is the closest approximation @@ -47,7 +47,7 @@ proc unidecode*(s: string): string = ## Example: ## ## ..code-block:: nimrod - ## unidecode("\x53\x17\x4E\xB0") + ## unidecode("\\x53\\x17\\x4E\\xB0") ## ## Results in: "Bei Jing" ## diff --git a/lib/pure/xmltree.nim b/lib/pure/xmltree.nim index c79b9ad40..8604078fb 100755 --- a/lib/pure/xmltree.nim +++ b/lib/pure/xmltree.nim @@ -12,9 +12,9 @@ import macros, strtabs type - PXmlNode* = ref TXmlNode ## an XML tree consists of ``PXmlNode``s. + PXmlNode* = ref TXmlNode ## an XML tree consists of ``PXmlNode``'s. - TXmlNodeKind* = enum ## different kinds of ``PXmlNode``s + TXmlNodeKind* = enum ## different kinds of ``PXmlNode``'s xnText, ## a text element xnElement, ## an element with 0 or more children xnCData, ## a CDATA node @@ -39,7 +39,7 @@ proc newXmlNode(kind: TXmlNodeKind): PXmlNode = result.k = kind proc newElement*(tag: string): PXmlNode = - ## creates a new ``PXmlNode``. of kind ``xnText`` with the given `tag`. + ## creates a new ``PXmlNode`` of kind ``xnText`` with the given `tag`. result = newXmlNode(xnElement) result.fTag = tag result.s = @[] @@ -208,9 +208,14 @@ proc add*(result: var string, n: PXmlNode, indent = 0, indWidth = 2) = result.add(n.fText) result.add(';') +const + xmlHeader* = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" + ## header to use for complete XML output + proc `$`*(n: PXmlNode): string = - ## converts `n` into its string representation. - result = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" + ## converts `n` into its string representation. No ``<$xml ...$>`` declaration + ## is produced, so that the produced XML fragments are composable. + result = "" result.add(n) proc newXmlTree*(tag: string, children: openArray[PXmlNode], @@ -227,16 +232,21 @@ proc xmlConstructor(e: PNimrodNode): PNimrodNode {.compileTime.} = var a = e[1] if a.kind == nnkCall: result = newCall("newXmlTree", toStrLit(a[0])) - var attrs = newCall("newStringTable", []) - var bracket = newNimNode(nnkBracket, a) + var attrs = newNimNode(nnkBracket, a) + var newStringTabCall = newCall("newStringTable", attrs, + newIdentNode("modeCaseSensitive")) + var elements = newNimNode(nnkBracket, a) for i in 1..a.len-1: - if a[i].kind == nnkExprEqExpr: + if a[i].kind == nnkExprEqExpr: attrs.add(toStrLit(a[i][0])) attrs.add(a[i][1]) + echo repr(attrs) else: - bracket.add(a[i]) - result.add(bracket) - if attrs.len > 1: result.add(attrs) + elements.add(a[i]) + result.add(elements) + if attrs.len > 1: + echo repr(newStringTabCall) + result.add(newStringTabCall) else: result = newCall("newXmlTree", toStrLit(a)) @@ -252,5 +262,3 @@ macro `<>`*(x: expr): expr = ## result = xmlConstructor(x) - - |