-
Notifications
You must be signed in to change notification settings - Fork 10
/
static_config.mli
79 lines (55 loc) · 2.01 KB
/
static_config.mli
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
(** Static mapping of simple config format.
Format is simple key-value pairs. Key must start with a letter and may include letters, numbers and underscore.
Lines starting with '#' are treated as comments, i.e. ignored.
Value can be arbitrary - there are several ways to represent them :
* if the value doesn't contain any spaces, just write out the value directly
<key> = <value>
* if the value is single-line, wrap it with any symbol (<DELIMITER> can be a quote, a doublequote or
any other character that doesn't occur in the value itself)
<key> := <DELIMITER><value><DELIMITER>
* multi-line symbols are written verbatim prefixed with the number of lines occupied
<key> : <N>
<line 1>
<line 2>
[...]
<line N>
Example usage:
module CONF = struct
open Static_config
(* fresh new group *)
let root = new_root ()
let save = save root
let load = load root
(* values stored *)
let last_id = int root "last_id" 0
let last_key = string root "last_key" ""
end
or as an object:
let simple_config filename =
let open Static_config in
let root = new_root () in
let port = int root "port" 8080 in
object
inherit base root filename
method port = port
end
let conf = simple_config "some.config" in (* get's loaded here *)
conf#port#set 8081;
conf#save ()
*)
exception Error of string
type 'a value = < get : 'a; set : 'a -> unit; dirty : bool; >
type group
val group : group -> string -> group
val new_root : unit -> group
val int : group -> string -> int -> int value
val long : group -> string -> int64 -> int64 value
val string : group -> string -> string -> string value
val float : group -> string -> float -> float value
val bool : group -> string -> bool -> bool value
val show : ?all:bool -> group -> string
val read : group -> string -> unit
val reset : group -> unit
val load : group -> string -> unit
val save : ?all:bool -> group -> string -> unit
class base : group -> string -> object method load : unit -> unit method save : unit -> unit end