fixes #21
This commit is contained in:
parent
5b789f2da8
commit
62eb5b124e
3 changed files with 9 additions and 9 deletions
|
|
@ -104,12 +104,10 @@ proc hasKey*[T](tbl: PGenTable[T], key: string): bool =
|
||||||
|
|
||||||
proc `[]`*[T](tbl: PGenTable[T], key: string): T =
|
proc `[]`*[T](tbl: PGenTable[T], key: string): T =
|
||||||
## retrieves the value at ``tbl[key]``. If `key` is not in `tbl`,
|
## retrieves the value at ``tbl[key]``. If `key` is not in `tbl`,
|
||||||
## "" is returned and no exception is raised. One can check
|
## default(T) is returned and no exception is raised. One can check
|
||||||
## with ``hasKey`` whether the key exists.
|
## with ``hasKey`` whether the key exists.
|
||||||
var index: int
|
var index = RawGet(tbl, key)
|
||||||
index = RawGet(tbl, key)
|
|
||||||
if index >= 0: result = tbl.data[index].val
|
if index >= 0: result = tbl.data[index].val
|
||||||
#else: result = "" ### Not sure what to do here
|
|
||||||
|
|
||||||
proc `[]=`*[T](tbl: PGenTable[T], key: string, val: T) =
|
proc `[]=`*[T](tbl: PGenTable[T], key: string, val: T) =
|
||||||
## puts a (key, value)-pair into `tbl`.
|
## puts a (key, value)-pair into `tbl`.
|
||||||
|
|
@ -141,8 +139,6 @@ when isMainModule:
|
||||||
assert(not x.hasKey("NOPE")) # ...but key "NOPE" is not in the table.
|
assert(not x.hasKey("NOPE")) # ...but key "NOPE" is not in the table.
|
||||||
for k,v in pairs(x): # make sure the 'pairs' iterator works
|
for k,v in pairs(x): # make sure the 'pairs' iterator works
|
||||||
assert(x[k]==v)
|
assert(x[k]==v)
|
||||||
echo()
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Verify a table of user-defined types
|
# Verify a table of user-defined types
|
||||||
|
|
@ -154,15 +150,18 @@ when isMainModule:
|
||||||
# value is TMyType tuple
|
# value is TMyType tuple
|
||||||
|
|
||||||
#var junk: TMyType = ("OK", "Here")
|
#var junk: TMyType = ("OK", "Here")
|
||||||
|
|
||||||
|
#echo junk.first, " ", junk.second
|
||||||
|
|
||||||
y["Hello"] = ("Hello", "World")
|
y["Hello"] = ("Hello", "World")
|
||||||
y["Goodbye"] = ("Goodbye", "Everyone")
|
y["Goodbye"] = ("Goodbye", "Everyone")
|
||||||
#y["Hello"] = TMyType( ("Hello", "World") )
|
#y["Hello"] = TMyType( ("Hello", "World") )
|
||||||
#y["Goodbye"] = TMyType( ("Goodbye", "Everyone") )
|
#y["Goodbye"] = TMyType( ("Goodbye", "Everyone") )
|
||||||
|
|
||||||
|
assert( not isNil(y["Hello"].first) )
|
||||||
assert( y["Hello"].first == "Hello" )
|
assert( y["Hello"].first == "Hello" )
|
||||||
assert( y["Hello"].second == "World" )
|
assert( y["Hello"].second == "World" )
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Verify table of tables
|
# Verify table of tables
|
||||||
#
|
#
|
||||||
|
|
|
||||||
|
|
@ -877,7 +877,7 @@ proc newSons(father: PType, length: int) =
|
||||||
proc addSon(father, son: PType) =
|
proc addSon(father, son: PType) =
|
||||||
if isNil(father.sons): father.sons = @[]
|
if isNil(father.sons): father.sons = @[]
|
||||||
add(father.sons, son)
|
add(father.sons, son)
|
||||||
assert((father.kind != tyGenericInvokation) or (son.kind != tyGenericInst))
|
#assert((father.kind != tyGenericInvokation) or (son.kind != tyGenericInst))
|
||||||
|
|
||||||
proc sonsLen(n: PNode): int =
|
proc sonsLen(n: PNode): int =
|
||||||
if isNil(n.sons): result = 0
|
if isNil(n.sons): result = 0
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ proc extractSpec(filename: string): string =
|
||||||
result = x.copy(a+3, b-1).replace("'''", tripleQuote)
|
result = x.copy(a+3, b-1).replace("'''", tripleQuote)
|
||||||
else:
|
else:
|
||||||
echo "warning: file does not contain spec: " & filename
|
echo "warning: file does not contain spec: " & filename
|
||||||
|
result = ""
|
||||||
|
|
||||||
template parseSpecAux(fillResult: stmt) =
|
template parseSpecAux(fillResult: stmt) =
|
||||||
var ss = newStringStream(extractSpec(filename))
|
var ss = newStringStream(extractSpec(filename))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue