SQLite wrapper

This commit is contained in:
Andreas Rumpf 2010-02-24 01:04:39 +01:00
commit f41bd71e61
43 changed files with 321 additions and 93 deletions

View file

@ -1,7 +1,7 @@
#
#
# 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.
@ -35,41 +35,41 @@ type
iterator objectFields*[T](x: T, skipInherited: bool): tuple[
key: string, val: TVariant] {.magic: "ObjectFields"}
proc `<>`*(x: ordinal): TVariant =
proc `?`*(x: ordinal): TVariant =
result.kind = vtEnum
result.vint = x
proc `<>`*(x: biggestInt): TVariant =
proc `?`*(x: biggestInt): TVariant =
result.kind = vtInt
result.vint = x
proc `<>`*(x: char): TVariant =
proc `?`*(x: char): TVariant =
result.kind = vtChar
result.vint = ord(x)
proc `<>`*(x: bool): TVariant =
proc `?`*(x: bool): TVariant =
result.kind = vtBool
result.vint = ord(x)
proc `<>`*(x: biggestFloat): TVariant =
proc `?`*(x: biggestFloat): TVariant =
result.kind = vtFloat
result.vfloat = x
proc `<>`*(x: string): TVariant =
proc `?`*(x: string): TVariant =
result.kind = vtString
result.vstring = x
proc `<>`*[T](x: openArray[T]): TVariant =
proc `?`*[T](x: openArray[T]): TVariant =
result.kind = vtSeq
newSeq(result.q, x.len)
for i in 0..x.len-1: result.q[i] = <>x[i]
proc `<>`*[T](x: set[T]): TVariant =
proc `?`*[T](x: set[T]): TVariant =
result.kind = vtSet
result.q = @[]
for a in items(x): result.q.add(<>a)
proc `<>`* [T: object](x: T): TVariant {.magic: "ToVariant".}
proc `?`* [T: object](x: T): TVariant {.magic: "ToVariant".}
## this converts a value to a variant ("boxing")
proc `><`*[T](v: TVariant, typ: T): T {.magic: "FromVariant".}
@ -140,10 +140,10 @@ proc `[]=`* (a, b, c: TVariant) =
variantError()
else: variantError()
proc `[]`* (a: TVariant, b: int): TVariant {.inline} = return a[<>b]
proc `[]`* (a: TVariant, b: string): TVariant {.inline} = return a[<>b]
proc `[]=`* (a: TVariant, b: int, c: TVariant) {.inline} = a[<>b] = c
proc `[]=`* (a: TVariant, b: string, c: TVariant) {.inline} = a[<>b] = c
proc `[]`* (a: TVariant, b: int): TVariant {.inline} = return a[?b]
proc `[]`* (a: TVariant, b: string): TVariant {.inline} = return a[?b]
proc `[]=`* (a: TVariant, b: int, c: TVariant) {.inline} = a[?b] = c
proc `[]=`* (a: TVariant, b: string, c: TVariant) {.inline} = a[?b] = c
proc `+`* (x, y: TVariant): TVariant =
case x.vtype

View file

@ -133,6 +133,22 @@ proc skip(my: var TYamlLexer) =
var buf = my.buf
while true:
case buf[pos]
of '#':
# skip line comment:
inc(pos)
while true:
case buf[pos]
of '\0': break
of '\c':
pos = lexbase.HandleCR(my, pos)
buf = my.buf
break
of '\L':
pos = lexbase.HandleLF(my, pos)
buf = my.buf
break
else:
inc(pos)
of '/':
if buf[pos+1] == '/':
# skip line comment:
@ -186,6 +202,26 @@ proc skip(my: var TYamlLexer) =
break
my.bufpos = pos
proc parseDirective(my: var TYamlLexer) =
var pos = my.bufpos
var buf = my.buf
inc(pos)
while buf[pos] in {'\t', ' '}: inc(pos)
while true:
case buf[pos]
of '\0': break
of '\c':
pos = lexbase.HandleCR(my, pos)
buf = my.buf
break
of '\L':
pos = lexbase.HandleLF(my, pos)
buf = my.buf
break
else:
add(my.a, buf[pos])
inc(pos)
proc parseNumber(my: var TYamlLexer) =
var pos = my.bufpos
var buf = my.buf
@ -230,11 +266,16 @@ proc getTok(my: var TYamlLexer): TTokKind =
setLen(my.a, 0)
skip(my) # skip whitespace, comments
case my.buf[my.bufpos]
of '-':
inc(my.bufpos)
result = tkHyphen
of '-', '.', '0'..'9':
parseNumber(my)
result = tkNumber
of '"':
result = parseString(my)
of '\'':
result = parseSingleQuote(my)
of '[':
inc(my.bufpos)
result = tkBracketLe
@ -253,8 +294,30 @@ proc getTok(my: var TYamlLexer): TTokKind =
of ':':
inc(my.bufpos)
result = tkColon
of '\0':
result = tkEof
of '?':
inc(my.bufpos)
result = tkQust
of '!':
inc(my.bufpos)
result = tkExcl
of '&':
inc(my.bufpos)
result = tkAmp
of '*':
inc(my.bufpos)
result = tkStar
of '|':
parseLiteralBlockScalar(my)
result = tkLiteralBlockScalar
of '>':
parseFoldedBlockScalar(my)
result = tkFoldedBlockScalar
of '%':
parseDirective(my)
result = tkDirective
of '@', '`':
inc(my.bufpos)
result = tkReserved
of 'a'..'z', 'A'..'Z', '_':
parseName(my)
case my.a
@ -262,6 +325,8 @@ proc getTok(my: var TYamlLexer): TTokKind =
of "true": result = tkTrue
of "false": result = tkFalse
else: result = tkError
of '\0':
result = tkEof
else:
inc(my.bufpos)
result = tkError