package lambdapi

All checked builds pass
  1. Overview
  2. Docs
Proof assistant for the λΠ-calculus modulo rewriting

Install

dune-project
 Dependency

Authors

Maintainers

Sources

lambdapi-4.0.0.tbz
sha256=0e2e73e0ea0c674f1263bf85ed3453ed3d6084d38eea29974a03ba9e382d29d7
sha512=2831db57fcd09206687a92fc9ee7d363e87bcec5167949e9c8161d41c63d5887b9f3556bfd63a7a9a0c12e5a5dc61a397baf4f496ebdb2a2fce122142c05e7a1

doc/src/lambdapi.tool/depend.ml.html

Source file depend.ml

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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
(** Fast extraction of the dependencies of a set of Lambdapi files without
    parsing them. *)

let space = function ' '|'\t'|'\r'|'\n' -> true | _ -> false
let not_space = function ' '|'\t'|'\r'|'\n' -> false | _ -> true

let print_deps filename =
  let is_lp =
    match Filename.extension filename with
    | ".lp" -> true
    | ".dk" -> false
    | _ -> Common.Error.fatal_no_pos
             {|"%s" does not end with ".lp" or ".dk"|} filename
  in
  print_string (Filename.chop_extension filename);
  print_string ".lpo:";
  let s = Lplib.String.string_of_file filename in
  let n = String.length s in
  let k = ref 0 in
  let comment_level = ref 0 in
  let print i k =
    for j=i to k do
      (*if s.[j] = '\r' then print_char '\n' else*)
      if s.[j] = '.' then print_char '/' else print_char s.[j]
    done
  in
  let starts_with w =
    let l = String.length w in
    try for i = 0 to l-1 do if w.[i] <> s.[!k+i] then raise Exit done; true
    with Exit -> false
  in
  (*let print_cur_char m = (* for debug *)
    let w = 10 in
    print_string m;
    print_string {|[before:"|}; print (max 0 (!k-w)) (!k-1);
    print_string {|",current(|}; print_int !k; print_string {|):"|};
    print_char s.[!k];
    print_string {|",after:"|}; print (min (!k+1) (n-1)) (min (!k+w) (n-1));
    print_string {|"]|}; print_string "\n";
    flush stdout
  in*)
  begin
    try
      if is_lp then
        let mod_end = function ' '|'\t'|'\r'|'\n'|';' -> true | _ -> false in
        let root_path = String.concat "." !Common.Library.root_path ^ "." in
        let p = String.length root_path in
        let rec skip_until f =
          if !k >= n then raise Exit;
          match s.[!k] with
          | '/' ->
            if !k+1 >= n then raise Exit
            else
              begin
                match s.[!k+1] with
                | '/' -> k := !k+2; skip_until ((=) '\n')
                | '*' -> k := !k+2; incr comment_level; skip_until f
                | c -> if f '/' || f c then () else (k := !k+2; skip_until f)
              end
          | '*' when !k+1 < n && s.[!k+1] = '/' ->
            decr comment_level; k := !k+2; skip_until f
          | c -> if f c then () else (incr k; skip_until f)
        in
        let skip_keyword w =
          let l = String.length w in
          if !k+l+1 < n && starts_with w && space s.[!k+l] then
            (k := !k+l+1; skip_until not_space)
        in
        let rec search_require() =
          skip_until ((=) 'r');
          if !k+7 >= n then raise Exit;
          if not (starts_with "require") then (incr k; search_require());
          k := !k+7;
          if not_space s.[!k] then (incr k; search_require());
          skip_until not_space;
          skip_keyword "private";
          skip_keyword "open";
          search_module()
        and search_module() =
          if !k >= n then raise Exit;
          if s.[!k] = ';' then (incr k; search_require());
          if not (starts_with root_path) then
            (skip_until mod_end; skip_until not_space; search_module());
          let i = !k + p in
          skip_until mod_end;
          print_char ' ';
          print i (!k-1);
          print_string ".lpo";
          skip_until not_space;
          search_module()
        in
        search_require()
      else
        let mod_end = function ' '|'\t'|'\r'|'\n'|'.' -> true | _ -> false in
        let rec skip_until f =
          if !k >= n then raise Exit;
          match s.[!k] with
          | '(' ->
            if !k+1 >= n then raise Exit
            else
              begin
                match s.[!k+1] with
                | ';' -> k := !k+2; incr comment_level; skip_until f
                | c -> if f '(' || f c then () else (k := !k+2; skip_until f)
              end
          | ';' when !k+1 < n && s.[!k+1] = ')' ->
            decr comment_level; k := !k+2; skip_until f
          | c -> if f c then () else (incr k; skip_until f)
        in
        let rec search_require() =
          skip_until ((=) '#');
          if !k+8 >= n then raise Exit;
          if not (starts_with "#REQUIRE") then (incr k; search_require());
          k := !k+8;
          if not_space s.[!k] then (incr k; search_require());
          search_module()
        and search_module() =
          skip_until not_space;
          if s.[!k] = '.' then (incr k; search_require());
          let i = !k in
          skip_until mod_end;
          print_char ' ';
          print i (!k-1);
          print_string ".lpo";
          search_module()
        in
        search_require()
    with Exit -> ()
  end;
  print_newline()