File: type_parser.mly

package info (click to toggle)
ocaml-odoc 3.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,008 kB
  • sloc: ml: 60,567; javascript: 2,572; sh: 566; makefile: 31
file content (60 lines) | stat: -rw-r--r-- 1,062 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
(* Type expressions parser, with error correction
   to support incomplete / partially written user queries. *)

%{
  module Printf = struct
    (* Without the following placeholder, [menhir_fail] induces
       a large dependency to [camlinternalFormat] in the js bundle. *)
    let eprintf _ = ()
  end

  open Db.Typexpr
%}

%token EOF
%token PARENS_OPEN PARENS_CLOSE
%token ARROW COMMA ANY STAR
%token<string> WORD
%token<string> POLY

%start main
%type<Db.Typexpr.t> main

%%

main:
  | t=typ EOF { t }
  ;

typ:
  | t=typ2 { t }
  | a=typ2 ARROW b=typ { Arrow (a, b) }
  ;

typ2:
  | xs=list1(typ1, STAR) { tuple xs }
  ;

typ1:
  | { Any }
  | ts=typs { tuple ts }
  | ts=typs w=WORD ws=list(WORD) {
      List.fold_left (fun acc w -> Constr (w, [acc])) (Constr (w, ts)) ws
    }
  ;

typ0:
  | ANY { Any }
  | w=POLY { Poly w }
  | w=WORD { Constr (w, []) }
  ;

typs:
  | t=typ0 { [t] }
  | PARENS_OPEN ts=list1(typ, COMMA) PARENS_CLOSE { ts }
  ;

list1(term, separator):
  | x=term { [x] }
  | x=term separator xs=list1(term, separator) { x::xs }
  ;