Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: ppx #6

Closed
wants to merge 4 commits into from
Closed

WIP: ppx #6

wants to merge 4 commits into from

Conversation

j0sh
Copy link
Contributor

@j0sh j0sh commented Nov 20, 2015

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.

let mklid s = {txt=Lident s; loc} in
let mkident s = Exp.ident (mklid s) in
let mkapply fn args = Exp.apply (mkident fn) args in
let mkpident txt = Pat.var {txt; loc} in
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure half of those are in Ast_convenience.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, didn't know about the Ast_convenience module. Thanks!

@Drup
Copy link

Drup commented Nov 25, 2015

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
Copy link
Contributor Author

j0sh commented Nov 25, 2015

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

@foretspaisibles
Copy link
Contributor

CC me

@mfp
Copy link
Owner

mfp commented Dec 1, 2015

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


(* logic to extract inputs and outputs *)
let inrgx = Re_pcre.regexp {|%([dlLfsSba])(\?)?|} in
let outrgx = Re_pcre.regexp {|@([dlLfsSba])(\?)?\{((\w|\.)+)\}|} in
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This (L50) seems to be the culprit of ppx_sqlexpr choking on the likes of [%sql "SELECT @d{%d}"].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. Fixed this and all the other remaining issues, sent another PR that goes into your ppx branch: #10

@j0sh j0sh closed this Dec 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants