summaryrefslogtreecommitdiff
path: root/camlp4/unmaintained/compile/comp_head.ml
blob: cd62343641fed6e45a70554add4e67a716647222 (plain)
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
61
62
63
64
65
66
67
68
69
70
(* camlp4r q_MLast.cmo pa_extend.cmo *)


module P =
  struct
    value gloc bp strm = Grammar.loc_of_token_interval bp (Stream.count strm);
    value list0 symb =
      let rec loop al =
        parser
        [ [: a = symb; s :] -> loop [a :: al] s
        | [: :] -> al ]
      in
      parser [: a = loop [] :] -> List.rev a
    ;
    value list0sep symb sep =
      let rec kont al =
        parser
        [ [: v = sep; a = symb; s :] -> kont [a :: al] s
        | [: :] -> al ]
      in
      parser
      [ [: a = symb; s :] -> List.rev (kont [a] s)
      | [: :] -> [] ]
    ;
    value list1 symb =
      let rec loop al =
        parser
        [ [: a = symb; s :] -> loop [a :: al] s
        | [: :] -> al ]
      in
      parser [: a = symb; s :] -> List.rev (loop [a] s)
    ;
    value list1sep symb sep =
      let rec kont al =
        parser
        [ [: v = sep; a = symb; s :] -> kont [a :: al] s
        | [: :] -> al ]
      in
      parser [: a = symb; s :] -> List.rev (kont [a] s)
    ;
    value option f =
      parser
      [ [: x = f :] -> Some x
      | [: :] -> None ]
    ;
    value token (p_con, p_prm) =
      if p_prm = "" then parser [: `(con, prm) when con = p_con :] -> prm
      else parser [: `(con, prm) when con = p_con && prm = p_prm :] -> prm
    ;
    value orzero f f0 =
      parser bp
      [ [: x = f :] -> x
      | [: x = f0 :] ep ->
(*
let (loc1, loc2) = Grammar.loc_of_token_interval bp ep in
let _ = do { Printf.eprintf "recovered or_zero at loc (%d, %d)\n" loc1 loc2; flush stderr } in
*)
           x ]
    ;
    value error entry prev_symb symb =
      symb ^ " expected" ^
      (if prev_symb = "" then "" else " after " ^ prev_symb) ^
      " (in [" ^ entry ^ "])"
    ;
    value lexer = Plexer.gmake();
  end
;

(****************************************)