-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.e
More file actions
96 lines (85 loc) · 2.29 KB
/
application.e
File metadata and controls
96 lines (85 loc) · 2.29 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
note
description: "[
yaml Parser load example Eiffel version.
For original C version, please see:
https://github.com/yaml/libyaml/blob/master/tests/run-loader.c
This demo show how to use the Parser API, parsing an input stream
and retrieving the next YAML document.
]"
date: "$Date$"
revision: "$Revision$"
EIS: "name=loader", "src=https://github.com/yaml/libyaml/blob/master/tests/run-loader.c", "protocol=uri"
class
APPLICATION
inherit
ARGUMENTS_32
create
make
feature {NONE} -- Initialization
make
-- Run application.
local
error: BOOLEAN
i, count: INTEGER
do
-- Input file name
if argument_count >= 1 then
from
i := 1
until
i > argument_count
loop
load_yaml (argument_array.at (i).to_string_8)
i := i + 1
count := count + 1
end
print ("Number of Documents: " + count.out +"%N")
else
print ("%NError: Missing files%N")
print ("Usage: loader %"PATH/file.yaml PATH/file2.yaml%", ...+%N")
error := True
end
end
load_yaml (a_fn: STRING)
local
file: FILE
l_parser: YAML_PARSER_S_STRUCT_API
l_document: YAML_DOCUMENT_S_STRUCT_API
done: BOOLEAN
do
create {RAW_FILE} file.make_with_name (a_fn)
if file.exists then
file.open_read
create l_parser.make
if {YAML_FUNCTIONS}.yaml_parser_initialize (l_parser) = 0 then
print ("Error initializing parser object%N")
{EXCEPTIONS}.die (1)
end
{YAML_FUNCTIONS}.yaml_parser_set_input_file (l_parser, file)
from
create l_document.make
until
done
loop
if {YAML_FUNCTIONS}.yaml_parser_load (l_parser, l_document) = 0 then
print ("Parse error%N")
{EXCEPTIONS}.die (1)
end
if attached {YAML_NODE_S_STRUCT_API} {YAML_FUNCTIONS}.yaml_document_get_root_node (l_document) as l_node then
if (create {YAML_NODE_TYPE_E_ENUM_API}).is_valid_enum (l_node.type) then
print ("Valid Node Type%N")
done := True
else
print ("Get document root error%N")
{EXCEPTIONS}.die (1)
end
end
{YAML_FUNCTIONS}.yaml_document_delete (l_document)
end
{YAML_FUNCTIONS}.yaml_parser_delete (l_parser)
file.close
else
print ("Error file [" + a_fn + "] does not exisit %N")
end
end
end