mfp / ocaml-sqlexpr

Minimalistic syntax extension for type-safe, convenient execution of SQL statements.
Other
86 stars 17 forks source link

WIP: ppx #6

Closed j0sh closed 8 years ago

j0sh commented 8 years ago

Also added some tests for the format-string parser, although the file is not in oasis yet.

The main test suite t_sqlexpr_sqlite.ml has also been converted to ppx, however it doesn't currently compile due to this strange type error:

josh@vesper:~/ocaml/ocaml-sqlexpr$ ocamlfind ocamlc -package sqlexpr.ppx,lwt.ppx,oUnit -thread -linkpkg -ppxopt lwt.ppx,-no-debug tests/t_ppx_sqlexpr.ml
File "tests/t_ppx_sqlexpr.ml", line 50, characters 8-70:
Error: This expression has type unit S.result = unit Lwt/1063.t
   but an expression was expected of type 'a Lwt/0.t

As far as I can tell, this is due to the wizardry in the Test module that redefines lwt and sqlexpr. Not sure how to fix this.

Note that because lwt is redefined, we need to disable lwt debug due to lwt's syntax extensions calling some lwt-specific functions (backtrace_catch and friends), which don't exist in the redefined signature.

Drup commented 8 years ago

The locations are not added for most of the generated parsetree. You should try to create ill-typed expressions and see where the error message points.

(Also, I have bad opinions about starting a module with 6 open, some of them largely optional, but I'm not the maintainer.)

j0sh commented 8 years ago

Locations should be fixed now (via Ast_helper.with_default_loc) and the opens have been trimmed a bit.

foretspaisibles commented 8 years ago

CC me

mfp commented 8 years ago

I've merged & adapted the OMake-based build system in my ppx branch.

I found the cause of the ... an expression was expected of type 'a Lwt/0.t type error, it was the outer (>>=).

Now it's choking on this:

    S.select db [%sql "SELECT @d{%d}"] 42 >|= aeq_list ~printer:(sprintf "%d") [42] >>= fun () ->

    File "t_ppx_sqlexpr.ml", line 121, characters 22-25:
    Error: The field Sqlexpr.sql_statement belongs to the record type
             Sqlexpr.statement
           but a field was expected belonging to the record type
             S.expression = Sqlexpr.expression