diff options
author | Araq <rumpf_a@web.de> | 2014-08-31 15:15:26 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-08-31 15:15:26 +0200 |
commit | 30823c1ce3992d48251069af48ed9d26b1238ba4 (patch) | |
tree | e674b8a26785a8b02c321c4d991de974d02477c4 /lib/pure | |
parent | 3ba34f1762742682a54dfdc30986818b5c1ecd81 (diff) | |
download | Nim-30823c1ce3992d48251069af48ed9d26b1238ba4.tar.gz |
make tests green
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/gentabs.nim | 16 | ||||
-rw-r--r-- | lib/pure/htmlparser.nim | 34 | ||||
-rw-r--r-- | lib/pure/parsexml.nim | 32 | ||||
-rw-r--r-- | lib/pure/ropes.nim | 18 |
4 files changed, 50 insertions, 50 deletions
diff --git a/lib/pure/gentabs.nim b/lib/pure/gentabs.nim index 694bfb542..a6128efc9 100644 --- a/lib/pure/gentabs.nim +++ b/lib/pure/gentabs.nim @@ -74,7 +74,7 @@ proc newGenTable*[T](mode: TGenTableMode): PGenTable[T] = proc nextTry(h, maxHash: THash): THash {.inline.} = result = ((5 * h) + 1) and maxHash -proc RawGet[T](tbl: PGenTable[T], key: string): int = +proc rawGet[T](tbl: PGenTable[T], key: string): int = var h: THash h = myhash(tbl, key) and high(tbl.data) # start with real hash value while not isNil(tbl.data[h].key): @@ -83,7 +83,7 @@ proc RawGet[T](tbl: PGenTable[T], key: string): int = h = nextTry(h, high(tbl.data)) result = - 1 -proc RawInsert[T](tbl: PGenTable[T], data: var TGenKeyValuePairSeq[T], +proc rawInsert[T](tbl: PGenTable[T], data: var TGenKeyValuePairSeq[T], key: string, val: T) = var h: THash h = myhash(tbl, key) and high(data) @@ -92,12 +92,12 @@ proc RawInsert[T](tbl: PGenTable[T], data: var TGenKeyValuePairSeq[T], data[h].key = key data[h].val = val -proc Enlarge[T](tbl: PGenTable[T]) = +proc enlarge[T](tbl: PGenTable[T]) = var n: TGenKeyValuePairSeq[T] newSeq(n, len(tbl.data) * growthFactor) for i in countup(0, high(tbl.data)): if not isNil(tbl.data[i].key): - RawInsert[T](tbl, n, tbl.data[i].key, tbl.data[i].val) + rawInsert[T](tbl, n, tbl.data[i].key, tbl.data[i].val) swap(tbl.data, n) proc hasKey*[T](tbl: PGenTable[T], key: string): bool = @@ -108,17 +108,17 @@ proc `[]`*[T](tbl: PGenTable[T], key: string): T = ## retrieves the value at ``tbl[key]``. If `key` is not in `tbl`, ## default(T) is returned and no exception is raised. One can check ## with ``hasKey`` whether the key exists. - var index = RawGet(tbl, key) + var index = rawGet(tbl, key) if index >= 0: result = tbl.data[index].val proc `[]=`*[T](tbl: PGenTable[T], key: string, val: T) = ## puts a (key, value)-pair into `tbl`. - var index = RawGet(tbl, key) + var index = rawGet(tbl, key) if index >= 0: tbl.data[index].val = val else: - if mustRehash(len(tbl.data), tbl.counter): Enlarge(tbl) - RawInsert(tbl, tbl.data, key, val) + if mustRehash(len(tbl.data), tbl.counter): enlarge(tbl) + rawInsert(tbl, tbl.data, key, val) inc(tbl.counter) diff --git a/lib/pure/htmlparser.nim b/lib/pure/htmlparser.nim index 54e917110..e2cbb4949 100644 --- a/lib/pure/htmlparser.nim +++ b/lib/pure/htmlparser.nim @@ -422,7 +422,7 @@ proc toHtmlTag(s: string): THtmlTag = of "wbr": tagWbr else: tagUnknown -proc htmlTag*(n: PXmlNode): THtmlTag = +proc htmlTag*(n: XmlNode): THtmlTag = ## gets `n`'s tag as a ``THtmlTag``. if n.clientData == 0: n.clientData = toHtmlTag(n.tag).ord @@ -438,24 +438,24 @@ proc entityToUtf8*(entity: string): string = ## converts an HTML entity name like ``Ü`` to its UTF-8 equivalent. ## "" is returned if the entity name is unknown. The HTML parser ## already converts entities to UTF-8. - for name, val in items(entities): - if name == entity: return toUTF8(TRune(val)) + for name, val in items(Entities): + if name == entity: return toUTF8(Rune(val)) result = "" -proc addNode(father, son: PXmlNode) = +proc addNode(father, son: XmlNode) = if son != nil: add(father, son) -proc parse(x: var TXmlParser, errors: var seq[string]): PXmlNode +proc parse(x: var XmlParser, errors: var seq[string]): XmlNode -proc expected(x: var TXmlParser, n: PXmlNode): string = +proc expected(x: var XmlParser, n: XmlNode): string = result = errorMsg(x, "</" & n.tag & "> expected") template elemName(x: expr): expr = rawData(x) -proc untilElementEnd(x: var TXmlParser, result: PXmlNode, +proc untilElementEnd(x: var XmlParser, result: XmlNode, errors: var seq[string]) = # we parsed e.g. ``<br>`` and don't really expect a ``</br>``: - if result.htmlTag in singleTags: + if result.htmlTag in SingleTags: if x.kind != xmlElementEnd or cmpIgnoreCase(x.elemName, result.tag) != 0: return while true: @@ -496,7 +496,7 @@ proc untilElementEnd(x: var TXmlParser, result: PXmlNode, else: result.addNode(parse(x, errors)) -proc parse(x: var TXmlParser, errors: var seq[string]): PXmlNode = +proc parse(x: var XmlParser, errors: var seq[string]): XmlNode = case x.kind of xmlComment: result = newComment(x.rawData) @@ -549,11 +549,11 @@ proc parse(x: var TXmlParser, errors: var seq[string]): PXmlNode = next(x) of xmlEof: discard -proc parseHtml*(s: PStream, filename: string, - errors: var seq[string]): PXmlNode = +proc parseHtml*(s: Stream, filename: string, + errors: var seq[string]): XmlNode = ## parses the XML from stream `s` and returns a ``PXmlNode``. Every ## occured parsing error is added to the `errors` sequence. - var x: TXmlParser + var x: XmlParser open(x, s, filename, {reportComments, reportWhitespace}) next(x) # skip the DOCTYPE: @@ -573,21 +573,21 @@ proc parseHtml*(s: PStream, filename: string, if result.len == 1: result = result[0] -proc parseHtml*(s: PStream): PXmlNode = +proc parseHtml*(s: Stream): XmlNode = ## parses the XTML from stream `s` and returns a ``PXmlNode``. All parsing ## errors are ignored. var errors: seq[string] = @[] result = parseHtml(s, "unknown_html_doc", errors) -proc loadHtml*(path: string, errors: var seq[string]): PXmlNode = +proc loadHtml*(path: string, errors: var seq[string]): XmlNode = ## Loads and parses HTML from file specified by ``path``, and returns ## a ``PXmlNode``. Every occured parsing error is added to ## the `errors` sequence. var s = newFileStream(path, fmRead) - if s == nil: raise newException(EIO, "Unable to read file: " & path) + if s == nil: raise newException(IOError, "Unable to read file: " & path) result = parseHtml(s, path, errors) -proc loadHtml*(path: string): PXmlNode = +proc loadHtml*(path: string): XmlNode = ## Loads and parses HTML from file specified by ``path``, and returns ## a ``PXmlNode``. All parsing errors are ignored. var errors: seq[string] = @[] @@ -600,7 +600,7 @@ when isMainModule: var x = loadHtml(paramStr(1), errors) for e in items(errors): echo e - var f: TFile + var f: File if open(f, "test.txt", fmWrite): f.write($x) f.close() diff --git a/lib/pure/parsexml.nim b/lib/pure/parsexml.nim index 9b2814b84..66135a971 100644 --- a/lib/pure/parsexml.nim +++ b/lib/pure/parsexml.nim @@ -276,14 +276,14 @@ proc parseComment(my: var XmlParser) = my.bufpos = pos my.kind = xmlComment -proc parseWhitespace(my: var XmlParser, skip=False) = +proc parseWhitespace(my: var XmlParser, skip=false) = var pos = my.bufpos var buf = my.buf while true: case buf[pos] of ' ', '\t': if not skip: add(my.a, buf[pos]) - Inc(pos) + inc(pos) of '\c': # the specification says that CR-LF, CR are to be transformed to LF pos = lexbase.handleCR(my, pos) @@ -304,7 +304,7 @@ const proc parseName(my: var XmlParser, dest: var string) = var pos = my.bufpos var buf = my.buf - if buf[pos] in nameStartChar: + if buf[pos] in NameStartChar: while true: add(dest, buf[pos]) inc(pos) @@ -385,11 +385,11 @@ proc parsePI(my: var XmlParser) = inc(pos) of '\c': # the specification says that CR-LF, CR are to be transformed to LF - pos = lexbase.HandleCR(my, pos) + pos = lexbase.handleCR(my, pos) buf = my.buf add(my.b, '\L') of '\L': - pos = lexbase.HandleLF(my, pos) + pos = lexbase.handleLF(my, pos) buf = my.buf add(my.b, '\L') else: @@ -420,11 +420,11 @@ proc parseSpecial(my: var XmlParser) = inc(pos) add(my.a, '>') of '\c': - pos = lexbase.HandleCR(my, pos) + pos = lexbase.handleCR(my, pos) buf = my.buf add(my.a, '\L') of '\L': - pos = lexbase.HandleLF(my, pos) + pos = lexbase.handleLF(my, pos) buf = my.buf add(my.a, '\L') else: @@ -441,7 +441,7 @@ proc parseTag(my: var XmlParser) = my.kind = xmlCharData add(my.a, '<') return - parseWhitespace(my, skip=True) + parseWhitespace(my, skip=true) if my.buf[my.bufpos] in NameStartChar: # an attribute follows: my.kind = xmlElementOpen @@ -461,7 +461,7 @@ proc parseTag(my: var XmlParser) = proc parseEndTag(my: var XmlParser) = inc(my.bufpos, 2) parseName(my, my.a) - parseWhitespace(my, skip=True) + parseWhitespace(my, skip=true) if my.buf[my.bufpos] == '>': inc(my.bufpos) else: @@ -477,12 +477,12 @@ proc parseAttribute(my: var XmlParser) = if my.a.len == 0: markError(my, errGtExpected) return - parseWhitespace(my, skip=True) + parseWhitespace(my, skip=true) if my.buf[my.bufpos] != '=': markError(my, errEqExpected) return inc(my.bufpos) - parseWhitespace(my, skip=True) + parseWhitespace(my, skip=true) var pos = my.bufpos var buf = my.buf @@ -507,11 +507,11 @@ proc parseAttribute(my: var XmlParser) = pendingSpace = true inc(pos) of '\c': - pos = lexbase.HandleCR(my, pos) + pos = lexbase.handleCR(my, pos) buf = my.buf pendingSpace = true of '\L': - pos = lexbase.HandleLF(my, pos) + pos = lexbase.handleLF(my, pos) buf = my.buf pendingSpace = true else: @@ -527,7 +527,7 @@ proc parseAttribute(my: var XmlParser) = else: markError(my, errQuoteExpected) my.bufpos = pos - parseWhitespace(my, skip=True) + parseWhitespace(my, skip=true) proc parseCharData(my: var XmlParser) = var pos = my.bufpos @@ -537,11 +537,11 @@ proc parseCharData(my: var XmlParser) = of '\0', '<', '&': break of '\c': # the specification says that CR-LF, CR are to be transformed to LF - pos = lexbase.HandleCR(my, pos) + pos = lexbase.handleCR(my, pos) buf = my.buf add(my.a, '\L') of '\L': - pos = lexbase.HandleLF(my, pos) + pos = lexbase.handleLF(my, pos) buf = my.buf add(my.a, '\L') else: diff --git a/lib/pure/ropes.nim b/lib/pure/ropes.nim index 8b0661063..995dff2aa 100644 --- a/lib/pure/ropes.nim +++ b/lib/pure/ropes.nim @@ -186,7 +186,7 @@ proc `&`*(a: string, b: Rope): Rope {.rtl, extern: "nroConcStrRope".} = ## the concatenation operator for ropes. result = rope(a) & b -proc `&`*(a: openarray[Rope]): Rope {.rtl, extern: "nroConcOpenArray".} = +proc `&`*(a: openArray[Rope]): Rope {.rtl, extern: "nroConcOpenArray".} = ## the concatenation operator for an openarray of ropes. for i in countup(0, high(a)): result = result & a[i] @@ -233,7 +233,7 @@ iterator items*(r: Rope): char = for s in leaves(r): for c in items(s): yield c -proc write*(f: TFile, r: Rope) {.rtl, extern: "nro$1".} = +proc write*(f: File, r: Rope) {.rtl, extern: "nro$1".} = ## writes a rope to a file. for s in leaves(r): write(f, s) @@ -291,7 +291,7 @@ when false: if i - 1 >= start: add(result, substr(frmt, start, i-1)) -proc `%`*(frmt: string, args: openarray[Rope]): Rope {. +proc `%`*(frmt: string, args: openArray[Rope]): Rope {. rtl, extern: "nroFormat".} = ## `%` substitution operator for ropes. Does not support the ``$identifier`` ## nor ``${identifier}`` notations. @@ -324,9 +324,9 @@ proc `%`*(frmt: string, args: openarray[Rope]): Rope {. j = j * 10 + ord(frmt[i]) - ord('0') inc(i) if frmt[i] == '}': inc(i) - else: raise newException(EInvalidValue, "invalid format string") + else: raise newException(ValueError, "invalid format string") add(result, args[j-1]) - else: raise newException(EInvalidValue, "invalid format string") + else: raise newException(ValueError, "invalid format string") var start = i while i < length: if frmt[i] != '$': inc(i) @@ -334,15 +334,15 @@ proc `%`*(frmt: string, args: openarray[Rope]): Rope {. if i - 1 >= start: add(result, substr(frmt, start, i - 1)) -proc addf*(c: var Rope, frmt: string, args: openarray[Rope]) {. +proc addf*(c: var Rope, frmt: string, args: openArray[Rope]) {. rtl, extern: "nro$1".} = ## shortcut for ``add(c, frmt % args)``. add(c, frmt % args) -proc equalsFile*(r: Rope, f: TFile): bool {.rtl, extern: "nro$1File".} = +proc equalsFile*(r: Rope, f: File): bool {.rtl, extern: "nro$1File".} = ## returns true if the contents of the file `f` equal `r`. var bufSize = 1024 # reasonable start value - var buf = alloc(BufSize) + var buf = alloc(bufSize) for s in leaves(r): if s.len > bufSize: bufSize = max(bufSize * 2, s.len) @@ -357,7 +357,7 @@ proc equalsFile*(r: Rope, f: TFile): bool {.rtl, extern: "nro$1File".} = proc equalsFile*(r: Rope, f: string): bool {.rtl, extern: "nro$1Str".} = ## returns true if the contents of the file `f` equal `r`. If `f` does not ## exist, false is returned. - var bin: TFile + var bin: File result = open(bin, f) if result: result = equalsFile(r, bin) |