diff options
-rw-r--r-- | config/nimrod.cfg | 2 | ||||
-rw-r--r-- | contributors.txt | 7 | ||||
-rw-r--r-- | examples/cairoex.nim (renamed from tests/cairotest.nim) | 0 | ||||
-rw-r--r-- | examples/cgiex.nim (renamed from tests/cgitest.nim) | 2 | ||||
-rw-r--r-- | examples/curlex.nim (renamed from tests/curltest.nim) | 2 | ||||
-rw-r--r-- | examples/gtk/ex1.nim (renamed from tests/gtk/ex1.nim) | 0 | ||||
-rw-r--r-- | examples/gtk/ex2.nim (renamed from tests/gtk/ex2.nim) | 0 | ||||
-rw-r--r-- | examples/gtk/ex3.nim (renamed from tests/gtk/ex3.nim) | 0 | ||||
-rw-r--r-- | examples/gtk/ex4.nim (renamed from tests/gtk/ex4.nim) | 0 | ||||
-rw-r--r-- | examples/gtk/ex5.nim (renamed from tests/gtk/ex5.nim) | 0 | ||||
-rw-r--r-- | examples/gtk/ex6.nim (renamed from tests/gtk/ex6.nim) | 0 | ||||
-rw-r--r-- | examples/gtk/ex7.nim (renamed from tests/gtk/ex7.nim) | 0 | ||||
-rw-r--r-- | examples/gtk/ex8.nim (renamed from tests/gtk/ex8.nim) | 0 | ||||
-rw-r--r-- | examples/gtk/ex9.nim (renamed from tests/gtk/ex9.nim) | 0 | ||||
-rw-r--r-- | examples/sdlex.nim (renamed from tests/sdltest.nim) | 0 | ||||
-rw-r--r-- | examples/wingui.nim (renamed from tests/wingui.nim) | 0 | ||||
-rw-r--r-- | examples/x11ex.nim (renamed from tests/x11test.nim) | 0 | ||||
-rw-r--r-- | lib/impure/db_mysql.nim | 14 | ||||
-rw-r--r-- | lib/impure/db_postgres.nim | 10 | ||||
-rw-r--r-- | lib/impure/db_sqlite.nim | 178 | ||||
-rw-r--r-- | lib/impure/web.nim | 2 | ||||
-rw-r--r-- | lib/newwrap/sqlite3.nim | 41 | ||||
-rw-r--r-- | lib/pure/variants.nim | 28 | ||||
-rw-r--r-- | lib/pure/yamllexer.nim | 69 | ||||
-rw-r--r-- | lib/wrappers/sqlite3.nim | 6 | ||||
-rw-r--r-- | tests/accept/compile/mrecmod.nim (renamed from tests/mrecmod.nim) | 0 | ||||
-rw-r--r-- | tests/accept/compile/mrecmod2.nim (renamed from tests/mrecmod2.nim) | 0 | ||||
-rw-r--r-- | tests/accept/run/mambsys1.nim (renamed from tests/mambsys1.nim) | 0 | ||||
-rw-r--r-- | tests/accept/run/mambsys2.nim (renamed from tests/mambsys2.nim) | 0 | ||||
-rw-r--r-- | tests/accept/run/minit.nim (renamed from tests/minit.nim) | 0 | ||||
-rw-r--r-- | tests/hallo.nim | 34 | ||||
-rw-r--r-- | tests/reject/mambsym1.nim (renamed from tests/mambsym1.nim) | 0 | ||||
-rw-r--r-- | tests/reject/mambsym2.nim (renamed from tests/mambsym2.nim) | 0 | ||||
-rw-r--r-- | tests/reject/mnamspc1.nim (renamed from tests/mnamspc1.nim) | 0 | ||||
-rw-r--r-- | tests/reject/mnamspc2.nim (renamed from tests/mnamspc2.nim) | 0 | ||||
-rw-r--r-- | tests/reject/mopaque.nim (renamed from tests/mopaque.nim) | 0 | ||||
-rw-r--r-- | tests/reject/tatomic.nim | 5 | ||||
-rw-r--r-- | tests/testdata/csvtest.csv (renamed from tests/csvtest.csv) | 0 | ||||
-rw-r--r-- | tests/testdata/data.csv (renamed from tests/data.csv) | 0 | ||||
-rw-r--r-- | tests/testdata/doc1.xml | 14 | ||||
-rw-r--r-- | tests/testdata/jsontest.json (renamed from tests/jsontest.json) | 0 | ||||
-rw-r--r-- | tests/testdata/wildhtml.html (renamed from tests/wildhtml.html) | 0 | ||||
-rw-r--r-- | tests/testdata/xmltest.html (renamed from tests/xmltest.html) | 0 |
43 files changed, 321 insertions, 93 deletions
diff --git a/config/nimrod.cfg b/config/nimrod.cfg index 5f4c12786..80d7a548d 100644 --- a/config/nimrod.cfg +++ b/config/nimrod.cfg @@ -16,7 +16,7 @@ cc = gcc path="$lib/pure" path="$lib/impure" -path="$lib/wrappers" +path="$lib/newwrap" path="$lib/wrappers/cairo" path="$lib/wrappers/gtk" path="$lib/wrappers/lua" diff --git a/contributors.txt b/contributors.txt index 803b4f9dc..2f025f422 100644 --- a/contributors.txt +++ b/contributors.txt @@ -1,5 +1,6 @@ -Mario Ray Mahardhika Philippe Lhoste -Alexander Rødseth -Jonathan Plona +Mario Ray Mahardhika Dominik Picheta +Jonathan Plona +Alexander Rødseth + diff --git a/tests/cairotest.nim b/examples/cairoex.nim index 2c28e1abf..2c28e1abf 100644 --- a/tests/cairotest.nim +++ b/examples/cairoex.nim diff --git a/tests/cgitest.nim b/examples/cgiex.nim index ef115c80b..857caa8ef 100644 --- a/tests/cgitest.nim +++ b/examples/cgiex.nim @@ -1,4 +1,4 @@ -# Test the new CGI module +# Test/show CGI module import strtabs, cgi diff --git a/tests/curltest.nim b/examples/curlex.nim index 7b040c20a..7f666f775 100644 --- a/tests/curltest.nim +++ b/examples/curlex.nim @@ -4,7 +4,7 @@ import var hCurl = curl_easy_init() if hCurl != nil: discard curl_easy_setopt(hCurl, CURLOPT_VERBOSE, True) - discard curl_easy_setopt(hCurl, CURLOPT_URL, "http://nimrod.ethexor.com") + discard curl_easy_setopt(hCurl, CURLOPT_URL, "http://force7.de/nimrod") discard curl_easy_perform(hCurl) curl_easy_cleanup(hCurl) diff --git a/tests/gtk/ex1.nim b/examples/gtk/ex1.nim index aa3ed2f66..aa3ed2f66 100644 --- a/tests/gtk/ex1.nim +++ b/examples/gtk/ex1.nim diff --git a/tests/gtk/ex2.nim b/examples/gtk/ex2.nim index 80ff6f104..80ff6f104 100644 --- a/tests/gtk/ex2.nim +++ b/examples/gtk/ex2.nim diff --git a/tests/gtk/ex3.nim b/examples/gtk/ex3.nim index 460b1e4dc..460b1e4dc 100644 --- a/tests/gtk/ex3.nim +++ b/examples/gtk/ex3.nim diff --git a/tests/gtk/ex4.nim b/examples/gtk/ex4.nim index a387da972..a387da972 100644 --- a/tests/gtk/ex4.nim +++ b/examples/gtk/ex4.nim diff --git a/tests/gtk/ex5.nim b/examples/gtk/ex5.nim index 3a5b076c6..3a5b076c6 100644 --- a/tests/gtk/ex5.nim +++ b/examples/gtk/ex5.nim diff --git a/tests/gtk/ex6.nim b/examples/gtk/ex6.nim index 5f18786fe..5f18786fe 100644 --- a/tests/gtk/ex6.nim +++ b/examples/gtk/ex6.nim diff --git a/tests/gtk/ex7.nim b/examples/gtk/ex7.nim index 53890d1e1..53890d1e1 100644 --- a/tests/gtk/ex7.nim +++ b/examples/gtk/ex7.nim diff --git a/tests/gtk/ex8.nim b/examples/gtk/ex8.nim index acbba2258..acbba2258 100644 --- a/tests/gtk/ex8.nim +++ b/examples/gtk/ex8.nim diff --git a/tests/gtk/ex9.nim b/examples/gtk/ex9.nim index ce2f73862..ce2f73862 100644 --- a/tests/gtk/ex9.nim +++ b/examples/gtk/ex9.nim diff --git a/tests/sdltest.nim b/examples/sdlex.nim index ae7f1b41e..ae7f1b41e 100644 --- a/tests/sdltest.nim +++ b/examples/sdlex.nim diff --git a/tests/wingui.nim b/examples/wingui.nim index f4941bcc7..f4941bcc7 100644 --- a/tests/wingui.nim +++ b/examples/wingui.nim diff --git a/tests/x11test.nim b/examples/x11ex.nim index db51df2e0..db51df2e0 100644 --- a/tests/x11test.nim +++ b/examples/x11ex.nim diff --git a/lib/impure/db_mysql.nim b/lib/impure/db_mysql.nim index 9c427ae3b..b9f697069 100644 --- a/lib/impure/db_mysql.nim +++ b/lib/impure/db_mysql.nim @@ -60,12 +60,12 @@ proc dbFormat(formatstr: TSqlQuery, args: openarray[string]): string = else: add(result, c) -proc TryQuery*(db: TDbConn, query: TSqlQuery, args: openarray[string]): bool = +proc TryExec*(db: TDbConn, query: TSqlQuery, args: openarray[string]): bool = ## tries to execute the query and returns true if successful, false otherwise. var q = dbFormat(query, args) return mysqlRealQuery(db, q, q.len) == 0'i32 -proc Query*(db: TDbConn, query: TSqlQuery, args: openarray[string]) = +proc Exec*(db: TDbConn, query: TSqlQuery, args: openarray[string]) = ## executes the query and raises EDB if not successful. var q = dbFormat(query, args) if mysqlRealQuery(db, q, q.len) != 0'i32: dbError(db) @@ -84,7 +84,7 @@ iterator FastRows*(db: TDbConn, query: TSqlQuery, ## executes the query and iterates over the result dataset. This is very ## fast, but potenially dangerous: If the for-loop-body executes another ## query, the results can be undefined. For Postgres it is safe though. - Query(db, query, args) + Exec(db, query, args) var sqlres = mysqlUseResult(db) if sqlres != nil: var L = int(mysql_num_fields(sqlres)) @@ -103,7 +103,7 @@ proc GetAllRows*(db: TDbConn, query: TSqlQuery, args: openarray[string]): seq[TRow] = ## executes the query and returns the whole result dataset. result = @[] - Query(db, query, args) + Exec(db, query, args) var sqlres = mysqlUseResult(db) if sqlres != nil: var L = int(mysql_num_fields(sqlres)) @@ -149,11 +149,11 @@ proc InsertID*(db: TDbConn, query: TSqlQuery, args: openArray[string]): int64 = result = TryInsertID(db, query, args) if result < 0: dbError(db) -proc QueryAffectedRows*(db: TDbConn, query: TSqlQuery, - args: openArray[string]): int64 = +proc ExecAffectedRows*(db: TDbConn, query: TSqlQuery, + args: openArray[string]): int64 = ## runs the query (typically "UPDATE") and returns the ## number of affected rows - Query(db, query, args) + Exec(db, query, args) result = mysql_affected_rows(db) proc Close*(db: TDbConn) = diff --git a/lib/impure/db_postgres.nim b/lib/impure/db_postgres.nim index 3296e688a..131609a64 100644 --- a/lib/impure/db_postgres.nim +++ b/lib/impure/db_postgres.nim @@ -59,15 +59,15 @@ proc dbFormat(formatstr: TSqlQuery, args: openarray[string]): string = else: add(result, c) -proc TryQuery*(db: TDbConn, query: TSqlQuery, - args: openarray[string]): bool = +proc TryExec*(db: TDbConn, query: TSqlQuery, + args: openarray[string]): bool = ## tries to execute the query and returns true if successful, false otherwise. var q = dbFormat(query, args) var res = PQExec(db, q) result = PQresultStatus(res) == PGRES_COMMAND_OK PQclear(res) -proc Query*(db: TDbConn, query: TSqlQuery, args: openarray[string]) = +proc Exec*(db: TDbConn, query: TSqlQuery, args: openarray[string]) = ## executes the query and raises EDB if not successful. var q = dbFormat(query, args) var res = PQExec(db, q) @@ -143,8 +143,8 @@ proc InsertID*(db: TDbConn, query: TSqlQuery, result = TryInsertID(db, query, args) if result < 0: dbError(db) -proc QueryAffectedRows*(db: TDbConn, query: TSqlQuery, - args: openArray[string]): int64 = +proc ExecAffectedRows*(db: TDbConn, query: TSqlQuery, + args: openArray[string]): int64 = ## executes the query (typically "UPDATE") and returns the ## number of affected rows. var q = dbFormat(query, args) diff --git a/lib/impure/db_sqlite.nim b/lib/impure/db_sqlite.nim new file mode 100644 index 000000000..0be5cc79d --- /dev/null +++ b/lib/impure/db_sqlite.nim @@ -0,0 +1,178 @@ +# +# +# Nimrod's Runtime Library +# (c) Copyright 2010 Andreas Rumpf +# +# See the file "copying.txt", included in this +# distribution, for details about the copyright. +# + +## A higher level `PostgreSQL`:idx: database wrapper. This interface +## is implemented for other databases too. + +import strutils, sqlite3 + +type + TDbConn* = PSqlite3 ## encapsulates a database connection + TRow* = seq[string] ## a row of a dataset + EDb* = object of EIO ## exception that is raised if a database error occurs + + TSqlQuery* = distinct string ## an SQL query string + +proc sql*(query: string): TSqlQuery {.noSideEffect, inline.} = + ## constructs a TSqlQuery from the string `query`. This is supposed to be + ## used as a raw-string-literal modifier: + ## ``sql"update user set counter = counter + 1"`` + ## + ## If assertions are turned off, it does nothing. If assertions are turned + ## on, later versions will check the string for valid syntax. + result = TSqlQuery(query) + +proc dbError(db: TDbConn) {.noreturn.} = + ## raises an EDb exception. + var e: ref EDb + new(e) + e.msg = $sqlite3.errmsg(db) + raise e + +proc dbError*(msg: string) {.noreturn.} = + ## raises an EDb exception with message `msg`. + var e: ref EDb + new(e) + e.msg = msg + raise e + +proc dbQuote(s: string): string = + result = "'" + for c in items(s): + if c == '\'': add(result, "''") + else: add(result, c) + add(result, '\'') + +proc dbFormat(formatstr: TSqlQuery, args: openarray[string]): string = + result = "" + var a = 0 + for c in items(string(formatstr)): + if c == '?': + add(result, dbQuote(args[a])) + inc(a) + else: + add(result, c) + +proc TryExec*(db: TDbConn, query: TSqlQuery, + args: openarray[string]): bool = + ## tries to execute the query and returns true if successful, false otherwise. + var q = dbFormat(query, args) + var stmt: sqlite3.PStmt + if prepare_v2(db, q, q.len, stmt, nil) == SQLITE_OK: + if step(stmt) == SQLITE_DONE: + result = finalize(stmt) == SQLITE_OK + +proc Exec*(db: TDbConn, query: TSqlQuery, args: openarray[string]) = + ## executes the query and raises EDB if not successful. + if not TryExec(db, query, args): dbError(db) + +proc newRow(L: int): TRow = + newSeq(result, L) + for i in 0..L-1: result[i] = "" + +proc setupQuery(db: TDbConn, query: TSqlQuery, + args: openarray[string]): PStmt = + var q = dbFormat(query, args) + if prepare_v2(db, q, q.len, result, nil) != SQLITE_OK: dbError(db) + +proc setRow(stmt: PStmt, r: var TRow, cols: int) = + for col in 0..cols-1: + setLen(r[col], column_bytes(stmt, col)) # set capacity + setLen(r[col], 0) + add(r[col], column_text(stmt, col)) + +iterator FastRows*(db: TDbConn, query: TSqlQuery, + args: openarray[string]): TRow = + ## executes the query and iterates over the result dataset. This is very + ## fast, but potenially dangerous: If the for-loop-body executes another + ## query, the results can be undefined. For Sqlite it is safe though. + var stmt = setupQuery(db, query, args) + var L = int(columnCount(stmt)) + var result = newRow(L) + while step(stmt) == SQLITE_ROW: + setRow(stmt, result, L) + yield result + if finalize(stmt) != SQLITE_OK: dbError(db) + +proc GetAllRows*(db: TDbConn, query: TSqlQuery, + args: openarray[string]): seq[TRow] = + ## executes the query and returns the whole result dataset. + result = @[] + for r in FastRows(db, query, args): + result.add(r) + +iterator Rows*(db: TDbConn, query: TSqlQuery, + args: openarray[string]): TRow = + ## same as `FastRows`, but slower and safe. + for r in FastRows(db, query, args): yield r + +proc GetValue*(db: TDbConn, query: TSqlQuery, + args: openarray[string]): string = + ## executes the query and returns the result dataset's the first column + ## of the first row. Returns "" if the dataset contains no rows. + var stmt = setupQuery(db, query, args) + if step(stmt) == SQLITE_ROW: + result = newString(column_bytes(stmt, 0)) + setLen(result, 0) + add(result, column_text(stmt, 0)) + if finalize(stmt) != SQLITE_OK: dbError(db) + else: + result = "" + +proc TryInsertID*(db: TDbConn, query: TSqlQuery, + args: openarray[string]): int64 = + ## executes the query (typically "INSERT") and returns the + ## generated ID for the row or -1 in case of an error. + if tryExec(db, query, args): + result = last_insert_rowid(db) + else: + result = -1 + +proc InsertID*(db: TDbConn, query: TSqlQuery, + args: openArray[string]): int64 = + ## executes the query (typically "INSERT") and returns the + ## generated ID for the row. For Postgre this adds + ## ``RETURNING id`` to the query, so it only works if your primary key is + ## named ``id``. + result = TryInsertID(db, query, args) + if result < 0: dbError(db) + +proc ExecAffectedRows*(db: TDbConn, query: TSqlQuery, + args: openArray[string]): int64 = + ## executes the query (typically "UPDATE") and returns the + ## number of affected rows. + Exec(db, query, args) + result = changes(db) + +proc Close*(db: TDbConn) = + ## closes the database connection. + if sqlite3.close(db) != SQLITE_OK: + dbError(db) + +proc Open*(connection, user, password, database: string): TDbConn = + ## opens a database connection. Raises `EDb` if the connection could not + ## be established. Only the ``connection`` parameter is used for ``sqlite``. + var db: TDbConn + if sqlite3.open(connection, db) == SQLITE_OK: + return db + else: + dbError(db) + +when isMainModule: + var db = open("db.sql", "", "", "") + Exec(db, sql"create table tbl1(one varchar(10), two smallint)", []) + exec(db, sql"insert into tbl1 values('hello!',10)", []) + exec(db, sql"insert into tbl1 values('goodbye', 20)", []) + #db.query("create table tbl1(one varchar(10), two smallint)") + #db.query("insert into tbl1 values('hello!',10)") + #db.query("insert into tbl1 values('goodbye', 20)") + for r in db.rows(sql"select * from tbl1", []): + echo(r[0], r[1]) + + db_sqlite.close(db) diff --git a/lib/impure/web.nim b/lib/impure/web.nim index db1ec4f1e..3893843c6 100644 --- a/lib/impure/web.nim +++ b/lib/impure/web.nim @@ -17,7 +17,7 @@ ## Currently only requesting URLs is implemented. The implementation depends ## on the libcurl library! ## -## **Deprecated since version 0.8.6:** Use the httpclient module instead. +## **Deprecated since version 0.8.6:** Use the ``httpclient`` module instead. ## {.deprecated.} diff --git a/lib/newwrap/sqlite3.nim b/lib/newwrap/sqlite3.nim index 23aaf091d..a5d2189a2 100644 --- a/lib/newwrap/sqlite3.nim +++ b/lib/newwrap/sqlite3.nim @@ -96,30 +96,24 @@ const SQLITE_TRANSIENT* = cast[pointer](- 1) type - sqlite_int64* = int64 - PPPChar* = ptr ptr cstring TSqlite3 {.pure, final.} = object PSqlite3* = ptr TSqlite3 PPSqlite3* = ptr PSqlite3 - TSqlLite3Context{.pure, final.} = object - Pcontext* = ptr TSqlLite3Context + TContext{.pure, final.} = object + Pcontext* = ptr TContext Tstmt{.pure, final.} = object Pstmt* = ptr Tstmt - PPsqlite3_stmt* = ptr Pstmt Tvalue{.pure, final.} = object Pvalue* = ptr Tvalue - PPsqlite3_value* = ptr Pvalue #Callback function types - #Notice that most functions - #were named using as prefix the - #function name that uses them, - #rather than describing their functions - Tcallback* = proc (para1: pointer, para2: int32, para3: var cstring, - para4: var cstring): int32{.cdecl.} + PPValue* = ptr Pvalue + + Tcallback* = proc (para1: pointer, para2: int32, para3, + para4: cstringArray): int32{.cdecl.} Tbind_destructor_func* = proc (para1: pointer){.cdecl.} Tcreate_function_step_func* = proc (para1: Pcontext, para2: int32, - para3: PPsqlite3_value){.cdecl.} + para3: PPValue){.cdecl.} Tcreate_function_func_func* = proc (para1: Pcontext, para2: int32, - para3: PPsqlite3_value){.cdecl.} + para3: PPValue){.cdecl.} Tcreate_function_final_func* = proc (para1: Pcontext){.cdecl.} Tresult_func* = proc (para1: pointer){.cdecl.} Tcreate_collation_func* = proc (para1: pointer, para2: int32, para3: pointer, @@ -131,7 +125,7 @@ proc close*(para1: PSqlite3): int32{.cdecl, dynlib: Lib, importc: "sqlite3_close proc exec*(para1: PSqlite3, sql: cstring, para3: Tcallback, para4: pointer, errmsg: var cstring): int32{.cdecl, dynlib: Lib, importc: "sqlite3_exec".} -proc last_insert_rowid*(para1: PSqlite3): sqlite_int64{.cdecl, dynlib: Lib, +proc last_insert_rowid*(para1: PSqlite3): int64{.cdecl, dynlib: Lib, importc: "sqlite3_last_insert_rowid".} proc changes*(para1: PSqlite3): int32{.cdecl, dynlib: Lib, importc: "sqlite3_changes".} proc total_changes*(para1: PSqlite3): int32{.cdecl, dynlib: Lib, @@ -183,10 +177,15 @@ proc errcode*(db: PSqlite3): int32{.cdecl, dynlib: Lib, importc: "sqlite3_errcod proc errmsg*(para1: PSqlite3): cstring{.cdecl, dynlib: Lib, importc: "sqlite3_errmsg".} proc errmsg16*(para1: PSqlite3): pointer{.cdecl, dynlib: Lib, importc: "sqlite3_errmsg16".} -proc prepare*(db: PSqlite3, zSql: cstring, nBytes: int32, ppStmt: PPsqlite3_stmt, +proc prepare*(db: PSqlite3, zSql: cstring, nBytes: int32, ppStmt: var PStmt, pzTail: ptr cstring): int32{.cdecl, dynlib: Lib, importc: "sqlite3_prepare".} -proc prepare16*(db: PSqlite3, zSql: pointer, nBytes: int32, ppStmt: PPsqlite3_stmt, + +proc prepare_v2*(db: PSqlite3, zSql: cstring, nByte: cint, ppStmt: var PStmt, + pzTail: ptr cstring): cint {. + importc: "sqlite3_prepare_v2", cdecl, dynlib: Lib.} + +proc prepare16*(db: PSqlite3, zSql: pointer, nBytes: int32, ppStmt: var PStmt, pzTail: var pointer): int32{.cdecl, dynlib: Lib, importc: "sqlite3_prepare16".} proc bind_blob*(para1: Pstmt, para2: int32, para3: pointer, n: int32, @@ -196,7 +195,7 @@ proc bind_double*(para1: Pstmt, para2: int32, para3: float64): int32{.cdecl, dynlib: Lib, importc: "sqlite3_bind_double".} proc bind_int*(para1: Pstmt, para2: int32, para3: int32): int32{.cdecl, dynlib: Lib, importc: "sqlite3_bind_int".} -proc bind_int64*(para1: Pstmt, para2: int32, para3: sqlite_int64): int32{.cdecl, +proc bind_int64*(para1: Pstmt, para2: int32, para3: int64): int32{.cdecl, dynlib: Lib, importc: "sqlite3_bind_int64".} proc bind_null*(para1: Pstmt, para2: int32): int32{.cdecl, dynlib: Lib, importc: "sqlite3_bind_null".} @@ -248,7 +247,7 @@ proc column_double*(para1: Pstmt, iCol: int32): float64{.cdecl, dynlib: Lib, importc: "sqlite3_column_double".} proc column_int*(para1: Pstmt, iCol: int32): int32{.cdecl, dynlib: Lib, importc: "sqlite3_column_int".} -proc column_int64*(para1: Pstmt, iCol: int32): sqlite_int64{.cdecl, dynlib: Lib, +proc column_int64*(para1: Pstmt, iCol: int32): int64{.cdecl, dynlib: Lib, importc: "sqlite3_column_int64".} proc column_text*(para1: Pstmt, iCol: int32): cstring{.cdecl, dynlib: Lib, importc: "sqlite3_column_text".} @@ -283,7 +282,7 @@ proc value_double*(para1: Pvalue): float64{.cdecl, dynlib: Lib, importc: "sqlite3_value_double".} proc value_int*(para1: Pvalue): int32{.cdecl, dynlib: Lib, importc: "sqlite3_value_int".} -proc value_int64*(para1: Pvalue): sqlite_int64{.cdecl, dynlib: Lib, +proc value_int64*(para1: Pvalue): int64{.cdecl, dynlib: Lib, importc: "sqlite3_value_int64".} proc value_text*(para1: Pvalue): cstring{.cdecl, dynlib: Lib, importc: "sqlite3_value_text".} @@ -315,7 +314,7 @@ proc result_error16*(para1: Pcontext, para2: pointer, para3: int32){.cdecl, dynlib: Lib, importc: "sqlite3_result_error16".} proc result_int*(para1: Pcontext, para2: int32){.cdecl, dynlib: Lib, importc: "sqlite3_result_int".} -proc result_int64*(para1: Pcontext, para2: sqlite_int64){.cdecl, dynlib: Lib, +proc result_int64*(para1: Pcontext, para2: int64){.cdecl, dynlib: Lib, importc: "sqlite3_result_int64".} proc result_null*(para1: Pcontext){.cdecl, dynlib: Lib, importc: "sqlite3_result_null".} diff --git a/lib/pure/variants.nim b/lib/pure/variants.nim index 61b4bf163..0b4f078e7 100644 --- a/lib/pure/variants.nim +++ b/lib/pure/variants.nim @@ -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 diff --git a/lib/pure/yamllexer.nim b/lib/pure/yamllexer.nim index d84440389..4640179c1 100644 --- a/lib/pure/yamllexer.nim +++ b/lib/pure/yamllexer.nim @@ -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 diff --git a/lib/wrappers/sqlite3.nim b/lib/wrappers/sqlite3.nim index 9a97330ec..7dd33f296 100644 --- a/lib/wrappers/sqlite3.nim +++ b/lib/wrappers/sqlite3.nim @@ -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. @@ -112,8 +112,8 @@ type #were named using as prefix the #function name that uses them, #rather than describing their functions - Tsqlite3_callback* = proc (para1: pointer, para2: int32, para3: var cstring, - para4: var cstring): int32{.cdecl.} + Tsqlite3_callback* = proc (para1: pointer, para2: int32, para3, + para4: cstringArray): int32{.cdecl.} Tbind_destructor_func* = proc (para1: pointer){.cdecl.} Tcreate_function_step_func* = proc (para1: Psqlite3_context, para2: int32, para3: PPsqlite3_value){.cdecl.} diff --git a/tests/mrecmod.nim b/tests/accept/compile/mrecmod.nim index fab9654d5..fab9654d5 100644 --- a/tests/mrecmod.nim +++ b/tests/accept/compile/mrecmod.nim diff --git a/tests/mrecmod2.nim b/tests/accept/compile/mrecmod2.nim index 9557ce729..9557ce729 100644 --- a/tests/mrecmod2.nim +++ b/tests/accept/compile/mrecmod2.nim diff --git a/tests/mambsys1.nim b/tests/accept/run/mambsys1.nim index 5472b5ae4..5472b5ae4 100644 --- a/tests/mambsys1.nim +++ b/tests/accept/run/mambsys1.nim diff --git a/tests/mambsys2.nim b/tests/accept/run/mambsys2.nim index 395425b86..395425b86 100644 --- a/tests/mambsys2.nim +++ b/tests/accept/run/mambsys2.nim diff --git a/tests/minit.nim b/tests/accept/run/minit.nim index d3b4b0be1..d3b4b0be1 100644 --- a/tests/minit.nim +++ b/tests/accept/run/minit.nim diff --git a/tests/hallo.nim b/tests/hallo.nim deleted file mode 100644 index 070633793..000000000 --- a/tests/hallo.nim +++ /dev/null @@ -1,34 +0,0 @@ -# Hallo world program - -echo("Hi! What's your name?") -var name = readLine(stdin) - -if name == "Andreas": - echo("What a nice name!") -elif name == "": - echo("Don't you have a name?") -else: - echo("Your name is not Andreas...") - -for i in 0..name.len-1: - if name[i] == 'm': - echo("hey, there is an *m* in your name!") - -echo("Please give your password: (12345)") -var pw = readLine(stdin) - -while pw != "12345": - echo("Wrong password! Next try: ") - pw = readLine(stdin) - -echo("""Login complete! -What do you want to do? -delete-everything -restart-computer -go-for-a-walk""") - -case readline(stdin) -of "delete-everything", "restart-computer": - echo("permission denied") -of "go-for-a-walk": echo("please yourself") -else: echo("unknown command") diff --git a/tests/mambsym1.nim b/tests/reject/mambsym1.nim index cf8ac5242..cf8ac5242 100644 --- a/tests/mambsym1.nim +++ b/tests/reject/mambsym1.nim diff --git a/tests/mambsym2.nim b/tests/reject/mambsym2.nim index eac8de6ba..eac8de6ba 100644 --- a/tests/mambsym2.nim +++ b/tests/reject/mambsym2.nim diff --git a/tests/mnamspc1.nim b/tests/reject/mnamspc1.nim index da13c5f24..da13c5f24 100644 --- a/tests/mnamspc1.nim +++ b/tests/reject/mnamspc1.nim diff --git a/tests/mnamspc2.nim b/tests/reject/mnamspc2.nim index 84ef8533e..84ef8533e 100644 --- a/tests/mnamspc2.nim +++ b/tests/reject/mnamspc2.nim diff --git a/tests/mopaque.nim b/tests/reject/mopaque.nim index b7c5180fd..b7c5180fd 100644 --- a/tests/mopaque.nim +++ b/tests/reject/mopaque.nim diff --git a/tests/reject/tatomic.nim b/tests/reject/tatomic.nim new file mode 100644 index 000000000..0f1b8125d --- /dev/null +++ b/tests/reject/tatomic.nim @@ -0,0 +1,5 @@ +var + atomic: int + +echo atomic + diff --git a/tests/csvtest.csv b/tests/testdata/csvtest.csv index 6e7e14103..6e7e14103 100644 --- a/tests/csvtest.csv +++ b/tests/testdata/csvtest.csv diff --git a/tests/data.csv b/tests/testdata/data.csv index ea73f7387..ea73f7387 100644 --- a/tests/data.csv +++ b/tests/testdata/data.csv diff --git a/tests/testdata/doc1.xml b/tests/testdata/doc1.xml new file mode 100644 index 000000000..2895cc32f --- /dev/null +++ b/tests/testdata/doc1.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<root> + <tag> + <test arg="blah" arg2="test"/> + <test2> + bla ah absy hsh + hsh + sjj + </test2> + <test><teh>bla</teh></test> + </tag> +</root> + + diff --git a/tests/jsontest.json b/tests/testdata/jsontest.json index 27b5ba1d1..27b5ba1d1 100644 --- a/tests/jsontest.json +++ b/tests/testdata/jsontest.json diff --git a/tests/wildhtml.html b/tests/testdata/wildhtml.html index dfab7ba95..dfab7ba95 100644 --- a/tests/wildhtml.html +++ b/tests/testdata/wildhtml.html diff --git a/tests/xmltest.html b/tests/testdata/xmltest.html index ca4abc4eb..ca4abc4eb 100644 --- a/tests/xmltest.html +++ b/tests/testdata/xmltest.html |