| 1 |
|
| 2 |
|
| 3 |
% Yojson bindings for Elpi |
| 4 |
|
| 5 |
% license: GNU Lesser General Public License Version 2.1 or later |
| 6 |
|
| 7 |
% ------------------------------------------------------------------------ |
| 8 |
|
| 9 |
% This code is not Rocq specific, i.e. could go to an Elpi specific |
| 10 |
% package. |
| 11 |
|
| 12 |
% Yojson.Basic.t |
| 13 |
kind json type. |
| 14 |
external symbol json.null : json = "1". |
| 15 |
external symbol json.bool : bool -> json = "1". |
| 16 |
external symbol json.int : int -> json = "1". |
| 17 |
external symbol json.float : float -> json = "1". |
| 18 |
external symbol json.string : string -> json = "1". |
| 19 |
external symbol json.assoc : list (pair string json) -> json = "1". % key value pairs. When generated from built-in predicates, keys are sorted |
| 20 |
external symbol json.list : list json -> json = "1". |
| 21 |
|
| 22 |
% [json.from_file File J D] like Yojson.Basic.from_file reads J from File. |
| 23 |
% If D is error then J is not assigned. |
| 24 |
external func json.from_file string -> json, diagnostic. |
| 25 |
|
| 26 |
% [json.from_string String J D] like Yojson.Basic.from_string reads J from |
| 27 |
% String. |
| 28 |
% If D is error then J is not assigned. |
| 29 |
external func json.from_string string -> json, diagnostic. |
| 30 |
|
| 31 |
% [json.to_file File J D] like Yojson.Basic.to_file write J to File. |
| 32 |
external func json.to_file string, json -> diagnostic. |
| 33 |
|
| 34 |
% [json.to_string J S D] like Yojson.Basic.to_string write J to a compact |
| 35 |
% string S. |
| 36 |
external func json.to_string json -> string, diagnostic. |
| 37 |
|
| 38 |
% [json.pretty_to_string J S D] like Yojson.Basic.pretty_to_string write J |
| 39 |
% to a nice string S. |
| 40 |
external func json.pretty_to_string json -> string, diagnostic. |
| 41 |
|
| 42 |
% ------------------------------------------------------------------------ |
| 43 |
|
| 44 |
% Rocq-Elpi APIs |
| 45 |
|
| 46 |
% ------------------------------------------------------------------------ |
| 47 |
|
| 48 |
|
| 49 |
func coq.json->string json -> string. |
| 50 |
coq.json->string J S :- json.pretty_to_string J S ok. |
| 51 |
|
| 52 |
func coq.string->json string -> json. |
| 53 |
coq.string->json S J :- json.from_string S J ok. |
| 54 |
|
| 55 |
% [coq.extra-dep->json Dep J D] reads a json file declared as an extra |
| 56 |
% dependency, see the coq.extra-dep API. |
| 57 |
func coq.extra-dep->json string -> json, diagnostic. |
| 58 |
coq.extra-dep->json S J D :- coq.extra-dep S (some P), !, json.from_file P J D. |
| 59 |
coq.extra-dep->json S _ (error Msg) :- Msg is "unknown Extra Dependency " ^ S. |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|