diff --git a/data/keywords.txt b/data/keywords.txt index 0ea2e16638..3cf9790efd 100755 --- a/data/keywords.txt +++ b/data/keywords.txt @@ -1,4 +1,4 @@ -addr and as asm +addr and as asm atomic bind block break case cast const continue converter discard distinct div diff --git a/lib/pure/math.nim b/lib/pure/math.nim index 50226f0f4a..cf4b6d95c0 100755 --- a/lib/pure/math.nim +++ b/lib/pure/math.nim @@ -1,12 +1,14 @@ # # # 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. # +## Constructive mathematics is naturally typed. -- Simon Thompson +## ## Basic math routines for Nimrod. ## This module is available for the ECMAScript target. diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim index 5cf1cf6a34..292810538e 100755 --- a/lib/pure/strutils.nim +++ b/lib/pure/strutils.nim @@ -328,7 +328,9 @@ proc ParseFloat*(s: string): float {.noSideEffect, procvar.} proc ParseHexInt*(s: string): int {.noSideEffect, procvar.} ## Parses a hexadecimal integer value contained in `s`. If `s` is not - ## a valid integer, `EInvalidValue` is raised. + ## a valid integer, `EInvalidValue` is raised. `s` can have one of the + ## following optional prefixes: ``0x``, ``0X``, ``#``. + ## Underscores within `s` are ignored. # the stringify and format operators: proc toString*[Ty](x: Ty): string {.deprecated.} @@ -735,10 +737,22 @@ proc ParseBiggestInt(s: string): biggestInt = if index == -1: raise newException(EInvalidValue, "invalid integer: " & s) +proc ParseOctInt*(s: string): int = + var i = 0 + if s[i] == '0' and (s[i+1] == 'o' or s[i+1] == 'O'): inc(i, 2) + while true: + case s[i] + of '_': inc(i) + of '0'..'7': + result = result shl 3 or (ord(s[i]) - ord('0')) + inc(i) + of '\0': break + else: raise newException(EInvalidValue, "invalid integer: " & s) proc ParseHexInt(s: string): int = var i = 0 if s[i] == '0' and (s[i+1] == 'x' or s[i+1] == 'X'): inc(i, 2) + elif s[i] == '#': inc(i) while true: case s[i] of '_': inc(i) diff --git a/rod/docgen.nim b/rod/docgen.nim index 711848e5f1..3a7ef14d80 100755 --- a/rod/docgen.nim +++ b/rod/docgen.nim @@ -91,20 +91,19 @@ proc initIndexFile(d: PDoc) = addSon(d.indexFile, h) proc newDocumentor(filename: string): PDoc = - var s: string new(result) result.tocPart = @ [] result.filename = filename result.id = 100 result.splitAfter = 20 - s = getConfigVar("split.item.toc") + var s = getConfigVar("split.item.toc") if s != "": result.splitAfter = parseInt(s) proc getVarIdx(varnames: openarray[string], id: string): int = for i in countup(0, high(varnames)): if cmpIgnoreStyle(varnames[i], id) == 0: return i - result = - 1 + result = -1 proc ropeFormatNamedVars(frmt: TFormatStr, varnames: openarray[string], varvalues: openarray[PRope]): PRope = @@ -277,12 +276,9 @@ proc genComment(d: PDoc, n: PNode): PRope = result = renderRstToOut(d, rstParse(n.comment, true, toFilename(n.info), toLineNumber(n.info), toColumn(n.info), dummyHasToc)) - else: - result = nil proc genRecComment(d: PDoc, n: PNode): PRope = - if n == nil: - return nil + if n == nil: return nil result = genComment(d, n) if result == nil: if not (n.kind in {nkEmpty..nkNilLit}): @@ -293,11 +289,10 @@ proc genRecComment(d: PDoc, n: PNode): PRope = n.comment = nil proc isVisible(n: PNode): bool = - var v: PIdent result = false if n.kind == nkPostfix: if (sonsLen(n) == 2) and (n.sons[0].kind == nkIdent): - v = n.sons[0].ident + var v = n.sons[0].ident result = (v.id == ord(wStar)) or (v.id == ord(wMinus)) elif n.kind == nkSym: result = sfInInterface in n.sym.flags @@ -388,14 +383,11 @@ proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind) = setIndexForSourceTerm(d, getRstName(nameNode), d.id) proc renderHeadline(d: PDoc, n: PRstNode): PRope = - var - length: int - refname: PRope result = nil for i in countup(0, rsonsLen(n) - 1): app(result, renderRstToOut(d, n.sons[i])) - refname = toRope(rstnodeToRefname(n)) + var refname = toRope(rstnodeToRefname(n)) if d.hasToc: - length = len(d.tocPart) + var length = len(d.tocPart) setlen(d.tocPart, length + 1) d.tocPart[length].refname = refname d.tocPart[length].n = n @@ -424,8 +416,8 @@ proc renderOverline(d: PDoc, n: PRstNode): PRope = proc renderRstToRst(d: PDoc, n: PRstNode): PRope proc renderRstSons(d: PDoc, n: PRstNode): PRope = - result = nil - for i in countup(0, rsonsLen(n) - 1): app(result, renderRstToRst(d, n.sons[i])) + for i in countup(0, rsonsLen(n) - 1): + app(result, renderRstToRst(d, n.sons[i])) proc renderRstToRst(d: PDoc, n: PRstNode): PRope = # this is needed for the index generation; it may also be useful for @@ -612,9 +604,8 @@ proc renderCodeBlock(d: PDoc, n: PRstNode): PRope = [result]) proc renderContainer(d: PDoc, n: PRstNode): PRope = - var arg: PRope result = renderRstToOut(d, n.sons[2]) - arg = toRope(strip(getArgument(n))) + var arg = toRope(strip(getArgument(n))) if arg == nil: result = dispF("