version 0.8.8
This commit is contained in:
parent
3dafd6856b
commit
7bf98411b6
52 changed files with 15732 additions and 6193 deletions
|
|
@ -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")
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
##
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue