-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.e
More file actions
93 lines (80 loc) · 2.24 KB
/
Copy pathapplication.e
File metadata and controls
93 lines (80 loc) · 2.24 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
note
description: "[
yaml Parser event example Eiffel version.
For original C version, please see:
https://github.com/yaml/libyaml/blob/master/tests/run-parser.c
This demo show how to use the Parser API, parsing an input stream
and retrieving the next parsing event.
]"
date: "$Date$"
revision: "$Revision$"
EIS: "name=parser", "src=https://github.com/yaml/libyaml/blob/master/tests/run-parser.c", "protocol=uri"
class
APPLICATION
inherit
ARGUMENTS_32
create
make
feature {NONE} -- Initialization
make
-- Run application.
local
error: BOOLEAN
do
-- Input file name
if attached separate_character_option_value ('f') as l_val then
parse_yaml (l_val.to_string_8)
else
print ("%NError: Missing file%N")
print ("Usage: parse -f %"PATH/file.yaml%"%N")
error := True
end
end
parse_yaml (a_fn: STRING)
local
file: FILE
l_parser: YAML_PARSER_S_STRUCT_API
y_event: YAML_EVENT_S_STRUCT_API
done: BOOLEAN
count: INTEGER
do
-- Create the file
create {RAW_FILE} file.make_with_name (a_fn)
if file.exists then
file.open_read
create l_parser.make
-- Initialize the parser object.
if {YAML_FUNCTIONS}.yaml_parser_initialize (l_parser) = 0 then
print ("Error initializing parser object%N")
{EXCEPTIONS}.die (1)
end
-- Set the input file
{YAML_FUNCTIONS}.yaml_parser_set_input_file (l_parser, file)
-- Read the event sequence
from
create y_event.make
until
done
loop
-- Retrieve the next event
-- Parse the input stream and produce the next parsing event
if {YAML_FUNCTIONS}.yaml_parser_parse (l_parser, y_event) = 0 then
print ("Parse error%N")
{EXCEPTIONS}.die (1)
end
-- Code to process the event
-- finished?
if y_event.type = {YAML_EVENT_TYPE_E_ENUM_API}.YAML_STREAM_END_EVENT then
done := True
end
{YAML_FUNCTIONS}.yaml_event_delete (y_event)
count := count + 1
end
print ("Number of Events: "+ count.out +" in file : " + a_fn + "%N")
{YAML_FUNCTIONS}.yaml_parser_delete (l_parser)
file.close
else
print ("Error file [" + a_fn + "] does not exisit%N")
end
end
end