Skip to content

Commit 248ea7c

Browse files
committed
Create main.yml
1 parent 76fc9f1 commit 248ea7c

File tree

2 files changed

+80
-20
lines changed

2 files changed

+80
-20
lines changed

.github/workflows/main.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: OCaml CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
build:
9+
name: OCaml ${{ matrix.ocaml-compiler }} on ${{ matrix.os }} ${{ matrix.arch }}
10+
runs-on: ${{ matrix.os }}
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
os: [ubuntu-22.04]
15+
arch: [x64]
16+
ocaml-compiler:
17+
- "4.08"
18+
- "4.09"
19+
- "4.10"
20+
- "4.11"
21+
- "4.12"
22+
- "4.13"
23+
- "4.14"
24+
- "5.0"
25+
- "5.1"
26+
- "5.2"
27+
- "5.3"
28+
- "5.4"
29+
30+
steps:
31+
- uses: actions/checkout@v5
32+
33+
- uses: avsm/setup-ocaml@v3
34+
with:
35+
ocaml-compiler: ${{ matrix.ocaml-compiler }}
36+
architecture: ${{ matrix.arch }}
37+
38+
- run: opam install . --deps-only --with-test -y
39+
- run: opam exec -- dune build
40+
- run: opam exec -- dune runtest

ppx/ppx_pacomb.ml

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -493,26 +493,39 @@ let vb_to_parser rec_ vb =
493493
let (params,exp) =
494494
let rec fn exp =
495495
match exp.pexp_desc with
496-
| Pexp_function (({pparam_desc = Pparam_val(lbl, def, param); _}::ls),
496+
| Pexp_function (ls,
497497
None, Pfunction_body exp) when rec_ = Recursive ->
498-
(*
499-
| Pexp_fun (lbl, def, param, exp) when rec_ = Recursive ->*)
500-
let exp =
501-
match ls with
502-
| [] -> exp
503-
| _ -> {exp with
504-
pexp_desc = Pexp_function (ls, None, Pfunction_body exp)}
505-
in
506498
let (params, exp) = fn exp in
507-
((lbl,def,param)::params, exp)
499+
(ls @ params, exp)
508500

509501
| _ -> ([], exp)
510502
in
511503
fn vb.pvb_expr
512504
in
505+
let poly, exp = match vb.pvb_constraint with
506+
| Some (Pvc_constraint _) -> true, vb.pvb_expr
507+
| None | Some (Pvc_coercion _) -> false, exp
508+
in
509+
let params, types = List.partition (function
510+
| { pparam_desc = Pparam_val(_); _} -> true
511+
| { pparam_desc = Pparam_newtype(_); _} -> false)
512+
params
513+
in
514+
let types = List.map (function
515+
| { pparam_desc = Pparam_newtype(a); _ } -> a
516+
| _ -> assert false) types
517+
in
518+
let params = List.map (function
519+
| { pparam_desc = Pparam_val(a,b,c); _ } -> (a,b,c)
520+
| _ -> assert false) params
521+
in
513522
let (name, param) = match params with
514523
[] -> (name, None)
515-
| [(Nolabel,None,p)] -> (name, Some (p,None))
524+
| _ when poly -> (name, None)
525+
| [(Nolabel,None,p)] when not poly -> (name, Some (p,None))
526+
| [(_,_,p)] ->
527+
( mkloc (name.txt^"@uncurry") name.loc
528+
, Some(p, None))
516529
| ps ->
517530
let curry = List.map (fun (lbl,def,_) -> (lbl,def)) ps in
518531
let ps = List.map (fun (_,_,p) -> p) ps in
@@ -564,18 +577,18 @@ let vb_to_parser rec_ vb =
564577
[%e rules]]
565578
else rules
566579
in
567-
(loc,changed,name,vb,name_param,rules)
580+
(loc,changed,name,vb,name_param,types,rules)
568581
in
569582
let ls = List.map gn vb in
570-
if not (List.exists (fun (_,changed,_,_,_,_) -> changed) ls)
583+
if not (List.exists (fun (_,changed,_,_,_,_,_) -> changed) ls)
571584
then raise Exit;
572585
let (gr,orig) = List.partition
573-
(fun (_,changed,_,_,_,_) -> changed && rec_ = Recursive)
586+
(fun (_,changed,_,_,_,_,_) -> changed && rec_ = Recursive)
574587
ls
575588
in
576589
let set name = "set__grammar__" ^ name.txt in
577590
let declarations =
578-
let gn (loc,changed,(name:string loc),vb,param,_) =
591+
let gn (loc,changed,(name:string loc),vb,param,_,_) =
579592
assert changed;
580593
match param with
581594
| None ->
@@ -605,7 +618,7 @@ let vb_to_parser rec_ vb =
605618
expr]
606619

607620
in
608-
let hn (loc,_,(name:string loc),vb,param,_) =
621+
let hn (loc,_,(name:string loc),vb,param,types,_) =
609622
match param with
610623
| Some(_,_,_,Some lbls) ->
611624
let args =
@@ -626,21 +639,25 @@ let vb_to_parser rec_ vb =
626639
let exp =
627640
List.fold_right (fun (lbl,def,v) exp ->
628641
let pat = Pat.var v in
629-
Exp.fun_ lbl def pat exp) args exp
642+
let exp = Exp.fun_ lbl def pat exp in
643+
List.fold_right (fun tyid exp ->
644+
Exp.newtype tyid exp) types exp
645+
) args exp
630646
in
631647
[Vb.mk ~loc vb.pvb_pat exp]
632648
| _ -> []
633649
in
634650
List.map gn gr @ List.map hn gr
635651
in
636652
let orig =
637-
let gn (_,_,_,vb,_,_) =
653+
let gn (_,_,_,vb,_,_,_) =
638654
vb
639655
in
640656
List.map gn orig
641657
in
642658
let definitions =
643-
let fn (loc,changed,name,_,param, rules) =
659+
let fn (loc,changed,name,_,param, types, rules) =
660+
Printf.eprintf "types: %d\n%!" (List.length types);
644661
assert changed;
645662
let exp =
646663
match param with
@@ -650,9 +667,12 @@ let vb_to_parser rec_ vb =
650667
[%e rules]]
651668
| Some (_,pn,pat,_) ->
652669
let pat = Pat.alias pat (mknoloc pn) in
670+
let exp = [%expr (fun [%p pat] -> [%e rules])] in
671+
let exp = List.fold_right (fun tyid exp ->
672+
Exp.newtype tyid exp) types exp in
653673
[%expr
654674
[%e Exp.ident (mkloc (Lident (set name)) name.loc)]
655-
(fun [%p pat] -> [%e rules])]
675+
[%e exp]]
656676
in
657677
[Vb.mk ~loc (Pat.any ()) exp]
658678
in

0 commit comments

Comments
 (0)