yaml.anubis
3.65 KB
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
/*
* Created by PyramIDE.
* User: フランスのトトロ aka (David RENÉ)
* Date: 07/06/2016
* Time: 23:15
* © Calexium
*/
read tools/streams.anubis
transmit yaml_type.anubis
read yaml_parser.anubis
public define Maybe(YAML_Value)
get_value
(
List(YAML_Key_Value) key_values,
String search_key
)=
if key_values is
{
[] then failure,
[h . t] then
since h is key_value(key, value),
if search_key = key then
success(*value)
else
get_value(t, search_key)
}.
public define Maybe(List(YAML_Key_Value))
get_map_in_list_entry
(
List(YAML_Value) list_values,
String search_key
)=
if list_values is
{
[] then failure,
[h . t] then
//check if the first entry of the list value is a map
if h is map(key_values) then
//if yes check if the map's first entry key is equal to search key
if *key_values is
{
[] then get_map_in_list_entry(t, search_key),
[_key_value . _] then
since _key_value is key_value(key, value),
if key = search_key then
//check if the entry is map
if *value is map(_key_values) then
success(*_key_values)
else
get_map_in_list_entry(t, search_key)
else
get_map_in_list_entry(t, search_key)
}
else
get_map_in_list_entry(t, search_key)
}.
public define Maybe(YAML_Value)
get_YAML_value
(
List(YAML_Key_Value) root,
List(String) path
)=
if path is
{
[] then failure,
[current_name . tail] then
with final = if tail is [] then true else false,
if get_value(root, current_name) is
{
failure then failure,
success(r_value) then
//if is the final round hence we return the result
if final then
success(r_value)
// NOT Final round, continue to recurse on path to get targeted YAML_Value
else if r_value is map(new_root) then
//this is a map hencec recurse next
get_YAML_value(*new_root, tail)
//this is a list.
else if r_value is list(current_list) then
//Hence try to get an entry (1st level only) with a yaml_value which is YAML_Key_Value
//get the map within a list which the name of the key is current_name
if get_map_in_list_entry(*current_list, current_name) is
{
failure then failure,
success(new_root) then get_YAML_value(new_root, tail)
}
else
failure
}
}
.
public define Maybe(Bool)
get_Bool
(
List(YAML_Key_Value) root,
List(String) path
)=
if get_YAML_value(root, path) is
{
failure then failure,
success(y_value) then
if y_value is bool(vb_value) then
success(*vb_value)
else
failure
}.
public define Bool
get_Bool
(
List(YAML_Key_Value) root,
List(String) path,
Bool default
)=
if get_Bool(root, path) is
{
failure then default,
success(b_value) then b_value
}.
public define YAML
load
(
String yaml_file
)=
if (Maybe(RStream))file(yaml_file, read) is
{
failure then yaml(var([])),
success(f) then parse_YAML_file(make_stream(f))
}.
global define One
yaml_test
(
List(String) dummy
)=
forget(load(my_anubis_directory+"/IDPS/suricata/suricata.yaml"))
.