Source file ast_tptp.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
(** {1 TPTP Ast} *)
open Logtk
module PT = STerm
module Loc = ParseLocation
type name =
| NameInt of int
| NameString of string
(** name of a formula *)
and role =
| R_axiom
| R_hypothesis
| R_definition
| R_assumption
| R_lemma
| R_theorem
| R_conjecture
| R_negated_conjecture
| R_plain
| R_finite of string
| R_question
| R_type
| R_unknown
(** formula role *)
and optional_info = general_data list
and general_data =
| GString of string
| GVar of string
| GInt of int
| GColumn of general_data * general_data
| GNode of string * general_data list
| GList of general_data list
let role_of_string = function
| "axiom" -> R_axiom
| "hypothesis" -> R_hypothesis
| "definition" -> R_definition
| "assumption" -> R_assumption
| "lemma" -> R_axiom
| "theorem" -> R_theorem
| "conjecture" -> R_conjecture
| "negated_conjecture" -> R_negated_conjecture
| "plain" -> R_plain
| "fi_domain" -> R_finite "domain"
| "fi_functors" -> R_finite "functors"
| "fi_predicates" -> R_finite "predicates"
| "question" -> R_question
| "type" -> R_type
| "unknown" -> R_unknown
| s -> failwith ("not a proper TPTP role: " ^ s)
let string_of_role = function
| R_axiom -> "axiom"
| R_hypothesis -> "hypothesis"
| R_definition -> "definition"
| R_assumption -> "assumption"
| R_lemma -> "lemma"
| R_theorem -> "theorem"
| R_conjecture -> "conjecture"
| R_negated_conjecture -> "negated_conjecture"
| R_plain -> "plain"
| R_finite what -> "fi_" ^ what
| R_question -> "question"
| R_type -> "type"
| R_unknown -> "unknown"
let pp_role out r =
CCFormat.string out (string_of_role r)
let string_of_name = function
| NameInt i -> string_of_int i
| NameString s -> s
let pp_name out n =
CCFormat.string out (string_of_name n)
let rec pp_general out d = match d with
| GString s -> CCFormat.string out s
| GInt i -> CCFormat.int out i
| GVar s -> CCFormat.string out s
| GColumn (a, b) -> Format.fprintf out "%a: %a" pp_general a pp_general b
| GNode (f, l) ->
Format.fprintf out "%s(%a)" f (Util.pp_list pp_general) l
| GList l ->
Format.fprintf out "[%a]" (Util.pp_list pp_general) l
let rec pp_general_debugf out d = match d with
| GString s -> Format.fprintf out "GSstr %s" s
| GInt i -> Format.fprintf out "GInt %d" i
| GVar s -> Format.fprintf out "GVar %s" s
| GColumn (a, b) -> Format.fprintf out "%a: %a" pp_general_debugf a pp_general_debugf b
| GNode (f, l) ->
Format.fprintf out "GNode(%s[%a])" f (Util.pp_list pp_general_debugf) l
| GList l ->
CCFormat.list pp_general_debugf out l
let pp_generals out l = match l with
| [] -> ()
| _::_ ->
Format.fprintf out ",@ ";
Util.pp_list ~sep:", " pp_general out l
type 'a t =
| CNF of name * role * 'a list * optional_info
| FOF of name * role * 'a * optional_info
| TFF of name * role * 'a * optional_info
| THF of name * role * 'a * optional_info
| TypeDecl of name * string * 'a * optional_info
| NewType of name * string * 'a * optional_info
| Include of string
| IncludeOnly of string * name list
(** top level declaration *)
type 'a declaration = 'a t
let get_name = function
| CNF (n, _, _, _) -> n
| FOF (n, _, _, _) -> n
| TFF (n, _, _, _) -> n
| THF (n, _, _, _) -> n
| TypeDecl (n, _, _, _) -> n
| NewType (n, _, _, _) -> n
| IncludeOnly _
| Include _ ->
invalid_arg "Ast_tptp.name_of_decl: include directive has no name"
(** {2 IO} *)
let fpf = Format.fprintf
let pp_form_ pp out (logic, name, role, f, generals) =
Format.fprintf out "@[<2>%s(%a,@ %a,@ (@[%a@])%a@])."
logic pp_name name pp_role role pp f pp_generals generals
let pp pp_t out = function
| Include filename -> fpf out "@[<hv2>include(@,'%s'@,).@]" filename
| IncludeOnly (filename, names) ->
fpf out "@[<2>include('%s',@ [@[%a@]]@])." filename (Util.pp_list pp_name) names
| TypeDecl (name, s, ty, g) ->
fpf out "@[<2>tff(%a, type,@ (@[%s : %a@])%a@])."
pp_name name s pp_t ty pp_generals g
| NewType (name, s, kind, g) ->
fpf out "@[<2>tff(%a, type,@ (@[%s : %a@])%a@])."
pp_name name s pp_t kind pp_generals g
| CNF (name, role, c, generals) ->
pp_form_
(Util.pp_list ~sep:" | " pp_t) out
("cnf", name, role, c, generals)
| FOF (name, role, f, generals) ->
pp_form_ pp_t out ("fof", name, role, f, generals)
| TFF (name, role, f, generals) ->
pp_form_ pp_t out ("tff", name, role, f, generals)
| THF (name, role, f, generals) ->
pp_form_ pp_t out ("thf", name, role, f, generals)
let to_string ppt = CCFormat.to_string (pp ppt)