author | František Kučera <franta-hg@frantovo.cz> |
Tue, 27 Oct 2020 22:39:50 +0100 | |
branch | v_0 |
changeset 17 | 75c6685cceb9 |
parent 16 | 3b197bf7a231 |
child 18 | 737c507a3e32 |
permissions | -rw-r--r-- |
14
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
1 |
/** |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
2 |
* Relational pipes |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
3 |
* Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info) |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
4 |
* |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
5 |
* This program is free software: you can redistribute it and/or modify |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
7 |
* the Free Software Foundation, version 3 of the License. |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
8 |
* |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
* |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
16 |
*/ |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
17 |
#pragma once |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
|
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
19 |
namespace relpipe { |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
20 |
namespace in { |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
21 |
namespace xmltable { |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
22 |
|
16
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
23 |
#include <codecvt> |
17
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
24 |
#include <vector> |
16
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
25 |
|
14
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
26 |
#include <libxml++-2.6/libxml++/libxml++.h> |
16
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
27 |
#include <yaml.h> |
14
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
28 |
|
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
29 |
class XMLDocumentConstructor { |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
30 |
private: |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
31 |
std::istream* input = nullptr; |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
32 |
xmlpp::DomParser* parser = nullptr; |
16
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
33 |
yaml_parser_t yamlParser; |
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
34 |
|
17
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
35 |
enum class Mode { |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
36 |
ROOT, |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
37 |
SEQUENCE, |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
38 |
MAPPING, |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
39 |
MAP_KEY |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
40 |
}; |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
41 |
|
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
42 |
xmlpp::Element* current; |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
43 |
std::vector<Mode> mode; |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
44 |
|
16
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
45 |
static int readFromInput(void* instance, unsigned char* buffer, size_t size, size_t* length) { |
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
46 |
std::istream* input = ((XMLDocumentConstructor*) instance)->input; |
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
47 |
input->read((char*) buffer, size); |
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
48 |
*length = input->gcount(); |
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
49 |
return (input->good() || input->eof()) ? 1 : 0; |
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
50 |
} |
17
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
51 |
|
16
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
52 |
/** |
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
53 |
* Both YAML and XML strings are in UTF-8. |
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
54 |
*/ |
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
55 |
const char* y2x(yaml_char_t* value) { |
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
56 |
return value ? (const char*) value : ""; |
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
57 |
} |
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
58 |
|
17
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
59 |
const std::string y2xname(yaml_char_t* value) { |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
60 |
// FIXME: escaping, assure valid XML names |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
61 |
//return std::string("name_") + y2x(value); |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
62 |
return y2x(value); |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
63 |
} |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
64 |
|
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
65 |
xmlpp::Element* parentOrSelf(xmlpp::Element* current) { |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
66 |
return current->get_parent() == nullptr ? current : current->get_parent(); |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
67 |
} |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
68 |
|
14
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
69 |
public: |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
70 |
|
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
71 |
XMLDocumentConstructor(std::istream* input, xmlpp::DomParser* parser) : input(input), parser(parser) { |
16
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
72 |
yaml_parser_initialize(&yamlParser); |
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
73 |
yaml_parser_set_input(&yamlParser, readFromInput, (void*) this); |
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
74 |
} |
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
75 |
|
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
76 |
virtual ~XMLDocumentConstructor() { |
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
77 |
yaml_parser_delete(&yamlParser); |
14
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
78 |
} |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
79 |
|
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
80 |
void process() { |
17
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
81 |
current = parser->get_document()->create_root_node("yaml"); |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
82 |
mode.push_back(Mode::ROOT); |
16
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
83 |
|
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
84 |
while (true) { |
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
85 |
yaml_event_t event; |
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
86 |
|
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
87 |
if (!yaml_parser_parse(&yamlParser, &event)) { |
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
88 |
// FIXME: throw exception |
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
89 |
std::wcerr << L"YAML error" << std::endl; |
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
90 |
return; |
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
91 |
} |
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
92 |
|
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
93 |
|
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
94 |
if (event.type == YAML_STREAM_END_EVENT) { |
17
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
95 |
std::cerr << "YAML_STREAM_END_EVENT" << std::endl; |
16
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
96 |
yaml_event_delete(&event); |
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
97 |
break; |
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
98 |
} else if (event.type == YAML_STREAM_START_EVENT) { |
17
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
99 |
std::cerr << "YAML_STREAM_START_EVENT" << std::endl; |
16
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
100 |
} else if (event.type == YAML_NO_EVENT) { |
17
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
101 |
std::cerr << "YAML_NO_EVENT" << std::endl; |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
102 |
current->add_child("null"); // TODO: null? |
16
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
103 |
} else if (event.type == YAML_DOCUMENT_START_EVENT) { |
17
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
104 |
std::cerr << "YAML_DOCUMENT_START_EVENT" << std::endl; |
16
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
105 |
} else if (event.type == YAML_DOCUMENT_END_EVENT) { |
17
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
106 |
std::cerr << "YAML_DOCUMENT_END_EVENT" << std::endl; |
16
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
107 |
} else if (event.type == YAML_ALIAS_EVENT) { |
17
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
108 |
std::cerr << "YAML_ALIAS_EVENT" << std::endl; |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
109 |
// TODO: alias? |
16
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
110 |
} else if (event.type == YAML_SCALAR_EVENT) { |
17
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
111 |
if (mode.back() == Mode::SEQUENCE) { |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
112 |
std::cerr << "YAML_SCALAR_EVENT: Mode::SEQUENCE: " << event.data.scalar.value << std::endl; |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
113 |
current->add_child("item")->add_child_text(y2x(event.data.scalar.value)); |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
114 |
} else if (mode.back() == Mode::MAPPING) { |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
115 |
std::cerr << "YAML_SCALAR_EVENT: Mode::MAPPING: " << event.data.scalar.value << std::endl; |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
116 |
current = current->add_child(y2xname(event.data.scalar.value)); |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
117 |
mode.push_back(Mode::MAP_KEY); |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
118 |
} else if (mode.back() == Mode::MAP_KEY) { |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
119 |
std::cerr << "YAML_SCALAR_EVENT: Mode::MAP_KEY: " << event.data.scalar.value << std::endl; |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
120 |
current->add_child_text(y2x(event.data.scalar.value)); |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
121 |
current = parentOrSelf(current); |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
122 |
mode.pop_back(); |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
123 |
} else { |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
124 |
std::cerr << "YAML_SCALAR_EVENT: ???" << std::endl; |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
125 |
} |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
126 |
|
16
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
127 |
} else if (event.type == YAML_SEQUENCE_START_EVENT) { |
17
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
128 |
std::cerr << "YAML_SEQUENCE_START_EVENT" << std::endl; |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
129 |
if (mode.back() == Mode::MAP_KEY) mode.pop_back(); |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
130 |
mode.push_back(Mode::SEQUENCE); |
16
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
131 |
} else if (event.type == YAML_SEQUENCE_END_EVENT) { |
17
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
132 |
std::cerr << "YAML_SEQUENCE_END_EVENT" << std::endl; |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
133 |
current = parentOrSelf(current); |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
134 |
mode.pop_back(); // TODO: assert sequence? |
16
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
135 |
} else if (event.type == YAML_MAPPING_START_EVENT) { |
17
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
136 |
|
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
137 |
if (mode.back() == Mode::SEQUENCE) { |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
138 |
std::cerr << "YAML_MAPPING_START_EVENT: Mode::SEQUENCE" << std::endl; |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
139 |
current = current->add_child("item"); |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
140 |
} else if (mode.back() == Mode::MAP_KEY) { |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
141 |
std::cerr << "YAML_MAPPING_START_EVENT: Mode::MAP_KEY" << std::endl; |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
142 |
mode.pop_back(); |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
143 |
} else { |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
144 |
std::cerr << "YAML_MAPPING_START_EVENT: Mode::?" << std::endl; |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
145 |
// TODO: map might be a key of another map → wrap/nest |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
146 |
} |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
147 |
|
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
148 |
mode.push_back(Mode::MAPPING); |
16
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
149 |
} else if (event.type == YAML_MAPPING_END_EVENT) { |
17
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
150 |
std::cerr << "YAML_MAPPING_END_EVENT" << std::endl; |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
151 |
current = parentOrSelf(current); |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
152 |
mode.pop_back(); // TODO: assert map? |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
153 |
} else { |
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
154 |
std::cerr << "???" << std::endl; |
16
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
155 |
} |
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
156 |
|
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
157 |
yaml_event_delete(&event); |
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
158 |
} |
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
159 |
|
3b197bf7a231
raw YAML events to DOM
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
160 |
|
14
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
161 |
} |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
162 |
}; |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
163 |
|
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
164 |
} |
5be268bc4c69
separate the „std::istream to DOM“ phase
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
165 |
} |
17
75c6685cceb9
YAML data to DOM: first dirty version with debug
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
166 |
} |