yaml_parser.anubis
2.34 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
/*
* Created by PyramIDE.
* User: フランスのトトロ aka (David RENÉ)
* Date: 07/06/2016
* Time: 23:15
* © Calexium
*/
read yaml_type.anubis
read tools/streams.anubis
read tools/string.anubis
read system/string.anubis
public define Maybe(YAML_Document)
get_yaml_document_content
(
Stream s,
YAML_Document doc
)=
if read_line(s) is
{
failure then success(doc),
success(_line) then
with line = trim(_line),
//check for comment
if start_with(line, "#") then
//println("skipping comment ["+line+"]");
get_yaml_document_content(s, doc)
//check for blank line
else if length(line) = 0 then
//println("skipping blank line");
get_yaml_document_content(s, doc)
//check for item of the list
else if start_with(line, "- ") then
with indent = count_blank(_line),
println("list item indent["+indent+"]["+line+"]");
get_yaml_document_content(s, doc)
//check for entry of the map
else
if find(":", line, 0) is
{
failure then
println("unrecognize line ["+line+"]");
get_yaml_document_content(s, doc),
success(pos) then
with indent = count_blank(_line),
println("map entry indent["+indent+"]["+line+"]");
get_yaml_document_content(s, doc)
}
}.
public define Maybe(YAML_Document)
get_yaml_document
(
Stream s,
)=
if read_line(s) is
{
failure then failure,
success(line) then
if start_with(line, "---") then
println("Start parsing YAML document");
get_yaml_document_content(s, yaml_document(var([])))
else
get_yaml_document(s)
}.
public define YAML
parse_YAML_file
(
Stream s,
Var(List(YAML_Document)) docs
)=
if get_yaml_document(s) is
{
failure then yaml(var(reverse(*docs))),
success(doc) then
docs <- [doc . *docs];
parse_YAML_file(s, docs)
}.
public define YAML
parse_YAML_file
(
Stream s
)=
if read_line(s) is
{
failure then yaml(var([])),
success(line) then
if start_with(line, "%YAML 1.1") then
println("%YAML 1.1 file");
parse_YAML_file(s, var([]))
else
yaml(var([]))
}.